blob: a9ac4fb33c27ec3a98498957e0e58584c5e90e33 [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
Tomasz Miąskoc4947bb2016-07-21 07:27:21 +020025 // Pull in extra goodies
Alex Crichton8dce9ad2015-12-03 11:44:14 -080026 if linux || android {
Alex Crichtond11e9142015-09-15 23:28:52 -070027 cfg.define("_GNU_SOURCE", None);
Tomasz Miąskoc4947bb2016-07-21 07:27:21 +020028 } else if netbsd {
29 cfg.define("_NETBSD_SOURCE", Some("1"));
Alex Crichton1ff96102015-09-17 15:09:02 -070030 } else if windows {
Alex Crichtond11e9142015-09-15 23:28:52 -070031 cfg.define("_WIN32_WINNT", Some("0x8000"));
Alex Crichton0df7c102015-09-10 16:35:37 -070032 }
33
Alex Crichton094f44d2015-09-16 16:27:23 -070034 // Android doesn't actually have in_port_t but it's much easier if we
35 // provide one for us to test against
Alex Crichton1ff96102015-09-17 15:09:02 -070036 if android {
Alex Crichton094f44d2015-09-16 16:27:23 -070037 cfg.define("in_port_t", Some("uint16_t"));
38 }
39
Alex Crichtond11e9142015-09-15 23:28:52 -070040 cfg.header("errno.h")
41 .header("fcntl.h")
42 .header("limits.h")
A.J. Gardnerb788a5c2016-03-30 01:13:55 -050043 .header("locale.h")
Alex Crichtond11e9142015-09-15 23:28:52 -070044 .header("stddef.h")
45 .header("stdint.h")
46 .header("stdio.h")
47 .header("stdlib.h")
48 .header("sys/stat.h")
49 .header("sys/types.h")
50 .header("time.h")
51 .header("wchar.h");
Alex Crichtonac2bd852015-09-10 17:21:20 -070052
Alex Crichton1ff96102015-09-17 15:09:02 -070053 if windows {
Alex Crichtond11e9142015-09-15 23:28:52 -070054 cfg.header("winsock2.h"); // must be before windows.h
55
56 cfg.header("direct.h");
57 cfg.header("io.h");
58 cfg.header("sys/utime.h");
59 cfg.header("windows.h");
60 cfg.header("process.h");
61 cfg.header("ws2ipdef.h");
62
63 if target.contains("gnu") {
64 cfg.header("ws2tcpip.h");
Alex Crichton310d6232015-09-10 10:56:31 -070065 }
Alex Crichtond11e9142015-09-15 23:28:52 -070066 } else {
67 cfg.header("ctype.h");
68 cfg.header("dirent.h");
Sébastien Mariec618f362015-12-21 17:26:41 +010069 if openbsd {
70 cfg.header("sys/socket.h");
71 }
Alex Crichtond11e9142015-09-15 23:28:52 -070072 cfg.header("net/if.h");
73 cfg.header("netdb.h");
74 cfg.header("netinet/in.h");
75 cfg.header("netinet/ip.h");
76 cfg.header("netinet/tcp.h");
77 cfg.header("pthread.h");
Alex Crichton1ff96102015-09-17 15:09:02 -070078 cfg.header("dlfcn.h");
Alex Crichtond11e9142015-09-15 23:28:52 -070079 cfg.header("signal.h");
80 cfg.header("string.h");
81 cfg.header("sys/file.h");
82 cfg.header("sys/ioctl.h");
83 cfg.header("sys/mman.h");
84 cfg.header("sys/resource.h");
85 cfg.header("sys/socket.h");
86 cfg.header("sys/time.h");
87 cfg.header("sys/un.h");
88 cfg.header("sys/wait.h");
89 cfg.header("unistd.h");
90 cfg.header("utime.h");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -070091 cfg.header("pwd.h");
92 cfg.header("grp.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -080093 cfg.header("sys/utsname.h");
94 cfg.header("sys/ptrace.h");
95 cfg.header("sys/mount.h");
96 cfg.header("sys/uio.h");
97 cfg.header("sched.h");
98 cfg.header("termios.h");
David Henningsson9d2493e2015-12-25 22:06:44 +010099 cfg.header("poll.h");
Raphael Cohn7fc09692016-05-05 15:41:21 +0100100 cfg.header("syslog.h");
Steven Fackler41699f72016-06-03 21:02:56 -0700101 cfg.header("semaphore.h");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700102 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700103
104 if android {
105 cfg.header("arpa/inet.h");
Alex Crichton568705e2015-11-03 14:18:52 -0800106 cfg.header("time64.h");
A.J. Gardner24c84f12016-03-31 20:08:03 -0500107 cfg.header("xlocale.h");
Knighta6b283b2016-07-27 19:42:36 +0800108 cfg.header("utmp.h");
Alex Crichtona1b948e2015-09-18 11:54:32 -0700109 } else if !windows {
110 cfg.header("glob.h");
111 cfg.header("ifaddrs.h");
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800112 cfg.header("sys/statvfs.h");
A.J. Gardner24c84f12016-03-31 20:08:03 -0500113 cfg.header("langinfo.h");
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800114
Michael Neumanna6a64d12016-02-20 13:34:01 +0100115 if !openbsd && !freebsd && !dragonfly {
Sébastien Mariec618f362015-12-21 17:26:41 +0100116 cfg.header("sys/quota.h");
117 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700118
119 if !musl {
Alex Crichtona1b948e2015-09-18 11:54:32 -0700120 cfg.header("sys/sysctl.h");
Alex Crichton49d7bca2015-11-27 09:40:37 -0800121
Sébastien Mariec618f362015-12-21 17:26:41 +0100122 if !netbsd && !openbsd {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800123 cfg.header("execinfo.h");
A.J. Gardner24c84f12016-03-31 20:08:03 -0500124 cfg.header("xlocale.h");
Alex Crichton49d7bca2015-11-27 09:40:37 -0800125 }
Knighta6b283b2016-07-27 19:42:36 +0800126
127 if openbsd {
128 cfg.header("utmp.h");
129 } else {
130 cfg.header("utmpx.h");
131 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700132 }
133 }
134
Alex Crichtonbaef6112015-09-19 23:20:53 -0700135 if apple {
Alex Crichtona1b948e2015-09-18 11:54:32 -0700136 cfg.header("mach-o/dyld.h");
137 cfg.header("mach/mach_time.h");
138 cfg.header("malloc/malloc.h");
Kamal Marhubi89a77002016-02-27 14:58:43 -0500139 cfg.header("util.h");
Alex Crichtonbaef6112015-09-19 23:20:53 -0700140 if target.starts_with("x86") {
141 cfg.header("crt_externs.h");
142 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700143 }
144
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800145 if bsdlike {
146 cfg.header("sys/event.h");
Kamal Marhubi9c4af102016-02-27 14:58:43 -0500147
148 if freebsd {
149 cfg.header("libutil.h");
150 } else {
151 cfg.header("util.h");
152 }
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800153 }
154
Alexander Polakov30baed02015-12-01 15:29:05 +0300155 if linux {
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800156 cfg.header("mqueue.h");
Philipp Matthias Schaefer7e3a1512016-02-22 20:11:01 +0100157 cfg.header("ucontext.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800158 cfg.header("sys/signalfd.h");
Alexander Polakov30baed02015-12-01 15:29:05 +0300159 cfg.header("sys/xattr.h");
Alexander Polakov58501562015-12-14 02:09:45 +0300160 cfg.header("sys/ipc.h");
161 cfg.header("sys/shm.h");
Kamal Marhubi9c4af102016-02-27 14:58:43 -0500162 cfg.header("pty.h");
Alexander Polakov30baed02015-12-01 15:29:05 +0300163 }
164
Alex Crichtona1b948e2015-09-18 11:54:32 -0700165 if linux || android {
Alex Crichtona1b948e2015-09-18 11:54:32 -0700166 cfg.header("malloc.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800167 cfg.header("net/ethernet.h");
168 cfg.header("netpacket/packet.h");
169 cfg.header("sched.h");
170 cfg.header("sys/epoll.h");
171 cfg.header("sys/eventfd.h");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700172 cfg.header("sys/prctl.h");
Kamal Marhubi143358b2016-02-04 14:08:50 -0500173 cfg.header("sys/sendfile.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800174 cfg.header("sys/vfs.h");
Alex Crichton881ef9b2015-12-01 09:04:13 -0800175 cfg.header("sys/syscall.h");
Raphael Cohne6150ae2016-05-13 11:18:34 +0100176 cfg.header("sys/sysinfo.h");
Sergey Bugaeva98c9832016-07-12 13:22:51 +0300177 cfg.header("sys/reboot.h");
Alexander Polakov420f2e42015-11-11 01:53:39 +0300178 if !musl {
179 cfg.header("linux/netlink.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800180 cfg.header("linux/magic.h");
Sergey Bugaeva98c9832016-07-12 13:22:51 +0300181 cfg.header("linux/reboot.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800182
183 if !mips {
184 cfg.header("linux/quota.h");
185 }
Alexander Polakov420f2e42015-11-11 01:53:39 +0300186 }
Alex Crichton310d6232015-09-10 10:56:31 -0700187 }
188
Alex Crichtona1b948e2015-09-18 11:54:32 -0700189 if freebsd {
190 cfg.header("pthread_np.h");
Alexander Polakov26974c72015-11-27 03:02:44 +0300191 cfg.header("sched.h");
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800192 cfg.header("ufs/ufs/quota.h");
Alex Crichtona1b948e2015-09-18 11:54:32 -0700193 }
194
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800195 if netbsd {
196 cfg.header("ufs/ufs/quota.h");
197 cfg.header("ufs/ufs/quota1.h");
198 cfg.header("sys/ioctl_compat.h");
199 }
200
Sébastien Mariec618f362015-12-21 17:26:41 +0100201 if openbsd {
202 cfg.header("ufs/ufs/quota.h");
203 cfg.header("rpcsvc/rex.h");
204 cfg.header("pthread_np.h");
205 cfg.header("sys/syscall.h");
206 }
207
Michael Neumanna6a64d12016-02-20 13:34:01 +0100208 if dragonfly {
209 cfg.header("ufs/ufs/quota.h");
210 cfg.header("pthread_np.h");
211 cfg.header("sys/ioctl_compat.h");
212 }
213
Alex Crichtond11e9142015-09-15 23:28:52 -0700214 cfg.type_name(move |ty, is_struct| {
Alex Crichton310d6232015-09-10 10:56:31 -0700215 match ty {
Alex Crichton31504842015-09-10 23:43:41 -0700216 // Just pass all these through, no need for a "struct" prefix
Alex Crichton22378822015-09-10 19:59:23 -0700217 "FILE" |
Alex Crichton07d3a0d2015-10-30 10:21:32 -0700218 "fd_set" |
Alex Crichton88d23e72015-11-02 17:03:19 -0800219 "Dl_info" |
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700220 "DIR" => ty.to_string(),
221
222 // Fixup a few types on windows that don't actually exist.
223 "time64_t" if windows => "__time64_t".to_string(),
224 "ssize_t" if windows => "SSIZE_T".to_string(),
225
Alex Crichtonde9736d2015-09-17 15:47:44 -0700226 // OSX calls this something else
Alex Crichtona1b948e2015-09-18 11:54:32 -0700227 "sighandler_t" if bsdlike => "sig_t".to_string(),
Alex Crichtonde9736d2015-09-17 15:47:44 -0700228
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700229 t if t.ends_with("_t") => t.to_string(),
Alex Crichton310d6232015-09-10 10:56:31 -0700230
Alex Crichton31504842015-09-10 23:43:41 -0700231 // Windows uppercase structs don't have `struct` in front, there's a
232 // few special cases for windows, and then otherwise put `struct` in
233 // front of everything.
Alex Crichtond11e9142015-09-15 23:28:52 -0700234 t if is_struct => {
Alex Crichton13a6f2d2015-09-10 18:10:58 -0700235 if windows && ty.chars().next().unwrap().is_uppercase() {
236 t.to_string()
237 } else if windows && t == "stat" {
238 "struct __stat64".to_string()
Alex Crichton7da9b102015-09-10 20:57:14 -0700239 } else if windows && t == "utimbuf" {
240 "struct __utimbuf64".to_string()
Alex Crichton13a6f2d2015-09-10 18:10:58 -0700241 } else {
242 format!("struct {}", t)
243 }
244 }
Alex Crichton310d6232015-09-10 10:56:31 -0700245
246 t => t.to_string(),
247 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700248 });
Alex Crichton310d6232015-09-10 10:56:31 -0700249
Alex Crichtond11e9142015-09-15 23:28:52 -0700250 let target2 = target.clone();
251 cfg.field_name(move |struct_, field| {
Alex Crichton310d6232015-09-10 10:56:31 -0700252 match field {
Sébastien Marie6c8a63a2015-12-23 18:54:25 +0100253 "st_birthtime" if openbsd && struct_ == "stat" => "__st_birthtime".to_string(),
Sébastien Mariec618f362015-12-21 17:26:41 +0100254 "st_birthtime_nsec" if openbsd && struct_ == "stat" => "__st_birthtimensec".to_string(),
Alex Crichton31504842015-09-10 23:43:41 -0700255 // Our stat *_nsec fields normally don't actually exist but are part
256 // of a timeval struct
Alex Crichton74825222015-10-29 17:36:55 -0700257 s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
Alex Crichtonbaef6112015-09-19 23:20:53 -0700258 if target2.contains("apple") {
Alex Crichton310d6232015-09-10 10:56:31 -0700259 s.replace("_nsec", "spec.tv_nsec")
Alex Crichtond11e9142015-09-15 23:28:52 -0700260 } else if target2.contains("android") {
Alex Crichtond3d77922015-09-11 17:03:39 -0700261 s.to_string()
Alex Crichton310d6232015-09-10 10:56:31 -0700262 } else {
263 s.replace("e_nsec", ".tv_nsec")
264 }
265 }
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800266 "u64" if struct_ == "epoll_event" => "data.u64".to_string(),
Alex Crichton310d6232015-09-10 10:56:31 -0700267 s => s.to_string(),
268 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700269 });
Alex Crichton310d6232015-09-10 10:56:31 -0700270
Alex Crichtond11e9142015-09-15 23:28:52 -0700271 cfg.skip_type(move |ty| {
Alex Crichton310d6232015-09-10 10:56:31 -0700272 match ty {
Alex Crichtond3d77922015-09-11 17:03:39 -0700273 // sighandler_t is crazy across platforms
Alex Crichtond11e9142015-09-15 23:28:52 -0700274 "sighandler_t" => true,
Alex Crichtond3d77922015-09-11 17:03:39 -0700275
Alex Crichtond11e9142015-09-15 23:28:52 -0700276 _ => false
Alex Crichton310d6232015-09-10 10:56:31 -0700277 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700278 });
Alex Crichton16083062015-09-09 22:59:24 -0700279
Alexander Polakov420f2e42015-11-11 01:53:39 +0300280 cfg.skip_struct(move |ty| {
281 match ty {
282 "sockaddr_nl" => musl,
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800283
284 // The alignment of this is 4 on 64-bit OSX...
285 "kevent" if apple && x86_64 => true,
286
Alexander Polakov420f2e42015-11-11 01:53:39 +0300287 _ => false
288 }
289 });
290
Michael Neumanna6a64d12016-02-20 13:34:01 +0100291 cfg.skip_signededness(move |c| {
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700292 match c {
Alex Crichton7b28c272015-09-15 20:56:16 -0700293 "LARGE_INTEGER" |
Alex Crichtoneef03da2015-09-15 16:57:06 -0700294 "mach_timebase_info_data_t" |
Alex Crichton7b28c272015-09-15 20:56:16 -0700295 "float" |
Alex Crichtond11e9142015-09-15 23:28:52 -0700296 "double" => true,
Michael Neumanna09fe712016-02-21 12:28:10 +0100297 // uuid_t is a struct, not an integer.
Michael Neumanna6a64d12016-02-20 13:34:01 +0100298 "uuid_t" if dragonfly => true,
Alex Crichtond11e9142015-09-15 23:28:52 -0700299 n if n.starts_with("pthread") => true,
Steven Fackler41699f72016-06-03 21:02:56 -0700300 // sem_t is a struct or pointer
301 "sem_t" if openbsd || freebsd || rumprun => true,
Alex Crichton18469182015-09-15 20:57:42 -0700302
303 // windows-isms
Alex Crichtond11e9142015-09-15 23:28:52 -0700304 n if n.starts_with("P") => true,
305 n if n.starts_with("H") => true,
306 n if n.starts_with("LP") => true,
307 _ => false,
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700308 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700309 });
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700310
Alex Crichtond11e9142015-09-15 23:28:52 -0700311 cfg.skip_const(move |name| {
Alex Crichton31504842015-09-10 23:43:41 -0700312 match name {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700313 // Apparently these don't exist in mingw headers?
Alex Crichton31504842015-09-10 23:43:41 -0700314 "MEM_RESET_UNDO" |
315 "FILE_ATTRIBUTE_NO_SCRUB_DATA" |
316 "FILE_ATTRIBUTE_INTEGRITY_STREAM" |
Alex Crichtond11e9142015-09-15 23:28:52 -0700317 "ERROR_NOTHING_TO_TERMINATE" if mingw => true,
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700318
Alex Crichtond11e9142015-09-15 23:28:52 -0700319 "SIG_IGN" => true, // sighandler_t weirdness
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700320
Alex Crichton15b83c22015-09-17 17:25:52 -0700321 // types on musl are defined a little differently
Alex Crichton3a572fd2015-10-29 16:52:25 -0700322 n if musl && n.contains("__SIZEOF_PTHREAD") => true,
Alex Crichton15b83c22015-09-17 17:25:52 -0700323
Alex Crichton74825222015-10-29 17:36:55 -0700324 // Skip constants not defined in MUSL but just passed down to the
325 // kernel regardless
326 "RLIMIT_NLIMITS" |
327 "TCP_COOKIE_TRANSACTIONS" |
328 "RLIMIT_RTTIME" if musl => true,
Alexander Polakov26974c72015-11-27 03:02:44 +0300329 // work around super old mips toolchain
Alexander Polakov58501562015-12-14 02:09:45 +0300330 "SCHED_IDLE" | "SHM_NORESERVE" => mips,
Alex Crichton74825222015-10-29 17:36:55 -0700331
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800332 // weird signed extension or something like that?
333 "MS_NOUSER" => true,
NODA, Kai4d1efd92016-04-03 21:53:49 +0800334 "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800335
336 // These OSX constants are flagged as deprecated
337 "NOTE_EXIT_REPARENTED" |
338 "NOTE_REAP" if apple => true,
339
340 // The linux/quota.h header file which defines these can't be
341 // included with sys/quota.h currently on MIPS, so we don't include
342 // it and just ignore these constants
343 "QFMT_VFS_OLD" |
344 "QFMT_VFS_V0" if mips && linux => true,
345
Alex Crichtond11e9142015-09-15 23:28:52 -0700346 _ => false,
Alex Crichton31504842015-09-10 23:43:41 -0700347 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700348 });
Alex Crichton31504842015-09-10 23:43:41 -0700349
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700350 cfg.skip_fn(move |name| {
Jim Blandyf8772f72016-01-12 16:28:07 -0800351 // skip those that are manually verified
Alex Crichton22378822015-09-10 19:59:23 -0700352 match name {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700353 "execv" | // crazy stuff with const/mut
Alex Crichton22378822015-09-10 19:59:23 -0700354 "execve" |
355 "execvp" |
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700356 "execvpe" => true,
357
Alex Crichton74825222015-10-29 17:36:55 -0700358 "getrlimit" | "getrlimit64" | // non-int in 1st arg
359 "setrlimit" | "setrlimit64" | // non-int in 1st arg
Kamal Marhubi95695992016-04-27 14:29:19 -0400360 "prlimit" | "prlimit64" | // non-int in 2nd arg
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700361 "strerror_r" if linux => true, // actually xpg-something-or-other
362
Alex Crichton1ff96102015-09-17 15:09:02 -0700363 // typed 2nd arg on linux and android
Michael Neumanna6a64d12016-02-20 13:34:01 +0100364 "gettimeofday" if linux || android || freebsd || openbsd || dragonfly => true,
Alex Crichton1ff96102015-09-17 15:09:02 -0700365
Alex Crichton881ef9b2015-12-01 09:04:13 -0800366 // not declared in newer android toolchains
367 "getdtablesize" if android => true,
368
Alex Crichton1ff96102015-09-17 15:09:02 -0700369 "dlerror" if android => true, // const-ness is added
Alex Crichton88d23e72015-11-02 17:03:19 -0800370 "dladdr" if musl => true, // const-ness only added recently
Alex Crichton1ff96102015-09-17 15:09:02 -0700371
Alex Crichton568705e2015-11-03 14:18:52 -0800372 // OSX has 'struct tm *const' which we can't actually represent in
373 // Rust, but is close enough to *mut
374 "timegm" if apple => true,
375
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800376 // OSX's daemon is deprecated in 10.5 so we'll get a warning (which
377 // we turn into an error) so just ignore it.
378 "daemon" if apple => true,
379
Steven Fackler41699f72016-06-03 21:02:56 -0700380 // Deprecated on OSX
381 "sem_destroy" if apple => true,
382 "sem_init" if apple => true,
383
Alex Crichton49d7bca2015-11-27 09:40:37 -0800384 // These functions presumably exist on netbsd but don't look like
385 // they're implemented on rumprun yet, just let them slide for now.
386 // Some of them look like they have headers but then don't have
387 // corresponding actual definitions either...
Alex Crichton49d7bca2015-11-27 09:40:37 -0800388 "shm_open" |
389 "shm_unlink" |
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800390 "syscall" |
391 "ptrace" |
Alex Crichton49d7bca2015-11-27 09:40:37 -0800392 "sigaltstack" if rumprun => true,
393
Jim Blandyf8772f72016-01-12 16:28:07 -0800394 // There seems to be a small error in EGLIBC's eventfd.h header. The
395 // [underlying system call][1] always takes its first `count`
396 // argument as an `unsigned int`, but [EGLIBC's <sys/eventfd.h>
397 // header][2] declares it to take an `int`. [GLIBC's header][3]
398 // matches the kernel.
399 //
400 // EGLIBC is no longer actively developed, and Debian, the largest
401 // distribution that had been using it, switched back to GLIBC in
402 // April 2015. So effectively all Linux <sys/eventfd.h> headers will
403 // be using `unsigned int` soon.
404 //
405 // [1]: https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/fs/eventfd.c?id=refs/tags/v3.12.51#n397
406 // [2]: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/eglibc/trusty/view/head:/sysdeps/unix/sysv/linux/sys/eventfd.h
407 // [3]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sys/eventfd.h;h=6295f32e937e779e74318eb9d3bdbe76aef8a8f3;hb=4e42b5b8f89f0e288e68be7ad70f9525aebc2cff#l34
408 "eventfd" if linux => true,
409
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800410 // The `uname` funcion in freebsd is now an inline wrapper that
411 // delegates to another, but the symbol still exists, so don't check
412 // the symbol.
413 "uname" if freebsd => true,
414
Alex Crichtond11e9142015-09-15 23:28:52 -0700415 _ => false,
Alex Crichton22378822015-09-10 19:59:23 -0700416 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700417 });
Alex Crichton22378822015-09-10 19:59:23 -0700418
Alex Crichton881ef9b2015-12-01 09:04:13 -0800419 cfg.skip_fn_ptrcheck(move |name| {
420 match name {
Alex Crichton881ef9b2015-12-01 09:04:13 -0800421 // dllimport weirdness?
422 _ if windows => true,
423
424 _ => false,
425 }
426 });
Alex Crichtone0f4d102015-09-16 09:48:14 -0700427
Alex Crichton15b83c22015-09-17 17:25:52 -0700428 cfg.skip_field_type(move |struct_, field| {
Alex Crichtonf3b97482015-09-16 14:13:20 -0700429 // This is a weird union, don't check the type.
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700430 (struct_ == "ifaddrs" && field == "ifa_ifu") ||
431 // sighandler_t type is super weird
432 (struct_ == "sigaction" && field == "sa_sigaction")
433 });
434
Alex Crichton15b83c22015-09-17 17:25:52 -0700435 cfg.skip_field(move |struct_, field| {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700436 // this is actually a union on linux, so we can't represent it well and
437 // just insert some padding.
Alex Crichton15b83c22015-09-17 17:25:52 -0700438 (struct_ == "siginfo_t" && field == "_pad") ||
439 // musl names this __dummy1 but it's still there
Brian Anderson773aab82015-12-29 20:00:29 +0000440 (musl && struct_ == "glob_t" && field == "gl_flags") ||
441 // musl seems to define this as an *anonymous* bitfield
442 (musl && struct_ == "statvfs" && field == "__f_unused")
Alex Crichtonf3b97482015-09-16 14:13:20 -0700443 });
444
Alex Crichton49d7bca2015-11-27 09:40:37 -0800445 cfg.fn_cname(move |name, cname| {
Alex Crichton881ef9b2015-12-01 09:04:13 -0800446 if windows {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800447 cname.unwrap_or(name).to_string()
Alex Crichton0af5e232015-11-30 15:07:28 -0800448 } else {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800449 name.to_string()
Alex Crichton0af5e232015-11-30 15:07:28 -0800450 }
451 });
452
Alex Crichtond820c4a2016-01-18 11:16:38 -0800453 if env::var("SKIP_COMPILE").is_ok() {
454 cfg.generate_files("../src/lib.rs", "all.rs");
455 } else {
456 cfg.generate("../src/lib.rs", "all.rs");
457 }
Alex Crichton310d6232015-09-10 10:56:31 -0700458}