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