]>
git.proxmox.com Git - rustc.git/blob - src/liblibc/libc-test/build.rs
8 let target
= env
::var("TARGET").unwrap();
9 let aarch64
= target
.contains("aarch64");
10 let x86_64
= target
.contains("x86_64");
11 let windows
= target
.contains("windows");
12 let mingw
= target
.contains("windows-gnu");
13 let linux
= target
.contains("unknown-linux");
14 let android
= target
.contains("android");
15 let apple
= target
.contains("apple");
16 let musl
= target
.contains("musl");
17 let freebsd
= target
.contains("freebsd");
18 let dragonfly
= target
.contains("dragonfly");
19 let mips
= target
.contains("mips");
20 let netbsd
= target
.contains("netbsd");
21 let openbsd
= target
.contains("openbsd");
22 let rumprun
= target
.contains("rumprun");
23 let bsdlike
= freebsd
|| apple
|| netbsd
|| openbsd
|| dragonfly
;
24 let mut cfg
= ctest
::TestGenerator
::new();
26 // Pull in extra goodies
28 cfg
.define("_GNU_SOURCE", None
);
30 cfg
.define("_NETBSD_SOURCE", Some("1"));
32 cfg
.define("_WIN32_WINNT", Some("0x8000"));
35 // Android doesn't actually have in_port_t but it's much easier if we
36 // provide one for us to test against
38 cfg
.define("in_port_t", Some("uint16_t"));
50 .header("sys/types.h")
55 cfg
.header("winsock2.h"); // must be before windows.h
57 cfg
.header("direct.h");
59 cfg
.header("sys/utime.h");
60 cfg
.header("windows.h");
61 cfg
.header("process.h");
62 cfg
.header("ws2ipdef.h");
64 if target
.contains("gnu") {
65 cfg
.header("ws2tcpip.h");
68 cfg
.flag("-Wno-deprecated-declarations");
70 cfg
.header("ctype.h");
71 cfg
.header("dirent.h");
73 cfg
.header("sys/socket.h");
75 cfg
.header("net/if.h");
76 cfg
.header("netdb.h");
77 cfg
.header("netinet/in.h");
78 cfg
.header("netinet/ip.h");
79 cfg
.header("netinet/tcp.h");
80 cfg
.header("resolv.h");
81 cfg
.header("pthread.h");
82 cfg
.header("dlfcn.h");
83 cfg
.header("signal.h");
84 cfg
.header("string.h");
85 cfg
.header("sys/file.h");
86 cfg
.header("sys/ioctl.h");
87 cfg
.header("sys/mman.h");
88 cfg
.header("sys/resource.h");
89 cfg
.header("sys/socket.h");
90 cfg
.header("sys/time.h");
91 cfg
.header("sys/un.h");
92 cfg
.header("sys/wait.h");
93 cfg
.header("unistd.h");
94 cfg
.header("utime.h");
97 cfg
.header("sys/utsname.h");
98 cfg
.header("sys/ptrace.h");
99 cfg
.header("sys/mount.h");
100 cfg
.header("sys/uio.h");
101 cfg
.header("sched.h");
102 cfg
.header("termios.h");
103 cfg
.header("poll.h");
104 cfg
.header("syslog.h");
105 cfg
.header("semaphore.h");
106 cfg
.header("sys/statvfs.h");
110 if !aarch64
&& !x86_64
{
111 // time64_t is not define for aarch64 and x86_64
112 // If included it will generate the error 'Your time_t is already 64-bit'
113 cfg
.header("time64.h");
115 cfg
.header("arpa/inet.h");
116 cfg
.header("xlocale.h");
117 cfg
.header("utmp.h");
119 cfg
.header("glob.h");
120 cfg
.header("ifaddrs.h");
121 cfg
.header("langinfo.h");
123 if !openbsd
&& !freebsd
&& !dragonfly
{
124 cfg
.header("sys/quota.h");
128 cfg
.header("sys/sysctl.h");
130 if !netbsd
&& !openbsd
{
131 cfg
.header("execinfo.h");
132 cfg
.header("xlocale.h");
136 cfg
.header("utmp.h");
138 cfg
.header("utmpx.h");
144 cfg
.header("mach-o/dyld.h");
145 cfg
.header("mach/mach_time.h");
146 cfg
.header("malloc/malloc.h");
147 cfg
.header("util.h");
148 if target
.starts_with("x86") {
149 cfg
.header("crt_externs.h");
154 cfg
.header("sys/event.h");
157 cfg
.header("libutil.h");
159 cfg
.header("util.h");
164 cfg
.header("mqueue.h");
165 cfg
.header("ucontext.h");
166 cfg
.header("sys/signalfd.h");
167 cfg
.header("sys/xattr.h");
168 cfg
.header("sys/ipc.h");
169 cfg
.header("sys/msg.h");
170 cfg
.header("sys/shm.h");
171 cfg
.header("sys/fsuid.h");
173 cfg
.header("shadow.h");
176 if linux
|| android
{
177 cfg
.header("malloc.h");
178 cfg
.header("net/ethernet.h");
179 cfg
.header("netpacket/packet.h");
180 cfg
.header("sched.h");
181 cfg
.header("sys/epoll.h");
182 cfg
.header("sys/eventfd.h");
183 cfg
.header("sys/prctl.h");
184 cfg
.header("sys/sendfile.h");
185 cfg
.header("sys/vfs.h");
186 cfg
.header("sys/syscall.h");
187 cfg
.header("sys/sysinfo.h");
188 cfg
.header("sys/reboot.h");
190 cfg
.header("linux/netlink.h");
191 cfg
.header("linux/magic.h");
192 cfg
.header("linux/reboot.h");
195 cfg
.header("linux/quota.h");
201 cfg
.header("pthread_np.h");
202 cfg
.header("sched.h");
203 cfg
.header("ufs/ufs/quota.h");
204 cfg
.header("sys/jail.h");
205 cfg
.header("sys/ipc.h");
206 cfg
.header("sys/msg.h");
207 cfg
.header("sys/shm.h");
211 cfg
.header("ufs/ufs/quota.h");
212 cfg
.header("ufs/ufs/quota1.h");
213 cfg
.header("sys/ioctl_compat.h");
217 cfg
.header("ufs/ufs/quota.h");
218 cfg
.header("pthread_np.h");
219 cfg
.header("sys/syscall.h");
223 cfg
.header("ufs/ufs/quota.h");
224 cfg
.header("pthread_np.h");
225 cfg
.header("sys/ioctl_compat.h");
228 if linux
|| freebsd
|| dragonfly
|| netbsd
|| apple
{
232 cfg
.type_name(move |ty
, is_struct
| {
234 // Just pass all these through, no need for a "struct" prefix
238 "DIR" => ty
.to_string(),
240 // Fixup a few types on windows that don't actually exist.
241 "time64_t" if windows
=> "__time64_t".to_string(),
242 "ssize_t" if windows
=> "SSIZE_T".to_string(),
244 // OSX calls this something else
245 "sighandler_t" if bsdlike
=> "sig_t".to_string(),
247 t
if t
.ends_with("_t") => t
.to_string(),
249 // Windows uppercase structs don't have `struct` in front, there's a
250 // few special cases for windows, and then otherwise put `struct` in
251 // front of everything.
253 if windows
&& ty
.chars().next().unwrap().is_uppercase() {
255 } else if windows
&& t
== "stat" {
256 "struct __stat64".to_string()
257 } else if windows
&& t
== "utimbuf" {
258 "struct __utimbuf64".to_string()
260 format
!("struct {}", t
)
268 let target2
= target
.clone();
269 cfg
.field_name(move |struct_
, field
| {
271 "st_birthtime" if openbsd
&& struct_
== "stat" => "__st_birthtime".to_string(),
272 "st_birthtime_nsec" if openbsd
&& struct_
== "stat" => "__st_birthtimensec".to_string(),
273 // Our stat *_nsec fields normally don't actually exist but are part
274 // of a timeval struct
275 s
if s
.ends_with("_nsec") && struct_
.starts_with("stat") => {
276 if target2
.contains("apple") {
277 s
.replace("_nsec", "spec.tv_nsec")
278 } else if target2
.contains("android") {
281 s
.replace("e_nsec", ".tv_nsec")
284 "u64" if struct_
== "epoll_event" => "data.u64".to_string(),
289 cfg
.skip_type(move |ty
| {
291 // sighandler_t is crazy across platforms
292 "sighandler_t" => true,
298 cfg
.skip_struct(move |ty
| {
300 "sockaddr_nl" => musl
,
302 // On Linux, the type of `ut_tv` field of `struct utmpx`
303 // can be an anonymous struct, so an extra struct,
304 // which is absent in glibc, has to be defined.
305 "__timeval" if linux
=> true,
307 // The alignment of this is 4 on 64-bit OSX...
308 "kevent" if apple
&& x86_64
=> true,
310 // This is actually a union, not a struct
317 cfg
.skip_signededness(move |c
| {
320 "mach_timebase_info_data_t" |
323 // uuid_t is a struct, not an integer.
324 "uuid_t" if dragonfly
=> true,
325 n
if n
.starts_with("pthread") => true,
326 // sem_t is a struct or pointer
327 "sem_t" if openbsd
|| freebsd
|| dragonfly
|| rumprun
=> true,
330 n
if n
.starts_with("P") => true,
331 n
if n
.starts_with("H") => true,
332 n
if n
.starts_with("LP") => true,
337 cfg
.skip_const(move |name
| {
339 // Apparently these don't exist in mingw headers?
341 "FILE_ATTRIBUTE_NO_SCRUB_DATA" |
342 "FILE_ATTRIBUTE_INTEGRITY_STREAM" |
343 "ERROR_NOTHING_TO_TERMINATE" if mingw
=> true,
345 "SIG_IGN" => true, // sighandler_t weirdness
347 // types on musl are defined a little differently
348 n
if musl
&& n
.contains("__SIZEOF_PTHREAD") => true,
350 // Skip constants not defined in MUSL but just passed down to the
353 "TCP_COOKIE_TRANSACTIONS" |
355 "MSG_COPY" if musl
=> true,
356 // work around super old mips toolchain
357 "SCHED_IDLE" | "SHM_NORESERVE" => mips
,
359 // weird signed extension or something like that?
361 "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13
363 // These OSX constants are flagged as deprecated
364 "NOTE_EXIT_REPARENTED" |
365 "NOTE_REAP" if apple
=> true,
367 // The linux/quota.h header file which defines these can't be
368 // included with sys/quota.h currently on MIPS, so we don't include
369 // it and just ignore these constants
371 "QFMT_VFS_V0" if mips
&& linux
=> true,
373 // These constants were removed in FreeBSD 11 (svn r273250) but will
374 // still be accepted and ignored at runtime.
376 "MAP_NORESERVE" if freebsd
=> true,
378 // These constants were removed in FreeBSD 11 (svn r262489),
379 // and they've never had any legitimate use outside of the
380 // base system anyway.
384 "USER_MAXID" if freebsd
=> true,
386 // These OSX constants are removed in Sierra.
387 // https://developer.apple.com/library/content/releasenotes/General/APIDiffsMacOS10_12/Swift/Darwin.html
388 "KERN_KDENABLE_BG_TRACE" if apple
=> true,
389 "KERN_KDDISABLE_BG_TRACE" if apple
=> true,
395 cfg
.skip_fn(move |name
| {
396 // skip those that are manually verified
398 "execv" | // crazy stuff with const/mut
403 "getrlimit" | "getrlimit64" | // non-int in 1st arg
404 "setrlimit" | "setrlimit64" | // non-int in 1st arg
405 "prlimit" | "prlimit64" | // non-int in 2nd arg
406 "strerror_r" if linux
=> true, // actually xpg-something-or-other
408 // int vs uint. Sorry musl, your prototype declarations are "correct" in the sense that
409 // they match the interface defined by Linux verbatim, but they conflict with other
410 // send*/recv* syscalls
411 "sendmmsg" | "recvmmsg" if musl
=> true,
413 // typed 2nd arg on linux and android
414 "gettimeofday" if linux
|| android
|| freebsd
|| openbsd
|| dragonfly
=> true,
416 // not declared in newer android toolchains
417 "getdtablesize" if android
=> true,
419 "dlerror" if android
=> true, // const-ness is added
420 "dladdr" if musl
=> true, // const-ness only added recently
422 // OSX has 'struct tm *const' which we can't actually represent in
423 // Rust, but is close enough to *mut
424 "timegm" if apple
=> true,
426 // OSX's daemon is deprecated in 10.5 so we'll get a warning (which
427 // we turn into an error) so just ignore it.
428 "daemon" if apple
=> true,
431 "sem_destroy" if apple
=> true,
432 "sem_init" if apple
=> true,
434 // These functions presumably exist on netbsd but don't look like
435 // they're implemented on rumprun yet, just let them slide for now.
436 // Some of them look like they have headers but then don't have
437 // corresponding actual definitions either...
442 "sigaltstack" if rumprun
=> true,
444 // There seems to be a small error in EGLIBC's eventfd.h header. The
445 // [underlying system call][1] always takes its first `count`
446 // argument as an `unsigned int`, but [EGLIBC's <sys/eventfd.h>
447 // header][2] declares it to take an `int`. [GLIBC's header][3]
448 // matches the kernel.
450 // EGLIBC is no longer actively developed, and Debian, the largest
451 // distribution that had been using it, switched back to GLIBC in
452 // April 2015. So effectively all Linux <sys/eventfd.h> headers will
453 // be using `unsigned int` soon.
455 // [1]: https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/fs/eventfd.c?id=refs/tags/v3.12.51#n397
456 // [2]: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/eglibc/trusty/view/head:/sysdeps/unix/sysv/linux/sys/eventfd.h
457 // [3]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sys/eventfd.h;h=6295f32e937e779e74318eb9d3bdbe76aef8a8f3;hb=4e42b5b8f89f0e288e68be7ad70f9525aebc2cff#l34
458 "eventfd" if linux
=> true,
460 // The `uname` function in freebsd is now an inline wrapper that
461 // delegates to another, but the symbol still exists, so don't check
463 "uname" if freebsd
=> true,
465 // aio_waitcomplete's return type changed between FreeBSD 10 and 11.
466 "aio_waitcomplete" if freebsd
=> true,
468 // lio_listio confuses the checker, probably because one of its
469 // arguments is an array
470 "lio_listio" if freebsd
=> true,
471 "lio_listio" if musl
=> true,
473 // Apparently the NDK doesn't have this defined on android, but
474 // it's in a header file?
475 "endpwent" if android
=> true,
477 // Apparently res_init exists on Android, but isn't defined in a header:
478 // https://mail.gnome.org/archives/commits-list/2013-May/msg01329.html
479 "res_init" if android
=> true,
481 // On macOS and iOS, res_init is available, but requires linking with libresolv:
482 // http://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html
483 // See discussion for skipping here:
484 // https://github.com/rust-lang/libc/pull/585#discussion_r114561460
485 "res_init" if apple
=> true,
491 cfg
.skip_fn_ptrcheck(move |name
| {
493 // dllimport weirdness?
494 _
if windows
=> true,
500 cfg
.skip_field_type(move |struct_
, field
| {
501 // This is a weird union, don't check the type.
502 (struct_
== "ifaddrs" && field
== "ifa_ifu") ||
503 // sighandler_t type is super weird
504 (struct_
== "sigaction" && field
== "sa_sigaction") ||
505 // __timeval type is a patch which doesn't exist in glibc
506 (linux
&& struct_
== "utmpx" && field
== "ut_tv") ||
507 // sigval is actually a union, but we pretend it's a struct
508 (struct_
== "sigevent" && field
== "sigev_value") ||
509 // aio_buf is "volatile void*" and Rust doesn't understand volatile
510 (struct_
== "aiocb" && field
== "aio_buf") ||
511 // stack_t.ss_sp's type changed from FreeBSD 10 to 11 in svn r294930
512 (freebsd
&& struct_
== "stack_t" && field
== "ss_sp")
515 cfg
.skip_field(move |struct_
, field
| {
516 // this is actually a union on linux, so we can't represent it well and
517 // just insert some padding.
518 (struct_
== "siginfo_t" && field
== "_pad") ||
519 // musl names this __dummy1 but it's still there
520 (musl
&& struct_
== "glob_t" && field
== "gl_flags") ||
521 // musl seems to define this as an *anonymous* bitfield
522 (musl
&& struct_
== "statvfs" && field
== "__f_unused") ||
523 // sigev_notify_thread_id is actually part of a sigev_un union
524 (struct_
== "sigevent" && field
== "sigev_notify_thread_id")
527 cfg
.fn_cname(move |name
, cname
| {
529 cname
.unwrap_or(name
).to_string()
535 if env
::var("SKIP_COMPILE").is_ok() {
536 cfg
.generate_files("../src/lib.rs", "all.rs");
538 cfg
.generate("../src/lib.rs", "all.rs");