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