Alex Crichton | b5da7c0 | 2015-09-16 17:44:40 -0700 | [diff] [blame] | 1 | #![deny(warnings)] |
| 2 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 3 | extern crate ctest; |
Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 4 | |
| 5 | use std::env; |
Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 6 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 7 | fn main() { |
| 8 | let target = env::var("TARGET").unwrap(); |
| 9 | let windows = target.contains("windows"); |
| 10 | let mingw = target.contains("windows-gnu"); |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 11 | let linux = target.contains("unknown-linux"); |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 12 | let android = target.contains("android"); |
Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 13 | let apple = target.contains("apple"); |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 14 | let musl = target.contains("musl"); |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 15 | let freebsd = target.contains("freebsd"); |
Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 16 | let bsdlike = freebsd || apple; |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 17 | let mut cfg = ctest::TestGenerator::new(); |
Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 18 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 19 | // Pull in extra goodies on linux/mingw |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 20 | if target.contains("unknown-linux") { |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 21 | cfg.define("_GNU_SOURCE", None); |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 22 | } else if windows { |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 23 | cfg.define("_WIN32_WINNT", Some("0x8000")); |
Alex Crichton | 0df7c10 | 2015-09-10 16:35:37 -0700 | [diff] [blame] | 24 | } |
| 25 | |
Alex Crichton | 094f44d | 2015-09-16 16:27:23 -0700 | [diff] [blame] | 26 | // Android doesn't actually have in_port_t but it's much easier if we |
| 27 | // provide one for us to test against |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 28 | if android { |
Alex Crichton | 094f44d | 2015-09-16 16:27:23 -0700 | [diff] [blame] | 29 | cfg.define("in_port_t", Some("uint16_t")); |
| 30 | } |
| 31 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 32 | cfg.header("errno.h") |
| 33 | .header("fcntl.h") |
| 34 | .header("limits.h") |
| 35 | .header("stddef.h") |
| 36 | .header("stdint.h") |
| 37 | .header("stdio.h") |
| 38 | .header("stdlib.h") |
| 39 | .header("sys/stat.h") |
| 40 | .header("sys/types.h") |
| 41 | .header("time.h") |
| 42 | .header("wchar.h"); |
Alex Crichton | ac2bd85 | 2015-09-10 17:21:20 -0700 | [diff] [blame] | 43 | |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 44 | if windows { |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 45 | cfg.header("winsock2.h"); // must be before windows.h |
| 46 | |
| 47 | cfg.header("direct.h"); |
| 48 | cfg.header("io.h"); |
| 49 | cfg.header("sys/utime.h"); |
| 50 | cfg.header("windows.h"); |
| 51 | cfg.header("process.h"); |
| 52 | cfg.header("ws2ipdef.h"); |
| 53 | |
| 54 | if target.contains("gnu") { |
| 55 | cfg.header("ws2tcpip.h"); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 56 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 57 | } else { |
| 58 | cfg.header("ctype.h"); |
| 59 | cfg.header("dirent.h"); |
| 60 | cfg.header("net/if.h"); |
| 61 | cfg.header("netdb.h"); |
| 62 | cfg.header("netinet/in.h"); |
| 63 | cfg.header("netinet/ip.h"); |
| 64 | cfg.header("netinet/tcp.h"); |
| 65 | cfg.header("pthread.h"); |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 66 | cfg.header("dlfcn.h"); |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 67 | cfg.header("signal.h"); |
| 68 | cfg.header("string.h"); |
| 69 | cfg.header("sys/file.h"); |
| 70 | cfg.header("sys/ioctl.h"); |
| 71 | cfg.header("sys/mman.h"); |
| 72 | cfg.header("sys/resource.h"); |
| 73 | cfg.header("sys/socket.h"); |
| 74 | cfg.header("sys/time.h"); |
| 75 | cfg.header("sys/un.h"); |
| 76 | cfg.header("sys/wait.h"); |
| 77 | cfg.header("unistd.h"); |
| 78 | cfg.header("utime.h"); |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 79 | cfg.header("pwd.h"); |
| 80 | cfg.header("grp.h"); |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 81 | } |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 82 | |
| 83 | if android { |
| 84 | cfg.header("arpa/inet.h"); |
| 85 | } else if !windows { |
| 86 | cfg.header("glob.h"); |
| 87 | cfg.header("ifaddrs.h"); |
| 88 | |
| 89 | if !musl { |
| 90 | cfg.header("execinfo.h"); |
| 91 | cfg.header("sys/sysctl.h"); |
| 92 | } |
| 93 | } |
| 94 | |
Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 95 | if apple { |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 96 | cfg.header("mach-o/dyld.h"); |
| 97 | cfg.header("mach/mach_time.h"); |
| 98 | cfg.header("malloc/malloc.h"); |
Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 99 | if target.starts_with("x86") { |
| 100 | cfg.header("crt_externs.h"); |
| 101 | } |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | if linux || android { |
| 105 | cfg.header("netpacket/packet.h"); |
| 106 | cfg.header("net/ethernet.h"); |
| 107 | cfg.header("malloc.h"); |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 108 | cfg.header("sys/prctl.h"); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 111 | if freebsd { |
| 112 | cfg.header("pthread_np.h"); |
| 113 | } |
| 114 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 115 | cfg.type_name(move |ty, is_struct| { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 116 | match ty { |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 117 | // Just pass all these through, no need for a "struct" prefix |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 118 | "FILE" | |
Alex Crichton | 07d3a0d | 2015-10-30 10:21:32 -0700 | [diff] [blame^] | 119 | "fd_set" | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 120 | "DIR" => ty.to_string(), |
| 121 | |
| 122 | // Fixup a few types on windows that don't actually exist. |
| 123 | "time64_t" if windows => "__time64_t".to_string(), |
| 124 | "ssize_t" if windows => "SSIZE_T".to_string(), |
| 125 | |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 126 | // OSX calls this something else |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 127 | "sighandler_t" if bsdlike => "sig_t".to_string(), |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 128 | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 129 | t if t.ends_with("_t") => t.to_string(), |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 130 | |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 131 | // Windows uppercase structs don't have `struct` in front, there's a |
| 132 | // few special cases for windows, and then otherwise put `struct` in |
| 133 | // front of everything. |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 134 | t if is_struct => { |
Alex Crichton | 13a6f2d | 2015-09-10 18:10:58 -0700 | [diff] [blame] | 135 | if windows && ty.chars().next().unwrap().is_uppercase() { |
| 136 | t.to_string() |
| 137 | } else if windows && t == "stat" { |
| 138 | "struct __stat64".to_string() |
Alex Crichton | 7da9b10 | 2015-09-10 20:57:14 -0700 | [diff] [blame] | 139 | } else if windows && t == "utimbuf" { |
| 140 | "struct __utimbuf64".to_string() |
Alex Crichton | 13a6f2d | 2015-09-10 18:10:58 -0700 | [diff] [blame] | 141 | } else { |
| 142 | format!("struct {}", t) |
| 143 | } |
| 144 | } |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 145 | |
| 146 | t => t.to_string(), |
| 147 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 148 | }); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 149 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 150 | let target2 = target.clone(); |
| 151 | cfg.field_name(move |struct_, field| { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 152 | match field { |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 153 | // Our stat *_nsec fields normally don't actually exist but are part |
| 154 | // of a timeval struct |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 155 | s if s.ends_with("_nsec") && struct_ == "stat" => { |
Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 156 | if target2.contains("apple") { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 157 | s.replace("_nsec", "spec.tv_nsec") |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 158 | } else if target2.contains("android") { |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 159 | s.to_string() |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 160 | } else { |
| 161 | s.replace("e_nsec", ".tv_nsec") |
| 162 | } |
| 163 | } |
| 164 | s => s.to_string(), |
| 165 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 166 | }); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 167 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 168 | cfg.skip_type(move |ty| { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 169 | match ty { |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 170 | // sighandler_t is crazy across platforms |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 171 | "sighandler_t" => true, |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 172 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 173 | _ => false |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 174 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 175 | }); |
Alex Crichton | 1608306 | 2015-09-09 22:59:24 -0700 | [diff] [blame] | 176 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 177 | cfg.skip_signededness(|c| { |
Alex Crichton | 6d3cfdb | 2015-09-15 14:53:01 -0700 | [diff] [blame] | 178 | match c { |
Alex Crichton | 7b28c27 | 2015-09-15 20:56:16 -0700 | [diff] [blame] | 179 | "LARGE_INTEGER" | |
Alex Crichton | eef03da | 2015-09-15 16:57:06 -0700 | [diff] [blame] | 180 | "mach_timebase_info_data_t" | |
Alex Crichton | 7b28c27 | 2015-09-15 20:56:16 -0700 | [diff] [blame] | 181 | "float" | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 182 | "double" => true, |
| 183 | n if n.starts_with("pthread") => true, |
Alex Crichton | 1846918 | 2015-09-15 20:57:42 -0700 | [diff] [blame] | 184 | |
| 185 | // windows-isms |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 186 | n if n.starts_with("P") => true, |
| 187 | n if n.starts_with("H") => true, |
| 188 | n if n.starts_with("LP") => true, |
| 189 | _ => false, |
Alex Crichton | 6d3cfdb | 2015-09-15 14:53:01 -0700 | [diff] [blame] | 190 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 191 | }); |
Alex Crichton | 6d3cfdb | 2015-09-15 14:53:01 -0700 | [diff] [blame] | 192 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 193 | cfg.skip_const(move |name| { |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 194 | match name { |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 195 | // Apparently these don't exist in mingw headers? |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 196 | "MEM_RESET_UNDO" | |
| 197 | "FILE_ATTRIBUTE_NO_SCRUB_DATA" | |
| 198 | "FILE_ATTRIBUTE_INTEGRITY_STREAM" | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 199 | "ERROR_NOTHING_TO_TERMINATE" if mingw => true, |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 200 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 201 | "SIG_IGN" => true, // sighandler_t weirdness |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 202 | |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 203 | // types on musl are defined a little differently |
Alex Crichton | 3a572fd | 2015-10-29 16:52:25 -0700 | [diff] [blame] | 204 | n if musl && n.contains("__SIZEOF_PTHREAD") => true, |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 205 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 206 | _ => false, |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 207 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 208 | }); |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 209 | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 210 | cfg.skip_fn(move |name| { |
| 211 | // skip those that are manually verifiedmanually verified |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 212 | match name { |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 213 | "execv" | // crazy stuff with const/mut |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 214 | "execve" | |
| 215 | "execvp" | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 216 | "execvpe" => true, |
| 217 | |
| 218 | "getrlimit" | // non-int in 1st arg |
| 219 | "setrlimit" | // non-int in 1st arg |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 220 | "strerror_r" if linux => true, // actually xpg-something-or-other |
| 221 | |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 222 | // typed 2nd arg on linux and android |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 223 | "gettimeofday" if linux || android || freebsd => true, |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 224 | |
| 225 | "dlerror" if android => true, // const-ness is added |
| 226 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 227 | _ => false, |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 228 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 229 | }); |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 230 | |
Alex Crichton | e0f4d10 | 2015-09-16 09:48:14 -0700 | [diff] [blame] | 231 | // Windows dllimport oddness? |
| 232 | cfg.skip_fn_ptrcheck(move |_| windows); |
| 233 | |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 234 | cfg.skip_field_type(move |struct_, field| { |
Alex Crichton | f3b9748 | 2015-09-16 14:13:20 -0700 | [diff] [blame] | 235 | // This is a weird union, don't check the type. |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 236 | (struct_ == "ifaddrs" && field == "ifa_ifu") || |
| 237 | // sighandler_t type is super weird |
| 238 | (struct_ == "sigaction" && field == "sa_sigaction") |
| 239 | }); |
| 240 | |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 241 | cfg.skip_field(move |struct_, field| { |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 242 | // this is actually a union on linux, so we can't represent it well and |
| 243 | // just insert some padding. |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 244 | (struct_ == "siginfo_t" && field == "_pad") || |
| 245 | // musl names this __dummy1 but it's still there |
| 246 | (musl && struct_ == "glob_t" && field == "gl_flags") |
Alex Crichton | f3b9748 | 2015-09-16 14:13:20 -0700 | [diff] [blame] | 247 | }); |
| 248 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 249 | cfg.generate("../src/lib.rs", "all.rs"); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 250 | } |