blob: e0bd795bb0e52ff0f9d4e51b7a3ed0bab61220e3 [file] [log] [blame]
Alex Crichtonb5da7c02015-09-16 17:44:40 -07001#![deny(warnings)]
2
Alan Somers38cf5b12019-01-31 22:34:17 -07003extern crate cc;
Alex Crichtond11e9142015-09-15 23:28:52 -07004extern crate ctest;
Alex Crichton8e5f0cd2015-09-09 22:46:19 -07005
6use std::env;
Alex Crichton8e5f0cd2015-09-09 22:46:19 -07007
Alan Somers38cf5b12019-01-31 22:34:17 -07008#[cfg(unix)]
9fn do_cc() {
gnzlbg0a5484e2019-02-07 11:13:38 +010010 cc::Build::new().file("src/cmsg.c").compile("cmsg");
Alan Somers38cf5b12019-01-31 22:34:17 -070011}
12#[cfg(not(unix))]
gnzlbg0a5484e2019-02-07 11:13:38 +010013fn do_cc() {}
Alan Somers38cf5b12019-01-31 22:34:17 -070014
15fn do_ctest() {
Alex Crichtond11e9142015-09-15 23:28:52 -070016 let target = env::var("TARGET").unwrap();
Marco A L Barbosa92ce5182017-02-23 18:15:02 -030017 let aarch64 = target.contains("aarch64");
Marcin Mielniczuk2a597672017-07-22 09:37:22 +020018 let i686 = target.contains("i686");
Alex Crichton8dce9ad2015-12-03 11:44:14 -080019 let x86_64 = target.contains("x86_64");
Marco A L Barbosa343b7c12017-10-18 12:08:36 -020020 let x32 = target.ends_with("gnux32");
Alex Crichtond11e9142015-09-15 23:28:52 -070021 let windows = target.contains("windows");
22 let mingw = target.contains("windows-gnu");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -070023 let linux = target.contains("unknown-linux");
Alex Crichton1ff96102015-09-17 15:09:02 -070024 let android = target.contains("android");
Alex Crichtonbaef6112015-09-19 23:20:53 -070025 let apple = target.contains("apple");
Alex Crichton83f78df2018-07-31 14:13:30 -070026 let ios = target.contains("apple-ios");
Alex Crichton22b98de2017-08-26 20:39:46 -070027 let emscripten = target.contains("asm");
28 let musl = target.contains("musl") || emscripten;
Kelvin Ly9a835582017-04-20 02:34:50 -040029 let uclibc = target.contains("uclibc");
Alex Crichtona1b948e2015-09-18 11:54:32 -070030 let freebsd = target.contains("freebsd");
Michael Neumanna6a64d12016-02-20 13:34:01 +010031 let dragonfly = target.contains("dragonfly");
Alexander Polakov26974c72015-11-27 03:02:44 +030032 let mips = target.contains("mips");
Alex Crichton49d7bca2015-11-27 09:40:37 -080033 let netbsd = target.contains("netbsd");
Sébastien Mariec618f362015-12-21 17:26:41 +010034 let openbsd = target.contains("openbsd");
Alex Crichton49d7bca2015-11-27 09:40:37 -080035 let rumprun = target.contains("rumprun");
bgermannb3870b42017-11-18 14:57:54 +010036 let solaris = target.contains("solaris");
Tom Parker-Shemiltb7580372018-11-23 21:21:24 +000037 let cloudabi = target.contains("cloudabi");
Tom Parker-Shemiltd75fc9c2018-11-23 21:25:23 +000038 let redox = target.contains("redox");
Michael Neumanna6a64d12016-02-20 13:34:01 +010039 let bsdlike = freebsd || apple || netbsd || openbsd || dragonfly;
Alex Crichtond11e9142015-09-15 23:28:52 -070040 let mut cfg = ctest::TestGenerator::new();
Alex Crichton8e5f0cd2015-09-09 22:46:19 -070041
Tomasz Miąskoc4947bb2016-07-21 07:27:21 +020042 // Pull in extra goodies
Alex Crichton22b98de2017-08-26 20:39:46 -070043 if linux || android || emscripten {
Alex Crichtond11e9142015-09-15 23:28:52 -070044 cfg.define("_GNU_SOURCE", None);
Tomasz Miąskoc4947bb2016-07-21 07:27:21 +020045 } else if netbsd {
46 cfg.define("_NETBSD_SOURCE", Some("1"));
Jake McGinty0e3cf472018-04-22 15:09:20 -070047 } else if apple {
48 cfg.define("__APPLE_USE_RFC_3542", None);
Alex Crichton1ff96102015-09-17 15:09:02 -070049 } else if windows {
Alex Crichtond11e9142015-09-15 23:28:52 -070050 cfg.define("_WIN32_WINNT", Some("0x8000"));
bgermannb3870b42017-11-18 14:57:54 +010051 } else if solaris {
bgermann85680dc2017-11-18 22:03:14 +010052 cfg.define("_XOPEN_SOURCE", Some("700"));
53 cfg.define("__EXTENSIONS__", None);
54 cfg.define("_LCONV_C99", None);
Tom Parker-Shemilt9c6714e2018-11-20 23:50:37 +000055 } else if freebsd {
56 cfg.define("_WITH_GETLINE", None);
Alex Crichton0df7c102015-09-10 16:35:37 -070057 }
58
Alex Crichton094f44d2015-09-16 16:27:23 -070059 // Android doesn't actually have in_port_t but it's much easier if we
60 // provide one for us to test against
Alex Crichton1ff96102015-09-17 15:09:02 -070061 if android {
Alex Crichton094f44d2015-09-16 16:27:23 -070062 cfg.define("in_port_t", Some("uint16_t"));
63 }
64
Alex Crichtond11e9142015-09-15 23:28:52 -070065 cfg.header("errno.h")
gnzlbgaca32d92018-11-19 15:24:41 +010066 .header("fcntl.h")
67 .header("limits.h")
68 .header("locale.h")
69 .header("stddef.h")
70 .header("stdint.h")
71 .header("stdio.h")
72 .header("stdlib.h")
73 .header("sys/stat.h")
74 .header("sys/types.h")
75 .header("time.h")
76 .header("wchar.h");
Alex Crichtonac2bd852015-09-10 17:21:20 -070077
Alex Crichton1ff96102015-09-17 15:09:02 -070078 if windows {
Alex Crichtond11e9142015-09-15 23:28:52 -070079 cfg.header("winsock2.h"); // must be before windows.h
80
81 cfg.header("direct.h");
82 cfg.header("io.h");
83 cfg.header("sys/utime.h");
84 cfg.header("windows.h");
85 cfg.header("process.h");
86 cfg.header("ws2ipdef.h");
Mackenzie Clark313483b2018-12-16 16:23:53 -080087 cfg.header("signal.h");
Alex Crichtond11e9142015-09-15 23:28:52 -070088
89 if target.contains("gnu") {
90 cfg.header("ws2tcpip.h");
Alex Crichton310d6232015-09-10 10:56:31 -070091 }
Alex Crichtond11e9142015-09-15 23:28:52 -070092 } else {
Knight0e0fb682016-08-09 13:59:40 +080093 cfg.flag("-Wno-deprecated-declarations");
94
Alex Crichtond11e9142015-09-15 23:28:52 -070095 cfg.header("ctype.h");
96 cfg.header("dirent.h");
Sébastien Mariec618f362015-12-21 17:26:41 +010097 if openbsd {
98 cfg.header("sys/socket.h");
99 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700100 cfg.header("net/if.h");
Alex Crichton83f78df2018-07-31 14:13:30 -0700101 if !ios {
102 cfg.header("net/route.h");
103 cfg.header("net/if_arp.h");
104 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700105 cfg.header("netdb.h");
106 cfg.header("netinet/in.h");
107 cfg.header("netinet/ip.h");
108 cfg.header("netinet/tcp.h");
Nicolas Dusart9f5766f2017-07-07 11:58:11 +0200109 cfg.header("netinet/udp.h");
Jon Gjengsetef20ddb2017-04-26 22:39:52 -0400110 cfg.header("resolv.h");
Alex Crichtond11e9142015-09-15 23:28:52 -0700111 cfg.header("pthread.h");
Alex Crichton1ff96102015-09-17 15:09:02 -0700112 cfg.header("dlfcn.h");
Alex Crichtond11e9142015-09-15 23:28:52 -0700113 cfg.header("signal.h");
114 cfg.header("string.h");
115 cfg.header("sys/file.h");
116 cfg.header("sys/ioctl.h");
117 cfg.header("sys/mman.h");
118 cfg.header("sys/resource.h");
119 cfg.header("sys/socket.h");
SilverWingedSeraph6f170ef2017-09-12 12:33:10 -0500120 if linux && !musl {
SilverWingedSeraph121795e2017-09-12 09:09:13 -0500121 cfg.header("linux/if.h");
gnzlbgc099bb92018-01-19 12:11:14 +0100122 cfg.header("sys/auxv.h");
SilverWingedSeraph121795e2017-09-12 09:09:13 -0500123 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700124 cfg.header("sys/time.h");
125 cfg.header("sys/un.h");
126 cfg.header("sys/wait.h");
127 cfg.header("unistd.h");
128 cfg.header("utime.h");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700129 cfg.header("pwd.h");
130 cfg.header("grp.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800131 cfg.header("sys/utsname.h");
Alex Crichton83f78df2018-07-31 14:13:30 -0700132 if !solaris && !ios {
bgermannb3870b42017-11-18 14:57:54 +0100133 cfg.header("sys/ptrace.h");
134 }
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800135 cfg.header("sys/mount.h");
136 cfg.header("sys/uio.h");
137 cfg.header("sched.h");
138 cfg.header("termios.h");
David Henningsson9d2493e2015-12-25 22:06:44 +0100139 cfg.header("poll.h");
Raphael Cohn7fc09692016-05-05 15:41:21 +0100140 cfg.header("syslog.h");
Steven Fackler41699f72016-06-03 21:02:56 -0700141 cfg.header("semaphore.h");
Marco A L Barbosabad80ba2017-02-21 16:58:03 -0300142 cfg.header("sys/statvfs.h");
Andrew Salmon6fb7c902017-05-26 15:24:54 -0700143 cfg.header("sys/times.h");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700144 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700145
146 if android {
Marco A L Barbosa3ca6ad92017-04-19 11:04:14 -0300147 if !aarch64 && !x86_64 {
148 // time64_t is not define for aarch64 and x86_64
Marco A L Barbosa92ce5182017-02-23 18:15:02 -0300149 // If included it will generate the error 'Your time_t is already 64-bit'
150 cfg.header("time64.h");
151 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700152 cfg.header("arpa/inet.h");
A.J. Gardner24c84f12016-03-31 20:08:03 -0500153 cfg.header("xlocale.h");
Knighta6b283b2016-07-27 19:42:36 +0800154 cfg.header("utmp.h");
Bastian Köcher6a6dc862018-05-26 08:59:30 +0200155 cfg.header("ifaddrs.h");
Marcin Mielniczukb9166f42017-08-01 16:20:13 +0200156 if i686 || x86_64 {
157 cfg.header("sys/reg.h");
158 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700159 } else if !windows {
160 cfg.header("glob.h");
161 cfg.header("ifaddrs.h");
A.J. Gardner24c84f12016-03-31 20:08:03 -0500162 cfg.header("langinfo.h");
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800163
bgermannb3870b42017-11-18 14:57:54 +0100164 if !openbsd && !freebsd && !dragonfly && !solaris {
Sébastien Mariec618f362015-12-21 17:26:41 +0100165 cfg.header("sys/quota.h");
166 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700167
bgermannb3870b42017-11-18 14:57:54 +0100168 if !musl && !x32 && !solaris {
Alex Crichtona1b948e2015-09-18 11:54:32 -0700169 cfg.header("sys/sysctl.h");
Kelvin Ly26670c72017-04-21 18:20:02 -0400170 }
Marco A L Barbosa343b7c12017-10-18 12:08:36 -0200171
Kelvin Ly26670c72017-04-21 18:20:02 -0400172 if !musl && !uclibc {
Kelvin Ly9a835582017-04-20 02:34:50 -0400173 if !netbsd && !openbsd && !uclibc {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800174 cfg.header("execinfo.h");
175 }
Knighta6b283b2016-07-27 19:42:36 +0800176
177 if openbsd {
178 cfg.header("utmp.h");
179 } else {
180 cfg.header("utmpx.h");
181 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700182 }
183 }
184
Alex Crichtonbaef6112015-09-19 23:20:53 -0700185 if apple {
Alex Crichton4621a342018-01-25 16:19:35 -0800186 cfg.header("spawn.h");
Alex Crichtona1b948e2015-09-18 11:54:32 -0700187 cfg.header("mach-o/dyld.h");
188 cfg.header("mach/mach_time.h");
189 cfg.header("malloc/malloc.h");
Kamal Marhubi89a77002016-02-27 14:58:43 -0500190 cfg.header("util.h");
Vojtech Kral4ed612c2017-10-09 18:36:52 +0200191 cfg.header("xlocale.h");
Lee Bousfieldfdbfe8f2017-05-07 15:40:15 -0600192 cfg.header("sys/xattr.h");
Alex Crichton83f78df2018-07-31 14:13:30 -0700193 if target.starts_with("x86") && !ios {
Alex Crichtonbaef6112015-09-19 23:20:53 -0700194 cfg.header("crt_externs.h");
195 }
Jake McGinty0e3cf472018-04-22 15:09:20 -0700196 cfg.header("netinet/in.h");
gnzlbg53e47332018-02-02 17:07:12 +0100197 cfg.header("sys/ipc.h");
Craig M. Brandenburg6d22f542018-12-02 09:10:10 -0700198 cfg.header("sys/sem.h");
gnzlbg53e47332018-02-02 17:07:12 +0100199 cfg.header("sys/shm.h");
Alex Crichton83f78df2018-07-31 14:13:30 -0700200
201 if !ios {
202 cfg.header("sys/sys_domain.h");
203 cfg.header("net/if_utun.h");
204 cfg.header("net/bpf.h");
205 cfg.header("net/route.h");
206 cfg.header("netinet/if_ether.h");
207 cfg.header("sys/proc_info.h");
208 cfg.header("sys/kern_control.h");
209 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700210 }
211
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800212 if bsdlike {
213 cfg.header("sys/event.h");
luozijun789fd5e2017-12-12 11:24:00 +0800214 cfg.header("net/if_dl.h");
Kamal Marhubi9c4af102016-02-27 14:58:43 -0500215 if freebsd {
luozijun536b5cf2017-12-26 16:02:17 +0800216 cfg.header("net/bpf.h");
Kamal Marhubi9c4af102016-02-27 14:58:43 -0500217 cfg.header("libutil.h");
218 } else {
219 cfg.header("util.h");
220 }
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800221 }
222
Alex Crichton22b98de2017-08-26 20:39:46 -0700223 if linux || emscripten {
Kelsey Z586867d2018-01-11 20:15:51 +1300224 cfg.header("mntent.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800225 cfg.header("mqueue.h");
Philipp Matthias Schaefer7e3a1512016-02-22 20:11:01 +0100226 cfg.header("ucontext.h");
Kelvin Ly26670c72017-04-21 18:20:02 -0400227 if !uclibc {
228 // optionally included in uclibc
229 cfg.header("sys/xattr.h");
230 }
Alexander Polakov58501562015-12-14 02:09:45 +0300231 cfg.header("sys/ipc.h");
Andrew Salmonbc482022017-05-26 12:47:53 -0700232 cfg.header("sys/sem.h");
Alexander Schlarb75905652016-09-17 22:17:17 +0200233 cfg.header("sys/msg.h");
Alexander Polakov58501562015-12-14 02:09:45 +0300234 cfg.header("sys/shm.h");
Daniel McKenna6acbf872017-05-29 18:27:27 +0100235 cfg.header("sys/user.h");
slyrz340cbbf2017-09-09 13:02:29 +0200236 cfg.header("sys/timerfd.h");
Philipp Keller04d0b712016-09-27 07:19:17 +0200237 cfg.header("shadow.h");
Alex Crichton22b98de2017-08-26 20:39:46 -0700238 if !emscripten {
239 cfg.header("linux/input.h");
240 cfg.header("linux/falloc.h");
241 }
Andrew Salmon553c5dc2017-06-07 19:27:14 -0700242 if x86_64 {
243 cfg.header("sys/io.h");
244 }
Marcin Mielniczuk2a597672017-07-22 09:37:22 +0200245 if i686 || x86_64 {
Marcin Mielniczuk37b4e732017-07-21 21:55:47 +0200246 cfg.header("sys/reg.h");
247 }
Alexander Polakov30baed02015-12-01 15:29:05 +0300248 }
Bryant Mairs46933f02018-01-14 20:44:34 -0800249
Alex Crichton22b98de2017-08-26 20:39:46 -0700250 if linux || android || emscripten {
Alex Crichtona1b948e2015-09-18 11:54:32 -0700251 cfg.header("malloc.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800252 cfg.header("net/ethernet.h");
253 cfg.header("netpacket/packet.h");
254 cfg.header("sched.h");
255 cfg.header("sys/epoll.h");
256 cfg.header("sys/eventfd.h");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700257 cfg.header("sys/prctl.h");
Kamal Marhubi143358b2016-02-04 14:08:50 -0500258 cfg.header("sys/sendfile.h");
Bryant Mairs83ab9a32017-07-16 22:49:28 -0700259 cfg.header("sys/signalfd.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800260 cfg.header("sys/vfs.h");
Alex Crichton881ef9b2015-12-01 09:04:13 -0800261 cfg.header("sys/syscall.h");
Andrew Salmonc98b9f72017-06-07 16:26:42 -0700262 cfg.header("sys/personality.h");
263 cfg.header("sys/swap.h");
Nicolas Dusart4abc3ce2017-06-29 21:25:55 +0200264 cfg.header("pty.h");
Kelvin Ly9a835582017-04-20 02:34:50 -0400265 if !uclibc {
266 cfg.header("sys/sysinfo.h");
267 }
Sergey Bugaeva98c9832016-07-12 13:22:51 +0300268 cfg.header("sys/reboot.h");
Alex Crichton305cec32017-08-27 09:07:18 -0700269 if !emscripten {
Andrew Cannb02c6a32018-05-30 18:08:28 +0800270 cfg.header("linux/sockios.h");
Linus Färnstrand69ae3462018-02-22 14:52:46 +0100271 cfg.header("linux/netlink.h");
272 cfg.header("linux/genetlink.h");
Alex Crichton305cec32017-08-27 09:07:18 -0700273 cfg.header("linux/netfilter_ipv4.h");
Linus Färnstrand750fcf52018-02-25 22:41:50 +0100274 cfg.header("linux/netfilter_ipv6.h");
Joerg Thalheim8c241172017-10-16 17:12:16 +0100275 cfg.header("linux/fs.h");
Alex Crichton305cec32017-08-27 09:07:18 -0700276 }
Alexander Polakov420f2e42015-11-11 01:53:39 +0300277 if !musl {
Alex Crichton22b98de2017-08-26 20:39:46 -0700278 cfg.header("asm/mman.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800279 cfg.header("linux/magic.h");
Sergey Bugaeva98c9832016-07-12 13:22:51 +0300280 cfg.header("linux/reboot.h");
Linus Färnstrand4d5ed472018-01-30 14:30:21 +0100281 cfg.header("linux/netfilter/nf_tables.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800282
283 if !mips {
284 cfg.header("linux/quota.h");
285 }
Alexander Polakov420f2e42015-11-11 01:53:39 +0300286 }
Alex Crichton310d6232015-09-10 10:56:31 -0700287 }
neirac30927482018-01-11 15:25:00 +0000288 if solaris {
289 cfg.header("sys/epoll.h");
Linus Färnstrand4d5ed472018-01-30 14:30:21 +0100290 }
Alex Crichton310d6232015-09-10 10:56:31 -0700291
Jack Pappas787addf2017-09-18 21:41:34 -0400292 if linux || android {
Joerg Thalheim3406fe92017-10-12 17:41:17 +0100293 cfg.header("sys/fsuid.h");
Pascal Bachebe0feb2018-07-16 20:24:50 +0200294 cfg.header("linux/module.h");
Jörg Thalheim9f720f32017-12-19 09:11:33 +0000295 cfg.header("linux/seccomp.h");
luozijun5ea536a2017-12-25 07:55:58 +0800296 cfg.header("linux/if_ether.h");
luozijun0f4ae0b2018-02-04 21:39:40 +0800297 cfg.header("linux/if_tun.h");
Gerd Zellweger2f83a7a2018-10-24 10:02:26 -0700298 cfg.header("linux/net_tstamp.h");
Vincent Dagonneaudfb7c0c2019-02-04 09:11:21 +0100299 cfg.header("sys/inotify.h");
Vincent Dagonneaueb3e48c2019-01-28 19:41:29 +0100300
Jack Pappas787addf2017-09-18 21:41:34 -0400301 // DCCP support
302 if !uclibc && !musl && !emscripten {
303 cfg.header("linux/dccp.h");
304 }
Bryant Mairsc0935ac2017-11-05 13:13:35 -0800305
306 if !musl || mips {
307 cfg.header("linux/memfd.h");
308 }
Jack Pappas787addf2017-09-18 21:41:34 -0400309 }
310
Marco A L Barbosaae496262017-11-01 18:41:58 -0200311 if linux {
312 cfg.header("linux/random.h");
Steven Fackler8f7839f2017-11-10 19:58:04 -0800313 cfg.header("elf.h");
314 cfg.header("link.h");
Alex Crichton4621a342018-01-25 16:19:35 -0800315 cfg.header("spawn.h");
Marco A L Barbosaae496262017-11-01 18:41:58 -0200316 }
317
Alex Crichtona1b948e2015-09-18 11:54:32 -0700318 if freebsd {
Alan Somers831ca992017-12-13 20:49:17 -0700319 cfg.header("mqueue.h");
Alex Crichtona1b948e2015-09-18 11:54:32 -0700320 cfg.header("pthread_np.h");
Alexander Polakov26974c72015-11-27 03:02:44 +0300321 cfg.header("sched.h");
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800322 cfg.header("ufs/ufs/quota.h");
Alan Somerscd35cda2018-10-30 14:04:04 -0600323 cfg.header("sys/extattr.h");
Ryan Moeller7c037112017-02-21 00:41:12 +0000324 cfg.header("sys/jail.h");
superriva21226162017-03-28 12:30:53 +0300325 cfg.header("sys/ipc.h");
326 cfg.header("sys/msg.h");
327 cfg.header("sys/shm.h");
Greg V6725fd62018-01-04 02:40:12 +0300328 cfg.header("sys/procdesc.h");
Greg Vc13302d2018-01-22 19:44:59 +0300329 cfg.header("sys/rtprio.h");
Bryan Drewery92d50c92018-02-26 16:36:13 -0800330 cfg.header("spawn.h");
Alex Crichtona1b948e2015-09-18 11:54:32 -0700331 }
332
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800333 if netbsd {
Alan Somers831ca992017-12-13 20:49:17 -0700334 cfg.header("mqueue.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800335 cfg.header("ufs/ufs/quota.h");
336 cfg.header("ufs/ufs/quota1.h");
Alan Somerscd35cda2018-10-30 14:04:04 -0600337 cfg.header("sys/extattr.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800338 cfg.header("sys/ioctl_compat.h");
Jack Pappas787addf2017-09-18 21:41:34 -0400339
340 // DCCP support
341 cfg.header("netinet/dccp.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800342 }
343
Sébastien Mariec618f362015-12-21 17:26:41 +0100344 if openbsd {
345 cfg.header("ufs/ufs/quota.h");
Sébastien Mariec618f362015-12-21 17:26:41 +0100346 cfg.header("pthread_np.h");
347 cfg.header("sys/syscall.h");
348 }
349
Michael Neumanna6a64d12016-02-20 13:34:01 +0100350 if dragonfly {
Alan Somers831ca992017-12-13 20:49:17 -0700351 cfg.header("mqueue.h");
Michael Neumanna6a64d12016-02-20 13:34:01 +0100352 cfg.header("ufs/ufs/quota.h");
353 cfg.header("pthread_np.h");
Greg Vc13302d2018-01-22 19:44:59 +0300354 cfg.header("sys/rtprio.h");
Michael Neumanna6a64d12016-02-20 13:34:01 +0100355 }
356
bgermannb3870b42017-11-18 14:57:54 +0100357 if solaris {
358 cfg.header("port.h");
359 cfg.header("ucontext.h");
360 cfg.header("sys/filio.h");
361 cfg.header("sys/loadavg.h");
362 }
363
Alex Crichton22b98de2017-08-26 20:39:46 -0700364 if linux || freebsd || dragonfly || netbsd || apple || emscripten {
Kelvin Ly9a835582017-04-20 02:34:50 -0400365 if !uclibc {
366 cfg.header("aio.h");
367 }
Alan Somers4ec884a2016-11-13 08:07:45 -0700368 }
369
Tom Parker-Shemiltd75fc9c2018-11-23 21:25:23 +0000370 if cloudabi || redox {
Tom Parker-Shemiltb7580372018-11-23 21:21:24 +0000371 cfg.header("strings.h");
372 }
373
alesharik5ec86992018-07-13 02:06:08 +0300374 cfg.type_name(move |ty, is_struct, is_union| {
Alex Crichton310d6232015-09-10 10:56:31 -0700375 match ty {
Alex Crichton31504842015-09-10 23:43:41 -0700376 // Just pass all these through, no need for a "struct" prefix
gnzlbg5c1a6b82018-11-21 20:34:50 +0100377 "FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr"
378 | "Elf64_Phdr" | "Elf32_Shdr" | "Elf64_Shdr" | "Elf32_Sym"
379 | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr"
380 | "Elf64_Chdr" => ty.to_string(),
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700381
382 // Fixup a few types on windows that don't actually exist.
383 "time64_t" if windows => "__time64_t".to_string(),
384 "ssize_t" if windows => "SSIZE_T".to_string(),
gnzlbg0a5484e2019-02-07 11:13:38 +0100385 // windows
Mackenzie Clarkaf199342018-12-17 18:46:48 -0800386 "sighandler_t" if windows && !mingw => "_crt_signal_t".to_string(),
387 "sighandler_t" if windows && mingw => "__p_sig_fn_t".to_string(),
Alex Crichtonde9736d2015-09-17 15:47:44 -0700388 // OSX calls this something else
Alex Crichtona1b948e2015-09-18 11:54:32 -0700389 "sighandler_t" if bsdlike => "sig_t".to_string(),
Alex Crichtonde9736d2015-09-17 15:47:44 -0700390
gnzlbgaca32d92018-11-19 15:24:41 +0100391 t if is_union => format!("union {}", t),
alesharik5ec86992018-07-13 02:06:08 +0300392
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700393 t if t.ends_with("_t") => t.to_string(),
Alex Crichton310d6232015-09-10 10:56:31 -0700394
Alex Crichton31504842015-09-10 23:43:41 -0700395 // Windows uppercase structs don't have `struct` in front, there's a
396 // few special cases for windows, and then otherwise put `struct` in
397 // front of everything.
Alex Crichtond11e9142015-09-15 23:28:52 -0700398 t if is_struct => {
Alex Crichton13a6f2d2015-09-10 18:10:58 -0700399 if windows && ty.chars().next().unwrap().is_uppercase() {
400 t.to_string()
401 } else if windows && t == "stat" {
402 "struct __stat64".to_string()
Alex Crichton7da9b102015-09-10 20:57:14 -0700403 } else if windows && t == "utimbuf" {
404 "struct __utimbuf64".to_string()
Alex Crichton13a6f2d2015-09-10 18:10:58 -0700405 } else {
406 format!("struct {}", t)
407 }
408 }
Alex Crichton310d6232015-09-10 10:56:31 -0700409
410 t => t.to_string(),
411 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700412 });
Alex Crichton310d6232015-09-10 10:56:31 -0700413
Alex Crichtond11e9142015-09-15 23:28:52 -0700414 let target2 = target.clone();
415 cfg.field_name(move |struct_, field| {
Alex Crichton310d6232015-09-10 10:56:31 -0700416 match field {
gnzlbg5c1a6b82018-11-21 20:34:50 +0100417 "st_birthtime" if openbsd && struct_ == "stat" => {
418 "__st_birthtime".to_string()
419 }
420 "st_birthtime_nsec" if openbsd && struct_ == "stat" => {
421 "__st_birthtimensec".to_string()
422 }
Alex Crichton31504842015-09-10 23:43:41 -0700423 // Our stat *_nsec fields normally don't actually exist but are part
424 // of a timeval struct
Alex Crichton74825222015-10-29 17:36:55 -0700425 s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
Alex Crichtonbaef6112015-09-19 23:20:53 -0700426 if target2.contains("apple") {
Alex Crichton310d6232015-09-10 10:56:31 -0700427 s.replace("_nsec", "spec.tv_nsec")
Alex Crichtond11e9142015-09-15 23:28:52 -0700428 } else if target2.contains("android") {
Alex Crichtond3d77922015-09-11 17:03:39 -0700429 s.to_string()
Alex Crichton310d6232015-09-10 10:56:31 -0700430 } else {
431 s.replace("e_nsec", ".tv_nsec")
432 }
433 }
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800434 "u64" if struct_ == "epoll_event" => "data.u64".to_string(),
gnzlbgaca32d92018-11-19 15:24:41 +0100435 "type_"
436 if (linux || freebsd || dragonfly)
437 && (struct_ == "input_event"
438 || struct_ == "input_mask"
439 || struct_ == "ff_effect"
440 || struct_ == "rtprio") =>
441 {
442 "type".to_string()
443 }
Alex Crichton310d6232015-09-10 10:56:31 -0700444 s => s.to_string(),
445 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700446 });
Alex Crichton310d6232015-09-10 10:56:31 -0700447
Alex Crichtond11e9142015-09-15 23:28:52 -0700448 cfg.skip_type(move |ty| {
Alex Crichton310d6232015-09-10 10:56:31 -0700449 match ty {
Alex Crichtond3d77922015-09-11 17:03:39 -0700450 // sighandler_t is crazy across platforms
Alex Crichtond11e9142015-09-15 23:28:52 -0700451 "sighandler_t" => true,
Alex Crichtond3d77922015-09-11 17:03:39 -0700452
gnzlbgaca32d92018-11-19 15:24:41 +0100453 _ => false,
Alex Crichton310d6232015-09-10 10:56:31 -0700454 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700455 });
Alex Crichton16083062015-09-09 22:59:24 -0700456
Alexander Polakov420f2e42015-11-11 01:53:39 +0300457 cfg.skip_struct(move |ty| {
458 match ty {
459 "sockaddr_nl" => musl,
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800460
Knight866c9e42016-08-09 14:01:33 +0800461 // On Linux, the type of `ut_tv` field of `struct utmpx`
462 // can be an anonymous struct, so an extra struct,
463 // which is absent in glibc, has to be defined.
464 "__timeval" if linux => true,
465
Alex Crichton91bd0792018-11-19 22:14:05 -0800466 // Fixed on feature=align with repr(packed(4))
gnzlbgdfee17f2018-04-15 14:50:00 +0200467 // Once repr_packed stabilizes we can fix this unconditionally
468 // and remove this check.
Craig M. Brandenburg6d22f542018-12-02 09:10:10 -0700469 "kevent" | "shmid_ds" | "semid_ds" if apple && x86_64 => true,
gnzlbgdfee17f2018-04-15 14:50:00 +0200470
Alan Somers9245e072016-11-13 13:52:34 -0700471 // This is actually a union, not a struct
472 "sigval" => true,
473
Mateusz Sieczko60d93222017-06-13 17:26:14 +0200474 // Linux kernel headers used on musl are too old to have this
475 // definition. Because it's tested on other Linux targets, skip it.
476 "input_mask" if musl => true,
477
Nicolas Dusart4abc3ce2017-06-29 21:25:55 +0200478 // These structs have changed since unified headers in NDK r14b.
479 // `st_atime` and `st_atime_nsec` have changed sign.
480 // FIXME: unskip it for next major release
481 "stat" | "stat64" if android => true,
482
Bryant Mairs6d55c242017-10-18 18:55:41 -0700483 // These are tested as part of the linux_fcntl tests since there are
484 // header conflicts when including them with all the other structs.
485 "termios2" => true,
486
Alex Crichton83f78df2018-07-31 14:13:30 -0700487 // Present on historical versions of iOS but missing in more recent
488 // SDKs
gnzlbg5c1a6b82018-11-21 20:34:50 +0100489 "bpf_hdr" | "proc_taskinfo" | "proc_taskallinfo"
490 | "proc_bsdinfo" | "proc_threadinfo" | "sockaddr_inarp"
491 | "sockaddr_ctl" | "arphdr"
gnzlbgaca32d92018-11-19 15:24:41 +0100492 if ios =>
493 {
494 true
495 }
Alex Crichton83f78df2018-07-31 14:13:30 -0700496
gnzlbgaca32d92018-11-19 15:24:41 +0100497 _ => false,
Alexander Polakov420f2e42015-11-11 01:53:39 +0300498 }
499 });
500
Michael Neumanna6a64d12016-02-20 13:34:01 +0100501 cfg.skip_signededness(move |c| {
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700502 match c {
gnzlbg5c1a6b82018-11-21 20:34:50 +0100503 "LARGE_INTEGER"
504 | "mach_timebase_info_data_t"
505 | "float"
506 | "double" => true,
Michael Neumanna09fe712016-02-21 12:28:10 +0100507 // uuid_t is a struct, not an integer.
Michael Neumanna6a64d12016-02-20 13:34:01 +0100508 "uuid_t" if dragonfly => true,
Alex Crichtond11e9142015-09-15 23:28:52 -0700509 n if n.starts_with("pthread") => true,
Steven Fackler41699f72016-06-03 21:02:56 -0700510 // sem_t is a struct or pointer
Alan Somers831ca992017-12-13 20:49:17 -0700511 "sem_t" if openbsd || freebsd || dragonfly || netbsd => true,
512 // mqd_t is a pointer on FreeBSD and DragonFly
513 "mqd_t" if freebsd || dragonfly => true,
Alex Crichton18469182015-09-15 20:57:42 -0700514
Alex Crichton4621a342018-01-25 16:19:35 -0800515 // Just some typedefs on osx, no need to check their sign
gnzlbgaca32d92018-11-19 15:24:41 +0100516 "posix_spawnattr_t" | "posix_spawn_file_actions_t" => true,
Alex Crichton4621a342018-01-25 16:19:35 -0800517
Alex Crichton18469182015-09-15 20:57:42 -0700518 // windows-isms
Alex Crichtond11e9142015-09-15 23:28:52 -0700519 n if n.starts_with("P") => true,
520 n if n.starts_with("H") => true,
521 n if n.starts_with("LP") => true,
Mackenzie Clark2f25aaa2018-12-17 17:24:37 -0800522 "__p_sig_fn_t" if mingw => true,
Alex Crichtond11e9142015-09-15 23:28:52 -0700523 _ => false,
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700524 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700525 });
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700526
Alex Crichtond11e9142015-09-15 23:28:52 -0700527 cfg.skip_const(move |name| {
Alex Crichton31504842015-09-10 23:43:41 -0700528 match name {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700529 // Apparently these don't exist in mingw headers?
gnzlbgaca32d92018-11-19 15:24:41 +0100530 "MEM_RESET_UNDO"
531 | "FILE_ATTRIBUTE_NO_SCRUB_DATA"
532 | "FILE_ATTRIBUTE_INTEGRITY_STREAM"
533 | "ERROR_NOTHING_TO_TERMINATE"
534 if mingw =>
535 {
536 true
537 }
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700538
gnzlbgaca32d92018-11-19 15:24:41 +0100539 "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness
540 "SIGUNUSED" => true, // removed in glibc 2.26
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700541
Alex Crichton15b83c22015-09-17 17:25:52 -0700542 // types on musl are defined a little differently
Alex Crichton3a572fd2015-10-29 16:52:25 -0700543 n if musl && n.contains("__SIZEOF_PTHREAD") => true,
Alex Crichton15b83c22015-09-17 17:25:52 -0700544
Alex Crichton74825222015-10-29 17:36:55 -0700545 // Skip constants not defined in MUSL but just passed down to the
546 // kernel regardless
gnzlbg5c1a6b82018-11-21 20:34:50 +0100547 "RLIMIT_NLIMITS"
548 | "TCP_COOKIE_TRANSACTIONS"
549 | "RLIMIT_RTTIME"
550 | "MSG_COPY"
551 if musl =>
552 {
gnzlbgaca32d92018-11-19 15:24:41 +0100553 true
554 }
Alexander Polakov26974c72015-11-27 03:02:44 +0300555 // work around super old mips toolchain
Alexander Polakov58501562015-12-14 02:09:45 +0300556 "SCHED_IDLE" | "SHM_NORESERVE" => mips,
Alex Crichton74825222015-10-29 17:36:55 -0700557
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800558 // weird signed extension or something like that?
559 "MS_NOUSER" => true,
NODA, Kai4d1efd92016-04-03 21:53:49 +0800560 "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800561
562 // These OSX constants are flagged as deprecated
gnzlbgaca32d92018-11-19 15:24:41 +0100563 "NOTE_EXIT_REPARENTED" | "NOTE_REAP" if apple => true,
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800564
Alan Somers9860c292016-11-13 08:45:59 -0700565 // These constants were removed in FreeBSD 11 (svn r273250) but will
566 // still be accepted and ignored at runtime.
gnzlbgaca32d92018-11-19 15:24:41 +0100567 "MAP_RENAME" | "MAP_NORESERVE" if freebsd => true,
Alan Somers9860c292016-11-13 08:45:59 -0700568
569 // These constants were removed in FreeBSD 11 (svn r262489),
570 // and they've never had any legitimate use outside of the
571 // base system anyway.
gnzlbg5c1a6b82018-11-21 20:34:50 +0100572 "CTL_MAXID" | "KERN_MAXID" | "HW_MAXID" | "NET_MAXID"
573 | "USER_MAXID"
574 if freebsd =>
575 {
576 true
577 }
Alan Somers9860c292016-11-13 08:45:59 -0700578
Greg V2aeb3822018-01-10 22:59:38 +0300579 // These constants were added in FreeBSD 11
gnzlbg5c1a6b82018-11-21 20:34:50 +0100580 "EVFILT_PROCDESC" | "EVFILT_SENDFILE" | "EVFILT_EMPTY"
581 | "PD_CLOEXEC" | "PD_ALLOWED_AT_FORK"
gnzlbgaca32d92018-11-19 15:24:41 +0100582 if freebsd =>
583 {
584 true
585 }
Greg V2aeb3822018-01-10 22:59:38 +0300586
Andrew Morrow96ee7bf2018-05-16 22:26:14 -0600587 // These constants were added in FreeBSD 12
gnzlbgaca32d92018-11-19 15:24:41 +0100588 "SF_USER_READAHEAD" | "SO_REUSEPORT_LB" if freebsd => true,
Andrew Morrow96ee7bf2018-05-16 22:26:14 -0600589
Kevin Brothaler7fbff3a2017-01-16 12:49:49 -0400590 // These OSX constants are removed in Sierra.
591 // https://developer.apple.com/library/content/releasenotes/General/APIDiffsMacOS10_12/Swift/Darwin.html
592 "KERN_KDENABLE_BG_TRACE" if apple => true,
593 "KERN_KDDISABLE_BG_TRACE" if apple => true,
594
Wesley Moore58c772b2017-08-03 18:10:21 +1000595 // These constants were removed in OpenBSD 6 (https://git.io/v7gBO
596 // https://git.io/v7gBq)
gnzlbgaca32d92018-11-19 15:24:41 +0100597 "KERN_USERMOUNT" | "KERN_ARND" if openbsd => true,
Wesley Moore58c772b2017-08-03 18:10:21 +1000598
Kelvin Lyc0bec432017-05-06 02:49:54 -0400599 // These are either unimplemented or optionally built into uClibc
gnzlbgaca32d92018-11-19 15:24:41 +0100600 "LC_CTYPE_MASK"
601 | "LC_NUMERIC_MASK"
602 | "LC_TIME_MASK"
603 | "LC_COLLATE_MASK"
604 | "LC_MONETARY_MASK"
605 | "LC_MESSAGES_MASK"
606 | "MADV_MERGEABLE"
607 | "MADV_UNMERGEABLE"
608 | "MADV_HWPOISON"
609 | "IPV6_ADD_MEMBERSHIP"
610 | "IPV6_DROP_MEMBERSHIP"
611 | "IPV6_MULTICAST_LOOP"
612 | "IPV6_V6ONLY"
613 | "MAP_STACK"
614 | "RTLD_DEEPBIND"
615 | "SOL_IPV6"
616 | "SOL_ICMPV6"
617 if uclibc =>
618 {
619 true
620 }
Kelvin Lyc0bec432017-05-06 02:49:54 -0400621
Gabrielf60ff2d2017-07-20 00:28:08 +0200622 // Musl uses old, patched kernel headers
gnzlbgaca32d92018-11-19 15:24:41 +0100623 "FALLOC_FL_COLLAPSE_RANGE"
624 | "FALLOC_FL_ZERO_RANGE"
625 | "FALLOC_FL_INSERT_RANGE"
626 | "FALLOC_FL_UNSHARE_RANGE"
627 | "RENAME_NOREPLACE"
628 | "RENAME_EXCHANGE"
629 | "RENAME_WHITEOUT"
630 if musl =>
631 {
632 true
633 }
Gabrielf60ff2d2017-07-20 00:28:08 +0200634
Marco A L Barbosaae496262017-11-01 18:41:58 -0200635 // Both android and musl use old kernel headers
636 // These are constants used in getrandom syscall
637 "GRND_NONBLOCK" | "GRND_RANDOM" if musl || android => true,
638
Lee Bousfield98889cf2017-05-15 09:15:53 -0600639 // Defined by libattr not libc on linux (hard to test).
640 // See constant definition for more details.
Mateusz Mikuła27043ec2018-07-04 18:43:48 +0200641 "ENOATTR" if android || linux => true,
Lee Bousfield98889cf2017-05-15 09:15:53 -0600642
Bryant Mairsf04b4422017-07-11 23:17:15 -0700643 // On mips*-unknown-linux-gnu* CMSPAR cannot be included with the set of headers we
644 // want to use here for testing. It's originally defined in asm/termbits.h, which is
645 // also included by asm/termios.h, but not the standard termios.h. There's no way to
646 // include both asm/termbits.h and termios.h and there's no way to include both
647 // asm/termios.h and ioctl.h (+ some other headers) because of redeclared types.
648 "CMSPAR" if mips && linux && !musl => true,
649
Bryant Mairsc9e6f552017-08-10 14:31:11 -0700650 // On mips Linux targets, MADV_SOFT_OFFLINE is currently missing, though it's been added but CI has too old
651 // of a Linux version. Since it exists on all other Linux targets, just ignore this for now and remove once
652 // it's been fixed in CI.
653 "MADV_SOFT_OFFLINE" if mips && linux => true,
654
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700655 // These constants are tested in a separate test program generated below because there
656 // are header conflicts if we try to include the headers that define them here.
657 "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => true,
gnzlbg5c1a6b82018-11-21 20:34:50 +0100658 "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW"
659 | "F_SEAL_WRITE" => true,
660 "QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1"
661 if mips && linux =>
662 {
663 true
664 } // Only on MIPS
Bryant Mairs12cfa1e2017-10-18 18:26:59 -0700665 "BOTHER" => true,
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700666
Bryant Mairsfa81ab32017-11-06 18:45:30 -0800667 "MFD_CLOEXEC" | "MFD_ALLOW_SEALING" if !mips && musl => true,
Tobias Klauserdf277e22018-12-12 16:46:41 +0100668 // MFD_HUGETLB is not available in some older libc versions on the CI builders. On the
669 // x86_64 and i686 builders it seems to be available for all targets, so at least test
670 // it there.
gnzlbg0a5484e2019-02-07 11:13:38 +0100671 "MFD_HUGETLB"
672 if !(x86_64 || i686) || musl || (x86_64 && android) =>
673 {
674 true
675 }
bgermannb3870b42017-11-18 14:57:54 +0100676
gnzlbg5c1a6b82018-11-21 20:34:50 +0100677 "DT_FIFO" | "DT_CHR" | "DT_DIR" | "DT_BLK" | "DT_REG"
678 | "DT_LNK" | "DT_SOCK"
gnzlbgaca32d92018-11-19 15:24:41 +0100679 if solaris =>
680 {
681 true
682 }
bgermannb3870b42017-11-18 14:57:54 +0100683 "USRQUOTA" | "GRPQUOTA" if solaris => true,
684 "PRIO_MIN" | "PRIO_MAX" if solaris => true,
685
686 // These are defined for Solaris 11, but the crate is tested on illumos, where they are currently not defined
gnzlbg5c1a6b82018-11-21 20:34:50 +0100687 "EADI"
688 | "PORT_SOURCE_POSTWAIT"
689 | "PORT_SOURCE_SIGNAL"
690 | "PTHREAD_STACK_MIN" => true,
bgermannb3870b42017-11-18 14:57:54 +0100691
Alex Crichton1f29ac32018-01-18 11:21:30 -0800692 // These change all the time from release to release of linux
693 // distros, let's just not bother trying to verify them. They
694 // shouldn't be used in code anyway...
695 "AF_MAX" | "PF_MAX" => true,
696
Tobias Klausercc229972018-12-04 17:36:48 +0100697 // These are not in a glibc release yet, only in kernel headers.
698 "AF_XDP" | "PF_XDP" | "SOL_XDP" if linux => true,
699
Alex Crichton83f78df2018-07-31 14:13:30 -0700700 // Present on historical versions of iOS, but now removed in more
701 // recent SDKs
gnzlbgaca32d92018-11-19 15:24:41 +0100702 "ARPOP_REQUEST"
703 | "ARPOP_REPLY"
704 | "ATF_COM"
705 | "ATF_PERM"
706 | "ATF_PUBL"
707 | "ATF_USETRAILERS"
708 | "AF_SYS_CONTROL"
709 | "SYSPROTO_EVENT"
710 | "PROC_PIDTASKALLINFO"
711 | "PROC_PIDTASKINFO"
712 | "PROC_PIDTHREADINFO"
713 | "UTUN_OPT_FLAGS"
714 | "UTUN_OPT_IFNAME"
715 | "BPF_ALIGNMENT"
716 | "SYSPROTO_CONTROL"
717 if ios =>
718 {
719 true
720 }
Alex Crichton83f78df2018-07-31 14:13:30 -0700721 s if ios && s.starts_with("RTF_") => true,
722 s if ios && s.starts_with("RTM_") => true,
723 s if ios && s.starts_with("RTA_") => true,
724 s if ios && s.starts_with("RTAX_") => true,
725 s if ios && s.starts_with("RTV_") => true,
726 s if ios && s.starts_with("DLT_") => true,
727
Alex Crichtond11e9142015-09-15 23:28:52 -0700728 _ => false,
Alex Crichton31504842015-09-10 23:43:41 -0700729 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700730 });
Alex Crichton31504842015-09-10 23:43:41 -0700731
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700732 cfg.skip_fn(move |name| {
Jim Blandyf8772f72016-01-12 16:28:07 -0800733 // skip those that are manually verified
Alex Crichton22378822015-09-10 19:59:23 -0700734 match name {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700735 "execv" | // crazy stuff with const/mut
Alex Crichton22378822015-09-10 19:59:23 -0700736 "execve" |
737 "execvp" |
Luca Bruno858d47c2017-07-21 15:13:44 +0000738 "execvpe" |
739 "fexecve" => true,
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700740
Alex Crichton74825222015-10-29 17:36:55 -0700741 "getrlimit" | "getrlimit64" | // non-int in 1st arg
742 "setrlimit" | "setrlimit64" | // non-int in 1st arg
Kamal Marhubi95695992016-04-27 14:29:19 -0400743 "prlimit" | "prlimit64" | // non-int in 2nd arg
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700744 "strerror_r" if linux => true, // actually xpg-something-or-other
745
NODA, Kai61c23fb2016-04-10 22:21:55 +0800746 // int vs uint. Sorry musl, your prototype declarations are "correct" in the sense that
747 // they match the interface defined by Linux verbatim, but they conflict with other
748 // send*/recv* syscalls
749 "sendmmsg" | "recvmmsg" if musl => true,
750
Alex Crichton1ff96102015-09-17 15:09:02 -0700751 // typed 2nd arg on linux and android
Michael Neumanna6a64d12016-02-20 13:34:01 +0100752 "gettimeofday" if linux || android || freebsd || openbsd || dragonfly => true,
Alex Crichton1ff96102015-09-17 15:09:02 -0700753
Alex Crichton881ef9b2015-12-01 09:04:13 -0800754 // not declared in newer android toolchains
755 "getdtablesize" if android => true,
756
Alex Crichton1ff96102015-09-17 15:09:02 -0700757 "dlerror" if android => true, // const-ness is added
bgermann85680dc2017-11-18 22:03:14 +0100758 "dladdr" if musl || solaris => true, // const-ness only added recently
Alex Crichton1ff96102015-09-17 15:09:02 -0700759
Alex Crichton568705e2015-11-03 14:18:52 -0800760 // OSX has 'struct tm *const' which we can't actually represent in
761 // Rust, but is close enough to *mut
762 "timegm" if apple => true,
763
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800764 // OSX's daemon is deprecated in 10.5 so we'll get a warning (which
765 // we turn into an error) so just ignore it.
766 "daemon" if apple => true,
767
Steven Fackler41699f72016-06-03 21:02:56 -0700768 // Deprecated on OSX
769 "sem_destroy" if apple => true,
770 "sem_init" if apple => true,
771
Alex Crichton49d7bca2015-11-27 09:40:37 -0800772 // These functions presumably exist on netbsd but don't look like
773 // they're implemented on rumprun yet, just let them slide for now.
774 // Some of them look like they have headers but then don't have
775 // corresponding actual definitions either...
Alex Crichton49d7bca2015-11-27 09:40:37 -0800776 "shm_open" |
777 "shm_unlink" |
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800778 "syscall" |
Alan Somers831ca992017-12-13 20:49:17 -0700779 "mq_open" |
780 "mq_close" |
781 "mq_getattr" |
782 "mq_notify" |
783 "mq_receive" |
784 "mq_send" |
785 "mq_setattr" |
786 "mq_timedreceive" |
787 "mq_timedsend" |
788 "mq_unlink" |
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800789 "ptrace" |
Alex Crichton49d7bca2015-11-27 09:40:37 -0800790 "sigaltstack" if rumprun => true,
791
Jim Blandyf8772f72016-01-12 16:28:07 -0800792 // There seems to be a small error in EGLIBC's eventfd.h header. The
793 // [underlying system call][1] always takes its first `count`
794 // argument as an `unsigned int`, but [EGLIBC's <sys/eventfd.h>
795 // header][2] declares it to take an `int`. [GLIBC's header][3]
796 // matches the kernel.
797 //
798 // EGLIBC is no longer actively developed, and Debian, the largest
799 // distribution that had been using it, switched back to GLIBC in
800 // April 2015. So effectively all Linux <sys/eventfd.h> headers will
801 // be using `unsigned int` soon.
802 //
803 // [1]: https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/fs/eventfd.c?id=refs/tags/v3.12.51#n397
804 // [2]: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/eglibc/trusty/view/head:/sysdeps/unix/sysv/linux/sys/eventfd.h
805 // [3]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sys/eventfd.h;h=6295f32e937e779e74318eb9d3bdbe76aef8a8f3;hb=4e42b5b8f89f0e288e68be7ad70f9525aebc2cff#l34
806 "eventfd" if linux => true,
807
Boris Faureda445b92016-11-05 20:16:50 +0100808 // The `uname` function in freebsd is now an inline wrapper that
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800809 // delegates to another, but the symbol still exists, so don't check
810 // the symbol.
811 "uname" if freebsd => true,
812
Fredrick Brennan6d959f12018-03-04 13:11:04 +0000813 // FIXME: need to upgrade FreeBSD version; see https://github.com/rust-lang/libc/issues/938
814 "setgrent" if freebsd => true,
815
Alan Somerse0ff0d62016-11-13 14:35:17 -0700816 // aio_waitcomplete's return type changed between FreeBSD 10 and 11.
817 "aio_waitcomplete" if freebsd => true,
818
Alan Somers9245e072016-11-13 13:52:34 -0700819 // lio_listio confuses the checker, probably because one of its
820 // arguments is an array
821 "lio_listio" if freebsd => true,
Alan Somerse0ff0d62016-11-13 14:35:17 -0700822 "lio_listio" if musl => true,
Alan Somers9245e072016-11-13 13:52:34 -0700823
Alex Crichtonc2842462016-11-16 14:12:12 -0800824 // Apparently the NDK doesn't have this defined on android, but
825 // it's in a header file?
826 "endpwent" if android => true,
827
Kelvin Ly96a83062017-05-04 22:08:48 -0400828
Kelvin Ly9a835582017-04-20 02:34:50 -0400829 // These are either unimplemented or optionally built into uClibc
830 // or "sysinfo", where it's defined but the structs in linux/sysinfo.h and sys/sysinfo.h
Kelvin Ly26670c72017-04-21 18:20:02 -0400831 // clash so it can't be tested
832 "getxattr" | "lgetxattr" | "fgetxattr" | "setxattr" | "lsetxattr" | "fsetxattr" |
833 "listxattr" | "llistxattr" | "flistxattr" | "removexattr" | "lremovexattr" |
834 "fremovexattr" |
835 "backtrace" |
836 "sysinfo" | "newlocale" | "duplocale" | "freelocale" | "uselocale" |
Kelvin Lyc14178c2017-04-26 23:01:05 -0400837 "nl_langinfo_l" | "wcslen" | "wcstombs" if uclibc => true,
Bryant Mairs9b9f36a2017-05-18 10:06:36 -0700838
Jon Gjengsetbe7e45f2017-05-03 15:57:29 -0400839 // Apparently res_init exists on Android, but isn't defined in a header:
Jon Gjengsetafebd982017-04-28 22:23:33 -0400840 // https://mail.gnome.org/archives/commits-list/2013-May/msg01329.html
841 "res_init" if android => true,
842
Jon Gjengsetbe7e45f2017-05-03 15:57:29 -0400843 // On macOS and iOS, res_init is available, but requires linking with libresolv:
844 // http://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html
845 // See discussion for skipping here:
846 // https://github.com/rust-lang/libc/pull/585#discussion_r114561460
847 "res_init" if apple => true,
848
Bryant Mairs9b9f36a2017-05-18 10:06:36 -0700849 // On Mac we don't use the default `close()`, instead using their $NOCANCEL variants.
850 "close" if apple => true,
851
Nicolas Dusart4abc3ce2017-06-29 21:25:55 +0200852 // Definition of those functions as changed since unified headers from NDK r14b
853 // These changes imply some API breaking changes but are still ABI compatible.
854 // We can wait for the next major release to be compliant with the new API.
855 // FIXME: unskip these for next major release
856 "strerror_r" | "madvise" | "msync" | "mprotect" | "recvfrom" | "getpriority" |
bgermann85680dc2017-11-18 22:03:14 +0100857 "setpriority" | "personality" if android || solaris => true,
Nicolas Dusart4abc3ce2017-06-29 21:25:55 +0200858 // In Android 64 bits, these functions have been fixed since unified headers.
859 // Ignore these until next major version.
860 "bind" | "writev" | "readv" | "sendmsg" | "recvmsg" if android && (aarch64 || x86_64) => true,
861
bgermannb3870b42017-11-18 14:57:54 +0100862 // signal is defined with sighandler_t, so ignore
863 "signal" if solaris => true,
864
865 "cfmakeraw" | "cfsetspeed" if solaris => true,
866
bgermann85680dc2017-11-18 22:03:14 +0100867 // FIXME: mincore is defined with caddr_t on Solaris.
868 "mincore" if solaris => true,
869
Alex Crichton83f78df2018-07-31 14:13:30 -0700870 // These were all included in historical versions of iOS but appear
871 // to be removed now
872 "system" | "ptrace" if ios => true,
873
Sébastien Marie1451f192019-01-13 09:06:05 +0100874 // Removed in OpenBSD 6.5
875 // https://marc.info/?l=openbsd-cvs&m=154723400730318
876 "mincore" if openbsd => true,
877
Alex Crichtond11e9142015-09-15 23:28:52 -0700878 _ => false,
Alex Crichton22378822015-09-10 19:59:23 -0700879 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700880 });
Alex Crichton22378822015-09-10 19:59:23 -0700881
Tobias Bucher8b1d8462018-09-05 09:48:49 +0200882 cfg.skip_static(move |name| {
883 match name {
884 // Internal constant, not declared in any headers.
885 "__progname" if android => true,
886 _ => false,
887 }
888 });
889
Alex Crichton881ef9b2015-12-01 09:04:13 -0800890 cfg.skip_fn_ptrcheck(move |name| {
891 match name {
Alex Crichton881ef9b2015-12-01 09:04:13 -0800892 // dllimport weirdness?
893 _ if windows => true,
894
895 _ => false,
896 }
897 });
Alex Crichtone0f4d102015-09-16 09:48:14 -0700898
Alex Crichton15b83c22015-09-17 17:25:52 -0700899 cfg.skip_field_type(move |struct_, field| {
Alex Crichtonf3b97482015-09-16 14:13:20 -0700900 // This is a weird union, don't check the type.
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700901 (struct_ == "ifaddrs" && field == "ifa_ifu") ||
902 // sighandler_t type is super weird
Knight866c9e42016-08-09 14:01:33 +0800903 (struct_ == "sigaction" && field == "sa_sigaction") ||
904 // __timeval type is a patch which doesn't exist in glibc
Alan Somers9245e072016-11-13 13:52:34 -0700905 (linux && struct_ == "utmpx" && field == "ut_tv") ||
906 // sigval is actually a union, but we pretend it's a struct
907 (struct_ == "sigevent" && field == "sigev_value") ||
908 // aio_buf is "volatile void*" and Rust doesn't understand volatile
Alan Somers9860c292016-11-13 08:45:59 -0700909 (struct_ == "aiocb" && field == "aio_buf") ||
910 // stack_t.ss_sp's type changed from FreeBSD 10 to 11 in svn r294930
Mateusz Sieczko60d93222017-06-13 17:26:14 +0200911 (freebsd && struct_ == "stack_t" && field == "ss_sp") ||
Sébastien Marie56701a72017-08-13 12:29:45 +0200912 // type siginfo_t.si_addr changed from OpenBSD 6.0 to 6.1
913 (openbsd && struct_ == "siginfo_t" && field == "si_addr") ||
Mateusz Sieczko60d93222017-06-13 17:26:14 +0200914 // this one is an anonymous union
915 (linux && struct_ == "ff_effect" && field == "u")
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700916 });
917
Alex Crichton15b83c22015-09-17 17:25:52 -0700918 cfg.skip_field(move |struct_, field| {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700919 // this is actually a union on linux, so we can't represent it well and
920 // just insert some padding.
Alex Crichton15b83c22015-09-17 17:25:52 -0700921 (struct_ == "siginfo_t" && field == "_pad") ||
922 // musl names this __dummy1 but it's still there
Brian Anderson773aab82015-12-29 20:00:29 +0000923 (musl && struct_ == "glob_t" && field == "gl_flags") ||
924 // musl seems to define this as an *anonymous* bitfield
Alan Somers9245e072016-11-13 13:52:34 -0700925 (musl && struct_ == "statvfs" && field == "__f_unused") ||
926 // sigev_notify_thread_id is actually part of a sigev_un union
Stephen Barber60ab3042018-11-05 16:02:26 -0800927 (struct_ == "sigevent" && field == "sigev_notify_thread_id") ||
928 // signalfd had SIGSYS fields added in Linux 4.18, but no libc release has them yet.
929 (struct_ == "signalfd_siginfo" && (field == "ssi_addr_lsb" ||
930 field == "_pad2" ||
931 field == "ssi_syscall" ||
932 field == "ssi_call_addr" ||
933 field == "ssi_arch"))
Alex Crichtonf3b97482015-09-16 14:13:20 -0700934 });
935
Alex Crichton49d7bca2015-11-27 09:40:37 -0800936 cfg.fn_cname(move |name, cname| {
Alex Crichton881ef9b2015-12-01 09:04:13 -0800937 if windows {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800938 cname.unwrap_or(name).to_string()
Alex Crichton0af5e232015-11-30 15:07:28 -0800939 } else {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800940 name.to_string()
Alex Crichton0af5e232015-11-30 15:07:28 -0800941 }
942 });
943
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700944 cfg.generate("../src/lib.rs", "main.rs");
945
946 // On Linux or Android also generate another script for testing linux/fcntl declarations.
947 // These cannot be tested normally because including both `linux/fcntl.h` and `fcntl.h`
948 // fails on a lot of platforms.
949 let mut cfg = ctest::TestGenerator::new();
950 cfg.skip_type(|_| true)
gnzlbgaca32d92018-11-19 15:24:41 +0100951 .skip_fn(|_| true)
952 .skip_static(|_| true);
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700953 if android || linux {
954 // musl defines these directly in `fcntl.h`
955 if musl {
956 cfg.header("fcntl.h");
957 } else {
958 cfg.header("linux/fcntl.h");
959 }
SilverWingedSeraph6f170ef2017-09-12 12:33:10 -0500960 if !musl {
961 cfg.header("net/if.h");
962 cfg.header("linux/if.h");
963 }
Bryant Mairsbd4c3482017-08-29 19:33:22 -0700964 cfg.header("linux/quota.h");
Bryant Mairs12cfa1e2017-10-18 18:26:59 -0700965 cfg.header("asm/termbits.h");
gnzlbgaca32d92018-11-19 15:24:41 +0100966 cfg.skip_const(move |name| match name {
967 "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false,
gnzlbg5c1a6b82018-11-21 20:34:50 +0100968 "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW"
969 | "F_SEAL_WRITE" => false,
970 "QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1"
971 if mips && linux =>
972 {
973 false
974 }
gnzlbgaca32d92018-11-19 15:24:41 +0100975 "BOTHER" => false,
976 _ => true,
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700977 });
gnzlbgaca32d92018-11-19 15:24:41 +0100978 cfg.skip_struct(|s| s != "termios2");
979 cfg.type_name(move |ty, is_struct, is_union| match ty {
980 t if is_struct => format!("struct {}", t),
981 t if is_union => format!("union {}", t),
982 t => t.to_string(),
Bryant Mairs6d55c242017-10-18 18:55:41 -0700983 });
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700984 } else {
985 cfg.skip_const(|_| true);
Bryant Mairs6d55c242017-10-18 18:55:41 -0700986 cfg.skip_struct(|_| true);
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700987 }
988 cfg.generate("../src/lib.rs", "linux_fcntl.rs");
Alex Crichton310d6232015-09-10 10:56:31 -0700989}
Alan Somers38cf5b12019-01-31 22:34:17 -0700990
991fn main() {
992 do_cc();
993 do_ctest();
994}