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