blob: cdfe358488d52d872aca2ac9744f3ae65bfbfd3b [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");
Raphael Cohn7fc09692016-05-05 15:41:21 +010098 cfg.header("syslog.h");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -070099 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700100
101 if android {
102 cfg.header("arpa/inet.h");
Alex Crichton568705e2015-11-03 14:18:52 -0800103 cfg.header("time64.h");
A.J. Gardner24c84f12016-03-31 20:08:03 -0500104 cfg.header("xlocale.h");
Alex Crichtona1b948e2015-09-18 11:54:32 -0700105 } else if !windows {
106 cfg.header("glob.h");
107 cfg.header("ifaddrs.h");
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800108 cfg.header("sys/statvfs.h");
A.J. Gardner24c84f12016-03-31 20:08:03 -0500109 cfg.header("langinfo.h");
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800110
Michael Neumanna6a64d12016-02-20 13:34:01 +0100111 if !openbsd && !freebsd && !dragonfly {
Sébastien Mariec618f362015-12-21 17:26:41 +0100112 cfg.header("sys/quota.h");
113 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700114
115 if !musl {
Alex Crichtona1b948e2015-09-18 11:54:32 -0700116 cfg.header("sys/sysctl.h");
Alex Crichton49d7bca2015-11-27 09:40:37 -0800117
Sébastien Mariec618f362015-12-21 17:26:41 +0100118 if !netbsd && !openbsd {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800119 cfg.header("execinfo.h");
A.J. Gardner24c84f12016-03-31 20:08:03 -0500120 cfg.header("xlocale.h");
Alex Crichton49d7bca2015-11-27 09:40:37 -0800121 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700122 }
123 }
124
Alex Crichtonbaef6112015-09-19 23:20:53 -0700125 if apple {
Alex Crichtona1b948e2015-09-18 11:54:32 -0700126 cfg.header("mach-o/dyld.h");
127 cfg.header("mach/mach_time.h");
128 cfg.header("malloc/malloc.h");
Kamal Marhubi89a77002016-02-27 14:58:43 -0500129 cfg.header("util.h");
Alex Crichtonbaef6112015-09-19 23:20:53 -0700130 if target.starts_with("x86") {
131 cfg.header("crt_externs.h");
132 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700133 }
134
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800135 if bsdlike {
136 cfg.header("sys/event.h");
Kamal Marhubi9c4af102016-02-27 14:58:43 -0500137
138 if freebsd {
139 cfg.header("libutil.h");
140 } else {
141 cfg.header("util.h");
142 }
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800143 }
144
Alexander Polakov30baed02015-12-01 15:29:05 +0300145 if linux {
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800146 cfg.header("mqueue.h");
Philipp Matthias Schaefer7e3a1512016-02-22 20:11:01 +0100147 cfg.header("ucontext.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800148 cfg.header("sys/signalfd.h");
Alexander Polakov30baed02015-12-01 15:29:05 +0300149 cfg.header("sys/xattr.h");
Alexander Polakov58501562015-12-14 02:09:45 +0300150 cfg.header("sys/ipc.h");
151 cfg.header("sys/shm.h");
Kamal Marhubi9c4af102016-02-27 14:58:43 -0500152 cfg.header("pty.h");
Alexander Polakov30baed02015-12-01 15:29:05 +0300153 }
154
Alex Crichtona1b948e2015-09-18 11:54:32 -0700155 if linux || android {
Alex Crichtona1b948e2015-09-18 11:54:32 -0700156 cfg.header("malloc.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800157 cfg.header("net/ethernet.h");
158 cfg.header("netpacket/packet.h");
159 cfg.header("sched.h");
160 cfg.header("sys/epoll.h");
161 cfg.header("sys/eventfd.h");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700162 cfg.header("sys/prctl.h");
Kamal Marhubi143358b2016-02-04 14:08:50 -0500163 cfg.header("sys/sendfile.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800164 cfg.header("sys/vfs.h");
Alex Crichton881ef9b2015-12-01 09:04:13 -0800165 cfg.header("sys/syscall.h");
Raphael Cohne6150ae2016-05-13 11:18:34 +0100166 cfg.header("sys/sysinfo.h");
Alexander Polakov420f2e42015-11-11 01:53:39 +0300167 if !musl {
168 cfg.header("linux/netlink.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800169 cfg.header("linux/magic.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800170
171 if !mips {
172 cfg.header("linux/quota.h");
173 }
Alexander Polakov420f2e42015-11-11 01:53:39 +0300174 }
Alex Crichton310d6232015-09-10 10:56:31 -0700175 }
176
Alex Crichtona1b948e2015-09-18 11:54:32 -0700177 if freebsd {
178 cfg.header("pthread_np.h");
Alexander Polakov26974c72015-11-27 03:02:44 +0300179 cfg.header("sched.h");
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800180 cfg.header("ufs/ufs/quota.h");
Alex Crichtona1b948e2015-09-18 11:54:32 -0700181 }
182
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800183 if netbsd {
184 cfg.header("ufs/ufs/quota.h");
185 cfg.header("ufs/ufs/quota1.h");
186 cfg.header("sys/ioctl_compat.h");
187 }
188
Sébastien Mariec618f362015-12-21 17:26:41 +0100189 if openbsd {
190 cfg.header("ufs/ufs/quota.h");
191 cfg.header("rpcsvc/rex.h");
192 cfg.header("pthread_np.h");
193 cfg.header("sys/syscall.h");
194 }
195
Michael Neumanna6a64d12016-02-20 13:34:01 +0100196 if dragonfly {
197 cfg.header("ufs/ufs/quota.h");
198 cfg.header("pthread_np.h");
199 cfg.header("sys/ioctl_compat.h");
200 }
201
Alex Crichtond11e9142015-09-15 23:28:52 -0700202 cfg.type_name(move |ty, is_struct| {
Alex Crichton310d6232015-09-10 10:56:31 -0700203 match ty {
Alex Crichton31504842015-09-10 23:43:41 -0700204 // Just pass all these through, no need for a "struct" prefix
Alex Crichton22378822015-09-10 19:59:23 -0700205 "FILE" |
Alex Crichton07d3a0d2015-10-30 10:21:32 -0700206 "fd_set" |
Alex Crichton88d23e72015-11-02 17:03:19 -0800207 "Dl_info" |
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700208 "DIR" => ty.to_string(),
209
210 // Fixup a few types on windows that don't actually exist.
211 "time64_t" if windows => "__time64_t".to_string(),
212 "ssize_t" if windows => "SSIZE_T".to_string(),
213
Alex Crichtonde9736d2015-09-17 15:47:44 -0700214 // OSX calls this something else
Alex Crichtona1b948e2015-09-18 11:54:32 -0700215 "sighandler_t" if bsdlike => "sig_t".to_string(),
Alex Crichtonde9736d2015-09-17 15:47:44 -0700216
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700217 t if t.ends_with("_t") => t.to_string(),
Alex Crichton310d6232015-09-10 10:56:31 -0700218
Alex Crichton31504842015-09-10 23:43:41 -0700219 // Windows uppercase structs don't have `struct` in front, there's a
220 // few special cases for windows, and then otherwise put `struct` in
221 // front of everything.
Alex Crichtond11e9142015-09-15 23:28:52 -0700222 t if is_struct => {
Alex Crichton13a6f2d2015-09-10 18:10:58 -0700223 if windows && ty.chars().next().unwrap().is_uppercase() {
224 t.to_string()
225 } else if windows && t == "stat" {
226 "struct __stat64".to_string()
Alex Crichton7da9b102015-09-10 20:57:14 -0700227 } else if windows && t == "utimbuf" {
228 "struct __utimbuf64".to_string()
Alex Crichton13a6f2d2015-09-10 18:10:58 -0700229 } else {
230 format!("struct {}", t)
231 }
232 }
Alex Crichton310d6232015-09-10 10:56:31 -0700233
234 t => t.to_string(),
235 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700236 });
Alex Crichton310d6232015-09-10 10:56:31 -0700237
Alex Crichtond11e9142015-09-15 23:28:52 -0700238 let target2 = target.clone();
239 cfg.field_name(move |struct_, field| {
Alex Crichton310d6232015-09-10 10:56:31 -0700240 match field {
Sébastien Marie6c8a63a2015-12-23 18:54:25 +0100241 "st_birthtime" if openbsd && struct_ == "stat" => "__st_birthtime".to_string(),
Sébastien Mariec618f362015-12-21 17:26:41 +0100242 "st_birthtime_nsec" if openbsd && struct_ == "stat" => "__st_birthtimensec".to_string(),
Alex Crichton31504842015-09-10 23:43:41 -0700243 // Our stat *_nsec fields normally don't actually exist but are part
244 // of a timeval struct
Alex Crichton74825222015-10-29 17:36:55 -0700245 s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
Alex Crichtonbaef6112015-09-19 23:20:53 -0700246 if target2.contains("apple") {
Alex Crichton310d6232015-09-10 10:56:31 -0700247 s.replace("_nsec", "spec.tv_nsec")
Alex Crichtond11e9142015-09-15 23:28:52 -0700248 } else if target2.contains("android") {
Alex Crichtond3d77922015-09-11 17:03:39 -0700249 s.to_string()
Alex Crichton310d6232015-09-10 10:56:31 -0700250 } else {
251 s.replace("e_nsec", ".tv_nsec")
252 }
253 }
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800254 "u64" if struct_ == "epoll_event" => "data.u64".to_string(),
Alex Crichton310d6232015-09-10 10:56:31 -0700255 s => s.to_string(),
256 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700257 });
Alex Crichton310d6232015-09-10 10:56:31 -0700258
Alex Crichtond11e9142015-09-15 23:28:52 -0700259 cfg.skip_type(move |ty| {
Alex Crichton310d6232015-09-10 10:56:31 -0700260 match ty {
Alex Crichtond3d77922015-09-11 17:03:39 -0700261 // sighandler_t is crazy across platforms
Alex Crichtond11e9142015-09-15 23:28:52 -0700262 "sighandler_t" => true,
Alex Crichtond3d77922015-09-11 17:03:39 -0700263
Alex Crichtond11e9142015-09-15 23:28:52 -0700264 _ => false
Alex Crichton310d6232015-09-10 10:56:31 -0700265 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700266 });
Alex Crichton16083062015-09-09 22:59:24 -0700267
Alexander Polakov420f2e42015-11-11 01:53:39 +0300268 cfg.skip_struct(move |ty| {
269 match ty {
270 "sockaddr_nl" => musl,
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800271
272 // The alignment of this is 4 on 64-bit OSX...
273 "kevent" if apple && x86_64 => true,
274
Alexander Polakov420f2e42015-11-11 01:53:39 +0300275 _ => false
276 }
277 });
278
Michael Neumanna6a64d12016-02-20 13:34:01 +0100279 cfg.skip_signededness(move |c| {
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700280 match c {
Alex Crichton7b28c272015-09-15 20:56:16 -0700281 "LARGE_INTEGER" |
Alex Crichtoneef03da2015-09-15 16:57:06 -0700282 "mach_timebase_info_data_t" |
Alex Crichton7b28c272015-09-15 20:56:16 -0700283 "float" |
Alex Crichtond11e9142015-09-15 23:28:52 -0700284 "double" => true,
Michael Neumanna09fe712016-02-21 12:28:10 +0100285 // uuid_t is a struct, not an integer.
Michael Neumanna6a64d12016-02-20 13:34:01 +0100286 "uuid_t" if dragonfly => true,
Alex Crichtond11e9142015-09-15 23:28:52 -0700287 n if n.starts_with("pthread") => true,
Alex Crichton18469182015-09-15 20:57:42 -0700288
289 // windows-isms
Alex Crichtond11e9142015-09-15 23:28:52 -0700290 n if n.starts_with("P") => true,
291 n if n.starts_with("H") => true,
292 n if n.starts_with("LP") => true,
293 _ => false,
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700294 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700295 });
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700296
Alex Crichtond11e9142015-09-15 23:28:52 -0700297 cfg.skip_const(move |name| {
Alex Crichton31504842015-09-10 23:43:41 -0700298 match name {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700299 // Apparently these don't exist in mingw headers?
Alex Crichton31504842015-09-10 23:43:41 -0700300 "MEM_RESET_UNDO" |
301 "FILE_ATTRIBUTE_NO_SCRUB_DATA" |
302 "FILE_ATTRIBUTE_INTEGRITY_STREAM" |
Alex Crichtond11e9142015-09-15 23:28:52 -0700303 "ERROR_NOTHING_TO_TERMINATE" if mingw => true,
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700304
Alex Crichtond11e9142015-09-15 23:28:52 -0700305 "SIG_IGN" => true, // sighandler_t weirdness
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700306
Alex Crichton15b83c22015-09-17 17:25:52 -0700307 // types on musl are defined a little differently
Alex Crichton3a572fd2015-10-29 16:52:25 -0700308 n if musl && n.contains("__SIZEOF_PTHREAD") => true,
Alex Crichton15b83c22015-09-17 17:25:52 -0700309
Alex Crichton74825222015-10-29 17:36:55 -0700310 // Skip constants not defined in MUSL but just passed down to the
311 // kernel regardless
312 "RLIMIT_NLIMITS" |
313 "TCP_COOKIE_TRANSACTIONS" |
314 "RLIMIT_RTTIME" if musl => true,
Alexander Polakov26974c72015-11-27 03:02:44 +0300315 // work around super old mips toolchain
Alexander Polakov58501562015-12-14 02:09:45 +0300316 "SCHED_IDLE" | "SHM_NORESERVE" => mips,
Alex Crichton74825222015-10-29 17:36:55 -0700317
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800318 // weird signed extension or something like that?
319 "MS_NOUSER" => true,
NODA, Kai4d1efd92016-04-03 21:53:49 +0800320 "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800321
322 // These OSX constants are flagged as deprecated
323 "NOTE_EXIT_REPARENTED" |
324 "NOTE_REAP" if apple => true,
325
326 // The linux/quota.h header file which defines these can't be
327 // included with sys/quota.h currently on MIPS, so we don't include
328 // it and just ignore these constants
329 "QFMT_VFS_OLD" |
330 "QFMT_VFS_V0" if mips && linux => true,
331
Alex Crichtond11e9142015-09-15 23:28:52 -0700332 _ => false,
Alex Crichton31504842015-09-10 23:43:41 -0700333 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700334 });
Alex Crichton31504842015-09-10 23:43:41 -0700335
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700336 cfg.skip_fn(move |name| {
Jim Blandyf8772f72016-01-12 16:28:07 -0800337 // skip those that are manually verified
Alex Crichton22378822015-09-10 19:59:23 -0700338 match name {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700339 "execv" | // crazy stuff with const/mut
Alex Crichton22378822015-09-10 19:59:23 -0700340 "execve" |
341 "execvp" |
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700342 "execvpe" => true,
343
Alex Crichton74825222015-10-29 17:36:55 -0700344 "getrlimit" | "getrlimit64" | // non-int in 1st arg
345 "setrlimit" | "setrlimit64" | // non-int in 1st arg
Kamal Marhubi95695992016-04-27 14:29:19 -0400346 "prlimit" | "prlimit64" | // non-int in 2nd arg
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700347 "strerror_r" if linux => true, // actually xpg-something-or-other
348
Alex Crichton1ff96102015-09-17 15:09:02 -0700349 // typed 2nd arg on linux and android
Michael Neumanna6a64d12016-02-20 13:34:01 +0100350 "gettimeofday" if linux || android || freebsd || openbsd || dragonfly => true,
Alex Crichton1ff96102015-09-17 15:09:02 -0700351
Alex Crichton881ef9b2015-12-01 09:04:13 -0800352 // not declared in newer android toolchains
353 "getdtablesize" if android => true,
354
Alex Crichton1ff96102015-09-17 15:09:02 -0700355 "dlerror" if android => true, // const-ness is added
Alex Crichton88d23e72015-11-02 17:03:19 -0800356 "dladdr" if musl => true, // const-ness only added recently
Alex Crichton1ff96102015-09-17 15:09:02 -0700357
Alex Crichton568705e2015-11-03 14:18:52 -0800358 // OSX has 'struct tm *const' which we can't actually represent in
359 // Rust, but is close enough to *mut
360 "timegm" if apple => true,
361
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800362 // OSX's daemon is deprecated in 10.5 so we'll get a warning (which
363 // we turn into an error) so just ignore it.
364 "daemon" if apple => true,
365
Alex Crichton49d7bca2015-11-27 09:40:37 -0800366 // These functions presumably exist on netbsd but don't look like
367 // they're implemented on rumprun yet, just let them slide for now.
368 // Some of them look like they have headers but then don't have
369 // corresponding actual definitions either...
Alex Crichton49d7bca2015-11-27 09:40:37 -0800370 "shm_open" |
371 "shm_unlink" |
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800372 "syscall" |
373 "ptrace" |
Alex Crichton49d7bca2015-11-27 09:40:37 -0800374 "sigaltstack" if rumprun => true,
375
Jim Blandyf8772f72016-01-12 16:28:07 -0800376 // There seems to be a small error in EGLIBC's eventfd.h header. The
377 // [underlying system call][1] always takes its first `count`
378 // argument as an `unsigned int`, but [EGLIBC's <sys/eventfd.h>
379 // header][2] declares it to take an `int`. [GLIBC's header][3]
380 // matches the kernel.
381 //
382 // EGLIBC is no longer actively developed, and Debian, the largest
383 // distribution that had been using it, switched back to GLIBC in
384 // April 2015. So effectively all Linux <sys/eventfd.h> headers will
385 // be using `unsigned int` soon.
386 //
387 // [1]: https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/fs/eventfd.c?id=refs/tags/v3.12.51#n397
388 // [2]: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/eglibc/trusty/view/head:/sysdeps/unix/sysv/linux/sys/eventfd.h
389 // [3]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sys/eventfd.h;h=6295f32e937e779e74318eb9d3bdbe76aef8a8f3;hb=4e42b5b8f89f0e288e68be7ad70f9525aebc2cff#l34
390 "eventfd" if linux => true,
391
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800392 // The `uname` funcion in freebsd is now an inline wrapper that
393 // delegates to another, but the symbol still exists, so don't check
394 // the symbol.
395 "uname" if freebsd => true,
396
Alex Crichtond11e9142015-09-15 23:28:52 -0700397 _ => false,
Alex Crichton22378822015-09-10 19:59:23 -0700398 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700399 });
Alex Crichton22378822015-09-10 19:59:23 -0700400
Alex Crichton881ef9b2015-12-01 09:04:13 -0800401 cfg.skip_fn_ptrcheck(move |name| {
402 match name {
Alex Crichton881ef9b2015-12-01 09:04:13 -0800403 // dllimport weirdness?
404 _ if windows => true,
405
406 _ => false,
407 }
408 });
Alex Crichtone0f4d102015-09-16 09:48:14 -0700409
Alex Crichton15b83c22015-09-17 17:25:52 -0700410 cfg.skip_field_type(move |struct_, field| {
Alex Crichtonf3b97482015-09-16 14:13:20 -0700411 // This is a weird union, don't check the type.
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700412 (struct_ == "ifaddrs" && field == "ifa_ifu") ||
413 // sighandler_t type is super weird
414 (struct_ == "sigaction" && field == "sa_sigaction")
415 });
416
Alex Crichton15b83c22015-09-17 17:25:52 -0700417 cfg.skip_field(move |struct_, field| {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700418 // this is actually a union on linux, so we can't represent it well and
419 // just insert some padding.
Alex Crichton15b83c22015-09-17 17:25:52 -0700420 (struct_ == "siginfo_t" && field == "_pad") ||
421 // musl names this __dummy1 but it's still there
Brian Anderson773aab82015-12-29 20:00:29 +0000422 (musl && struct_ == "glob_t" && field == "gl_flags") ||
423 // musl seems to define this as an *anonymous* bitfield
424 (musl && struct_ == "statvfs" && field == "__f_unused")
Alex Crichtonf3b97482015-09-16 14:13:20 -0700425 });
426
Alex Crichton49d7bca2015-11-27 09:40:37 -0800427 cfg.fn_cname(move |name, cname| {
Alex Crichton881ef9b2015-12-01 09:04:13 -0800428 if windows {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800429 cname.unwrap_or(name).to_string()
Alex Crichton0af5e232015-11-30 15:07:28 -0800430 } else {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800431 name.to_string()
Alex Crichton0af5e232015-11-30 15:07:28 -0800432 }
433 });
434
Alex Crichtond820c4a2016-01-18 11:16:38 -0800435 if env::var("SKIP_COMPILE").is_ok() {
436 cfg.generate_files("../src/lib.rs", "all.rs");
437 } else {
438 cfg.generate("../src/lib.rs", "all.rs");
439 }
Alex Crichton310d6232015-09-10 10:56:31 -0700440}