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"); |
| 11 | let mut cfg = ctest::TestGenerator::new(); |
Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 12 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 13 | // 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 Crichton | 0df7c10 | 2015-09-10 16:35:37 -0700 | [diff] [blame] | 18 | } |
| 19 | |
Alex Crichton | 094f44d | 2015-09-16 16:27:23 -0700 | [diff] [blame] | 20 | // 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 Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 26 | 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 Crichton | ac2bd85 | 2015-09-10 17:21:20 -0700 | [diff] [blame] | 37 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 38 | 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 Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 46 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 47 | 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 Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 59 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 60 | } 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 Crichton | ac2bd85 | 2015-09-10 17:21:20 -0700 | [diff] [blame] | 81 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 82 | if target.contains("android") { |
| 83 | cfg.header("arpa/inet.h"); |
Alex Crichton | ac2bd85 | 2015-09-10 17:21:20 -0700 | [diff] [blame] | 84 | } else { |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 85 | cfg.header("glob.h"); |
| 86 | cfg.header("ifaddrs.h"); |
| 87 | cfg.header("sys/sysctl.h"); |
Alex Crichton | ac2bd85 | 2015-09-10 17:21:20 -0700 | [diff] [blame] | 88 | } |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 91 | cfg.type_name(move |ty, is_struct| { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 92 | match ty { |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 93 | // Just pass all these through, no need for a "struct" prefix |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 94 | "glob_t" | |
| 95 | "FILE" | |
| 96 | "DIR" | |
| 97 | "fpos_t" => ty.to_string(), |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 98 | t if t.starts_with("pthread") => t.to_string(), |
| 99 | |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 100 | // 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 Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 103 | t if is_struct => { |
Alex Crichton | 13a6f2d | 2015-09-10 18:10:58 -0700 | [diff] [blame] | 104 | if windows && ty.chars().next().unwrap().is_uppercase() { |
| 105 | t.to_string() |
| 106 | } else if windows && t == "stat" { |
| 107 | "struct __stat64".to_string() |
Alex Crichton | 7da9b10 | 2015-09-10 20:57:14 -0700 | [diff] [blame] | 108 | } else if windows && t == "utimbuf" { |
| 109 | "struct __utimbuf64".to_string() |
Alex Crichton | 13a6f2d | 2015-09-10 18:10:58 -0700 | [diff] [blame] | 110 | } else { |
| 111 | format!("struct {}", t) |
| 112 | } |
| 113 | } |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 114 | |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 115 | // Fixup a few types on windows that don't actually exist. |
Alex Crichton | 13a6f2d | 2015-09-10 18:10:58 -0700 | [diff] [blame] | 116 | "time64_t" if windows => "__time64_t".to_string(), |
| 117 | "ssize_t" if windows => "SSIZE_T".to_string(), |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 118 | |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 119 | t => t.to_string(), |
| 120 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 121 | }); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 122 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 123 | let target2 = target.clone(); |
| 124 | cfg.field_name(move |struct_, field| { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 125 | match field { |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 126 | // Our stat *_nsec fields normally don't actually exist but are part |
| 127 | // of a timeval struct |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 128 | s if s.ends_with("_nsec") && struct_ == "stat" => { |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 129 | if target2.contains("apple-darwin") { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 130 | s.replace("_nsec", "spec.tv_nsec") |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 131 | } else if target2.contains("android") { |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 132 | s.to_string() |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 133 | } else { |
| 134 | s.replace("e_nsec", ".tv_nsec") |
| 135 | } |
| 136 | } |
| 137 | s => s.to_string(), |
| 138 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 139 | }); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 140 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 141 | cfg.skip_type(move |ty| { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 142 | match ty { |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 143 | // sighandler_t is crazy across platforms |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 144 | "sighandler_t" => true, |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 145 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 146 | _ => false |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 147 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 148 | }); |
Alex Crichton | 1608306 | 2015-09-09 22:59:24 -0700 | [diff] [blame] | 149 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 150 | cfg.skip_signededness(|c| { |
Alex Crichton | 6d3cfdb | 2015-09-15 14:53:01 -0700 | [diff] [blame] | 151 | match c { |
Alex Crichton | 7b28c27 | 2015-09-15 20:56:16 -0700 | [diff] [blame] | 152 | "LARGE_INTEGER" | |
Alex Crichton | eef03da | 2015-09-15 16:57:06 -0700 | [diff] [blame] | 153 | "mach_timebase_info_data_t" | |
Alex Crichton | 7b28c27 | 2015-09-15 20:56:16 -0700 | [diff] [blame] | 154 | "float" | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 155 | "double" => true, |
| 156 | n if n.starts_with("pthread") => true, |
Alex Crichton | 1846918 | 2015-09-15 20:57:42 -0700 | [diff] [blame] | 157 | |
| 158 | // windows-isms |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 159 | 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 Crichton | 6d3cfdb | 2015-09-15 14:53:01 -0700 | [diff] [blame] | 163 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 164 | }); |
Alex Crichton | 6d3cfdb | 2015-09-15 14:53:01 -0700 | [diff] [blame] | 165 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 166 | // Apparently these don't exist in mingw headers? |
| 167 | cfg.skip_const(move |name| { |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 168 | match name { |
| 169 | "MEM_RESET_UNDO" | |
| 170 | "FILE_ATTRIBUTE_NO_SCRUB_DATA" | |
| 171 | "FILE_ATTRIBUTE_INTEGRITY_STREAM" | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 172 | "ERROR_NOTHING_TO_TERMINATE" if mingw => true, |
| 173 | "SIG_IGN" => true, // sighandler_t weirdness |
| 174 | _ => false, |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 175 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 176 | }); |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 177 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 178 | cfg.skip_fn(|name| { |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 179 | match name { |
| 180 | // manually verified |
| 181 | "execv" | |
| 182 | "execve" | |
| 183 | "execvp" | |
Alex Crichton | 7da9b10 | 2015-09-10 20:57:14 -0700 | [diff] [blame] | 184 | "execvpe" | |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 185 | "glob" | |
| 186 | "getrlimit" | |
| 187 | "setrlimit" | |
Alex Crichton | e860619 | 2015-09-10 20:19:44 -0700 | [diff] [blame] | 188 | "signal" | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 189 | "getopt" => true, |
| 190 | _ => false, |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 191 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 192 | }); |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 193 | |
Alex Crichton | e0f4d10 | 2015-09-16 09:48:14 -0700 | [diff] [blame] | 194 | // Windows dllimport oddness? |
| 195 | cfg.skip_fn_ptrcheck(move |_| windows); |
| 196 | |
Alex Crichton | f3b9748 | 2015-09-16 14:13:20 -0700 | [diff] [blame] | 197 | 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 Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 202 | cfg.generate("../src/lib.rs", "all.rs"); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 203 | } |