Alex Crichton | b5da7c0 | 2015-09-16 17:44:40 -0700 | [diff] [blame] | 1 | #![deny(warnings)] |
| 2 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 3 | extern crate ctest; |
Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 4 | |
| 5 | use std::env; |
Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 6 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 7 | fn main() { |
| 8 | let target = env::var("TARGET").unwrap(); |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 9 | let x86_64 = target.contains("x86_64"); |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 10 | let windows = target.contains("windows"); |
| 11 | let mingw = target.contains("windows-gnu"); |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 12 | let linux = target.contains("unknown-linux"); |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 13 | let android = target.contains("android"); |
Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 14 | let apple = target.contains("apple"); |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 15 | let musl = target.contains("musl"); |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 16 | let freebsd = target.contains("freebsd"); |
Michael Neumann | a6a64d1 | 2016-02-20 13:34:01 +0100 | [diff] [blame] | 17 | let dragonfly = target.contains("dragonfly"); |
Alexander Polakov | 26974c7 | 2015-11-27 03:02:44 +0300 | [diff] [blame] | 18 | let mips = target.contains("mips"); |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 19 | let netbsd = target.contains("netbsd"); |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 20 | let openbsd = target.contains("openbsd"); |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 21 | let rumprun = target.contains("rumprun"); |
Michael Neumann | a6a64d1 | 2016-02-20 13:34:01 +0100 | [diff] [blame] | 22 | let bsdlike = freebsd || apple || netbsd || openbsd || dragonfly; |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 23 | let mut cfg = ctest::TestGenerator::new(); |
Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 24 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 25 | // Pull in extra goodies on linux/mingw |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 26 | if linux || android { |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 27 | cfg.define("_GNU_SOURCE", None); |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 28 | } else if windows { |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 29 | cfg.define("_WIN32_WINNT", Some("0x8000")); |
Alex Crichton | 0df7c10 | 2015-09-10 16:35:37 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Alex Crichton | 094f44d | 2015-09-16 16:27:23 -0700 | [diff] [blame] | 32 | // Android doesn't actually have in_port_t but it's much easier if we |
| 33 | // provide one for us to test against |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 34 | if android { |
Alex Crichton | 094f44d | 2015-09-16 16:27:23 -0700 | [diff] [blame] | 35 | cfg.define("in_port_t", Some("uint16_t")); |
| 36 | } |
| 37 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 38 | cfg.header("errno.h") |
| 39 | .header("fcntl.h") |
| 40 | .header("limits.h") |
| 41 | .header("stddef.h") |
| 42 | .header("stdint.h") |
| 43 | .header("stdio.h") |
| 44 | .header("stdlib.h") |
| 45 | .header("sys/stat.h") |
| 46 | .header("sys/types.h") |
| 47 | .header("time.h") |
| 48 | .header("wchar.h"); |
Alex Crichton | ac2bd85 | 2015-09-10 17:21:20 -0700 | [diff] [blame] | 49 | |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 50 | if windows { |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 51 | cfg.header("winsock2.h"); // must be before windows.h |
| 52 | |
| 53 | cfg.header("direct.h"); |
| 54 | cfg.header("io.h"); |
| 55 | cfg.header("sys/utime.h"); |
| 56 | cfg.header("windows.h"); |
| 57 | cfg.header("process.h"); |
| 58 | cfg.header("ws2ipdef.h"); |
| 59 | |
| 60 | if target.contains("gnu") { |
| 61 | cfg.header("ws2tcpip.h"); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 62 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 63 | } else { |
| 64 | cfg.header("ctype.h"); |
| 65 | cfg.header("dirent.h"); |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 66 | if openbsd { |
| 67 | cfg.header("sys/socket.h"); |
| 68 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 69 | cfg.header("net/if.h"); |
| 70 | cfg.header("netdb.h"); |
| 71 | cfg.header("netinet/in.h"); |
| 72 | cfg.header("netinet/ip.h"); |
| 73 | cfg.header("netinet/tcp.h"); |
| 74 | cfg.header("pthread.h"); |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 75 | cfg.header("dlfcn.h"); |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 76 | cfg.header("signal.h"); |
| 77 | cfg.header("string.h"); |
| 78 | cfg.header("sys/file.h"); |
| 79 | cfg.header("sys/ioctl.h"); |
| 80 | cfg.header("sys/mman.h"); |
| 81 | cfg.header("sys/resource.h"); |
| 82 | cfg.header("sys/socket.h"); |
| 83 | cfg.header("sys/time.h"); |
| 84 | cfg.header("sys/un.h"); |
| 85 | cfg.header("sys/wait.h"); |
| 86 | cfg.header("unistd.h"); |
| 87 | cfg.header("utime.h"); |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 88 | cfg.header("pwd.h"); |
| 89 | cfg.header("grp.h"); |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 90 | cfg.header("sys/utsname.h"); |
| 91 | cfg.header("sys/ptrace.h"); |
| 92 | cfg.header("sys/mount.h"); |
| 93 | cfg.header("sys/uio.h"); |
| 94 | cfg.header("sched.h"); |
| 95 | cfg.header("termios.h"); |
David Henningsson | 9d2493e | 2015-12-25 22:06:44 +0100 | [diff] [blame] | 96 | cfg.header("poll.h"); |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 97 | } |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 98 | |
| 99 | if android { |
| 100 | cfg.header("arpa/inet.h"); |
Alex Crichton | 568705e | 2015-11-03 14:18:52 -0800 | [diff] [blame] | 101 | cfg.header("time64.h"); |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 102 | } else if !windows { |
| 103 | cfg.header("glob.h"); |
| 104 | cfg.header("ifaddrs.h"); |
Alex Crichton | bb6f198 | 2016-01-18 11:18:22 -0800 | [diff] [blame] | 105 | cfg.header("sys/statvfs.h"); |
| 106 | |
Michael Neumann | a6a64d1 | 2016-02-20 13:34:01 +0100 | [diff] [blame] | 107 | if !openbsd && !freebsd && !dragonfly { |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 108 | cfg.header("sys/quota.h"); |
| 109 | } |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 110 | |
| 111 | if !musl { |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 112 | cfg.header("sys/sysctl.h"); |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 113 | |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 114 | if !netbsd && !openbsd { |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 115 | cfg.header("execinfo.h"); |
| 116 | } |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 120 | if apple { |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 121 | cfg.header("mach-o/dyld.h"); |
| 122 | cfg.header("mach/mach_time.h"); |
| 123 | cfg.header("malloc/malloc.h"); |
Kamal Marhubi | 89a7700 | 2016-02-27 14:58:43 -0500 | [diff] [blame] | 124 | cfg.header("util.h"); |
Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 125 | if target.starts_with("x86") { |
| 126 | cfg.header("crt_externs.h"); |
| 127 | } |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 130 | if bsdlike { |
| 131 | cfg.header("sys/event.h"); |
| 132 | } |
| 133 | |
Alexander Polakov | 30baed0 | 2015-12-01 15:29:05 +0300 | [diff] [blame] | 134 | if linux { |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 135 | cfg.header("mqueue.h"); |
Philipp Matthias Schaefer | 7e3a151 | 2016-02-22 20:11:01 +0100 | [diff] [blame] | 136 | cfg.header("ucontext.h"); |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 137 | cfg.header("sys/signalfd.h"); |
Alexander Polakov | 30baed0 | 2015-12-01 15:29:05 +0300 | [diff] [blame] | 138 | cfg.header("sys/xattr.h"); |
Alexander Polakov | 5850156 | 2015-12-14 02:09:45 +0300 | [diff] [blame] | 139 | cfg.header("sys/ipc.h"); |
| 140 | cfg.header("sys/shm.h"); |
Alexander Polakov | 30baed0 | 2015-12-01 15:29:05 +0300 | [diff] [blame] | 141 | } |
| 142 | |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 143 | if linux || android { |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 144 | cfg.header("malloc.h"); |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 145 | cfg.header("net/ethernet.h"); |
| 146 | cfg.header("netpacket/packet.h"); |
| 147 | cfg.header("sched.h"); |
| 148 | cfg.header("sys/epoll.h"); |
| 149 | cfg.header("sys/eventfd.h"); |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 150 | cfg.header("sys/prctl.h"); |
Kamal Marhubi | 143358b | 2016-02-04 14:08:50 -0500 | [diff] [blame] | 151 | cfg.header("sys/sendfile.h"); |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 152 | cfg.header("sys/vfs.h"); |
Alex Crichton | 881ef9b | 2015-12-01 09:04:13 -0800 | [diff] [blame] | 153 | cfg.header("sys/syscall.h"); |
Alexander Polakov | 420f2e4 | 2015-11-11 01:53:39 +0300 | [diff] [blame] | 154 | if !musl { |
| 155 | cfg.header("linux/netlink.h"); |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 156 | cfg.header("linux/magic.h"); |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 157 | |
| 158 | if !mips { |
| 159 | cfg.header("linux/quota.h"); |
| 160 | } |
Alexander Polakov | 420f2e4 | 2015-11-11 01:53:39 +0300 | [diff] [blame] | 161 | } |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 164 | if freebsd { |
| 165 | cfg.header("pthread_np.h"); |
Alexander Polakov | 26974c7 | 2015-11-27 03:02:44 +0300 | [diff] [blame] | 166 | cfg.header("sched.h"); |
Alex Crichton | bb6f198 | 2016-01-18 11:18:22 -0800 | [diff] [blame] | 167 | cfg.header("ufs/ufs/quota.h"); |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 170 | if netbsd { |
| 171 | cfg.header("ufs/ufs/quota.h"); |
| 172 | cfg.header("ufs/ufs/quota1.h"); |
| 173 | cfg.header("sys/ioctl_compat.h"); |
| 174 | } |
| 175 | |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 176 | if openbsd { |
| 177 | cfg.header("ufs/ufs/quota.h"); |
| 178 | cfg.header("rpcsvc/rex.h"); |
| 179 | cfg.header("pthread_np.h"); |
| 180 | cfg.header("sys/syscall.h"); |
| 181 | } |
| 182 | |
Michael Neumann | a6a64d1 | 2016-02-20 13:34:01 +0100 | [diff] [blame] | 183 | if dragonfly { |
| 184 | cfg.header("ufs/ufs/quota.h"); |
| 185 | cfg.header("pthread_np.h"); |
| 186 | cfg.header("sys/ioctl_compat.h"); |
| 187 | } |
| 188 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 189 | cfg.type_name(move |ty, is_struct| { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 190 | match ty { |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 191 | // Just pass all these through, no need for a "struct" prefix |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 192 | "FILE" | |
Alex Crichton | 07d3a0d | 2015-10-30 10:21:32 -0700 | [diff] [blame] | 193 | "fd_set" | |
Alex Crichton | 88d23e7 | 2015-11-02 17:03:19 -0800 | [diff] [blame] | 194 | "Dl_info" | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 195 | "DIR" => ty.to_string(), |
| 196 | |
| 197 | // Fixup a few types on windows that don't actually exist. |
| 198 | "time64_t" if windows => "__time64_t".to_string(), |
| 199 | "ssize_t" if windows => "SSIZE_T".to_string(), |
| 200 | |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 201 | // OSX calls this something else |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 202 | "sighandler_t" if bsdlike => "sig_t".to_string(), |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 203 | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 204 | t if t.ends_with("_t") => t.to_string(), |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 205 | |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 206 | // Windows uppercase structs don't have `struct` in front, there's a |
| 207 | // few special cases for windows, and then otherwise put `struct` in |
| 208 | // front of everything. |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 209 | t if is_struct => { |
Alex Crichton | 13a6f2d | 2015-09-10 18:10:58 -0700 | [diff] [blame] | 210 | if windows && ty.chars().next().unwrap().is_uppercase() { |
| 211 | t.to_string() |
| 212 | } else if windows && t == "stat" { |
| 213 | "struct __stat64".to_string() |
Alex Crichton | 7da9b10 | 2015-09-10 20:57:14 -0700 | [diff] [blame] | 214 | } else if windows && t == "utimbuf" { |
| 215 | "struct __utimbuf64".to_string() |
Alex Crichton | 13a6f2d | 2015-09-10 18:10:58 -0700 | [diff] [blame] | 216 | } else { |
| 217 | format!("struct {}", t) |
| 218 | } |
| 219 | } |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 220 | |
| 221 | t => t.to_string(), |
| 222 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 223 | }); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 224 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 225 | let target2 = target.clone(); |
| 226 | cfg.field_name(move |struct_, field| { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 227 | match field { |
Sébastien Marie | 6c8a63a | 2015-12-23 18:54:25 +0100 | [diff] [blame] | 228 | "st_birthtime" if openbsd && struct_ == "stat" => "__st_birthtime".to_string(), |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 229 | "st_birthtime_nsec" if openbsd && struct_ == "stat" => "__st_birthtimensec".to_string(), |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 230 | // Our stat *_nsec fields normally don't actually exist but are part |
| 231 | // of a timeval struct |
Alex Crichton | 7482522 | 2015-10-29 17:36:55 -0700 | [diff] [blame] | 232 | s if s.ends_with("_nsec") && struct_.starts_with("stat") => { |
Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 233 | if target2.contains("apple") { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 234 | s.replace("_nsec", "spec.tv_nsec") |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 235 | } else if target2.contains("android") { |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 236 | s.to_string() |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 237 | } else { |
| 238 | s.replace("e_nsec", ".tv_nsec") |
| 239 | } |
| 240 | } |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 241 | "u64" if struct_ == "epoll_event" => "data.u64".to_string(), |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 242 | s => s.to_string(), |
| 243 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 244 | }); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 245 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 246 | cfg.skip_type(move |ty| { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 247 | match ty { |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 248 | // sighandler_t is crazy across platforms |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 249 | "sighandler_t" => true, |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 250 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 251 | _ => false |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 252 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 253 | }); |
Alex Crichton | 1608306 | 2015-09-09 22:59:24 -0700 | [diff] [blame] | 254 | |
Alexander Polakov | 420f2e4 | 2015-11-11 01:53:39 +0300 | [diff] [blame] | 255 | cfg.skip_struct(move |ty| { |
| 256 | match ty { |
| 257 | "sockaddr_nl" => musl, |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 258 | |
| 259 | // The alignment of this is 4 on 64-bit OSX... |
| 260 | "kevent" if apple && x86_64 => true, |
| 261 | |
Alexander Polakov | 420f2e4 | 2015-11-11 01:53:39 +0300 | [diff] [blame] | 262 | _ => false |
| 263 | } |
| 264 | }); |
| 265 | |
Michael Neumann | a6a64d1 | 2016-02-20 13:34:01 +0100 | [diff] [blame] | 266 | cfg.skip_signededness(move |c| { |
Alex Crichton | 6d3cfdb | 2015-09-15 14:53:01 -0700 | [diff] [blame] | 267 | match c { |
Alex Crichton | 7b28c27 | 2015-09-15 20:56:16 -0700 | [diff] [blame] | 268 | "LARGE_INTEGER" | |
Alex Crichton | eef03da | 2015-09-15 16:57:06 -0700 | [diff] [blame] | 269 | "mach_timebase_info_data_t" | |
Alex Crichton | 7b28c27 | 2015-09-15 20:56:16 -0700 | [diff] [blame] | 270 | "float" | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 271 | "double" => true, |
Michael Neumann | a09fe71 | 2016-02-21 12:28:10 +0100 | [diff] [blame] | 272 | // uuid_t is a struct, not an integer. |
Michael Neumann | a6a64d1 | 2016-02-20 13:34:01 +0100 | [diff] [blame] | 273 | "uuid_t" if dragonfly => true, |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 274 | n if n.starts_with("pthread") => true, |
Alex Crichton | 1846918 | 2015-09-15 20:57:42 -0700 | [diff] [blame] | 275 | |
| 276 | // windows-isms |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 277 | n if n.starts_with("P") => true, |
| 278 | n if n.starts_with("H") => true, |
| 279 | n if n.starts_with("LP") => true, |
| 280 | _ => false, |
Alex Crichton | 6d3cfdb | 2015-09-15 14:53:01 -0700 | [diff] [blame] | 281 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 282 | }); |
Alex Crichton | 6d3cfdb | 2015-09-15 14:53:01 -0700 | [diff] [blame] | 283 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 284 | cfg.skip_const(move |name| { |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 285 | match name { |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 286 | // Apparently these don't exist in mingw headers? |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 287 | "MEM_RESET_UNDO" | |
| 288 | "FILE_ATTRIBUTE_NO_SCRUB_DATA" | |
| 289 | "FILE_ATTRIBUTE_INTEGRITY_STREAM" | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 290 | "ERROR_NOTHING_TO_TERMINATE" if mingw => true, |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 291 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 292 | "SIG_IGN" => true, // sighandler_t weirdness |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 293 | |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 294 | // types on musl are defined a little differently |
Alex Crichton | 3a572fd | 2015-10-29 16:52:25 -0700 | [diff] [blame] | 295 | n if musl && n.contains("__SIZEOF_PTHREAD") => true, |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 296 | |
Alex Crichton | 7482522 | 2015-10-29 17:36:55 -0700 | [diff] [blame] | 297 | // Skip constants not defined in MUSL but just passed down to the |
| 298 | // kernel regardless |
| 299 | "RLIMIT_NLIMITS" | |
| 300 | "TCP_COOKIE_TRANSACTIONS" | |
| 301 | "RLIMIT_RTTIME" if musl => true, |
Alexander Polakov | 26974c7 | 2015-11-27 03:02:44 +0300 | [diff] [blame] | 302 | // work around super old mips toolchain |
Alexander Polakov | 5850156 | 2015-12-14 02:09:45 +0300 | [diff] [blame] | 303 | "SCHED_IDLE" | "SHM_NORESERVE" => mips, |
Alex Crichton | 7482522 | 2015-10-29 17:36:55 -0700 | [diff] [blame] | 304 | |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 305 | // weird signed extension or something like that? |
| 306 | "MS_NOUSER" => true, |
| 307 | |
| 308 | // These OSX constants are flagged as deprecated |
| 309 | "NOTE_EXIT_REPARENTED" | |
| 310 | "NOTE_REAP" if apple => true, |
| 311 | |
| 312 | // The linux/quota.h header file which defines these can't be |
| 313 | // included with sys/quota.h currently on MIPS, so we don't include |
| 314 | // it and just ignore these constants |
| 315 | "QFMT_VFS_OLD" | |
| 316 | "QFMT_VFS_V0" if mips && linux => true, |
| 317 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 318 | _ => false, |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 319 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 320 | }); |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 321 | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 322 | cfg.skip_fn(move |name| { |
Jim Blandy | f8772f7 | 2016-01-12 16:28:07 -0800 | [diff] [blame] | 323 | // skip those that are manually verified |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 324 | match name { |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 325 | "execv" | // crazy stuff with const/mut |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 326 | "execve" | |
| 327 | "execvp" | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 328 | "execvpe" => true, |
| 329 | |
Alex Crichton | 7482522 | 2015-10-29 17:36:55 -0700 | [diff] [blame] | 330 | "getrlimit" | "getrlimit64" | // non-int in 1st arg |
| 331 | "setrlimit" | "setrlimit64" | // non-int in 1st arg |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 332 | "strerror_r" if linux => true, // actually xpg-something-or-other |
| 333 | |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 334 | // typed 2nd arg on linux and android |
Michael Neumann | a6a64d1 | 2016-02-20 13:34:01 +0100 | [diff] [blame] | 335 | "gettimeofday" if linux || android || freebsd || openbsd || dragonfly => true, |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 336 | |
Alex Crichton | 881ef9b | 2015-12-01 09:04:13 -0800 | [diff] [blame] | 337 | // not declared in newer android toolchains |
| 338 | "getdtablesize" if android => true, |
| 339 | |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 340 | "dlerror" if android => true, // const-ness is added |
Alex Crichton | 88d23e7 | 2015-11-02 17:03:19 -0800 | [diff] [blame] | 341 | "dladdr" if musl => true, // const-ness only added recently |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 342 | |
Alex Crichton | 568705e | 2015-11-03 14:18:52 -0800 | [diff] [blame] | 343 | // OSX has 'struct tm *const' which we can't actually represent in |
| 344 | // Rust, but is close enough to *mut |
| 345 | "timegm" if apple => true, |
| 346 | |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 347 | // OSX's daemon is deprecated in 10.5 so we'll get a warning (which |
| 348 | // we turn into an error) so just ignore it. |
| 349 | "daemon" if apple => true, |
| 350 | |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 351 | // These functions presumably exist on netbsd but don't look like |
| 352 | // they're implemented on rumprun yet, just let them slide for now. |
| 353 | // Some of them look like they have headers but then don't have |
| 354 | // corresponding actual definitions either... |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 355 | "shm_open" | |
| 356 | "shm_unlink" | |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 357 | "syscall" | |
| 358 | "ptrace" | |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 359 | "sigaltstack" if rumprun => true, |
| 360 | |
Jim Blandy | f8772f7 | 2016-01-12 16:28:07 -0800 | [diff] [blame] | 361 | // There seems to be a small error in EGLIBC's eventfd.h header. The |
| 362 | // [underlying system call][1] always takes its first `count` |
| 363 | // argument as an `unsigned int`, but [EGLIBC's <sys/eventfd.h> |
| 364 | // header][2] declares it to take an `int`. [GLIBC's header][3] |
| 365 | // matches the kernel. |
| 366 | // |
| 367 | // EGLIBC is no longer actively developed, and Debian, the largest |
| 368 | // distribution that had been using it, switched back to GLIBC in |
| 369 | // April 2015. So effectively all Linux <sys/eventfd.h> headers will |
| 370 | // be using `unsigned int` soon. |
| 371 | // |
| 372 | // [1]: https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/fs/eventfd.c?id=refs/tags/v3.12.51#n397 |
| 373 | // [2]: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/eglibc/trusty/view/head:/sysdeps/unix/sysv/linux/sys/eventfd.h |
| 374 | // [3]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sys/eventfd.h;h=6295f32e937e779e74318eb9d3bdbe76aef8a8f3;hb=4e42b5b8f89f0e288e68be7ad70f9525aebc2cff#l34 |
| 375 | "eventfd" if linux => true, |
| 376 | |
Alex Crichton | bb6f198 | 2016-01-18 11:18:22 -0800 | [diff] [blame] | 377 | // The `uname` funcion in freebsd is now an inline wrapper that |
| 378 | // delegates to another, but the symbol still exists, so don't check |
| 379 | // the symbol. |
| 380 | "uname" if freebsd => true, |
| 381 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 382 | _ => false, |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 383 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 384 | }); |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 385 | |
Alex Crichton | 881ef9b | 2015-12-01 09:04:13 -0800 | [diff] [blame] | 386 | cfg.skip_fn_ptrcheck(move |name| { |
| 387 | match name { |
| 388 | // This used to be called bsd_signal in rev 18 of the android |
| 389 | // platform and is now just called signal, the old `bsd_signal` |
| 390 | // symbol, however, still remains, just gives a different function |
| 391 | // pointer. |
| 392 | "signal" if android => true, |
| 393 | |
| 394 | // dllimport weirdness? |
| 395 | _ if windows => true, |
| 396 | |
| 397 | _ => false, |
| 398 | } |
| 399 | }); |
Alex Crichton | e0f4d10 | 2015-09-16 09:48:14 -0700 | [diff] [blame] | 400 | |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 401 | cfg.skip_field_type(move |struct_, field| { |
Alex Crichton | f3b9748 | 2015-09-16 14:13:20 -0700 | [diff] [blame] | 402 | // This is a weird union, don't check the type. |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 403 | (struct_ == "ifaddrs" && field == "ifa_ifu") || |
| 404 | // sighandler_t type is super weird |
| 405 | (struct_ == "sigaction" && field == "sa_sigaction") |
| 406 | }); |
| 407 | |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 408 | cfg.skip_field(move |struct_, field| { |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 409 | // this is actually a union on linux, so we can't represent it well and |
| 410 | // just insert some padding. |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 411 | (struct_ == "siginfo_t" && field == "_pad") || |
| 412 | // musl names this __dummy1 but it's still there |
Brian Anderson | 773aab8 | 2015-12-29 20:00:29 +0000 | [diff] [blame] | 413 | (musl && struct_ == "glob_t" && field == "gl_flags") || |
| 414 | // musl seems to define this as an *anonymous* bitfield |
| 415 | (musl && struct_ == "statvfs" && field == "__f_unused") |
Alex Crichton | f3b9748 | 2015-09-16 14:13:20 -0700 | [diff] [blame] | 416 | }); |
| 417 | |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 418 | cfg.fn_cname(move |name, cname| { |
Alex Crichton | 881ef9b | 2015-12-01 09:04:13 -0800 | [diff] [blame] | 419 | if windows { |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 420 | cname.unwrap_or(name).to_string() |
Alex Crichton | 0af5e23 | 2015-11-30 15:07:28 -0800 | [diff] [blame] | 421 | } else { |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 422 | name.to_string() |
Alex Crichton | 0af5e23 | 2015-11-30 15:07:28 -0800 | [diff] [blame] | 423 | } |
| 424 | }); |
| 425 | |
Alex Crichton | d820c4a | 2016-01-18 11:16:38 -0800 | [diff] [blame] | 426 | if env::var("SKIP_COMPILE").is_ok() { |
| 427 | cfg.generate_files("../src/lib.rs", "all.rs"); |
| 428 | } else { |
| 429 | cfg.generate("../src/lib.rs", "all.rs"); |
| 430 | } |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 431 | } |