xref: /rust-libc-0.2.174/libc-test/build.rs (revision aa41265f)
1 #![deny(warnings)]
2 
3 extern crate ctest;
4 
5 use std::env;
6 
7 fn main() {
8     let target = env::var("TARGET").unwrap();
9     let aarch64 = target.contains("aarch64");
10     let i686 = target.contains("i686");
11     let x86_64 = target.contains("x86_64");
12     let x32 = target.ends_with("gnux32");
13     let windows = target.contains("windows");
14     let mingw = target.contains("windows-gnu");
15     let linux = target.contains("unknown-linux");
16     let android = target.contains("android");
17     let apple = target.contains("apple");
18     let emscripten = target.contains("asm");
19     let musl = target.contains("musl") || emscripten;
20     let uclibc = target.contains("uclibc");
21     let freebsd = target.contains("freebsd");
22     let dragonfly = target.contains("dragonfly");
23     let mips = target.contains("mips");
24     let netbsd = target.contains("netbsd");
25     let openbsd = target.contains("openbsd");
26     let rumprun = target.contains("rumprun");
27     let solaris = target.contains("solaris");
28     let bsdlike = freebsd || apple || netbsd || openbsd || dragonfly;
29     let mut cfg = ctest::TestGenerator::new();
30 
31     // Pull in extra goodies
32     if linux || android || emscripten {
33         cfg.define("_GNU_SOURCE", None);
34     } else if netbsd {
35         cfg.define("_NETBSD_SOURCE", Some("1"));
36     } else if apple {
37         cfg.define("__APPLE_USE_RFC_3542", None);
38     } else if windows {
39         cfg.define("_WIN32_WINNT", Some("0x8000"));
40     } else if solaris {
41         cfg.define("_XOPEN_SOURCE", Some("700"));
42         cfg.define("__EXTENSIONS__", None);
43         cfg.define("_LCONV_C99", None);
44     }
45 
46     // Android doesn't actually have in_port_t but it's much easier if we
47     // provide one for us to test against
48     if android {
49         cfg.define("in_port_t", Some("uint16_t"));
50     }
51 
52     cfg.header("errno.h")
53        .header("fcntl.h")
54        .header("limits.h")
55        .header("locale.h")
56        .header("stddef.h")
57        .header("stdint.h")
58        .header("stdio.h")
59        .header("stdlib.h")
60        .header("sys/stat.h")
61        .header("sys/types.h")
62        .header("time.h")
63        .header("wchar.h");
64 
65     if windows {
66         cfg.header("winsock2.h"); // must be before windows.h
67 
68         cfg.header("direct.h");
69         cfg.header("io.h");
70         cfg.header("sys/utime.h");
71         cfg.header("windows.h");
72         cfg.header("process.h");
73         cfg.header("ws2ipdef.h");
74 
75         if target.contains("gnu") {
76             cfg.header("ws2tcpip.h");
77         }
78     } else {
79         cfg.flag("-Wno-deprecated-declarations");
80 
81         cfg.header("ctype.h");
82         cfg.header("dirent.h");
83         if openbsd {
84             cfg.header("sys/socket.h");
85         }
86         cfg.header("net/if.h");
87         cfg.header("net/route.h");
88         cfg.header("net/if_arp.h");
89         cfg.header("netdb.h");
90         cfg.header("netinet/in.h");
91         cfg.header("netinet/ip.h");
92         cfg.header("netinet/tcp.h");
93         cfg.header("netinet/udp.h");
94         cfg.header("resolv.h");
95         cfg.header("pthread.h");
96         cfg.header("dlfcn.h");
97         cfg.header("signal.h");
98         cfg.header("string.h");
99         cfg.header("sys/file.h");
100         cfg.header("sys/ioctl.h");
101         cfg.header("sys/mman.h");
102         cfg.header("sys/resource.h");
103         cfg.header("sys/socket.h");
104         if linux && !musl {
105             cfg.header("linux/if.h");
106             cfg.header("sys/auxv.h");
107         }
108         cfg.header("sys/time.h");
109         cfg.header("sys/un.h");
110         cfg.header("sys/wait.h");
111         cfg.header("unistd.h");
112         cfg.header("utime.h");
113         cfg.header("pwd.h");
114         cfg.header("grp.h");
115         cfg.header("sys/utsname.h");
116         if !solaris {
117             cfg.header("sys/ptrace.h");
118         }
119         cfg.header("sys/mount.h");
120         cfg.header("sys/uio.h");
121         cfg.header("sched.h");
122         cfg.header("termios.h");
123         cfg.header("poll.h");
124         cfg.header("syslog.h");
125         cfg.header("semaphore.h");
126         cfg.header("sys/statvfs.h");
127         cfg.header("sys/times.h");
128     }
129 
130     if android {
131         if !aarch64 && !x86_64 {
132             // time64_t is not define for aarch64 and x86_64
133             // If included it will generate the error 'Your time_t is already 64-bit'
134             cfg.header("time64.h");
135         }
136         cfg.header("arpa/inet.h");
137         cfg.header("xlocale.h");
138         cfg.header("utmp.h");
139         cfg.header("ifaddrs.h");
140         if i686 || x86_64 {
141             cfg.header("sys/reg.h");
142         }
143     } else if !windows {
144         cfg.header("glob.h");
145         cfg.header("ifaddrs.h");
146         cfg.header("langinfo.h");
147 
148         if !openbsd && !freebsd && !dragonfly && !solaris {
149             cfg.header("sys/quota.h");
150         }
151 
152         if !musl && !x32 && !solaris {
153             cfg.header("sys/sysctl.h");
154         }
155 
156         if !musl && !uclibc {
157 
158             if !netbsd && !openbsd && !uclibc {
159                 cfg.header("execinfo.h");
160             }
161 
162             if openbsd {
163                 cfg.header("utmp.h");
164             } else {
165                 cfg.header("utmpx.h");
166             }
167         }
168     }
169 
170     if apple {
171         cfg.header("spawn.h");
172         cfg.header("mach-o/dyld.h");
173         cfg.header("mach/mach_time.h");
174         cfg.header("malloc/malloc.h");
175         cfg.header("util.h");
176         cfg.header("xlocale.h");
177         cfg.header("sys/xattr.h");
178         cfg.header("sys/sys_domain.h");
179         cfg.header("net/if_utun.h");
180         cfg.header("net/bpf.h");
181         if target.starts_with("x86") {
182             cfg.header("crt_externs.h");
183         }
184         cfg.header("net/route.h");
185         cfg.header("netinet/if_ether.h");
186         cfg.header("netinet/in.h");
187         cfg.header("sys/proc_info.h");
188         cfg.header("sys/kern_control.h");
189         cfg.header("sys/ipc.h");
190         cfg.header("sys/shm.h");
191     }
192 
193     if bsdlike {
194         cfg.header("sys/event.h");
195         cfg.header("net/if_dl.h");
196         if freebsd {
197             cfg.header("net/bpf.h");
198             cfg.header("libutil.h");
199         } else {
200             cfg.header("util.h");
201         }
202     }
203 
204     if linux || emscripten {
205         cfg.header("mntent.h");
206         cfg.header("mqueue.h");
207         cfg.header("ucontext.h");
208         if !uclibc {
209             // optionally included in uclibc
210             cfg.header("sys/xattr.h");
211         }
212         cfg.header("sys/ipc.h");
213         cfg.header("sys/sem.h");
214         cfg.header("sys/msg.h");
215         cfg.header("sys/shm.h");
216         cfg.header("sys/user.h");
217         cfg.header("sys/timerfd.h");
218         cfg.header("shadow.h");
219         if !emscripten {
220             cfg.header("linux/input.h");
221             cfg.header("linux/falloc.h");
222         }
223         if x86_64 {
224             cfg.header("sys/io.h");
225         }
226         if i686 || x86_64 {
227             cfg.header("sys/reg.h");
228         }
229     }
230 
231     if linux || android || emscripten {
232         cfg.header("malloc.h");
233         cfg.header("net/ethernet.h");
234         cfg.header("netpacket/packet.h");
235         cfg.header("sched.h");
236         cfg.header("sys/epoll.h");
237         cfg.header("sys/eventfd.h");
238         cfg.header("sys/prctl.h");
239         cfg.header("sys/sendfile.h");
240         cfg.header("sys/signalfd.h");
241         cfg.header("sys/vfs.h");
242         cfg.header("sys/syscall.h");
243         cfg.header("sys/personality.h");
244         cfg.header("sys/swap.h");
245         cfg.header("pty.h");
246         if !uclibc {
247             cfg.header("sys/sysinfo.h");
248         }
249         cfg.header("sys/reboot.h");
250         if !emscripten {
251             cfg.header("linux/sockios.h");
252             cfg.header("linux/netlink.h");
253             cfg.header("linux/genetlink.h");
254             cfg.header("linux/netfilter_ipv4.h");
255             cfg.header("linux/netfilter_ipv6.h");
256             cfg.header("linux/fs.h");
257         }
258         if !musl {
259             cfg.header("asm/mman.h");
260             cfg.header("linux/magic.h");
261             cfg.header("linux/reboot.h");
262             cfg.header("linux/netfilter/nf_tables.h");
263 
264             if !mips {
265                 cfg.header("linux/quota.h");
266             }
267         }
268     }
269     if solaris {
270         cfg.header("sys/epoll.h");
271     }
272 
273     if linux || android {
274         cfg.header("sys/fsuid.h");
275         cfg.header("linux/module.h");
276         cfg.header("linux/seccomp.h");
277         cfg.header("linux/if_ether.h");
278         cfg.header("linux/if_tun.h");
279         // DCCP support
280         if !uclibc && !musl && !emscripten {
281             cfg.header("linux/dccp.h");
282         }
283 
284         if !musl || mips {
285             cfg.header("linux/memfd.h");
286         }
287     }
288 
289     if linux {
290         cfg.header("linux/random.h");
291         cfg.header("elf.h");
292         cfg.header("link.h");
293         cfg.header("spawn.h");
294     }
295 
296     if freebsd {
297         cfg.header("mqueue.h");
298         cfg.header("pthread_np.h");
299         cfg.header("sched.h");
300         cfg.header("ufs/ufs/quota.h");
301         cfg.header("sys/jail.h");
302         cfg.header("sys/ipc.h");
303         cfg.header("sys/msg.h");
304         cfg.header("sys/shm.h");
305         cfg.header("sys/procdesc.h");
306         cfg.header("sys/rtprio.h");
307         cfg.header("spawn.h");
308     }
309 
310     if netbsd {
311         cfg.header("mqueue.h");
312         cfg.header("ufs/ufs/quota.h");
313         cfg.header("ufs/ufs/quota1.h");
314         cfg.header("sys/ioctl_compat.h");
315 
316         // DCCP support
317         cfg.header("netinet/dccp.h");
318     }
319 
320     if openbsd {
321         cfg.header("ufs/ufs/quota.h");
322         cfg.header("pthread_np.h");
323         cfg.header("sys/syscall.h");
324     }
325 
326     if dragonfly {
327         cfg.header("mqueue.h");
328         cfg.header("ufs/ufs/quota.h");
329         cfg.header("pthread_np.h");
330         cfg.header("sys/ioctl_compat.h");
331         cfg.header("sys/rtprio.h");
332     }
333 
334     if solaris {
335         cfg.header("port.h");
336         cfg.header("ucontext.h");
337         cfg.header("sys/filio.h");
338         cfg.header("sys/loadavg.h");
339     }
340 
341     if linux || freebsd || dragonfly || netbsd || apple || emscripten {
342         if !uclibc {
343             cfg.header("aio.h");
344         }
345     }
346 
347     cfg.type_name(move |ty, is_struct, is_union| {
348         match ty {
349             // Just pass all these through, no need for a "struct" prefix
350             "FILE" |
351             "fd_set" |
352             "Dl_info" |
353             "DIR" |
354             "Elf32_Phdr" |
355             "Elf64_Phdr" => ty.to_string(),
356 
357             // Fixup a few types on windows that don't actually exist.
358             "time64_t" if windows => "__time64_t".to_string(),
359             "ssize_t" if windows => "SSIZE_T".to_string(),
360 
361             // OSX calls this something else
362             "sighandler_t" if bsdlike => "sig_t".to_string(),
363 
364             t if is_union => {
365                 format!("union {}", t)
366             }
367 
368             t if t.ends_with("_t") => t.to_string(),
369 
370             // Windows uppercase structs don't have `struct` in front, there's a
371             // few special cases for windows, and then otherwise put `struct` in
372             // front of everything.
373             t if is_struct => {
374                 if windows && ty.chars().next().unwrap().is_uppercase() {
375                     t.to_string()
376                 } else if windows && t == "stat" {
377                     "struct __stat64".to_string()
378                 } else if windows && t == "utimbuf" {
379                     "struct __utimbuf64".to_string()
380                 } else {
381                     format!("struct {}", t)
382                 }
383             }
384 
385             t => t.to_string(),
386         }
387     });
388 
389     let target2 = target.clone();
390     cfg.field_name(move |struct_, field| {
391         match field {
392             "st_birthtime"      if openbsd && struct_ == "stat" => "__st_birthtime".to_string(),
393             "st_birthtime_nsec" if openbsd && struct_ == "stat" => "__st_birthtimensec".to_string(),
394             // Our stat *_nsec fields normally don't actually exist but are part
395             // of a timeval struct
396             s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
397                 if target2.contains("apple") {
398                     s.replace("_nsec", "spec.tv_nsec")
399                 } else if target2.contains("android") {
400                     s.to_string()
401                 } else {
402                     s.replace("e_nsec", ".tv_nsec")
403                 }
404             }
405             "u64" if struct_ == "epoll_event" => "data.u64".to_string(),
406             "type_" if (linux || freebsd || dragonfly) &&
407                 (struct_ == "input_event" || struct_ == "input_mask" ||
408                  struct_ == "ff_effect" || struct_ == "rtprio") => "type".to_string(),
409             s => s.to_string(),
410         }
411     });
412 
413     cfg.skip_type(move |ty| {
414         match ty {
415             // sighandler_t is crazy across platforms
416             "sighandler_t" => true,
417 
418             _ => false
419         }
420     });
421 
422     cfg.skip_struct(move |ty| {
423         match ty {
424             "sockaddr_nl" => musl,
425 
426             // On Linux, the type of `ut_tv` field of `struct utmpx`
427             // can be an anonymous struct, so an extra struct,
428             // which is absent in glibc, has to be defined.
429             "__timeval" if linux => true,
430 
431             // Fixed on stdbuild with repr(packed(4))
432             // Once repr_packed stabilizes we can fix this unconditionally
433             // and remove this check.
434             "kevent" | "shmid_ds" if apple && x86_64 => true,
435 
436             // This is actually a union, not a struct
437             "sigval" => true,
438 
439             // Linux kernel headers used on musl are too old to have this
440             // definition. Because it's tested on other Linux targets, skip it.
441             "input_mask" if musl => true,
442 
443             // These structs have changed since unified headers in NDK r14b.
444             // `st_atime` and `st_atime_nsec` have changed sign.
445             // FIXME: unskip it for next major release
446             "stat" | "stat64" if android => true,
447 
448             // These are tested as part of the linux_fcntl tests since there are
449             // header conflicts when including them with all the other structs.
450             "termios2" => true,
451 
452             _ => false
453         }
454     });
455 
456     cfg.skip_signededness(move |c| {
457         match c {
458             "LARGE_INTEGER" |
459             "mach_timebase_info_data_t" |
460             "float" |
461             "double" => true,
462             // uuid_t is a struct, not an integer.
463             "uuid_t" if dragonfly => true,
464             n if n.starts_with("pthread") => true,
465             // sem_t is a struct or pointer
466             "sem_t" if openbsd || freebsd || dragonfly || netbsd => true,
467             // mqd_t is a pointer on FreeBSD and DragonFly
468             "mqd_t" if freebsd || dragonfly => true,
469 
470             // Just some typedefs on osx, no need to check their sign
471             "posix_spawnattr_t" |
472             "posix_spawn_file_actions_t" => true,
473 
474             // windows-isms
475             n if n.starts_with("P") => true,
476             n if n.starts_with("H") => true,
477             n if n.starts_with("LP") => true,
478             _ => false,
479         }
480     });
481 
482     cfg.skip_const(move |name| {
483         match name {
484             // Apparently these don't exist in mingw headers?
485             "MEM_RESET_UNDO" |
486             "FILE_ATTRIBUTE_NO_SCRUB_DATA" |
487             "FILE_ATTRIBUTE_INTEGRITY_STREAM" |
488             "ERROR_NOTHING_TO_TERMINATE" if mingw => true,
489 
490             "SIG_DFL" |
491             "SIG_ERR" |
492             "SIG_IGN" => true, // sighandler_t weirdness
493             "SIGUNUSED" => true, // removed in glibc 2.26
494 
495             // types on musl are defined a little differently
496             n if musl && n.contains("__SIZEOF_PTHREAD") => true,
497 
498             // Skip constants not defined in MUSL but just passed down to the
499             // kernel regardless
500             "RLIMIT_NLIMITS" |
501             "TCP_COOKIE_TRANSACTIONS" |
502             "RLIMIT_RTTIME" |
503             "MSG_COPY" if musl => true,
504             // work around super old mips toolchain
505             "SCHED_IDLE" | "SHM_NORESERVE" => mips,
506 
507             // weird signed extension or something like that?
508             "MS_NOUSER" => true,
509             "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13
510 
511             // These OSX constants are flagged as deprecated
512             "NOTE_EXIT_REPARENTED" |
513             "NOTE_REAP" if apple => true,
514 
515             // These constants were removed in FreeBSD 11 (svn r273250) but will
516             // still be accepted and ignored at runtime.
517             "MAP_RENAME" |
518             "MAP_NORESERVE" if freebsd => true,
519 
520             // These constants were removed in FreeBSD 11 (svn r262489),
521             // and they've never had any legitimate use outside of the
522             // base system anyway.
523             "CTL_MAXID" |
524             "KERN_MAXID" |
525             "HW_MAXID" |
526             "NET_MAXID" |
527             "USER_MAXID" if freebsd => true,
528 
529             // These constants were added in FreeBSD 11
530             "EVFILT_PROCDESC" | "EVFILT_SENDFILE" | "EVFILT_EMPTY" |
531             "PD_CLOEXEC" | "PD_ALLOWED_AT_FORK" if freebsd => true,
532 
533             // These constants were added in FreeBSD 12
534             "SF_USER_READAHEAD" if freebsd => true,
535 
536             // These OSX constants are removed in Sierra.
537             // https://developer.apple.com/library/content/releasenotes/General/APIDiffsMacOS10_12/Swift/Darwin.html
538             "KERN_KDENABLE_BG_TRACE" if apple => true,
539             "KERN_KDDISABLE_BG_TRACE" if apple => true,
540 
541             // These constants were removed in OpenBSD 6 (https://git.io/v7gBO
542             // https://git.io/v7gBq)
543             "KERN_USERMOUNT" |
544             "KERN_ARND" if openbsd => true,
545 
546             // These are either unimplemented or optionally built into uClibc
547             "LC_CTYPE_MASK" | "LC_NUMERIC_MASK" | "LC_TIME_MASK" | "LC_COLLATE_MASK" | "LC_MONETARY_MASK" | "LC_MESSAGES_MASK" |
548             "MADV_MERGEABLE" | "MADV_UNMERGEABLE" | "MADV_HWPOISON" | "IPV6_ADD_MEMBERSHIP" | "IPV6_DROP_MEMBERSHIP" | "IPV6_MULTICAST_LOOP" | "IPV6_V6ONLY" |
549             "MAP_STACK" | "RTLD_DEEPBIND" | "SOL_IPV6" | "SOL_ICMPV6" if uclibc => true,
550 
551             // Musl uses old, patched kernel headers
552             "FALLOC_FL_COLLAPSE_RANGE" | "FALLOC_FL_ZERO_RANGE" |
553             "FALLOC_FL_INSERT_RANGE" | "FALLOC_FL_UNSHARE_RANGE" |
554             "RENAME_NOREPLACE" | "RENAME_EXCHANGE" | "RENAME_WHITEOUT" if musl => true,
555 
556             // Both android and musl use old kernel headers
557             // These are constants used in getrandom syscall
558             "GRND_NONBLOCK" | "GRND_RANDOM" if musl || android => true,
559 
560             // Defined by libattr not libc on linux (hard to test).
561             // See constant definition for more details.
562             "ENOATTR" if android || linux => true,
563 
564             // On mips*-unknown-linux-gnu* CMSPAR cannot be included with the set of headers we
565             // want to use here for testing. It's originally defined in asm/termbits.h, which is
566             // also included by asm/termios.h, but not the standard termios.h. There's no way to
567             // include both asm/termbits.h and termios.h and there's no way to include both
568             // asm/termios.h and ioctl.h (+ some other headers) because of redeclared types.
569             "CMSPAR" if mips && linux && !musl => true,
570 
571             // On mips Linux targets, MADV_SOFT_OFFLINE is currently missing, though it's been added but CI has too old
572             // of a Linux version. Since it exists on all other Linux targets, just ignore this for now and remove once
573             // it's been fixed in CI.
574             "MADV_SOFT_OFFLINE" if mips && linux => true,
575 
576             // These constants are tested in a separate test program generated below because there
577             // are header conflicts if we try to include the headers that define them here.
578             "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => true,
579             "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => true,
580             "QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1" if mips && linux => true, // Only on MIPS
581             "BOTHER" => true,
582 
583             "MFD_CLOEXEC" | "MFD_ALLOW_SEALING" if !mips && musl => true,
584 
585             "DT_FIFO" | "DT_CHR" | "DT_DIR" | "DT_BLK" | "DT_REG" | "DT_LNK" | "DT_SOCK" if solaris => true,
586             "USRQUOTA" | "GRPQUOTA" if solaris => true,
587             "PRIO_MIN" | "PRIO_MAX" if solaris => true,
588 
589             // These are defined for Solaris 11, but the crate is tested on illumos, where they are currently not defined
590             "EADI" | "PORT_SOURCE_POSTWAIT" | "PORT_SOURCE_SIGNAL" | "PTHREAD_STACK_MIN" => true,
591 
592             // These change all the time from release to release of linux
593             // distros, let's just not bother trying to verify them. They
594             // shouldn't be used in code anyway...
595             "AF_MAX" | "PF_MAX" => true,
596 
597             _ => false,
598         }
599     });
600 
601     cfg.skip_fn(move |name| {
602         // skip those that are manually verified
603         match name {
604             "execv" |       // crazy stuff with const/mut
605             "execve" |
606             "execvp" |
607             "execvpe" |
608             "fexecve" => true,
609 
610             "getrlimit" | "getrlimit64" |    // non-int in 1st arg
611             "setrlimit" | "setrlimit64" |    // non-int in 1st arg
612             "prlimit" | "prlimit64" |        // non-int in 2nd arg
613             "strerror_r" if linux => true,   // actually xpg-something-or-other
614 
615             // int vs uint. Sorry musl, your prototype declarations are "correct" in the sense that
616             // they match the interface defined by Linux verbatim, but they conflict with other
617             // send*/recv* syscalls
618             "sendmmsg" | "recvmmsg" if musl => true,
619 
620             // typed 2nd arg on linux and android
621             "gettimeofday" if linux || android || freebsd || openbsd || dragonfly => true,
622 
623             // not declared in newer android toolchains
624             "getdtablesize" if android => true,
625 
626             "dlerror" if android => true, // const-ness is added
627             "dladdr" if musl || solaris => true, // const-ness only added recently
628 
629             // OSX has 'struct tm *const' which we can't actually represent in
630             // Rust, but is close enough to *mut
631             "timegm" if apple => true,
632 
633             // OSX's daemon is deprecated in 10.5 so we'll get a warning (which
634             // we turn into an error) so just ignore it.
635             "daemon" if apple => true,
636 
637             // Deprecated on OSX
638             "sem_destroy" if apple => true,
639             "sem_init" if apple => true,
640 
641             // These functions presumably exist on netbsd but don't look like
642             // they're implemented on rumprun yet, just let them slide for now.
643             // Some of them look like they have headers but then don't have
644             // corresponding actual definitions either...
645             "shm_open" |
646             "shm_unlink" |
647             "syscall" |
648             "mq_open" |
649             "mq_close" |
650             "mq_getattr" |
651             "mq_notify" |
652             "mq_receive" |
653             "mq_send" |
654             "mq_setattr" |
655             "mq_timedreceive" |
656             "mq_timedsend" |
657             "mq_unlink" |
658             "ptrace" |
659             "sigaltstack" if rumprun => true,
660 
661             // There seems to be a small error in EGLIBC's eventfd.h header. The
662             // [underlying system call][1] always takes its first `count`
663             // argument as an `unsigned int`, but [EGLIBC's <sys/eventfd.h>
664             // header][2] declares it to take an `int`. [GLIBC's header][3]
665             // matches the kernel.
666             //
667             // EGLIBC is no longer actively developed, and Debian, the largest
668             // distribution that had been using it, switched back to GLIBC in
669             // April 2015. So effectively all Linux <sys/eventfd.h> headers will
670             // be using `unsigned int` soon.
671             //
672             // [1]: https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/fs/eventfd.c?id=refs/tags/v3.12.51#n397
673             // [2]: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/eglibc/trusty/view/head:/sysdeps/unix/sysv/linux/sys/eventfd.h
674             // [3]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sys/eventfd.h;h=6295f32e937e779e74318eb9d3bdbe76aef8a8f3;hb=4e42b5b8f89f0e288e68be7ad70f9525aebc2cff#l34
675             "eventfd" if linux => true,
676 
677             // The `uname` function in freebsd is now an inline wrapper that
678             // delegates to another, but the symbol still exists, so don't check
679             // the symbol.
680             "uname" if freebsd => true,
681 
682             // FIXME: need to upgrade FreeBSD version; see https://github.com/rust-lang/libc/issues/938
683             "setgrent" if freebsd => true,
684 
685             // aio_waitcomplete's return type changed between FreeBSD 10 and 11.
686             "aio_waitcomplete" if freebsd => true,
687 
688             // lio_listio confuses the checker, probably because one of its
689             // arguments is an array
690             "lio_listio" if freebsd => true,
691             "lio_listio" if musl => true,
692 
693             // Apparently the NDK doesn't have this defined on android, but
694             // it's in a header file?
695             "endpwent" if android => true,
696 
697 
698             // These are either unimplemented or optionally built into uClibc
699             // or "sysinfo", where it's defined but the structs in linux/sysinfo.h and sys/sysinfo.h
700             // clash so it can't be tested
701             "getxattr" | "lgetxattr" | "fgetxattr" | "setxattr" | "lsetxattr" | "fsetxattr" |
702             "listxattr" | "llistxattr" | "flistxattr" | "removexattr" | "lremovexattr" |
703             "fremovexattr" |
704             "backtrace" |
705             "sysinfo" | "newlocale" | "duplocale" | "freelocale" | "uselocale" |
706             "nl_langinfo_l" | "wcslen" | "wcstombs" if uclibc => true,
707 
708             // Apparently res_init exists on Android, but isn't defined in a header:
709             // https://mail.gnome.org/archives/commits-list/2013-May/msg01329.html
710             "res_init" if android => true,
711 
712             // On macOS and iOS, res_init is available, but requires linking with libresolv:
713             // http://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html
714             // See discussion for skipping here:
715             // https://github.com/rust-lang/libc/pull/585#discussion_r114561460
716             "res_init" if apple => true,
717 
718             // On Mac we don't use the default `close()`, instead using their $NOCANCEL variants.
719             "close" if apple => true,
720 
721             // Definition of those functions as changed since unified headers from NDK r14b
722             // These changes imply some API breaking changes but are still ABI compatible.
723             // We can wait for the next major release to be compliant with the new API.
724             // FIXME: unskip these for next major release
725             "strerror_r" | "madvise" | "msync" | "mprotect" | "recvfrom" | "getpriority" |
726             "setpriority" | "personality" if android || solaris => true,
727             // In Android 64 bits, these functions have been fixed since unified headers.
728             // Ignore these until next major version.
729             "bind" | "writev" | "readv" | "sendmsg" | "recvmsg" if android && (aarch64 || x86_64) => true,
730 
731             // signal is defined with sighandler_t, so ignore
732             "signal" if solaris => true,
733 
734             "cfmakeraw" | "cfsetspeed" if solaris => true,
735 
736             // FIXME: mincore is defined with caddr_t on Solaris.
737             "mincore" if solaris => true,
738 
739             _ => false,
740         }
741     });
742 
743     cfg.skip_fn_ptrcheck(move |name| {
744         match name {
745             // dllimport weirdness?
746             _ if windows => true,
747 
748             _ => false,
749         }
750     });
751 
752     cfg.skip_field_type(move |struct_, field| {
753         // This is a weird union, don't check the type.
754         (struct_ == "ifaddrs" && field == "ifa_ifu") ||
755         // sighandler_t type is super weird
756         (struct_ == "sigaction" && field == "sa_sigaction") ||
757         // __timeval type is a patch which doesn't exist in glibc
758         (linux && struct_ == "utmpx" && field == "ut_tv") ||
759         // sigval is actually a union, but we pretend it's a struct
760         (struct_ == "sigevent" && field == "sigev_value") ||
761         // aio_buf is "volatile void*" and Rust doesn't understand volatile
762         (struct_ == "aiocb" && field == "aio_buf") ||
763         // stack_t.ss_sp's type changed from FreeBSD 10 to 11 in svn r294930
764         (freebsd && struct_ == "stack_t" && field == "ss_sp") ||
765         // type siginfo_t.si_addr changed from OpenBSD 6.0 to 6.1
766         (openbsd && struct_ == "siginfo_t" && field == "si_addr") ||
767         // this one is an anonymous union
768         (linux && struct_ == "ff_effect" && field == "u")
769     });
770 
771     cfg.skip_field(move |struct_, field| {
772         // this is actually a union on linux, so we can't represent it well and
773         // just insert some padding.
774         (struct_ == "siginfo_t" && field == "_pad") ||
775         // musl names this __dummy1 but it's still there
776         (musl && struct_ == "glob_t" && field == "gl_flags") ||
777         // musl seems to define this as an *anonymous* bitfield
778         (musl && struct_ == "statvfs" && field == "__f_unused") ||
779         // sigev_notify_thread_id is actually part of a sigev_un union
780         (struct_ == "sigevent" && field == "sigev_notify_thread_id")
781     });
782 
783     cfg.fn_cname(move |name, cname| {
784         if windows {
785             cname.unwrap_or(name).to_string()
786         } else {
787             name.to_string()
788         }
789     });
790 
791     cfg.generate("../src/lib.rs", "main.rs");
792 
793     // On Linux or Android also generate another script for testing linux/fcntl declarations.
794     // These cannot be tested normally because including both `linux/fcntl.h` and `fcntl.h`
795     // fails on a lot of platforms.
796     let mut cfg = ctest::TestGenerator::new();
797     cfg.skip_type(|_| true)
798        .skip_fn(|_| true);
799     if android || linux {
800         // musl defines these directly in `fcntl.h`
801         if musl {
802             cfg.header("fcntl.h");
803         } else {
804             cfg.header("linux/fcntl.h");
805         }
806         if !musl {
807             cfg.header("net/if.h");
808             cfg.header("linux/if.h");
809         }
810         cfg.header("linux/quota.h");
811         cfg.header("asm/termbits.h");
812         cfg.skip_const(move |name| {
813             match name {
814                 "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false,
815                 "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => false,
816                 "QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1" if mips && linux => false,
817                 "BOTHER" => false,
818                 _ => true,
819             }
820         });
821         cfg.skip_struct(|s| {
822             s != "termios2"
823         });
824         cfg.type_name(move |ty, is_struct, is_union| {
825             match ty {
826                 t if is_struct => format!("struct {}", t),
827                 t if is_union => format!("union {}", t),
828                 t => t.to_string(),
829             }
830         });
831     } else {
832         cfg.skip_const(|_| true);
833         cfg.skip_struct(|_| true);
834     }
835     cfg.generate("../src/lib.rs", "linux_fcntl.rs");
836 }
837