blob: 0f9c10c3ff948209b27c1b25230c48b18224a9ef [file] [log] [blame]
Alex Crichtonb5da7c02015-09-16 17:44:40 -07001#![deny(warnings)]
2
Alex Crichtond11e9142015-09-15 23:28:52 -07003extern crate ctest;
Alex Crichton8e5f0cd2015-09-09 22:46:19 -07004
5use std::env;
Alex Crichton8e5f0cd2015-09-09 22:46:19 -07006
Alex Crichtond11e9142015-09-15 23:28:52 -07007fn main() {
8 let target = env::var("TARGET").unwrap();
Alex Crichton8dce9ad2015-12-03 11:44:14 -08009 let x86_64 = target.contains("x86_64");
Alex Crichtond11e9142015-09-15 23:28:52 -070010 let windows = target.contains("windows");
11 let mingw = target.contains("windows-gnu");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -070012 let linux = target.contains("unknown-linux");
Alex Crichton1ff96102015-09-17 15:09:02 -070013 let android = target.contains("android");
Alex Crichtonbaef6112015-09-19 23:20:53 -070014 let apple = target.contains("apple");
Alex Crichton15b83c22015-09-17 17:25:52 -070015 let musl = target.contains("musl");
Alex Crichtona1b948e2015-09-18 11:54:32 -070016 let freebsd = target.contains("freebsd");
Michael Neumanna6a64d12016-02-20 13:34:01 +010017 let dragonfly = target.contains("dragonfly");
Alexander Polakov26974c72015-11-27 03:02:44 +030018 let mips = target.contains("mips");
Alex Crichton49d7bca2015-11-27 09:40:37 -080019 let netbsd = target.contains("netbsd");
Sébastien Mariec618f362015-12-21 17:26:41 +010020 let openbsd = target.contains("openbsd");
Alex Crichton49d7bca2015-11-27 09:40:37 -080021 let rumprun = target.contains("rumprun");
Michael Neumanna6a64d12016-02-20 13:34:01 +010022 let bsdlike = freebsd || apple || netbsd || openbsd || dragonfly;
Alex Crichtond11e9142015-09-15 23:28:52 -070023 let mut cfg = ctest::TestGenerator::new();
Alex Crichton8e5f0cd2015-09-09 22:46:19 -070024
Alex Crichtond11e9142015-09-15 23:28:52 -070025 // Pull in extra goodies on linux/mingw
Alex Crichton8dce9ad2015-12-03 11:44:14 -080026 if linux || android {
Alex Crichtond11e9142015-09-15 23:28:52 -070027 cfg.define("_GNU_SOURCE", None);
Alex Crichton1ff96102015-09-17 15:09:02 -070028 } else if windows {
Alex Crichtond11e9142015-09-15 23:28:52 -070029 cfg.define("_WIN32_WINNT", Some("0x8000"));
Alex Crichton0df7c102015-09-10 16:35:37 -070030 }
31
Alex Crichton094f44d2015-09-16 16:27:23 -070032 // Android doesn't actually have in_port_t but it's much easier if we
33 // provide one for us to test against
Alex Crichton1ff96102015-09-17 15:09:02 -070034 if android {
Alex Crichton094f44d2015-09-16 16:27:23 -070035 cfg.define("in_port_t", Some("uint16_t"));
36 }
37
Alex Crichtond11e9142015-09-15 23:28:52 -070038 cfg.header("errno.h")
39 .header("fcntl.h")
40 .header("limits.h")
A.J. Gardnerb788a5c2016-03-30 01:13:55 -050041 .header("locale.h")
Alex Crichtond11e9142015-09-15 23:28:52 -070042 .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 Crichtonac2bd852015-09-10 17:21:20 -070050
Alex Crichton1ff96102015-09-17 15:09:02 -070051 if windows {
Alex Crichtond11e9142015-09-15 23:28:52 -070052 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 Crichton310d6232015-09-10 10:56:31 -070063 }
Alex Crichtond11e9142015-09-15 23:28:52 -070064 } else {
65 cfg.header("ctype.h");
66 cfg.header("dirent.h");
Sébastien Mariec618f362015-12-21 17:26:41 +010067 if openbsd {
68 cfg.header("sys/socket.h");
69 }
Alex Crichtond11e9142015-09-15 23:28:52 -070070 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 Crichton1ff96102015-09-17 15:09:02 -070076 cfg.header("dlfcn.h");
Alex Crichtond11e9142015-09-15 23:28:52 -070077 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 Crichtoncd9b33e2015-09-17 14:47:40 -070089 cfg.header("pwd.h");
90 cfg.header("grp.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -080091 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 Henningsson9d2493e2015-12-25 22:06:44 +010097 cfg.header("poll.h");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -070098 }
Alex Crichtona1b948e2015-09-18 11:54:32 -070099
100 if android {
101 cfg.header("arpa/inet.h");
Alex Crichton568705e2015-11-03 14:18:52 -0800102 cfg.header("time64.h");
Alex Crichtona1b948e2015-09-18 11:54:32 -0700103 } else if !windows {
104 cfg.header("glob.h");
105 cfg.header("ifaddrs.h");
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800106 cfg.header("sys/statvfs.h");
107
Michael Neumanna6a64d12016-02-20 13:34:01 +0100108 if !openbsd && !freebsd && !dragonfly {
Sébastien Mariec618f362015-12-21 17:26:41 +0100109 cfg.header("sys/quota.h");
110 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700111
112 if !musl {
Alex Crichtona1b948e2015-09-18 11:54:32 -0700113 cfg.header("sys/sysctl.h");
Alex Crichton49d7bca2015-11-27 09:40:37 -0800114
Sébastien Mariec618f362015-12-21 17:26:41 +0100115 if !netbsd && !openbsd {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800116 cfg.header("execinfo.h");
117 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700118 }
119 }
120
Alex Crichtonbaef6112015-09-19 23:20:53 -0700121 if apple {
Alex Crichtona1b948e2015-09-18 11:54:32 -0700122 cfg.header("mach-o/dyld.h");
123 cfg.header("mach/mach_time.h");
124 cfg.header("malloc/malloc.h");
Kamal Marhubi89a77002016-02-27 14:58:43 -0500125 cfg.header("util.h");
Alex Crichtonbaef6112015-09-19 23:20:53 -0700126 if target.starts_with("x86") {
127 cfg.header("crt_externs.h");
128 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700129 }
130
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800131 if bsdlike {
132 cfg.header("sys/event.h");
133 }
134
Alexander Polakov30baed02015-12-01 15:29:05 +0300135 if linux {
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800136 cfg.header("mqueue.h");
Philipp Matthias Schaefer7e3a1512016-02-22 20:11:01 +0100137 cfg.header("ucontext.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800138 cfg.header("sys/signalfd.h");
Alexander Polakov30baed02015-12-01 15:29:05 +0300139 cfg.header("sys/xattr.h");
Alexander Polakov58501562015-12-14 02:09:45 +0300140 cfg.header("sys/ipc.h");
141 cfg.header("sys/shm.h");
Alexander Polakov30baed02015-12-01 15:29:05 +0300142 }
143
Alex Crichtona1b948e2015-09-18 11:54:32 -0700144 if linux || android {
Alex Crichtona1b948e2015-09-18 11:54:32 -0700145 cfg.header("malloc.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800146 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 Crichtoncd9b33e2015-09-17 14:47:40 -0700151 cfg.header("sys/prctl.h");
Kamal Marhubi143358b2016-02-04 14:08:50 -0500152 cfg.header("sys/sendfile.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800153 cfg.header("sys/vfs.h");
Alex Crichton881ef9b2015-12-01 09:04:13 -0800154 cfg.header("sys/syscall.h");
Alexander Polakov420f2e42015-11-11 01:53:39 +0300155 if !musl {
156 cfg.header("linux/netlink.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800157 cfg.header("linux/magic.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800158
159 if !mips {
160 cfg.header("linux/quota.h");
161 }
Alexander Polakov420f2e42015-11-11 01:53:39 +0300162 }
Alex Crichton310d6232015-09-10 10:56:31 -0700163 }
164
Alex Crichtona1b948e2015-09-18 11:54:32 -0700165 if freebsd {
166 cfg.header("pthread_np.h");
Alexander Polakov26974c72015-11-27 03:02:44 +0300167 cfg.header("sched.h");
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800168 cfg.header("ufs/ufs/quota.h");
Alex Crichtona1b948e2015-09-18 11:54:32 -0700169 }
170
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800171 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 Mariec618f362015-12-21 17:26:41 +0100177 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 Neumanna6a64d12016-02-20 13:34:01 +0100184 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 Crichtond11e9142015-09-15 23:28:52 -0700190 cfg.type_name(move |ty, is_struct| {
Alex Crichton310d6232015-09-10 10:56:31 -0700191 match ty {
Alex Crichton31504842015-09-10 23:43:41 -0700192 // Just pass all these through, no need for a "struct" prefix
Alex Crichton22378822015-09-10 19:59:23 -0700193 "FILE" |
Alex Crichton07d3a0d2015-10-30 10:21:32 -0700194 "fd_set" |
Alex Crichton88d23e72015-11-02 17:03:19 -0800195 "Dl_info" |
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700196 "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 Crichtonde9736d2015-09-17 15:47:44 -0700202 // OSX calls this something else
Alex Crichtona1b948e2015-09-18 11:54:32 -0700203 "sighandler_t" if bsdlike => "sig_t".to_string(),
Alex Crichtonde9736d2015-09-17 15:47:44 -0700204
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700205 t if t.ends_with("_t") => t.to_string(),
Alex Crichton310d6232015-09-10 10:56:31 -0700206
Alex Crichton31504842015-09-10 23:43:41 -0700207 // 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 Crichtond11e9142015-09-15 23:28:52 -0700210 t if is_struct => {
Alex Crichton13a6f2d2015-09-10 18:10:58 -0700211 if windows && ty.chars().next().unwrap().is_uppercase() {
212 t.to_string()
213 } else if windows && t == "stat" {
214 "struct __stat64".to_string()
Alex Crichton7da9b102015-09-10 20:57:14 -0700215 } else if windows && t == "utimbuf" {
216 "struct __utimbuf64".to_string()
Alex Crichton13a6f2d2015-09-10 18:10:58 -0700217 } else {
218 format!("struct {}", t)
219 }
220 }
Alex Crichton310d6232015-09-10 10:56:31 -0700221
222 t => t.to_string(),
223 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700224 });
Alex Crichton310d6232015-09-10 10:56:31 -0700225
Alex Crichtond11e9142015-09-15 23:28:52 -0700226 let target2 = target.clone();
227 cfg.field_name(move |struct_, field| {
Alex Crichton310d6232015-09-10 10:56:31 -0700228 match field {
Sébastien Marie6c8a63a2015-12-23 18:54:25 +0100229 "st_birthtime" if openbsd && struct_ == "stat" => "__st_birthtime".to_string(),
Sébastien Mariec618f362015-12-21 17:26:41 +0100230 "st_birthtime_nsec" if openbsd && struct_ == "stat" => "__st_birthtimensec".to_string(),
Alex Crichton31504842015-09-10 23:43:41 -0700231 // Our stat *_nsec fields normally don't actually exist but are part
232 // of a timeval struct
Alex Crichton74825222015-10-29 17:36:55 -0700233 s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
Alex Crichtonbaef6112015-09-19 23:20:53 -0700234 if target2.contains("apple") {
Alex Crichton310d6232015-09-10 10:56:31 -0700235 s.replace("_nsec", "spec.tv_nsec")
Alex Crichtond11e9142015-09-15 23:28:52 -0700236 } else if target2.contains("android") {
Alex Crichtond3d77922015-09-11 17:03:39 -0700237 s.to_string()
Alex Crichton310d6232015-09-10 10:56:31 -0700238 } else {
239 s.replace("e_nsec", ".tv_nsec")
240 }
241 }
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800242 "u64" if struct_ == "epoll_event" => "data.u64".to_string(),
Alex Crichton310d6232015-09-10 10:56:31 -0700243 s => s.to_string(),
244 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700245 });
Alex Crichton310d6232015-09-10 10:56:31 -0700246
Alex Crichtond11e9142015-09-15 23:28:52 -0700247 cfg.skip_type(move |ty| {
Alex Crichton310d6232015-09-10 10:56:31 -0700248 match ty {
Alex Crichtond3d77922015-09-11 17:03:39 -0700249 // sighandler_t is crazy across platforms
Alex Crichtond11e9142015-09-15 23:28:52 -0700250 "sighandler_t" => true,
Alex Crichtond3d77922015-09-11 17:03:39 -0700251
Alex Crichtond11e9142015-09-15 23:28:52 -0700252 _ => false
Alex Crichton310d6232015-09-10 10:56:31 -0700253 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700254 });
Alex Crichton16083062015-09-09 22:59:24 -0700255
Alexander Polakov420f2e42015-11-11 01:53:39 +0300256 cfg.skip_struct(move |ty| {
257 match ty {
258 "sockaddr_nl" => musl,
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800259
260 // The alignment of this is 4 on 64-bit OSX...
261 "kevent" if apple && x86_64 => true,
262
Alexander Polakov420f2e42015-11-11 01:53:39 +0300263 _ => false
264 }
265 });
266
Michael Neumanna6a64d12016-02-20 13:34:01 +0100267 cfg.skip_signededness(move |c| {
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700268 match c {
Alex Crichton7b28c272015-09-15 20:56:16 -0700269 "LARGE_INTEGER" |
Alex Crichtoneef03da2015-09-15 16:57:06 -0700270 "mach_timebase_info_data_t" |
Alex Crichton7b28c272015-09-15 20:56:16 -0700271 "float" |
Alex Crichtond11e9142015-09-15 23:28:52 -0700272 "double" => true,
Michael Neumanna09fe712016-02-21 12:28:10 +0100273 // uuid_t is a struct, not an integer.
Michael Neumanna6a64d12016-02-20 13:34:01 +0100274 "uuid_t" if dragonfly => true,
Alex Crichtond11e9142015-09-15 23:28:52 -0700275 n if n.starts_with("pthread") => true,
Alex Crichton18469182015-09-15 20:57:42 -0700276
277 // windows-isms
Alex Crichtond11e9142015-09-15 23:28:52 -0700278 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 Crichton6d3cfdb2015-09-15 14:53:01 -0700282 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700283 });
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700284
Alex Crichtond11e9142015-09-15 23:28:52 -0700285 cfg.skip_const(move |name| {
Alex Crichton31504842015-09-10 23:43:41 -0700286 match name {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700287 // Apparently these don't exist in mingw headers?
Alex Crichton31504842015-09-10 23:43:41 -0700288 "MEM_RESET_UNDO" |
289 "FILE_ATTRIBUTE_NO_SCRUB_DATA" |
290 "FILE_ATTRIBUTE_INTEGRITY_STREAM" |
Alex Crichtond11e9142015-09-15 23:28:52 -0700291 "ERROR_NOTHING_TO_TERMINATE" if mingw => true,
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700292
Alex Crichtond11e9142015-09-15 23:28:52 -0700293 "SIG_IGN" => true, // sighandler_t weirdness
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700294
Alex Crichton15b83c22015-09-17 17:25:52 -0700295 // types on musl are defined a little differently
Alex Crichton3a572fd2015-10-29 16:52:25 -0700296 n if musl && n.contains("__SIZEOF_PTHREAD") => true,
Alex Crichton15b83c22015-09-17 17:25:52 -0700297
Alex Crichton74825222015-10-29 17:36:55 -0700298 // 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 Polakov26974c72015-11-27 03:02:44 +0300303 // work around super old mips toolchain
Alexander Polakov58501562015-12-14 02:09:45 +0300304 "SCHED_IDLE" | "SHM_NORESERVE" => mips,
Alex Crichton74825222015-10-29 17:36:55 -0700305
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800306 // 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 Crichtond11e9142015-09-15 23:28:52 -0700319 _ => false,
Alex Crichton31504842015-09-10 23:43:41 -0700320 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700321 });
Alex Crichton31504842015-09-10 23:43:41 -0700322
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700323 cfg.skip_fn(move |name| {
Jim Blandyf8772f72016-01-12 16:28:07 -0800324 // skip those that are manually verified
Alex Crichton22378822015-09-10 19:59:23 -0700325 match name {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700326 "execv" | // crazy stuff with const/mut
Alex Crichton22378822015-09-10 19:59:23 -0700327 "execve" |
328 "execvp" |
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700329 "execvpe" => true,
330
Alex Crichton74825222015-10-29 17:36:55 -0700331 "getrlimit" | "getrlimit64" | // non-int in 1st arg
332 "setrlimit" | "setrlimit64" | // non-int in 1st arg
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700333 "strerror_r" if linux => true, // actually xpg-something-or-other
334
Alex Crichton1ff96102015-09-17 15:09:02 -0700335 // typed 2nd arg on linux and android
Michael Neumanna6a64d12016-02-20 13:34:01 +0100336 "gettimeofday" if linux || android || freebsd || openbsd || dragonfly => true,
Alex Crichton1ff96102015-09-17 15:09:02 -0700337
Alex Crichton881ef9b2015-12-01 09:04:13 -0800338 // not declared in newer android toolchains
339 "getdtablesize" if android => true,
340
Alex Crichton1ff96102015-09-17 15:09:02 -0700341 "dlerror" if android => true, // const-ness is added
Alex Crichton88d23e72015-11-02 17:03:19 -0800342 "dladdr" if musl => true, // const-ness only added recently
Alex Crichton1ff96102015-09-17 15:09:02 -0700343
Alex Crichton568705e2015-11-03 14:18:52 -0800344 // 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 Crichton8dce9ad2015-12-03 11:44:14 -0800348 // 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 Crichton49d7bca2015-11-27 09:40:37 -0800352 // 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 Crichton49d7bca2015-11-27 09:40:37 -0800356 "shm_open" |
357 "shm_unlink" |
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800358 "syscall" |
359 "ptrace" |
Alex Crichton49d7bca2015-11-27 09:40:37 -0800360 "sigaltstack" if rumprun => true,
361
Jim Blandyf8772f72016-01-12 16:28:07 -0800362 // 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 Crichtonbb6f1982016-01-18 11:18:22 -0800378 // 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 Crichtond11e9142015-09-15 23:28:52 -0700383 _ => false,
Alex Crichton22378822015-09-10 19:59:23 -0700384 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700385 });
Alex Crichton22378822015-09-10 19:59:23 -0700386
Alex Crichton881ef9b2015-12-01 09:04:13 -0800387 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 Crichtone0f4d102015-09-16 09:48:14 -0700401
Alex Crichton15b83c22015-09-17 17:25:52 -0700402 cfg.skip_field_type(move |struct_, field| {
Alex Crichtonf3b97482015-09-16 14:13:20 -0700403 // This is a weird union, don't check the type.
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700404 (struct_ == "ifaddrs" && field == "ifa_ifu") ||
405 // sighandler_t type is super weird
406 (struct_ == "sigaction" && field == "sa_sigaction")
407 });
408
Alex Crichton15b83c22015-09-17 17:25:52 -0700409 cfg.skip_field(move |struct_, field| {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700410 // this is actually a union on linux, so we can't represent it well and
411 // just insert some padding.
Alex Crichton15b83c22015-09-17 17:25:52 -0700412 (struct_ == "siginfo_t" && field == "_pad") ||
413 // musl names this __dummy1 but it's still there
Brian Anderson773aab82015-12-29 20:00:29 +0000414 (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 Crichtonf3b97482015-09-16 14:13:20 -0700417 });
418
Alex Crichton49d7bca2015-11-27 09:40:37 -0800419 cfg.fn_cname(move |name, cname| {
Alex Crichton881ef9b2015-12-01 09:04:13 -0800420 if windows {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800421 cname.unwrap_or(name).to_string()
Alex Crichton0af5e232015-11-30 15:07:28 -0800422 } else {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800423 name.to_string()
Alex Crichton0af5e232015-11-30 15:07:28 -0800424 }
425 });
426
Alex Crichtond820c4a2016-01-18 11:16:38 -0800427 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 Crichton310d6232015-09-10 10:56:31 -0700432}