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(); |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 9 | let x86_64 = target.contains("x86_64"); |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 10 | let windows = target.contains("windows"); |
| 11 | let mingw = target.contains("windows-gnu"); |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 12 | let linux = target.contains("unknown-linux"); |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 13 | let android = target.contains("android"); |
Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 14 | let apple = target.contains("apple"); |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 15 | let musl = target.contains("musl"); |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 16 | let freebsd = target.contains("freebsd"); |
Alexander Polakov | 26974c7 | 2015-11-27 03:02:44 +0300 | [diff] [blame] | 17 | let mips = target.contains("mips"); |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 18 | let netbsd = target.contains("netbsd"); |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 19 | let openbsd = target.contains("openbsd"); |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 20 | let rumprun = target.contains("rumprun"); |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 21 | let bsdlike = freebsd || apple || netbsd || openbsd; |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 22 | let mut cfg = ctest::TestGenerator::new(); |
Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 23 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 24 | // Pull in extra goodies on linux/mingw |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 25 | if linux || android { |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 26 | cfg.define("_GNU_SOURCE", None); |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 27 | } else if windows { |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 28 | cfg.define("_WIN32_WINNT", Some("0x8000")); |
Alex Crichton | 0df7c10 | 2015-09-10 16:35:37 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Alex Crichton | 094f44d | 2015-09-16 16:27:23 -0700 | [diff] [blame] | 31 | // Android doesn't actually have in_port_t but it's much easier if we |
| 32 | // provide one for us to test against |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 33 | if android { |
Alex Crichton | 094f44d | 2015-09-16 16:27:23 -0700 | [diff] [blame] | 34 | cfg.define("in_port_t", Some("uint16_t")); |
| 35 | } |
| 36 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 37 | cfg.header("errno.h") |
| 38 | .header("fcntl.h") |
| 39 | .header("limits.h") |
| 40 | .header("stddef.h") |
| 41 | .header("stdint.h") |
| 42 | .header("stdio.h") |
| 43 | .header("stdlib.h") |
| 44 | .header("sys/stat.h") |
| 45 | .header("sys/types.h") |
| 46 | .header("time.h") |
| 47 | .header("wchar.h"); |
Alex Crichton | ac2bd85 | 2015-09-10 17:21:20 -0700 | [diff] [blame] | 48 | |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 49 | if windows { |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 50 | cfg.header("winsock2.h"); // must be before windows.h |
| 51 | |
| 52 | cfg.header("direct.h"); |
| 53 | cfg.header("io.h"); |
| 54 | cfg.header("sys/utime.h"); |
| 55 | cfg.header("windows.h"); |
| 56 | cfg.header("process.h"); |
| 57 | cfg.header("ws2ipdef.h"); |
| 58 | |
| 59 | if target.contains("gnu") { |
| 60 | cfg.header("ws2tcpip.h"); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 61 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 62 | } else { |
| 63 | cfg.header("ctype.h"); |
| 64 | cfg.header("dirent.h"); |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 65 | if openbsd { |
| 66 | cfg.header("sys/socket.h"); |
| 67 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 68 | cfg.header("net/if.h"); |
| 69 | cfg.header("netdb.h"); |
| 70 | cfg.header("netinet/in.h"); |
| 71 | cfg.header("netinet/ip.h"); |
| 72 | cfg.header("netinet/tcp.h"); |
| 73 | cfg.header("pthread.h"); |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 74 | cfg.header("dlfcn.h"); |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 75 | cfg.header("signal.h"); |
| 76 | cfg.header("string.h"); |
| 77 | cfg.header("sys/file.h"); |
| 78 | cfg.header("sys/ioctl.h"); |
| 79 | cfg.header("sys/mman.h"); |
| 80 | cfg.header("sys/resource.h"); |
| 81 | cfg.header("sys/socket.h"); |
| 82 | cfg.header("sys/time.h"); |
| 83 | cfg.header("sys/un.h"); |
| 84 | cfg.header("sys/wait.h"); |
| 85 | cfg.header("unistd.h"); |
| 86 | cfg.header("utime.h"); |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 87 | cfg.header("pwd.h"); |
| 88 | cfg.header("grp.h"); |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 89 | cfg.header("sys/utsname.h"); |
| 90 | cfg.header("sys/ptrace.h"); |
| 91 | cfg.header("sys/mount.h"); |
| 92 | cfg.header("sys/uio.h"); |
| 93 | cfg.header("sched.h"); |
| 94 | cfg.header("termios.h"); |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 95 | } |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 96 | |
| 97 | if android { |
| 98 | cfg.header("arpa/inet.h"); |
Alex Crichton | 568705e | 2015-11-03 14:18:52 -0800 | [diff] [blame] | 99 | cfg.header("time64.h"); |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 100 | } else if !windows { |
| 101 | cfg.header("glob.h"); |
| 102 | cfg.header("ifaddrs.h"); |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 103 | if !openbsd { |
| 104 | cfg.header("sys/quota.h"); |
| 105 | } |
Dan Burkert | 85a76f8 | 2015-11-04 20:26:27 -0800 | [diff] [blame] | 106 | cfg.header("sys/statvfs.h"); |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 107 | |
| 108 | if !musl { |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 109 | cfg.header("sys/sysctl.h"); |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 110 | |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 111 | if !netbsd && !openbsd { |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 112 | cfg.header("execinfo.h"); |
| 113 | } |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 117 | if apple { |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 118 | cfg.header("mach-o/dyld.h"); |
| 119 | cfg.header("mach/mach_time.h"); |
| 120 | cfg.header("malloc/malloc.h"); |
Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 121 | if target.starts_with("x86") { |
| 122 | cfg.header("crt_externs.h"); |
| 123 | } |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 126 | if bsdlike { |
| 127 | cfg.header("sys/event.h"); |
| 128 | } |
| 129 | |
Alexander Polakov | 30baed0 | 2015-12-01 15:29:05 +0300 | [diff] [blame] | 130 | if linux { |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 131 | cfg.header("mqueue.h"); |
| 132 | cfg.header("sys/signalfd.h"); |
Alexander Polakov | 30baed0 | 2015-12-01 15:29:05 +0300 | [diff] [blame] | 133 | cfg.header("sys/xattr.h"); |
Alexander Polakov | 5850156 | 2015-12-14 02:09:45 +0300 | [diff] [blame] | 134 | cfg.header("sys/ipc.h"); |
| 135 | cfg.header("sys/shm.h"); |
Alexander Polakov | 30baed0 | 2015-12-01 15:29:05 +0300 | [diff] [blame] | 136 | } |
| 137 | |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 138 | if linux || android { |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 139 | cfg.header("malloc.h"); |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 140 | cfg.header("net/ethernet.h"); |
| 141 | cfg.header("netpacket/packet.h"); |
| 142 | cfg.header("sched.h"); |
| 143 | cfg.header("sys/epoll.h"); |
| 144 | cfg.header("sys/eventfd.h"); |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 145 | cfg.header("sys/prctl.h"); |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 146 | cfg.header("sys/vfs.h"); |
Alex Crichton | 881ef9b | 2015-12-01 09:04:13 -0800 | [diff] [blame] | 147 | cfg.header("sys/syscall.h"); |
Alexander Polakov | 420f2e4 | 2015-11-11 01:53:39 +0300 | [diff] [blame] | 148 | if !musl { |
| 149 | cfg.header("linux/netlink.h"); |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 150 | cfg.header("linux/magic.h"); |
| 151 | cfg.header("linux/fs.h"); |
| 152 | |
| 153 | if !mips { |
| 154 | cfg.header("linux/quota.h"); |
| 155 | } |
Alexander Polakov | 420f2e4 | 2015-11-11 01:53:39 +0300 | [diff] [blame] | 156 | } |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 159 | if freebsd { |
| 160 | cfg.header("pthread_np.h"); |
Alexander Polakov | 26974c7 | 2015-11-27 03:02:44 +0300 | [diff] [blame] | 161 | cfg.header("sched.h"); |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 164 | if netbsd { |
| 165 | cfg.header("ufs/ufs/quota.h"); |
| 166 | cfg.header("ufs/ufs/quota1.h"); |
| 167 | cfg.header("sys/ioctl_compat.h"); |
| 168 | } |
| 169 | |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 170 | if openbsd { |
| 171 | cfg.header("ufs/ufs/quota.h"); |
| 172 | cfg.header("rpcsvc/rex.h"); |
| 173 | cfg.header("pthread_np.h"); |
| 174 | cfg.header("sys/syscall.h"); |
| 175 | } |
| 176 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 177 | cfg.type_name(move |ty, is_struct| { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 178 | match ty { |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 179 | // Just pass all these through, no need for a "struct" prefix |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 180 | "FILE" | |
Alex Crichton | 07d3a0d | 2015-10-30 10:21:32 -0700 | [diff] [blame] | 181 | "fd_set" | |
Alex Crichton | 88d23e7 | 2015-11-02 17:03:19 -0800 | [diff] [blame] | 182 | "Dl_info" | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 183 | "DIR" => ty.to_string(), |
| 184 | |
| 185 | // Fixup a few types on windows that don't actually exist. |
| 186 | "time64_t" if windows => "__time64_t".to_string(), |
| 187 | "ssize_t" if windows => "SSIZE_T".to_string(), |
| 188 | |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 189 | // OSX calls this something else |
Alex Crichton | a1b948e | 2015-09-18 11:54:32 -0700 | [diff] [blame] | 190 | "sighandler_t" if bsdlike => "sig_t".to_string(), |
Alex Crichton | de9736d | 2015-09-17 15:47:44 -0700 | [diff] [blame] | 191 | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 192 | t if t.ends_with("_t") => t.to_string(), |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 193 | |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 194 | // Windows uppercase structs don't have `struct` in front, there's a |
| 195 | // few special cases for windows, and then otherwise put `struct` in |
| 196 | // front of everything. |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 197 | t if is_struct => { |
Alex Crichton | 13a6f2d | 2015-09-10 18:10:58 -0700 | [diff] [blame] | 198 | if windows && ty.chars().next().unwrap().is_uppercase() { |
| 199 | t.to_string() |
| 200 | } else if windows && t == "stat" { |
| 201 | "struct __stat64".to_string() |
Alex Crichton | 7da9b10 | 2015-09-10 20:57:14 -0700 | [diff] [blame] | 202 | } else if windows && t == "utimbuf" { |
| 203 | "struct __utimbuf64".to_string() |
Alex Crichton | 13a6f2d | 2015-09-10 18:10:58 -0700 | [diff] [blame] | 204 | } else { |
| 205 | format!("struct {}", t) |
| 206 | } |
| 207 | } |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 208 | |
| 209 | t => t.to_string(), |
| 210 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 211 | }); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 212 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 213 | let target2 = target.clone(); |
| 214 | cfg.field_name(move |struct_, field| { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 215 | match field { |
Sébastien Marie | 6c8a63a | 2015-12-23 18:54:25 +0100 | [diff] [blame^] | 216 | "st_birthtime" if openbsd && struct_ == "stat" => "__st_birthtime".to_string(), |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 217 | "st_birthtime_nsec" if openbsd && struct_ == "stat" => "__st_birthtimensec".to_string(), |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 218 | // Our stat *_nsec fields normally don't actually exist but are part |
| 219 | // of a timeval struct |
Alex Crichton | 7482522 | 2015-10-29 17:36:55 -0700 | [diff] [blame] | 220 | s if s.ends_with("_nsec") && struct_.starts_with("stat") => { |
Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 221 | if target2.contains("apple") { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 222 | s.replace("_nsec", "spec.tv_nsec") |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 223 | } else if target2.contains("android") { |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 224 | s.to_string() |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 225 | } else { |
| 226 | s.replace("e_nsec", ".tv_nsec") |
| 227 | } |
| 228 | } |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 229 | "u64" if struct_ == "epoll_event" => "data.u64".to_string(), |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 230 | s => s.to_string(), |
| 231 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 232 | }); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 233 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 234 | cfg.skip_type(move |ty| { |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 235 | match ty { |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 236 | // sighandler_t is crazy across platforms |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 237 | "sighandler_t" => true, |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 238 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 239 | _ => false |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 240 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 241 | }); |
Alex Crichton | 1608306 | 2015-09-09 22:59:24 -0700 | [diff] [blame] | 242 | |
Alexander Polakov | 420f2e4 | 2015-11-11 01:53:39 +0300 | [diff] [blame] | 243 | cfg.skip_struct(move |ty| { |
| 244 | match ty { |
| 245 | "sockaddr_nl" => musl, |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 246 | |
| 247 | // The alignment of this is 4 on 64-bit OSX... |
| 248 | "kevent" if apple && x86_64 => true, |
| 249 | |
Alexander Polakov | 420f2e4 | 2015-11-11 01:53:39 +0300 | [diff] [blame] | 250 | _ => false |
| 251 | } |
| 252 | }); |
| 253 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 254 | cfg.skip_signededness(|c| { |
Alex Crichton | 6d3cfdb | 2015-09-15 14:53:01 -0700 | [diff] [blame] | 255 | match c { |
Alex Crichton | 7b28c27 | 2015-09-15 20:56:16 -0700 | [diff] [blame] | 256 | "LARGE_INTEGER" | |
Alex Crichton | eef03da | 2015-09-15 16:57:06 -0700 | [diff] [blame] | 257 | "mach_timebase_info_data_t" | |
Alex Crichton | 7b28c27 | 2015-09-15 20:56:16 -0700 | [diff] [blame] | 258 | "float" | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 259 | "double" => true, |
| 260 | n if n.starts_with("pthread") => true, |
Alex Crichton | 1846918 | 2015-09-15 20:57:42 -0700 | [diff] [blame] | 261 | |
| 262 | // windows-isms |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 263 | n if n.starts_with("P") => true, |
| 264 | n if n.starts_with("H") => true, |
| 265 | n if n.starts_with("LP") => true, |
| 266 | _ => false, |
Alex Crichton | 6d3cfdb | 2015-09-15 14:53:01 -0700 | [diff] [blame] | 267 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 268 | }); |
Alex Crichton | 6d3cfdb | 2015-09-15 14:53:01 -0700 | [diff] [blame] | 269 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 270 | cfg.skip_const(move |name| { |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 271 | match name { |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 272 | // Apparently these don't exist in mingw headers? |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 273 | "MEM_RESET_UNDO" | |
| 274 | "FILE_ATTRIBUTE_NO_SCRUB_DATA" | |
| 275 | "FILE_ATTRIBUTE_INTEGRITY_STREAM" | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 276 | "ERROR_NOTHING_TO_TERMINATE" if mingw => true, |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 277 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 278 | "SIG_IGN" => true, // sighandler_t weirdness |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 279 | |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 280 | // types on musl are defined a little differently |
Alex Crichton | 3a572fd | 2015-10-29 16:52:25 -0700 | [diff] [blame] | 281 | n if musl && n.contains("__SIZEOF_PTHREAD") => true, |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 282 | |
Alex Crichton | 7482522 | 2015-10-29 17:36:55 -0700 | [diff] [blame] | 283 | // Skip constants not defined in MUSL but just passed down to the |
| 284 | // kernel regardless |
| 285 | "RLIMIT_NLIMITS" | |
| 286 | "TCP_COOKIE_TRANSACTIONS" | |
| 287 | "RLIMIT_RTTIME" if musl => true, |
Alexander Polakov | 26974c7 | 2015-11-27 03:02:44 +0300 | [diff] [blame] | 288 | // work around super old mips toolchain |
Alexander Polakov | 5850156 | 2015-12-14 02:09:45 +0300 | [diff] [blame] | 289 | "SCHED_IDLE" | "SHM_NORESERVE" => mips, |
Alex Crichton | 7482522 | 2015-10-29 17:36:55 -0700 | [diff] [blame] | 290 | |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 291 | // weird signed extension or something like that? |
| 292 | "MS_NOUSER" => true, |
| 293 | |
| 294 | // These OSX constants are flagged as deprecated |
| 295 | "NOTE_EXIT_REPARENTED" | |
| 296 | "NOTE_REAP" if apple => true, |
| 297 | |
| 298 | // The linux/quota.h header file which defines these can't be |
| 299 | // included with sys/quota.h currently on MIPS, so we don't include |
| 300 | // it and just ignore these constants |
| 301 | "QFMT_VFS_OLD" | |
| 302 | "QFMT_VFS_V0" if mips && linux => true, |
| 303 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 304 | _ => false, |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 305 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 306 | }); |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 307 | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 308 | cfg.skip_fn(move |name| { |
| 309 | // skip those that are manually verifiedmanually verified |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 310 | match name { |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 311 | "execv" | // crazy stuff with const/mut |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 312 | "execve" | |
| 313 | "execvp" | |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 314 | "execvpe" => true, |
| 315 | |
Alex Crichton | 7482522 | 2015-10-29 17:36:55 -0700 | [diff] [blame] | 316 | "getrlimit" | "getrlimit64" | // non-int in 1st arg |
| 317 | "setrlimit" | "setrlimit64" | // non-int in 1st arg |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 318 | "strerror_r" if linux => true, // actually xpg-something-or-other |
| 319 | |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 320 | // typed 2nd arg on linux and android |
Sébastien Marie | c618f36 | 2015-12-21 17:26:41 +0100 | [diff] [blame] | 321 | "gettimeofday" if linux || android || freebsd || openbsd => true, |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 322 | |
Alex Crichton | 881ef9b | 2015-12-01 09:04:13 -0800 | [diff] [blame] | 323 | // not declared in newer android toolchains |
| 324 | "getdtablesize" if android => true, |
| 325 | |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 326 | "dlerror" if android => true, // const-ness is added |
Alex Crichton | 88d23e7 | 2015-11-02 17:03:19 -0800 | [diff] [blame] | 327 | "dladdr" if musl => true, // const-ness only added recently |
Alex Crichton | 1ff9610 | 2015-09-17 15:09:02 -0700 | [diff] [blame] | 328 | |
Alex Crichton | 568705e | 2015-11-03 14:18:52 -0800 | [diff] [blame] | 329 | // OSX has 'struct tm *const' which we can't actually represent in |
| 330 | // Rust, but is close enough to *mut |
| 331 | "timegm" if apple => true, |
| 332 | |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 333 | // OSX's daemon is deprecated in 10.5 so we'll get a warning (which |
| 334 | // we turn into an error) so just ignore it. |
| 335 | "daemon" if apple => true, |
| 336 | |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 337 | // These functions presumably exist on netbsd but don't look like |
| 338 | // they're implemented on rumprun yet, just let them slide for now. |
| 339 | // Some of them look like they have headers but then don't have |
| 340 | // corresponding actual definitions either... |
| 341 | "backtrace" | |
| 342 | "pthread_main_np" | |
| 343 | "pthread_set_name_np" | |
| 344 | "pthread_stackseg_np" | |
| 345 | "shm_open" | |
| 346 | "shm_unlink" | |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 347 | "syscall" | |
| 348 | "ptrace" | |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 349 | "sigaltstack" if rumprun => true, |
| 350 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 351 | _ => false, |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 352 | } |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 353 | }); |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 354 | |
Alex Crichton | 881ef9b | 2015-12-01 09:04:13 -0800 | [diff] [blame] | 355 | cfg.skip_fn_ptrcheck(move |name| { |
| 356 | match name { |
| 357 | // This used to be called bsd_signal in rev 18 of the android |
| 358 | // platform and is now just called signal, the old `bsd_signal` |
| 359 | // symbol, however, still remains, just gives a different function |
| 360 | // pointer. |
| 361 | "signal" if android => true, |
| 362 | |
| 363 | // dllimport weirdness? |
| 364 | _ if windows => true, |
| 365 | |
| 366 | _ => false, |
| 367 | } |
| 368 | }); |
Alex Crichton | e0f4d10 | 2015-09-16 09:48:14 -0700 | [diff] [blame] | 369 | |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 370 | cfg.skip_field_type(move |struct_, field| { |
Alex Crichton | f3b9748 | 2015-09-16 14:13:20 -0700 | [diff] [blame] | 371 | // This is a weird union, don't check the type. |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 372 | (struct_ == "ifaddrs" && field == "ifa_ifu") || |
| 373 | // sighandler_t type is super weird |
| 374 | (struct_ == "sigaction" && field == "sa_sigaction") |
| 375 | }); |
| 376 | |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 377 | cfg.skip_field(move |struct_, field| { |
Alex Crichton | cd9b33e | 2015-09-17 14:47:40 -0700 | [diff] [blame] | 378 | // this is actually a union on linux, so we can't represent it well and |
| 379 | // just insert some padding. |
Alex Crichton | 15b83c2 | 2015-09-17 17:25:52 -0700 | [diff] [blame] | 380 | (struct_ == "siginfo_t" && field == "_pad") || |
| 381 | // musl names this __dummy1 but it's still there |
| 382 | (musl && struct_ == "glob_t" && field == "gl_flags") |
Alex Crichton | f3b9748 | 2015-09-16 14:13:20 -0700 | [diff] [blame] | 383 | }); |
| 384 | |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 385 | cfg.fn_cname(move |name, cname| { |
Alex Crichton | 881ef9b | 2015-12-01 09:04:13 -0800 | [diff] [blame] | 386 | if windows { |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 387 | cname.unwrap_or(name).to_string() |
Alex Crichton | 0af5e23 | 2015-11-30 15:07:28 -0800 | [diff] [blame] | 388 | } else { |
Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 389 | name.to_string() |
Alex Crichton | 0af5e23 | 2015-11-30 15:07:28 -0800 | [diff] [blame] | 390 | } |
| 391 | }); |
| 392 | |
Alex Crichton | d11e914 | 2015-09-15 23:28:52 -0700 | [diff] [blame] | 393 | cfg.generate("../src/lib.rs", "all.rs"); |
Alex Crichton | 310d623 | 2015-09-10 10:56:31 -0700 | [diff] [blame] | 394 | } |