blob: 7e0928fe00a38e64c93717a546efde2e06bf31f8 [file] [log] [blame]
Alex Crichtonb5da7c02015-09-16 17:44:40 -07001#![deny(warnings)]
2
Alex Crichtond11e9142015-09-15 23:28:52 -07003extern crate ctest;
Alex Crichton8e5f0cd2015-09-09 22:46:19 -07004
5use std::env;
Alex Crichton8e5f0cd2015-09-09 22:46:19 -07006
Alex Crichtond11e9142015-09-15 23:28:52 -07007fn main() {
8 let target = env::var("TARGET").unwrap();
Marco A L Barbosa92ce5182017-02-23 18:15:02 -03009 let aarch64 = target.contains("aarch64");
Marcin Mielniczuk2a597672017-07-22 09:37:22 +020010 let i686 = target.contains("i686");
Alex Crichton8dce9ad2015-12-03 11:44:14 -080011 let x86_64 = target.contains("x86_64");
Marco A L Barbosa343b7c12017-10-18 12:08:36 -020012 let x32 = target.ends_with("gnux32");
Alex Crichtond11e9142015-09-15 23:28:52 -070013 let windows = target.contains("windows");
14 let mingw = target.contains("windows-gnu");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -070015 let linux = target.contains("unknown-linux");
Alex Crichton1ff96102015-09-17 15:09:02 -070016 let android = target.contains("android");
Alex Crichtonbaef6112015-09-19 23:20:53 -070017 let apple = target.contains("apple");
Alex Crichton83f78df2018-07-31 14:13:30 -070018 let ios = target.contains("apple-ios");
Alex Crichton22b98de2017-08-26 20:39:46 -070019 let emscripten = target.contains("asm");
20 let musl = target.contains("musl") || emscripten;
Kelvin Ly9a835582017-04-20 02:34:50 -040021 let uclibc = target.contains("uclibc");
Alex Crichtona1b948e2015-09-18 11:54:32 -070022 let freebsd = target.contains("freebsd");
Michael Neumanna6a64d12016-02-20 13:34:01 +010023 let dragonfly = target.contains("dragonfly");
Alexander Polakov26974c72015-11-27 03:02:44 +030024 let mips = target.contains("mips");
Alex Crichton49d7bca2015-11-27 09:40:37 -080025 let netbsd = target.contains("netbsd");
Sébastien Mariec618f362015-12-21 17:26:41 +010026 let openbsd = target.contains("openbsd");
Alex Crichton49d7bca2015-11-27 09:40:37 -080027 let rumprun = target.contains("rumprun");
bgermannb3870b42017-11-18 14:57:54 +010028 let solaris = target.contains("solaris");
Tom Parker-Shemiltb7580372018-11-23 21:21:24 +000029 let cloudabi = target.contains("cloudabi");
Tom Parker-Shemiltd75fc9c2018-11-23 21:25:23 +000030 let redox = target.contains("redox");
Michael Neumanna6a64d12016-02-20 13:34:01 +010031 let bsdlike = freebsd || apple || netbsd || openbsd || dragonfly;
Alex Crichtond11e9142015-09-15 23:28:52 -070032 let mut cfg = ctest::TestGenerator::new();
Alex Crichton8e5f0cd2015-09-09 22:46:19 -070033
Tomasz Miąskoc4947bb2016-07-21 07:27:21 +020034 // Pull in extra goodies
Alex Crichton22b98de2017-08-26 20:39:46 -070035 if linux || android || emscripten {
Alex Crichtond11e9142015-09-15 23:28:52 -070036 cfg.define("_GNU_SOURCE", None);
Tomasz Miąskoc4947bb2016-07-21 07:27:21 +020037 } else if netbsd {
38 cfg.define("_NETBSD_SOURCE", Some("1"));
Jake McGinty0e3cf472018-04-22 15:09:20 -070039 } else if apple {
40 cfg.define("__APPLE_USE_RFC_3542", None);
Alex Crichton1ff96102015-09-17 15:09:02 -070041 } else if windows {
Alex Crichtond11e9142015-09-15 23:28:52 -070042 cfg.define("_WIN32_WINNT", Some("0x8000"));
bgermannb3870b42017-11-18 14:57:54 +010043 } else if solaris {
bgermann85680dc2017-11-18 22:03:14 +010044 cfg.define("_XOPEN_SOURCE", Some("700"));
45 cfg.define("__EXTENSIONS__", None);
46 cfg.define("_LCONV_C99", None);
Tom Parker-Shemilt9c6714e2018-11-20 23:50:37 +000047 } else if freebsd {
48 cfg.define("_WITH_GETLINE", None);
Alex Crichton0df7c102015-09-10 16:35:37 -070049 }
50
Alex Crichton094f44d2015-09-16 16:27:23 -070051 // Android doesn't actually have in_port_t but it's much easier if we
52 // provide one for us to test against
Alex Crichton1ff96102015-09-17 15:09:02 -070053 if android {
Alex Crichton094f44d2015-09-16 16:27:23 -070054 cfg.define("in_port_t", Some("uint16_t"));
55 }
56
Alex Crichtond11e9142015-09-15 23:28:52 -070057 cfg.header("errno.h")
gnzlbgaca32d92018-11-19 15:24:41 +010058 .header("fcntl.h")
59 .header("limits.h")
60 .header("locale.h")
61 .header("stddef.h")
62 .header("stdint.h")
63 .header("stdio.h")
64 .header("stdlib.h")
65 .header("sys/stat.h")
66 .header("sys/types.h")
67 .header("time.h")
68 .header("wchar.h");
Alex Crichtonac2bd852015-09-10 17:21:20 -070069
Alex Crichton1ff96102015-09-17 15:09:02 -070070 if windows {
Alex Crichtond11e9142015-09-15 23:28:52 -070071 cfg.header("winsock2.h"); // must be before windows.h
72
73 cfg.header("direct.h");
74 cfg.header("io.h");
75 cfg.header("sys/utime.h");
76 cfg.header("windows.h");
77 cfg.header("process.h");
78 cfg.header("ws2ipdef.h");
79
80 if target.contains("gnu") {
81 cfg.header("ws2tcpip.h");
Alex Crichton310d6232015-09-10 10:56:31 -070082 }
Alex Crichtond11e9142015-09-15 23:28:52 -070083 } else {
Knight0e0fb682016-08-09 13:59:40 +080084 cfg.flag("-Wno-deprecated-declarations");
85
Alex Crichtond11e9142015-09-15 23:28:52 -070086 cfg.header("ctype.h");
87 cfg.header("dirent.h");
Sébastien Mariec618f362015-12-21 17:26:41 +010088 if openbsd {
89 cfg.header("sys/socket.h");
90 }
Alex Crichtond11e9142015-09-15 23:28:52 -070091 cfg.header("net/if.h");
Alex Crichton83f78df2018-07-31 14:13:30 -070092 if !ios {
93 cfg.header("net/route.h");
94 cfg.header("net/if_arp.h");
95 }
Alex Crichtond11e9142015-09-15 23:28:52 -070096 cfg.header("netdb.h");
97 cfg.header("netinet/in.h");
98 cfg.header("netinet/ip.h");
99 cfg.header("netinet/tcp.h");
Nicolas Dusart9f5766f2017-07-07 11:58:11 +0200100 cfg.header("netinet/udp.h");
Jon Gjengsetef20ddb2017-04-26 22:39:52 -0400101 cfg.header("resolv.h");
Alex Crichtond11e9142015-09-15 23:28:52 -0700102 cfg.header("pthread.h");
Alex Crichton1ff96102015-09-17 15:09:02 -0700103 cfg.header("dlfcn.h");
Alex Crichtond11e9142015-09-15 23:28:52 -0700104 cfg.header("signal.h");
105 cfg.header("string.h");
106 cfg.header("sys/file.h");
107 cfg.header("sys/ioctl.h");
108 cfg.header("sys/mman.h");
109 cfg.header("sys/resource.h");
110 cfg.header("sys/socket.h");
SilverWingedSeraph6f170ef2017-09-12 12:33:10 -0500111 if linux && !musl {
SilverWingedSeraph121795e2017-09-12 09:09:13 -0500112 cfg.header("linux/if.h");
gnzlbgc099bb92018-01-19 12:11:14 +0100113 cfg.header("sys/auxv.h");
SilverWingedSeraph121795e2017-09-12 09:09:13 -0500114 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700115 cfg.header("sys/time.h");
116 cfg.header("sys/un.h");
117 cfg.header("sys/wait.h");
118 cfg.header("unistd.h");
119 cfg.header("utime.h");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700120 cfg.header("pwd.h");
121 cfg.header("grp.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800122 cfg.header("sys/utsname.h");
Alex Crichton83f78df2018-07-31 14:13:30 -0700123 if !solaris && !ios {
bgermannb3870b42017-11-18 14:57:54 +0100124 cfg.header("sys/ptrace.h");
125 }
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800126 cfg.header("sys/mount.h");
127 cfg.header("sys/uio.h");
128 cfg.header("sched.h");
129 cfg.header("termios.h");
David Henningsson9d2493e2015-12-25 22:06:44 +0100130 cfg.header("poll.h");
Raphael Cohn7fc09692016-05-05 15:41:21 +0100131 cfg.header("syslog.h");
Steven Fackler41699f72016-06-03 21:02:56 -0700132 cfg.header("semaphore.h");
Marco A L Barbosabad80ba2017-02-21 16:58:03 -0300133 cfg.header("sys/statvfs.h");
Andrew Salmon6fb7c902017-05-26 15:24:54 -0700134 cfg.header("sys/times.h");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700135 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700136
137 if android {
Marco A L Barbosa3ca6ad92017-04-19 11:04:14 -0300138 if !aarch64 && !x86_64 {
139 // time64_t is not define for aarch64 and x86_64
Marco A L Barbosa92ce5182017-02-23 18:15:02 -0300140 // If included it will generate the error 'Your time_t is already 64-bit'
141 cfg.header("time64.h");
142 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700143 cfg.header("arpa/inet.h");
A.J. Gardner24c84f12016-03-31 20:08:03 -0500144 cfg.header("xlocale.h");
Knighta6b283b2016-07-27 19:42:36 +0800145 cfg.header("utmp.h");
Bastian Köcher6a6dc862018-05-26 08:59:30 +0200146 cfg.header("ifaddrs.h");
Marcin Mielniczukb9166f42017-08-01 16:20:13 +0200147 if i686 || x86_64 {
148 cfg.header("sys/reg.h");
149 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700150 } else if !windows {
151 cfg.header("glob.h");
152 cfg.header("ifaddrs.h");
A.J. Gardner24c84f12016-03-31 20:08:03 -0500153 cfg.header("langinfo.h");
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800154
bgermannb3870b42017-11-18 14:57:54 +0100155 if !openbsd && !freebsd && !dragonfly && !solaris {
Sébastien Mariec618f362015-12-21 17:26:41 +0100156 cfg.header("sys/quota.h");
157 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700158
bgermannb3870b42017-11-18 14:57:54 +0100159 if !musl && !x32 && !solaris {
Alex Crichtona1b948e2015-09-18 11:54:32 -0700160 cfg.header("sys/sysctl.h");
Kelvin Ly26670c72017-04-21 18:20:02 -0400161 }
Marco A L Barbosa343b7c12017-10-18 12:08:36 -0200162
Kelvin Ly26670c72017-04-21 18:20:02 -0400163 if !musl && !uclibc {
Kelvin Ly9a835582017-04-20 02:34:50 -0400164 if !netbsd && !openbsd && !uclibc {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800165 cfg.header("execinfo.h");
166 }
Knighta6b283b2016-07-27 19:42:36 +0800167
168 if openbsd {
169 cfg.header("utmp.h");
170 } else {
171 cfg.header("utmpx.h");
172 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700173 }
174 }
175
Alex Crichtonbaef6112015-09-19 23:20:53 -0700176 if apple {
Alex Crichton4621a342018-01-25 16:19:35 -0800177 cfg.header("spawn.h");
Alex Crichtona1b948e2015-09-18 11:54:32 -0700178 cfg.header("mach-o/dyld.h");
179 cfg.header("mach/mach_time.h");
180 cfg.header("malloc/malloc.h");
Kamal Marhubi89a77002016-02-27 14:58:43 -0500181 cfg.header("util.h");
Vojtech Kral4ed612c2017-10-09 18:36:52 +0200182 cfg.header("xlocale.h");
Lee Bousfieldfdbfe8f2017-05-07 15:40:15 -0600183 cfg.header("sys/xattr.h");
Alex Crichton83f78df2018-07-31 14:13:30 -0700184 if target.starts_with("x86") && !ios {
Alex Crichtonbaef6112015-09-19 23:20:53 -0700185 cfg.header("crt_externs.h");
186 }
Jake McGinty0e3cf472018-04-22 15:09:20 -0700187 cfg.header("netinet/in.h");
gnzlbg53e47332018-02-02 17:07:12 +0100188 cfg.header("sys/ipc.h");
189 cfg.header("sys/shm.h");
Alex Crichton83f78df2018-07-31 14:13:30 -0700190
191 if !ios {
192 cfg.header("sys/sys_domain.h");
193 cfg.header("net/if_utun.h");
194 cfg.header("net/bpf.h");
195 cfg.header("net/route.h");
196 cfg.header("netinet/if_ether.h");
197 cfg.header("sys/proc_info.h");
198 cfg.header("sys/kern_control.h");
199 }
Alex Crichtona1b948e2015-09-18 11:54:32 -0700200 }
201
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800202 if bsdlike {
203 cfg.header("sys/event.h");
luozijun789fd5e2017-12-12 11:24:00 +0800204 cfg.header("net/if_dl.h");
Kamal Marhubi9c4af102016-02-27 14:58:43 -0500205 if freebsd {
luozijun536b5cf2017-12-26 16:02:17 +0800206 cfg.header("net/bpf.h");
Kamal Marhubi9c4af102016-02-27 14:58:43 -0500207 cfg.header("libutil.h");
208 } else {
209 cfg.header("util.h");
210 }
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800211 }
212
Alex Crichton22b98de2017-08-26 20:39:46 -0700213 if linux || emscripten {
Kelsey Z586867d2018-01-11 20:15:51 +1300214 cfg.header("mntent.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800215 cfg.header("mqueue.h");
Philipp Matthias Schaefer7e3a1512016-02-22 20:11:01 +0100216 cfg.header("ucontext.h");
Kelvin Ly26670c72017-04-21 18:20:02 -0400217 if !uclibc {
218 // optionally included in uclibc
219 cfg.header("sys/xattr.h");
220 }
Alexander Polakov58501562015-12-14 02:09:45 +0300221 cfg.header("sys/ipc.h");
Andrew Salmonbc482022017-05-26 12:47:53 -0700222 cfg.header("sys/sem.h");
Alexander Schlarb75905652016-09-17 22:17:17 +0200223 cfg.header("sys/msg.h");
Alexander Polakov58501562015-12-14 02:09:45 +0300224 cfg.header("sys/shm.h");
Daniel McKenna6acbf872017-05-29 18:27:27 +0100225 cfg.header("sys/user.h");
slyrz340cbbf2017-09-09 13:02:29 +0200226 cfg.header("sys/timerfd.h");
Philipp Keller04d0b712016-09-27 07:19:17 +0200227 cfg.header("shadow.h");
Alex Crichton22b98de2017-08-26 20:39:46 -0700228 if !emscripten {
229 cfg.header("linux/input.h");
230 cfg.header("linux/falloc.h");
231 }
Andrew Salmon553c5dc2017-06-07 19:27:14 -0700232 if x86_64 {
233 cfg.header("sys/io.h");
234 }
Marcin Mielniczuk2a597672017-07-22 09:37:22 +0200235 if i686 || x86_64 {
Marcin Mielniczuk37b4e732017-07-21 21:55:47 +0200236 cfg.header("sys/reg.h");
237 }
Alexander Polakov30baed02015-12-01 15:29:05 +0300238 }
Bryant Mairs46933f02018-01-14 20:44:34 -0800239
Alex Crichton22b98de2017-08-26 20:39:46 -0700240 if linux || android || emscripten {
Alex Crichtona1b948e2015-09-18 11:54:32 -0700241 cfg.header("malloc.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800242 cfg.header("net/ethernet.h");
243 cfg.header("netpacket/packet.h");
244 cfg.header("sched.h");
245 cfg.header("sys/epoll.h");
246 cfg.header("sys/eventfd.h");
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700247 cfg.header("sys/prctl.h");
Kamal Marhubi143358b2016-02-04 14:08:50 -0500248 cfg.header("sys/sendfile.h");
Bryant Mairs83ab9a32017-07-16 22:49:28 -0700249 cfg.header("sys/signalfd.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800250 cfg.header("sys/vfs.h");
Alex Crichton881ef9b2015-12-01 09:04:13 -0800251 cfg.header("sys/syscall.h");
Andrew Salmonc98b9f72017-06-07 16:26:42 -0700252 cfg.header("sys/personality.h");
253 cfg.header("sys/swap.h");
Nicolas Dusart4abc3ce2017-06-29 21:25:55 +0200254 cfg.header("pty.h");
Kelvin Ly9a835582017-04-20 02:34:50 -0400255 if !uclibc {
256 cfg.header("sys/sysinfo.h");
257 }
Sergey Bugaeva98c9832016-07-12 13:22:51 +0300258 cfg.header("sys/reboot.h");
Alex Crichton305cec32017-08-27 09:07:18 -0700259 if !emscripten {
Andrew Cannb02c6a32018-05-30 18:08:28 +0800260 cfg.header("linux/sockios.h");
Linus Färnstrand69ae3462018-02-22 14:52:46 +0100261 cfg.header("linux/netlink.h");
262 cfg.header("linux/genetlink.h");
Alex Crichton305cec32017-08-27 09:07:18 -0700263 cfg.header("linux/netfilter_ipv4.h");
Linus Färnstrand750fcf52018-02-25 22:41:50 +0100264 cfg.header("linux/netfilter_ipv6.h");
Joerg Thalheim8c241172017-10-16 17:12:16 +0100265 cfg.header("linux/fs.h");
Alex Crichton305cec32017-08-27 09:07:18 -0700266 }
Alexander Polakov420f2e42015-11-11 01:53:39 +0300267 if !musl {
Alex Crichton22b98de2017-08-26 20:39:46 -0700268 cfg.header("asm/mman.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800269 cfg.header("linux/magic.h");
Sergey Bugaeva98c9832016-07-12 13:22:51 +0300270 cfg.header("linux/reboot.h");
Linus Färnstrand4d5ed472018-01-30 14:30:21 +0100271 cfg.header("linux/netfilter/nf_tables.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800272
273 if !mips {
274 cfg.header("linux/quota.h");
275 }
Alexander Polakov420f2e42015-11-11 01:53:39 +0300276 }
Alex Crichton310d6232015-09-10 10:56:31 -0700277 }
neirac30927482018-01-11 15:25:00 +0000278 if solaris {
279 cfg.header("sys/epoll.h");
Linus Färnstrand4d5ed472018-01-30 14:30:21 +0100280 }
Alex Crichton310d6232015-09-10 10:56:31 -0700281
Jack Pappas787addf2017-09-18 21:41:34 -0400282 if linux || android {
Joerg Thalheim3406fe92017-10-12 17:41:17 +0100283 cfg.header("sys/fsuid.h");
Pascal Bachebe0feb2018-07-16 20:24:50 +0200284 cfg.header("linux/module.h");
Jörg Thalheim9f720f32017-12-19 09:11:33 +0000285 cfg.header("linux/seccomp.h");
luozijun5ea536a2017-12-25 07:55:58 +0800286 cfg.header("linux/if_ether.h");
luozijun0f4ae0b2018-02-04 21:39:40 +0800287 cfg.header("linux/if_tun.h");
Gerd Zellweger2f83a7a2018-10-24 10:02:26 -0700288 cfg.header("linux/net_tstamp.h");
Jack Pappas787addf2017-09-18 21:41:34 -0400289 // DCCP support
290 if !uclibc && !musl && !emscripten {
291 cfg.header("linux/dccp.h");
292 }
Bryant Mairsc0935ac2017-11-05 13:13:35 -0800293
294 if !musl || mips {
295 cfg.header("linux/memfd.h");
296 }
Jack Pappas787addf2017-09-18 21:41:34 -0400297 }
298
Marco A L Barbosaae496262017-11-01 18:41:58 -0200299 if linux {
300 cfg.header("linux/random.h");
Steven Fackler8f7839f2017-11-10 19:58:04 -0800301 cfg.header("elf.h");
302 cfg.header("link.h");
Alex Crichton4621a342018-01-25 16:19:35 -0800303 cfg.header("spawn.h");
Marco A L Barbosaae496262017-11-01 18:41:58 -0200304 }
305
Alex Crichtona1b948e2015-09-18 11:54:32 -0700306 if freebsd {
Alan Somers831ca992017-12-13 20:49:17 -0700307 cfg.header("mqueue.h");
Alex Crichtona1b948e2015-09-18 11:54:32 -0700308 cfg.header("pthread_np.h");
Alexander Polakov26974c72015-11-27 03:02:44 +0300309 cfg.header("sched.h");
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800310 cfg.header("ufs/ufs/quota.h");
Alan Somerscd35cda2018-10-30 14:04:04 -0600311 cfg.header("sys/extattr.h");
Ryan Moeller7c037112017-02-21 00:41:12 +0000312 cfg.header("sys/jail.h");
superriva21226162017-03-28 12:30:53 +0300313 cfg.header("sys/ipc.h");
314 cfg.header("sys/msg.h");
315 cfg.header("sys/shm.h");
Greg V6725fd62018-01-04 02:40:12 +0300316 cfg.header("sys/procdesc.h");
Greg Vc13302d2018-01-22 19:44:59 +0300317 cfg.header("sys/rtprio.h");
Bryan Drewery92d50c92018-02-26 16:36:13 -0800318 cfg.header("spawn.h");
Alex Crichtona1b948e2015-09-18 11:54:32 -0700319 }
320
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800321 if netbsd {
Alan Somers831ca992017-12-13 20:49:17 -0700322 cfg.header("mqueue.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800323 cfg.header("ufs/ufs/quota.h");
324 cfg.header("ufs/ufs/quota1.h");
Alan Somerscd35cda2018-10-30 14:04:04 -0600325 cfg.header("sys/extattr.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800326 cfg.header("sys/ioctl_compat.h");
Jack Pappas787addf2017-09-18 21:41:34 -0400327
328 // DCCP support
329 cfg.header("netinet/dccp.h");
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800330 }
331
Sébastien Mariec618f362015-12-21 17:26:41 +0100332 if openbsd {
333 cfg.header("ufs/ufs/quota.h");
Sébastien Mariec618f362015-12-21 17:26:41 +0100334 cfg.header("pthread_np.h");
335 cfg.header("sys/syscall.h");
336 }
337
Michael Neumanna6a64d12016-02-20 13:34:01 +0100338 if dragonfly {
Alan Somers831ca992017-12-13 20:49:17 -0700339 cfg.header("mqueue.h");
Michael Neumanna6a64d12016-02-20 13:34:01 +0100340 cfg.header("ufs/ufs/quota.h");
341 cfg.header("pthread_np.h");
342 cfg.header("sys/ioctl_compat.h");
Greg Vc13302d2018-01-22 19:44:59 +0300343 cfg.header("sys/rtprio.h");
Michael Neumanna6a64d12016-02-20 13:34:01 +0100344 }
345
bgermannb3870b42017-11-18 14:57:54 +0100346 if solaris {
347 cfg.header("port.h");
348 cfg.header("ucontext.h");
349 cfg.header("sys/filio.h");
350 cfg.header("sys/loadavg.h");
351 }
352
Alex Crichton22b98de2017-08-26 20:39:46 -0700353 if linux || freebsd || dragonfly || netbsd || apple || emscripten {
Kelvin Ly9a835582017-04-20 02:34:50 -0400354 if !uclibc {
355 cfg.header("aio.h");
356 }
Alan Somers4ec884a2016-11-13 08:07:45 -0700357 }
358
Tom Parker-Shemiltd75fc9c2018-11-23 21:25:23 +0000359 if cloudabi || redox {
Tom Parker-Shemiltb7580372018-11-23 21:21:24 +0000360 cfg.header("strings.h");
361 }
362
alesharik5ec86992018-07-13 02:06:08 +0300363 cfg.type_name(move |ty, is_struct, is_union| {
Alex Crichton310d6232015-09-10 10:56:31 -0700364 match ty {
Alex Crichton31504842015-09-10 23:43:41 -0700365 // Just pass all these through, no need for a "struct" prefix
gnzlbg5c1a6b82018-11-21 20:34:50 +0100366 "FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr"
367 | "Elf64_Phdr" | "Elf32_Shdr" | "Elf64_Shdr" | "Elf32_Sym"
368 | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr"
369 | "Elf64_Chdr" => ty.to_string(),
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700370
371 // Fixup a few types on windows that don't actually exist.
372 "time64_t" if windows => "__time64_t".to_string(),
373 "ssize_t" if windows => "SSIZE_T".to_string(),
374
Alex Crichtonde9736d2015-09-17 15:47:44 -0700375 // OSX calls this something else
Alex Crichtona1b948e2015-09-18 11:54:32 -0700376 "sighandler_t" if bsdlike => "sig_t".to_string(),
Alex Crichtonde9736d2015-09-17 15:47:44 -0700377
gnzlbgaca32d92018-11-19 15:24:41 +0100378 t if is_union => format!("union {}", t),
alesharik5ec86992018-07-13 02:06:08 +0300379
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700380 t if t.ends_with("_t") => t.to_string(),
Alex Crichton310d6232015-09-10 10:56:31 -0700381
Alex Crichton31504842015-09-10 23:43:41 -0700382 // Windows uppercase structs don't have `struct` in front, there's a
383 // few special cases for windows, and then otherwise put `struct` in
384 // front of everything.
Alex Crichtond11e9142015-09-15 23:28:52 -0700385 t if is_struct => {
Alex Crichton13a6f2d2015-09-10 18:10:58 -0700386 if windows && ty.chars().next().unwrap().is_uppercase() {
387 t.to_string()
388 } else if windows && t == "stat" {
389 "struct __stat64".to_string()
Alex Crichton7da9b102015-09-10 20:57:14 -0700390 } else if windows && t == "utimbuf" {
391 "struct __utimbuf64".to_string()
Alex Crichton13a6f2d2015-09-10 18:10:58 -0700392 } else {
393 format!("struct {}", t)
394 }
395 }
Alex Crichton310d6232015-09-10 10:56:31 -0700396
397 t => t.to_string(),
398 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700399 });
Alex Crichton310d6232015-09-10 10:56:31 -0700400
Alex Crichtond11e9142015-09-15 23:28:52 -0700401 let target2 = target.clone();
402 cfg.field_name(move |struct_, field| {
Alex Crichton310d6232015-09-10 10:56:31 -0700403 match field {
gnzlbg5c1a6b82018-11-21 20:34:50 +0100404 "st_birthtime" if openbsd && struct_ == "stat" => {
405 "__st_birthtime".to_string()
406 }
407 "st_birthtime_nsec" if openbsd && struct_ == "stat" => {
408 "__st_birthtimensec".to_string()
409 }
Alex Crichton31504842015-09-10 23:43:41 -0700410 // Our stat *_nsec fields normally don't actually exist but are part
411 // of a timeval struct
Alex Crichton74825222015-10-29 17:36:55 -0700412 s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
Alex Crichtonbaef6112015-09-19 23:20:53 -0700413 if target2.contains("apple") {
Alex Crichton310d6232015-09-10 10:56:31 -0700414 s.replace("_nsec", "spec.tv_nsec")
Alex Crichtond11e9142015-09-15 23:28:52 -0700415 } else if target2.contains("android") {
Alex Crichtond3d77922015-09-11 17:03:39 -0700416 s.to_string()
Alex Crichton310d6232015-09-10 10:56:31 -0700417 } else {
418 s.replace("e_nsec", ".tv_nsec")
419 }
420 }
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800421 "u64" if struct_ == "epoll_event" => "data.u64".to_string(),
gnzlbgaca32d92018-11-19 15:24:41 +0100422 "type_"
423 if (linux || freebsd || dragonfly)
424 && (struct_ == "input_event"
425 || struct_ == "input_mask"
426 || struct_ == "ff_effect"
427 || struct_ == "rtprio") =>
428 {
429 "type".to_string()
430 }
Alex Crichton310d6232015-09-10 10:56:31 -0700431 s => s.to_string(),
432 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700433 });
Alex Crichton310d6232015-09-10 10:56:31 -0700434
Alex Crichtond11e9142015-09-15 23:28:52 -0700435 cfg.skip_type(move |ty| {
Alex Crichton310d6232015-09-10 10:56:31 -0700436 match ty {
Alex Crichtond3d77922015-09-11 17:03:39 -0700437 // sighandler_t is crazy across platforms
Alex Crichtond11e9142015-09-15 23:28:52 -0700438 "sighandler_t" => true,
Alex Crichtond3d77922015-09-11 17:03:39 -0700439
gnzlbgaca32d92018-11-19 15:24:41 +0100440 _ => false,
Alex Crichton310d6232015-09-10 10:56:31 -0700441 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700442 });
Alex Crichton16083062015-09-09 22:59:24 -0700443
Alexander Polakov420f2e42015-11-11 01:53:39 +0300444 cfg.skip_struct(move |ty| {
445 match ty {
446 "sockaddr_nl" => musl,
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800447
Knight866c9e42016-08-09 14:01:33 +0800448 // On Linux, the type of `ut_tv` field of `struct utmpx`
449 // can be an anonymous struct, so an extra struct,
450 // which is absent in glibc, has to be defined.
451 "__timeval" if linux => true,
452
Alex Crichton91bd0792018-11-19 22:14:05 -0800453 // Fixed on feature=align with repr(packed(4))
gnzlbgdfee17f2018-04-15 14:50:00 +0200454 // Once repr_packed stabilizes we can fix this unconditionally
455 // and remove this check.
456 "kevent" | "shmid_ds" if apple && x86_64 => true,
457
Alan Somers9245e072016-11-13 13:52:34 -0700458 // This is actually a union, not a struct
459 "sigval" => true,
460
Mateusz Sieczko60d93222017-06-13 17:26:14 +0200461 // Linux kernel headers used on musl are too old to have this
462 // definition. Because it's tested on other Linux targets, skip it.
463 "input_mask" if musl => true,
464
Nicolas Dusart4abc3ce2017-06-29 21:25:55 +0200465 // These structs have changed since unified headers in NDK r14b.
466 // `st_atime` and `st_atime_nsec` have changed sign.
467 // FIXME: unskip it for next major release
468 "stat" | "stat64" if android => true,
469
Bryant Mairs6d55c242017-10-18 18:55:41 -0700470 // These are tested as part of the linux_fcntl tests since there are
471 // header conflicts when including them with all the other structs.
472 "termios2" => true,
473
Alex Crichton83f78df2018-07-31 14:13:30 -0700474 // Present on historical versions of iOS but missing in more recent
475 // SDKs
gnzlbg5c1a6b82018-11-21 20:34:50 +0100476 "bpf_hdr" | "proc_taskinfo" | "proc_taskallinfo"
477 | "proc_bsdinfo" | "proc_threadinfo" | "sockaddr_inarp"
478 | "sockaddr_ctl" | "arphdr"
gnzlbgaca32d92018-11-19 15:24:41 +0100479 if ios =>
480 {
481 true
482 }
Alex Crichton83f78df2018-07-31 14:13:30 -0700483
gnzlbgaca32d92018-11-19 15:24:41 +0100484 _ => false,
Alexander Polakov420f2e42015-11-11 01:53:39 +0300485 }
486 });
487
Michael Neumanna6a64d12016-02-20 13:34:01 +0100488 cfg.skip_signededness(move |c| {
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700489 match c {
gnzlbg5c1a6b82018-11-21 20:34:50 +0100490 "LARGE_INTEGER"
491 | "mach_timebase_info_data_t"
492 | "float"
493 | "double" => true,
Michael Neumanna09fe712016-02-21 12:28:10 +0100494 // uuid_t is a struct, not an integer.
Michael Neumanna6a64d12016-02-20 13:34:01 +0100495 "uuid_t" if dragonfly => true,
Alex Crichtond11e9142015-09-15 23:28:52 -0700496 n if n.starts_with("pthread") => true,
Steven Fackler41699f72016-06-03 21:02:56 -0700497 // sem_t is a struct or pointer
Alan Somers831ca992017-12-13 20:49:17 -0700498 "sem_t" if openbsd || freebsd || dragonfly || netbsd => true,
499 // mqd_t is a pointer on FreeBSD and DragonFly
500 "mqd_t" if freebsd || dragonfly => true,
Alex Crichton18469182015-09-15 20:57:42 -0700501
Alex Crichton4621a342018-01-25 16:19:35 -0800502 // Just some typedefs on osx, no need to check their sign
gnzlbgaca32d92018-11-19 15:24:41 +0100503 "posix_spawnattr_t" | "posix_spawn_file_actions_t" => true,
Alex Crichton4621a342018-01-25 16:19:35 -0800504
Alex Crichton18469182015-09-15 20:57:42 -0700505 // windows-isms
Alex Crichtond11e9142015-09-15 23:28:52 -0700506 n if n.starts_with("P") => true,
507 n if n.starts_with("H") => true,
508 n if n.starts_with("LP") => true,
509 _ => false,
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700510 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700511 });
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700512
Alex Crichtond11e9142015-09-15 23:28:52 -0700513 cfg.skip_const(move |name| {
Alex Crichton31504842015-09-10 23:43:41 -0700514 match name {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700515 // Apparently these don't exist in mingw headers?
gnzlbgaca32d92018-11-19 15:24:41 +0100516 "MEM_RESET_UNDO"
517 | "FILE_ATTRIBUTE_NO_SCRUB_DATA"
518 | "FILE_ATTRIBUTE_INTEGRITY_STREAM"
519 | "ERROR_NOTHING_TO_TERMINATE"
520 if mingw =>
521 {
522 true
523 }
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700524
gnzlbgaca32d92018-11-19 15:24:41 +0100525 "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness
526 "SIGUNUSED" => true, // removed in glibc 2.26
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700527
Alex Crichton15b83c22015-09-17 17:25:52 -0700528 // types on musl are defined a little differently
Alex Crichton3a572fd2015-10-29 16:52:25 -0700529 n if musl && n.contains("__SIZEOF_PTHREAD") => true,
Alex Crichton15b83c22015-09-17 17:25:52 -0700530
Alex Crichton74825222015-10-29 17:36:55 -0700531 // Skip constants not defined in MUSL but just passed down to the
532 // kernel regardless
gnzlbg5c1a6b82018-11-21 20:34:50 +0100533 "RLIMIT_NLIMITS"
534 | "TCP_COOKIE_TRANSACTIONS"
535 | "RLIMIT_RTTIME"
536 | "MSG_COPY"
537 if musl =>
538 {
gnzlbgaca32d92018-11-19 15:24:41 +0100539 true
540 }
Alexander Polakov26974c72015-11-27 03:02:44 +0300541 // work around super old mips toolchain
Alexander Polakov58501562015-12-14 02:09:45 +0300542 "SCHED_IDLE" | "SHM_NORESERVE" => mips,
Alex Crichton74825222015-10-29 17:36:55 -0700543
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800544 // weird signed extension or something like that?
545 "MS_NOUSER" => true,
NODA, Kai4d1efd92016-04-03 21:53:49 +0800546 "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800547
548 // These OSX constants are flagged as deprecated
gnzlbgaca32d92018-11-19 15:24:41 +0100549 "NOTE_EXIT_REPARENTED" | "NOTE_REAP" if apple => true,
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800550
Alan Somers9860c292016-11-13 08:45:59 -0700551 // These constants were removed in FreeBSD 11 (svn r273250) but will
552 // still be accepted and ignored at runtime.
gnzlbgaca32d92018-11-19 15:24:41 +0100553 "MAP_RENAME" | "MAP_NORESERVE" if freebsd => true,
Alan Somers9860c292016-11-13 08:45:59 -0700554
555 // These constants were removed in FreeBSD 11 (svn r262489),
556 // and they've never had any legitimate use outside of the
557 // base system anyway.
gnzlbg5c1a6b82018-11-21 20:34:50 +0100558 "CTL_MAXID" | "KERN_MAXID" | "HW_MAXID" | "NET_MAXID"
559 | "USER_MAXID"
560 if freebsd =>
561 {
562 true
563 }
Alan Somers9860c292016-11-13 08:45:59 -0700564
Greg V2aeb3822018-01-10 22:59:38 +0300565 // These constants were added in FreeBSD 11
gnzlbg5c1a6b82018-11-21 20:34:50 +0100566 "EVFILT_PROCDESC" | "EVFILT_SENDFILE" | "EVFILT_EMPTY"
567 | "PD_CLOEXEC" | "PD_ALLOWED_AT_FORK"
gnzlbgaca32d92018-11-19 15:24:41 +0100568 if freebsd =>
569 {
570 true
571 }
Greg V2aeb3822018-01-10 22:59:38 +0300572
Andrew Morrow96ee7bf2018-05-16 22:26:14 -0600573 // These constants were added in FreeBSD 12
gnzlbgaca32d92018-11-19 15:24:41 +0100574 "SF_USER_READAHEAD" | "SO_REUSEPORT_LB" if freebsd => true,
Andrew Morrow96ee7bf2018-05-16 22:26:14 -0600575
Kevin Brothaler7fbff3a2017-01-16 12:49:49 -0400576 // These OSX constants are removed in Sierra.
577 // https://developer.apple.com/library/content/releasenotes/General/APIDiffsMacOS10_12/Swift/Darwin.html
578 "KERN_KDENABLE_BG_TRACE" if apple => true,
579 "KERN_KDDISABLE_BG_TRACE" if apple => true,
580
Wesley Moore58c772b2017-08-03 18:10:21 +1000581 // These constants were removed in OpenBSD 6 (https://git.io/v7gBO
582 // https://git.io/v7gBq)
gnzlbgaca32d92018-11-19 15:24:41 +0100583 "KERN_USERMOUNT" | "KERN_ARND" if openbsd => true,
Wesley Moore58c772b2017-08-03 18:10:21 +1000584
Kelvin Lyc0bec432017-05-06 02:49:54 -0400585 // These are either unimplemented or optionally built into uClibc
gnzlbgaca32d92018-11-19 15:24:41 +0100586 "LC_CTYPE_MASK"
587 | "LC_NUMERIC_MASK"
588 | "LC_TIME_MASK"
589 | "LC_COLLATE_MASK"
590 | "LC_MONETARY_MASK"
591 | "LC_MESSAGES_MASK"
592 | "MADV_MERGEABLE"
593 | "MADV_UNMERGEABLE"
594 | "MADV_HWPOISON"
595 | "IPV6_ADD_MEMBERSHIP"
596 | "IPV6_DROP_MEMBERSHIP"
597 | "IPV6_MULTICAST_LOOP"
598 | "IPV6_V6ONLY"
599 | "MAP_STACK"
600 | "RTLD_DEEPBIND"
601 | "SOL_IPV6"
602 | "SOL_ICMPV6"
603 if uclibc =>
604 {
605 true
606 }
Kelvin Lyc0bec432017-05-06 02:49:54 -0400607
Gabrielf60ff2d2017-07-20 00:28:08 +0200608 // Musl uses old, patched kernel headers
gnzlbgaca32d92018-11-19 15:24:41 +0100609 "FALLOC_FL_COLLAPSE_RANGE"
610 | "FALLOC_FL_ZERO_RANGE"
611 | "FALLOC_FL_INSERT_RANGE"
612 | "FALLOC_FL_UNSHARE_RANGE"
613 | "RENAME_NOREPLACE"
614 | "RENAME_EXCHANGE"
615 | "RENAME_WHITEOUT"
616 if musl =>
617 {
618 true
619 }
Gabrielf60ff2d2017-07-20 00:28:08 +0200620
Marco A L Barbosaae496262017-11-01 18:41:58 -0200621 // Both android and musl use old kernel headers
622 // These are constants used in getrandom syscall
623 "GRND_NONBLOCK" | "GRND_RANDOM" if musl || android => true,
624
Lee Bousfield98889cf2017-05-15 09:15:53 -0600625 // Defined by libattr not libc on linux (hard to test).
626 // See constant definition for more details.
Mateusz Mikuła27043ec2018-07-04 18:43:48 +0200627 "ENOATTR" if android || linux => true,
Lee Bousfield98889cf2017-05-15 09:15:53 -0600628
Bryant Mairsf04b4422017-07-11 23:17:15 -0700629 // On mips*-unknown-linux-gnu* CMSPAR cannot be included with the set of headers we
630 // want to use here for testing. It's originally defined in asm/termbits.h, which is
631 // also included by asm/termios.h, but not the standard termios.h. There's no way to
632 // include both asm/termbits.h and termios.h and there's no way to include both
633 // asm/termios.h and ioctl.h (+ some other headers) because of redeclared types.
634 "CMSPAR" if mips && linux && !musl => true,
635
Bryant Mairsc9e6f552017-08-10 14:31:11 -0700636 // On mips Linux targets, MADV_SOFT_OFFLINE is currently missing, though it's been added but CI has too old
637 // of a Linux version. Since it exists on all other Linux targets, just ignore this for now and remove once
638 // it's been fixed in CI.
639 "MADV_SOFT_OFFLINE" if mips && linux => true,
640
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700641 // These constants are tested in a separate test program generated below because there
642 // are header conflicts if we try to include the headers that define them here.
643 "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => true,
gnzlbg5c1a6b82018-11-21 20:34:50 +0100644 "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW"
645 | "F_SEAL_WRITE" => true,
646 "QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1"
647 if mips && linux =>
648 {
649 true
650 } // Only on MIPS
Bryant Mairs12cfa1e2017-10-18 18:26:59 -0700651 "BOTHER" => true,
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700652
Bryant Mairsfa81ab32017-11-06 18:45:30 -0800653 "MFD_CLOEXEC" | "MFD_ALLOW_SEALING" if !mips && musl => true,
bgermannb3870b42017-11-18 14:57:54 +0100654
gnzlbg5c1a6b82018-11-21 20:34:50 +0100655 "DT_FIFO" | "DT_CHR" | "DT_DIR" | "DT_BLK" | "DT_REG"
656 | "DT_LNK" | "DT_SOCK"
gnzlbgaca32d92018-11-19 15:24:41 +0100657 if solaris =>
658 {
659 true
660 }
bgermannb3870b42017-11-18 14:57:54 +0100661 "USRQUOTA" | "GRPQUOTA" if solaris => true,
662 "PRIO_MIN" | "PRIO_MAX" if solaris => true,
663
664 // 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 +0100665 "EADI"
666 | "PORT_SOURCE_POSTWAIT"
667 | "PORT_SOURCE_SIGNAL"
668 | "PTHREAD_STACK_MIN" => true,
bgermannb3870b42017-11-18 14:57:54 +0100669
Alex Crichton1f29ac32018-01-18 11:21:30 -0800670 // These change all the time from release to release of linux
671 // distros, let's just not bother trying to verify them. They
672 // shouldn't be used in code anyway...
673 "AF_MAX" | "PF_MAX" => true,
674
Tobias Klausercc229972018-12-04 17:36:48 +0100675 // These are not in a glibc release yet, only in kernel headers.
676 "AF_XDP" | "PF_XDP" | "SOL_XDP" if linux => true,
677
Alex Crichton83f78df2018-07-31 14:13:30 -0700678 // Present on historical versions of iOS, but now removed in more
679 // recent SDKs
gnzlbgaca32d92018-11-19 15:24:41 +0100680 "ARPOP_REQUEST"
681 | "ARPOP_REPLY"
682 | "ATF_COM"
683 | "ATF_PERM"
684 | "ATF_PUBL"
685 | "ATF_USETRAILERS"
686 | "AF_SYS_CONTROL"
687 | "SYSPROTO_EVENT"
688 | "PROC_PIDTASKALLINFO"
689 | "PROC_PIDTASKINFO"
690 | "PROC_PIDTHREADINFO"
691 | "UTUN_OPT_FLAGS"
692 | "UTUN_OPT_IFNAME"
693 | "BPF_ALIGNMENT"
694 | "SYSPROTO_CONTROL"
695 if ios =>
696 {
697 true
698 }
Alex Crichton83f78df2018-07-31 14:13:30 -0700699 s if ios && s.starts_with("RTF_") => true,
700 s if ios && s.starts_with("RTM_") => true,
701 s if ios && s.starts_with("RTA_") => true,
702 s if ios && s.starts_with("RTAX_") => true,
703 s if ios && s.starts_with("RTV_") => true,
704 s if ios && s.starts_with("DLT_") => true,
705
Alex Crichtond11e9142015-09-15 23:28:52 -0700706 _ => false,
Alex Crichton31504842015-09-10 23:43:41 -0700707 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700708 });
Alex Crichton31504842015-09-10 23:43:41 -0700709
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700710 cfg.skip_fn(move |name| {
Jim Blandyf8772f72016-01-12 16:28:07 -0800711 // skip those that are manually verified
Alex Crichton22378822015-09-10 19:59:23 -0700712 match name {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700713 "execv" | // crazy stuff with const/mut
Alex Crichton22378822015-09-10 19:59:23 -0700714 "execve" |
715 "execvp" |
Luca Bruno858d47c2017-07-21 15:13:44 +0000716 "execvpe" |
717 "fexecve" => true,
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700718
Alex Crichton74825222015-10-29 17:36:55 -0700719 "getrlimit" | "getrlimit64" | // non-int in 1st arg
720 "setrlimit" | "setrlimit64" | // non-int in 1st arg
Kamal Marhubi95695992016-04-27 14:29:19 -0400721 "prlimit" | "prlimit64" | // non-int in 2nd arg
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700722 "strerror_r" if linux => true, // actually xpg-something-or-other
723
NODA, Kai61c23fb2016-04-10 22:21:55 +0800724 // int vs uint. Sorry musl, your prototype declarations are "correct" in the sense that
725 // they match the interface defined by Linux verbatim, but they conflict with other
726 // send*/recv* syscalls
727 "sendmmsg" | "recvmmsg" if musl => true,
728
Alex Crichton1ff96102015-09-17 15:09:02 -0700729 // typed 2nd arg on linux and android
Michael Neumanna6a64d12016-02-20 13:34:01 +0100730 "gettimeofday" if linux || android || freebsd || openbsd || dragonfly => true,
Alex Crichton1ff96102015-09-17 15:09:02 -0700731
Alex Crichton881ef9b2015-12-01 09:04:13 -0800732 // not declared in newer android toolchains
733 "getdtablesize" if android => true,
734
Alex Crichton1ff96102015-09-17 15:09:02 -0700735 "dlerror" if android => true, // const-ness is added
bgermann85680dc2017-11-18 22:03:14 +0100736 "dladdr" if musl || solaris => true, // const-ness only added recently
Alex Crichton1ff96102015-09-17 15:09:02 -0700737
Alex Crichton568705e2015-11-03 14:18:52 -0800738 // OSX has 'struct tm *const' which we can't actually represent in
739 // Rust, but is close enough to *mut
740 "timegm" if apple => true,
741
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800742 // OSX's daemon is deprecated in 10.5 so we'll get a warning (which
743 // we turn into an error) so just ignore it.
744 "daemon" if apple => true,
745
Steven Fackler41699f72016-06-03 21:02:56 -0700746 // Deprecated on OSX
747 "sem_destroy" if apple => true,
748 "sem_init" if apple => true,
749
Alex Crichton49d7bca2015-11-27 09:40:37 -0800750 // These functions presumably exist on netbsd but don't look like
751 // they're implemented on rumprun yet, just let them slide for now.
752 // Some of them look like they have headers but then don't have
753 // corresponding actual definitions either...
Alex Crichton49d7bca2015-11-27 09:40:37 -0800754 "shm_open" |
755 "shm_unlink" |
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800756 "syscall" |
Alan Somers831ca992017-12-13 20:49:17 -0700757 "mq_open" |
758 "mq_close" |
759 "mq_getattr" |
760 "mq_notify" |
761 "mq_receive" |
762 "mq_send" |
763 "mq_setattr" |
764 "mq_timedreceive" |
765 "mq_timedsend" |
766 "mq_unlink" |
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800767 "ptrace" |
Alex Crichton49d7bca2015-11-27 09:40:37 -0800768 "sigaltstack" if rumprun => true,
769
Jim Blandyf8772f72016-01-12 16:28:07 -0800770 // There seems to be a small error in EGLIBC's eventfd.h header. The
771 // [underlying system call][1] always takes its first `count`
772 // argument as an `unsigned int`, but [EGLIBC's <sys/eventfd.h>
773 // header][2] declares it to take an `int`. [GLIBC's header][3]
774 // matches the kernel.
775 //
776 // EGLIBC is no longer actively developed, and Debian, the largest
777 // distribution that had been using it, switched back to GLIBC in
778 // April 2015. So effectively all Linux <sys/eventfd.h> headers will
779 // be using `unsigned int` soon.
780 //
781 // [1]: https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/fs/eventfd.c?id=refs/tags/v3.12.51#n397
782 // [2]: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/eglibc/trusty/view/head:/sysdeps/unix/sysv/linux/sys/eventfd.h
783 // [3]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sys/eventfd.h;h=6295f32e937e779e74318eb9d3bdbe76aef8a8f3;hb=4e42b5b8f89f0e288e68be7ad70f9525aebc2cff#l34
784 "eventfd" if linux => true,
785
Boris Faureda445b92016-11-05 20:16:50 +0100786 // The `uname` function in freebsd is now an inline wrapper that
Alex Crichtonbb6f1982016-01-18 11:18:22 -0800787 // delegates to another, but the symbol still exists, so don't check
788 // the symbol.
789 "uname" if freebsd => true,
790
Fredrick Brennan6d959f12018-03-04 13:11:04 +0000791 // FIXME: need to upgrade FreeBSD version; see https://github.com/rust-lang/libc/issues/938
792 "setgrent" if freebsd => true,
793
Alan Somerse0ff0d62016-11-13 14:35:17 -0700794 // aio_waitcomplete's return type changed between FreeBSD 10 and 11.
795 "aio_waitcomplete" if freebsd => true,
796
Alan Somers9245e072016-11-13 13:52:34 -0700797 // lio_listio confuses the checker, probably because one of its
798 // arguments is an array
799 "lio_listio" if freebsd => true,
Alan Somerse0ff0d62016-11-13 14:35:17 -0700800 "lio_listio" if musl => true,
Alan Somers9245e072016-11-13 13:52:34 -0700801
Alex Crichtonc2842462016-11-16 14:12:12 -0800802 // Apparently the NDK doesn't have this defined on android, but
803 // it's in a header file?
804 "endpwent" if android => true,
805
Kelvin Ly96a83062017-05-04 22:08:48 -0400806
Kelvin Ly9a835582017-04-20 02:34:50 -0400807 // These are either unimplemented or optionally built into uClibc
808 // or "sysinfo", where it's defined but the structs in linux/sysinfo.h and sys/sysinfo.h
Kelvin Ly26670c72017-04-21 18:20:02 -0400809 // clash so it can't be tested
810 "getxattr" | "lgetxattr" | "fgetxattr" | "setxattr" | "lsetxattr" | "fsetxattr" |
811 "listxattr" | "llistxattr" | "flistxattr" | "removexattr" | "lremovexattr" |
812 "fremovexattr" |
813 "backtrace" |
814 "sysinfo" | "newlocale" | "duplocale" | "freelocale" | "uselocale" |
Kelvin Lyc14178c2017-04-26 23:01:05 -0400815 "nl_langinfo_l" | "wcslen" | "wcstombs" if uclibc => true,
Bryant Mairs9b9f36a2017-05-18 10:06:36 -0700816
Jon Gjengsetbe7e45f2017-05-03 15:57:29 -0400817 // Apparently res_init exists on Android, but isn't defined in a header:
Jon Gjengsetafebd982017-04-28 22:23:33 -0400818 // https://mail.gnome.org/archives/commits-list/2013-May/msg01329.html
819 "res_init" if android => true,
820
Jon Gjengsetbe7e45f2017-05-03 15:57:29 -0400821 // On macOS and iOS, res_init is available, but requires linking with libresolv:
822 // http://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html
823 // See discussion for skipping here:
824 // https://github.com/rust-lang/libc/pull/585#discussion_r114561460
825 "res_init" if apple => true,
826
Bryant Mairs9b9f36a2017-05-18 10:06:36 -0700827 // On Mac we don't use the default `close()`, instead using their $NOCANCEL variants.
828 "close" if apple => true,
829
Nicolas Dusart4abc3ce2017-06-29 21:25:55 +0200830 // Definition of those functions as changed since unified headers from NDK r14b
831 // These changes imply some API breaking changes but are still ABI compatible.
832 // We can wait for the next major release to be compliant with the new API.
833 // FIXME: unskip these for next major release
834 "strerror_r" | "madvise" | "msync" | "mprotect" | "recvfrom" | "getpriority" |
bgermann85680dc2017-11-18 22:03:14 +0100835 "setpriority" | "personality" if android || solaris => true,
Nicolas Dusart4abc3ce2017-06-29 21:25:55 +0200836 // In Android 64 bits, these functions have been fixed since unified headers.
837 // Ignore these until next major version.
838 "bind" | "writev" | "readv" | "sendmsg" | "recvmsg" if android && (aarch64 || x86_64) => true,
839
bgermannb3870b42017-11-18 14:57:54 +0100840 // signal is defined with sighandler_t, so ignore
841 "signal" if solaris => true,
842
843 "cfmakeraw" | "cfsetspeed" if solaris => true,
844
bgermann85680dc2017-11-18 22:03:14 +0100845 // FIXME: mincore is defined with caddr_t on Solaris.
846 "mincore" if solaris => true,
847
Alex Crichton83f78df2018-07-31 14:13:30 -0700848 // These were all included in historical versions of iOS but appear
849 // to be removed now
850 "system" | "ptrace" if ios => true,
851
Alex Crichtond11e9142015-09-15 23:28:52 -0700852 _ => false,
Alex Crichton22378822015-09-10 19:59:23 -0700853 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700854 });
Alex Crichton22378822015-09-10 19:59:23 -0700855
Tobias Bucher8b1d8462018-09-05 09:48:49 +0200856 cfg.skip_static(move |name| {
857 match name {
858 // Internal constant, not declared in any headers.
859 "__progname" if android => true,
860 _ => false,
861 }
862 });
863
Alex Crichton881ef9b2015-12-01 09:04:13 -0800864 cfg.skip_fn_ptrcheck(move |name| {
865 match name {
Alex Crichton881ef9b2015-12-01 09:04:13 -0800866 // dllimport weirdness?
867 _ if windows => true,
868
869 _ => false,
870 }
871 });
Alex Crichtone0f4d102015-09-16 09:48:14 -0700872
Alex Crichton15b83c22015-09-17 17:25:52 -0700873 cfg.skip_field_type(move |struct_, field| {
Alex Crichtonf3b97482015-09-16 14:13:20 -0700874 // This is a weird union, don't check the type.
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700875 (struct_ == "ifaddrs" && field == "ifa_ifu") ||
876 // sighandler_t type is super weird
Knight866c9e42016-08-09 14:01:33 +0800877 (struct_ == "sigaction" && field == "sa_sigaction") ||
878 // __timeval type is a patch which doesn't exist in glibc
Alan Somers9245e072016-11-13 13:52:34 -0700879 (linux && struct_ == "utmpx" && field == "ut_tv") ||
880 // sigval is actually a union, but we pretend it's a struct
881 (struct_ == "sigevent" && field == "sigev_value") ||
882 // aio_buf is "volatile void*" and Rust doesn't understand volatile
Alan Somers9860c292016-11-13 08:45:59 -0700883 (struct_ == "aiocb" && field == "aio_buf") ||
884 // stack_t.ss_sp's type changed from FreeBSD 10 to 11 in svn r294930
Mateusz Sieczko60d93222017-06-13 17:26:14 +0200885 (freebsd && struct_ == "stack_t" && field == "ss_sp") ||
Sébastien Marie56701a72017-08-13 12:29:45 +0200886 // type siginfo_t.si_addr changed from OpenBSD 6.0 to 6.1
887 (openbsd && struct_ == "siginfo_t" && field == "si_addr") ||
Mateusz Sieczko60d93222017-06-13 17:26:14 +0200888 // this one is an anonymous union
889 (linux && struct_ == "ff_effect" && field == "u")
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700890 });
891
Alex Crichton15b83c22015-09-17 17:25:52 -0700892 cfg.skip_field(move |struct_, field| {
Alex Crichtoncd9b33e2015-09-17 14:47:40 -0700893 // this is actually a union on linux, so we can't represent it well and
894 // just insert some padding.
Alex Crichton15b83c22015-09-17 17:25:52 -0700895 (struct_ == "siginfo_t" && field == "_pad") ||
896 // musl names this __dummy1 but it's still there
Brian Anderson773aab82015-12-29 20:00:29 +0000897 (musl && struct_ == "glob_t" && field == "gl_flags") ||
898 // musl seems to define this as an *anonymous* bitfield
Alan Somers9245e072016-11-13 13:52:34 -0700899 (musl && struct_ == "statvfs" && field == "__f_unused") ||
900 // sigev_notify_thread_id is actually part of a sigev_un union
Stephen Barber60ab3042018-11-05 16:02:26 -0800901 (struct_ == "sigevent" && field == "sigev_notify_thread_id") ||
902 // signalfd had SIGSYS fields added in Linux 4.18, but no libc release has them yet.
903 (struct_ == "signalfd_siginfo" && (field == "ssi_addr_lsb" ||
904 field == "_pad2" ||
905 field == "ssi_syscall" ||
906 field == "ssi_call_addr" ||
907 field == "ssi_arch"))
Alex Crichtonf3b97482015-09-16 14:13:20 -0700908 });
909
Alex Crichton49d7bca2015-11-27 09:40:37 -0800910 cfg.fn_cname(move |name, cname| {
Alex Crichton881ef9b2015-12-01 09:04:13 -0800911 if windows {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800912 cname.unwrap_or(name).to_string()
Alex Crichton0af5e232015-11-30 15:07:28 -0800913 } else {
Alex Crichton49d7bca2015-11-27 09:40:37 -0800914 name.to_string()
Alex Crichton0af5e232015-11-30 15:07:28 -0800915 }
916 });
917
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700918 cfg.generate("../src/lib.rs", "main.rs");
919
920 // On Linux or Android also generate another script for testing linux/fcntl declarations.
921 // These cannot be tested normally because including both `linux/fcntl.h` and `fcntl.h`
922 // fails on a lot of platforms.
923 let mut cfg = ctest::TestGenerator::new();
924 cfg.skip_type(|_| true)
gnzlbgaca32d92018-11-19 15:24:41 +0100925 .skip_fn(|_| true)
926 .skip_static(|_| true);
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700927 if android || linux {
928 // musl defines these directly in `fcntl.h`
929 if musl {
930 cfg.header("fcntl.h");
931 } else {
932 cfg.header("linux/fcntl.h");
933 }
SilverWingedSeraph6f170ef2017-09-12 12:33:10 -0500934 if !musl {
935 cfg.header("net/if.h");
936 cfg.header("linux/if.h");
937 }
Bryant Mairsbd4c3482017-08-29 19:33:22 -0700938 cfg.header("linux/quota.h");
Bryant Mairs12cfa1e2017-10-18 18:26:59 -0700939 cfg.header("asm/termbits.h");
gnzlbgaca32d92018-11-19 15:24:41 +0100940 cfg.skip_const(move |name| match name {
941 "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false,
gnzlbg5c1a6b82018-11-21 20:34:50 +0100942 "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW"
943 | "F_SEAL_WRITE" => false,
944 "QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1"
945 if mips && linux =>
946 {
947 false
948 }
gnzlbgaca32d92018-11-19 15:24:41 +0100949 "BOTHER" => false,
950 _ => true,
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700951 });
gnzlbgaca32d92018-11-19 15:24:41 +0100952 cfg.skip_struct(|s| s != "termios2");
953 cfg.type_name(move |ty, is_struct, is_union| match ty {
954 t if is_struct => format!("struct {}", t),
955 t if is_union => format!("union {}", t),
956 t => t.to_string(),
Bryant Mairs6d55c242017-10-18 18:55:41 -0700957 });
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700958 } else {
959 cfg.skip_const(|_| true);
Bryant Mairs6d55c242017-10-18 18:55:41 -0700960 cfg.skip_struct(|_| true);
Bryant Mairs2e11d9e2017-08-10 10:33:19 -0700961 }
962 cfg.generate("../src/lib.rs", "linux_fcntl.rs");
Alex Crichton310d6232015-09-10 10:56:31 -0700963}