blob: 41c17598d03e682fd868c102b633da66a6e1639b [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();
9 let windows = target.contains("windows");
10 let mingw = target.contains("windows-gnu");
11 let mut cfg = ctest::TestGenerator::new();
Alex Crichton8e5f0cd2015-09-09 22:46:19 -070012
Alex Crichtond11e9142015-09-15 23:28:52 -070013 // Pull in extra goodies on linux/mingw
14 if target.contains("unknown-linux-gnu") {
15 cfg.define("_GNU_SOURCE", None);
16 } else if target.contains("windows") {
17 cfg.define("_WIN32_WINNT", Some("0x8000"));
Alex Crichton0df7c102015-09-10 16:35:37 -070018 }
19
Alex Crichton094f44d2015-09-16 16:27:23 -070020 // Android doesn't actually have in_port_t but it's much easier if we
21 // provide one for us to test against
22 if target.contains("android") {
23 cfg.define("in_port_t", Some("uint16_t"));
24 }
25
Alex Crichtond11e9142015-09-15 23:28:52 -070026 cfg.header("errno.h")
27 .header("fcntl.h")
28 .header("limits.h")
29 .header("stddef.h")
30 .header("stdint.h")
31 .header("stdio.h")
32 .header("stdlib.h")
33 .header("sys/stat.h")
34 .header("sys/types.h")
35 .header("time.h")
36 .header("wchar.h");
Alex Crichtonac2bd852015-09-10 17:21:20 -070037
Alex Crichtond11e9142015-09-15 23:28:52 -070038 if target.contains("apple-darwin") {
39 cfg.header("mach-o/dyld.h");
40 cfg.header("mach/mach_time.h");
41 } else if target.contains("unknown-linux") ||
42 target.contains("android") {
43 cfg.header("linux/if_packet.h");
44 cfg.header("net/ethernet.h");
45 }
Alex Crichton310d6232015-09-10 10:56:31 -070046
Alex Crichtond11e9142015-09-15 23:28:52 -070047 if target.contains("windows") {
48 cfg.header("winsock2.h"); // must be before windows.h
49
50 cfg.header("direct.h");
51 cfg.header("io.h");
52 cfg.header("sys/utime.h");
53 cfg.header("windows.h");
54 cfg.header("process.h");
55 cfg.header("ws2ipdef.h");
56
57 if target.contains("gnu") {
58 cfg.header("ws2tcpip.h");
Alex Crichton310d6232015-09-10 10:56:31 -070059 }
Alex Crichtond11e9142015-09-15 23:28:52 -070060 } else {
61 cfg.header("ctype.h");
62 cfg.header("dirent.h");
63 cfg.header("net/if.h");
64 cfg.header("netdb.h");
65 cfg.header("netinet/in.h");
66 cfg.header("netinet/ip.h");
67 cfg.header("netinet/tcp.h");
68 cfg.header("pthread.h");
69 cfg.header("signal.h");
70 cfg.header("string.h");
71 cfg.header("sys/file.h");
72 cfg.header("sys/ioctl.h");
73 cfg.header("sys/mman.h");
74 cfg.header("sys/resource.h");
75 cfg.header("sys/socket.h");
76 cfg.header("sys/time.h");
77 cfg.header("sys/un.h");
78 cfg.header("sys/wait.h");
79 cfg.header("unistd.h");
80 cfg.header("utime.h");
Alex Crichtonac2bd852015-09-10 17:21:20 -070081
Alex Crichtond11e9142015-09-15 23:28:52 -070082 if target.contains("android") {
83 cfg.header("arpa/inet.h");
Alex Crichtonac2bd852015-09-10 17:21:20 -070084 } else {
Alex Crichtond11e9142015-09-15 23:28:52 -070085 cfg.header("glob.h");
86 cfg.header("ifaddrs.h");
87 cfg.header("sys/sysctl.h");
Alex Crichtonac2bd852015-09-10 17:21:20 -070088 }
Alex Crichton310d6232015-09-10 10:56:31 -070089 }
90
Alex Crichtond11e9142015-09-15 23:28:52 -070091 cfg.type_name(move |ty, is_struct| {
Alex Crichton310d6232015-09-10 10:56:31 -070092 match ty {
Alex Crichton31504842015-09-10 23:43:41 -070093 // Just pass all these through, no need for a "struct" prefix
Alex Crichton22378822015-09-10 19:59:23 -070094 "glob_t" |
95 "FILE" |
96 "DIR" |
97 "fpos_t" => ty.to_string(),
Alex Crichton310d6232015-09-10 10:56:31 -070098 t if t.starts_with("pthread") => t.to_string(),
99
Alex Crichton31504842015-09-10 23:43:41 -0700100 // Windows uppercase structs don't have `struct` in front, there's a
101 // few special cases for windows, and then otherwise put `struct` in
102 // front of everything.
Alex Crichtond11e9142015-09-15 23:28:52 -0700103 t if is_struct => {
Alex Crichton13a6f2d2015-09-10 18:10:58 -0700104 if windows && ty.chars().next().unwrap().is_uppercase() {
105 t.to_string()
106 } else if windows && t == "stat" {
107 "struct __stat64".to_string()
Alex Crichton7da9b102015-09-10 20:57:14 -0700108 } else if windows && t == "utimbuf" {
109 "struct __utimbuf64".to_string()
Alex Crichton13a6f2d2015-09-10 18:10:58 -0700110 } else {
111 format!("struct {}", t)
112 }
113 }
Alex Crichton310d6232015-09-10 10:56:31 -0700114
Alex Crichton31504842015-09-10 23:43:41 -0700115 // Fixup a few types on windows that don't actually exist.
Alex Crichton13a6f2d2015-09-10 18:10:58 -0700116 "time64_t" if windows => "__time64_t".to_string(),
117 "ssize_t" if windows => "SSIZE_T".to_string(),
Alex Crichton31504842015-09-10 23:43:41 -0700118
Alex Crichton310d6232015-09-10 10:56:31 -0700119 t => t.to_string(),
120 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700121 });
Alex Crichton310d6232015-09-10 10:56:31 -0700122
Alex Crichtond11e9142015-09-15 23:28:52 -0700123 let target2 = target.clone();
124 cfg.field_name(move |struct_, field| {
Alex Crichton310d6232015-09-10 10:56:31 -0700125 match field {
Alex Crichton31504842015-09-10 23:43:41 -0700126 // Our stat *_nsec fields normally don't actually exist but are part
127 // of a timeval struct
Alex Crichton310d6232015-09-10 10:56:31 -0700128 s if s.ends_with("_nsec") && struct_ == "stat" => {
Alex Crichtond11e9142015-09-15 23:28:52 -0700129 if target2.contains("apple-darwin") {
Alex Crichton310d6232015-09-10 10:56:31 -0700130 s.replace("_nsec", "spec.tv_nsec")
Alex Crichtond11e9142015-09-15 23:28:52 -0700131 } else if target2.contains("android") {
Alex Crichtond3d77922015-09-11 17:03:39 -0700132 s.to_string()
Alex Crichton310d6232015-09-10 10:56:31 -0700133 } else {
134 s.replace("e_nsec", ".tv_nsec")
135 }
136 }
137 s => s.to_string(),
138 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700139 });
Alex Crichton310d6232015-09-10 10:56:31 -0700140
Alex Crichtond11e9142015-09-15 23:28:52 -0700141 cfg.skip_type(move |ty| {
Alex Crichton310d6232015-09-10 10:56:31 -0700142 match ty {
Alex Crichtond3d77922015-09-11 17:03:39 -0700143 // sighandler_t is crazy across platforms
Alex Crichtond11e9142015-09-15 23:28:52 -0700144 "sighandler_t" => true,
Alex Crichtond3d77922015-09-11 17:03:39 -0700145
Alex Crichtond11e9142015-09-15 23:28:52 -0700146 _ => false
Alex Crichton310d6232015-09-10 10:56:31 -0700147 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700148 });
Alex Crichton16083062015-09-09 22:59:24 -0700149
Alex Crichtond11e9142015-09-15 23:28:52 -0700150 cfg.skip_signededness(|c| {
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700151 match c {
Alex Crichton7b28c272015-09-15 20:56:16 -0700152 "LARGE_INTEGER" |
Alex Crichtoneef03da2015-09-15 16:57:06 -0700153 "mach_timebase_info_data_t" |
Alex Crichton7b28c272015-09-15 20:56:16 -0700154 "float" |
Alex Crichtond11e9142015-09-15 23:28:52 -0700155 "double" => true,
156 n if n.starts_with("pthread") => true,
Alex Crichton18469182015-09-15 20:57:42 -0700157
158 // windows-isms
Alex Crichtond11e9142015-09-15 23:28:52 -0700159 n if n.starts_with("P") => true,
160 n if n.starts_with("H") => true,
161 n if n.starts_with("LP") => true,
162 _ => false,
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700163 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700164 });
Alex Crichton6d3cfdb2015-09-15 14:53:01 -0700165
Alex Crichtond11e9142015-09-15 23:28:52 -0700166 // Apparently these don't exist in mingw headers?
167 cfg.skip_const(move |name| {
Alex Crichton31504842015-09-10 23:43:41 -0700168 match name {
169 "MEM_RESET_UNDO" |
170 "FILE_ATTRIBUTE_NO_SCRUB_DATA" |
171 "FILE_ATTRIBUTE_INTEGRITY_STREAM" |
Alex Crichtond11e9142015-09-15 23:28:52 -0700172 "ERROR_NOTHING_TO_TERMINATE" if mingw => true,
173 "SIG_IGN" => true, // sighandler_t weirdness
174 _ => false,
Alex Crichton31504842015-09-10 23:43:41 -0700175 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700176 });
Alex Crichton31504842015-09-10 23:43:41 -0700177
Alex Crichtond11e9142015-09-15 23:28:52 -0700178 cfg.skip_fn(|name| {
Alex Crichton22378822015-09-10 19:59:23 -0700179 match name {
180 // manually verified
181 "execv" |
182 "execve" |
183 "execvp" |
Alex Crichton7da9b102015-09-10 20:57:14 -0700184 "execvpe" |
Alex Crichton22378822015-09-10 19:59:23 -0700185 "glob" |
186 "getrlimit" |
187 "setrlimit" |
Alex Crichtone8606192015-09-10 20:19:44 -0700188 "signal" |
Alex Crichtond11e9142015-09-15 23:28:52 -0700189 "getopt" => true,
190 _ => false,
Alex Crichton22378822015-09-10 19:59:23 -0700191 }
Alex Crichtond11e9142015-09-15 23:28:52 -0700192 });
Alex Crichton22378822015-09-10 19:59:23 -0700193
Alex Crichtone0f4d102015-09-16 09:48:14 -0700194 // Windows dllimport oddness?
195 cfg.skip_fn_ptrcheck(move |_| windows);
196
Alex Crichtonf3b97482015-09-16 14:13:20 -0700197 cfg.skip_field_type(|struct_, field| {
198 // This is a weird union, don't check the type.
199 struct_ == "ifaddrs" && field == "ifa_ifu"
200 });
201
Alex Crichtond11e9142015-09-15 23:28:52 -0700202 cfg.generate("../src/lib.rs", "all.rs");
Alex Crichton310d6232015-09-10 10:56:31 -0700203}