libc-rs/libc-test/build.rs

194 lines
5.7 KiB
Rust
Raw Normal View History

2015-09-16 08:28:52 +02:00
extern crate ctest;
2015-09-10 07:46:19 +02:00
use std::env;
2015-09-16 08:28:52 +02:00
fn main() {
let target = env::var("TARGET").unwrap();
let windows = target.contains("windows");
let mingw = target.contains("windows-gnu");
let mut cfg = ctest::TestGenerator::new();
// Pull in extra goodies on linux/mingw
if target.contains("unknown-linux-gnu") {
cfg.define("_GNU_SOURCE", None);
} else if target.contains("windows") {
cfg.define("_WIN32_WINNT", Some("0x8000"));
}
cfg.header("errno.h")
.header("fcntl.h")
.header("limits.h")
.header("stddef.h")
.header("stdint.h")
.header("stdio.h")
.header("stdlib.h")
.header("sys/stat.h")
.header("sys/types.h")
.header("time.h")
.header("wchar.h");
if target.contains("apple-darwin") {
cfg.header("mach-o/dyld.h");
cfg.header("mach/mach_time.h");
} else if target.contains("unknown-linux") ||
target.contains("android") {
cfg.header("linux/if_packet.h");
cfg.header("net/ethernet.h");
}
if target.contains("windows") {
cfg.header("winsock2.h"); // must be before windows.h
cfg.header("direct.h");
cfg.header("io.h");
cfg.header("sys/utime.h");
cfg.header("windows.h");
cfg.header("process.h");
cfg.header("ws2ipdef.h");
if target.contains("gnu") {
cfg.header("ws2tcpip.h");
2015-09-10 19:56:31 +02:00
}
2015-09-16 08:28:52 +02:00
} else {
cfg.header("ctype.h");
cfg.header("dirent.h");
cfg.header("net/if.h");
cfg.header("netdb.h");
cfg.header("netinet/in.h");
cfg.header("netinet/ip.h");
cfg.header("netinet/tcp.h");
cfg.header("pthread.h");
cfg.header("signal.h");
cfg.header("string.h");
cfg.header("sys/file.h");
cfg.header("sys/ioctl.h");
cfg.header("sys/mman.h");
cfg.header("sys/resource.h");
cfg.header("sys/socket.h");
cfg.header("sys/time.h");
cfg.header("sys/un.h");
cfg.header("sys/wait.h");
cfg.header("unistd.h");
cfg.header("utime.h");
if target.contains("android") {
cfg.header("arpa/inet.h");
2015-09-11 02:21:20 +02:00
} else {
2015-09-16 08:28:52 +02:00
cfg.header("glob.h");
cfg.header("ifaddrs.h");
cfg.header("sys/sysctl.h");
2015-09-11 02:21:20 +02:00
}
2015-09-10 19:56:31 +02:00
}
2015-09-16 08:28:52 +02:00
cfg.type_name(move |ty, is_struct| {
2015-09-10 19:56:31 +02:00
match ty {
2015-09-11 08:43:41 +02:00
// Just pass all these through, no need for a "struct" prefix
2015-09-11 04:59:23 +02:00
"glob_t" |
"FILE" |
"DIR" |
"fpos_t" => ty.to_string(),
2015-09-10 19:56:31 +02:00
t if t.starts_with("pthread") => t.to_string(),
2015-09-11 08:43:41 +02:00
// Windows uppercase structs don't have `struct` in front, there's a
// few special cases for windows, and then otherwise put `struct` in
// front of everything.
2015-09-16 08:28:52 +02:00
t if is_struct => {
2015-09-11 03:10:58 +02:00
if windows && ty.chars().next().unwrap().is_uppercase() {
t.to_string()
} else if windows && t == "stat" {
"struct __stat64".to_string()
2015-09-11 05:57:14 +02:00
} else if windows && t == "utimbuf" {
"struct __utimbuf64".to_string()
2015-09-11 03:10:58 +02:00
} else {
format!("struct {}", t)
}
}
2015-09-10 19:56:31 +02:00
2015-09-11 08:43:41 +02:00
// Fixup a few types on windows that don't actually exist.
2015-09-11 03:10:58 +02:00
"time64_t" if windows => "__time64_t".to_string(),
"ssize_t" if windows => "SSIZE_T".to_string(),
2015-09-11 08:43:41 +02:00
2015-09-10 19:56:31 +02:00
t => t.to_string(),
}
2015-09-16 08:28:52 +02:00
});
2015-09-10 19:56:31 +02:00
2015-09-16 08:28:52 +02:00
let target2 = target.clone();
cfg.field_name(move |struct_, field| {
2015-09-10 19:56:31 +02:00
match field {
2015-09-11 08:43:41 +02:00
// Our stat *_nsec fields normally don't actually exist but are part
// of a timeval struct
2015-09-10 19:56:31 +02:00
s if s.ends_with("_nsec") && struct_ == "stat" => {
2015-09-16 08:28:52 +02:00
if target2.contains("apple-darwin") {
2015-09-10 19:56:31 +02:00
s.replace("_nsec", "spec.tv_nsec")
2015-09-16 08:28:52 +02:00
} else if target2.contains("android") {
2015-09-12 02:03:39 +02:00
s.to_string()
2015-09-10 19:56:31 +02:00
} else {
s.replace("e_nsec", ".tv_nsec")
}
}
s => s.to_string(),
}
2015-09-16 08:28:52 +02:00
});
2015-09-11 08:43:41 +02:00
2015-09-16 08:28:52 +02:00
let target2 = target.clone();
cfg.skip_type(move |ty| {
2015-09-10 19:56:31 +02:00
match ty {
2015-09-12 02:03:39 +02:00
// sighandler_t is crazy across platforms
2015-09-16 08:28:52 +02:00
"sighandler_t" => true,
2015-09-12 02:03:39 +02:00
// Not actually defined on android, but it's not hurting anyone
2015-09-16 08:28:52 +02:00
"in_port_t" if target2.contains("android") => true,
_ => false
2015-09-10 19:56:31 +02:00
}
2015-09-16 08:28:52 +02:00
});
2015-09-10 08:21:27 +02:00
2015-09-16 08:28:52 +02:00
cfg.skip_signededness(|c| {
2015-09-15 23:53:01 +02:00
match c {
2015-09-16 05:56:16 +02:00
"LARGE_INTEGER" |
"mach_timebase_info_data_t" |
2015-09-16 05:56:16 +02:00
"float" |
2015-09-16 08:28:52 +02:00
"double" => true,
n if n.starts_with("pthread") => true,
2015-09-16 05:57:42 +02:00
// windows-isms
2015-09-16 08:28:52 +02:00
n if n.starts_with("P") => true,
n if n.starts_with("H") => true,
n if n.starts_with("LP") => true,
_ => false,
2015-09-15 23:53:01 +02:00
}
2015-09-16 08:28:52 +02:00
});
2015-09-15 23:53:01 +02:00
2015-09-16 08:28:52 +02:00
// Apparently these don't exist in mingw headers?
cfg.skip_const(move |name| {
2015-09-11 08:43:41 +02:00
match name {
"MEM_RESET_UNDO" |
"FILE_ATTRIBUTE_NO_SCRUB_DATA" |
"FILE_ATTRIBUTE_INTEGRITY_STREAM" |
2015-09-16 08:28:52 +02:00
"ERROR_NOTHING_TO_TERMINATE" if mingw => true,
"SIG_IGN" => true, // sighandler_t weirdness
_ => false,
2015-09-11 08:43:41 +02:00
}
2015-09-16 08:28:52 +02:00
});
2015-09-11 08:43:41 +02:00
2015-09-16 08:28:52 +02:00
cfg.skip_fn(|name| {
2015-09-11 04:59:23 +02:00
match name {
// manually verified
"execv" |
"execve" |
"execvp" |
2015-09-11 05:57:14 +02:00
"execvpe" |
2015-09-11 04:59:23 +02:00
"glob" |
"getrlimit" |
"setrlimit" |
2015-09-11 05:19:44 +02:00
"signal" |
2015-09-16 08:28:52 +02:00
"getopt" => true,
_ => false,
2015-09-11 04:59:23 +02:00
}
2015-09-16 08:28:52 +02:00
});
2015-09-11 04:59:23 +02:00
// Windows dllimport oddness?
cfg.skip_fn_ptrcheck(move |_| windows);
2015-09-16 08:28:52 +02:00
cfg.generate("../src/lib.rs", "all.rs");
2015-09-10 19:56:31 +02:00
}