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