Skip to content

Commit 2ea7206

Browse files
committed
Auto merge of #1275 - gnzlbg:win_clean, r=gnzlbg
Cleanup Windows libc-test build.rs
2 parents a5c20d6 + 0980cf5 commit 2ea7206

File tree

2 files changed

+175
-128
lines changed

2 files changed

+175
-128
lines changed

appveyor.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ install:
2323
build: false
2424

2525
test_script:
26-
- cargo test --target %TARGET%
27-
- cargo test --no-default-features --target %TARGET%
28-
- cargo test --manifest-path libc-test/Cargo.toml --target %TARGET%
26+
- cargo -vv test --target %TARGET%
27+
- cargo -vv test --no-default-features --target %TARGET%
28+
- cargo -vv test --manifest-path libc-test/Cargo.toml --target %TARGET%

libc-test/build.rs

Lines changed: 172 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ fn do_ctest() {
1818
let i686 = target.contains("i686");
1919
let x86_64 = target.contains("x86_64");
2020
let x32 = target.ends_with("gnux32");
21-
let windows = target.contains("windows");
22-
let mingw = target.contains("windows-gnu");
2321
let linux = target.contains("unknown-linux");
2422
let android = target.contains("android");
25-
let apple = target.contains("apple");
2623
let emscripten = target.contains("asm");
2724
let musl = target.contains("musl") || emscripten;
2825
let uclibc = target.contains("uclibc");
@@ -35,20 +32,20 @@ fn do_ctest() {
3532
let solaris = target.contains("solaris");
3633
let cloudabi = target.contains("cloudabi");
3734
let redox = target.contains("redox");
38-
let bsdlike = freebsd || apple || netbsd || openbsd || dragonfly;
35+
let bsdlike = freebsd || netbsd || openbsd || dragonfly;
3936
let mut cfg = ctest::TestGenerator::new();
4037

41-
if apple {
42-
return test_apple(&target);
38+
match &target {
39+
t if t.contains("apple") => return test_apple(t),
40+
t if t.contains("windows") => return test_windows(t),
41+
_ => (),
4342
}
4443

4544
// Pull in extra goodies
4645
if linux || android || emscripten {
4746
cfg.define("_GNU_SOURCE", None);
4847
} else if netbsd {
4948
cfg.define("_NETBSD_SOURCE", Some("1"));
50-
} else if windows {
51-
cfg.define("_WIN32_WINNT", Some("0x8000"));
5249
} else if solaris {
5350
cfg.define("_XOPEN_SOURCE", Some("700"));
5451
cfg.define("__EXTENSIONS__", None);
@@ -76,74 +73,58 @@ fn do_ctest() {
7673
.header("time.h")
7774
.header("wchar.h");
7875

79-
if windows {
80-
cfg.header("winsock2.h"); // must be before windows.h
81-
82-
cfg.header("direct.h");
83-
cfg.header("io.h");
84-
cfg.header("sys/utime.h");
85-
cfg.header("windows.h");
86-
cfg.header("process.h");
87-
cfg.header("ws2ipdef.h");
88-
cfg.header("signal.h");
89-
90-
if target.contains("gnu") {
91-
cfg.header("ws2tcpip.h");
92-
}
93-
} else {
94-
cfg.flag("-Wno-deprecated-declarations");
76+
cfg.flag("-Wno-deprecated-declarations");
9577

96-
cfg.header("ctype.h");
97-
cfg.header("dirent.h");
98-
if openbsd {
99-
cfg.header("sys/socket.h");
100-
}
101-
cfg.header("net/if.h");
102-
cfg.header("net/route.h");
103-
cfg.header("net/if_arp.h");
104-
if linux || android {
105-
cfg.header("linux/if_alg.h");
106-
}
107-
cfg.header("netdb.h");
108-
cfg.header("netinet/in.h");
109-
cfg.header("netinet/ip.h");
110-
cfg.header("netinet/tcp.h");
111-
cfg.header("netinet/udp.h");
112-
cfg.header("resolv.h");
113-
cfg.header("pthread.h");
114-
cfg.header("dlfcn.h");
115-
cfg.header("signal.h");
116-
cfg.header("string.h");
117-
cfg.header("sys/file.h");
118-
cfg.header("sys/ioctl.h");
119-
cfg.header("sys/mman.h");
120-
cfg.header("sys/resource.h");
78+
cfg.header("ctype.h");
79+
cfg.header("dirent.h");
80+
if openbsd {
12181
cfg.header("sys/socket.h");
122-
if linux && !musl {
123-
cfg.header("linux/if.h");
124-
cfg.header("sys/auxv.h");
125-
}
126-
cfg.header("sys/time.h");
127-
cfg.header("sys/un.h");
128-
cfg.header("sys/wait.h");
129-
cfg.header("unistd.h");
130-
cfg.header("utime.h");
131-
cfg.header("pwd.h");
132-
cfg.header("grp.h");
133-
cfg.header("sys/utsname.h");
134-
if !solaris {
135-
cfg.header("sys/ptrace.h");
136-
}
137-
cfg.header("sys/mount.h");
138-
cfg.header("sys/uio.h");
139-
cfg.header("sched.h");
140-
cfg.header("termios.h");
141-
cfg.header("poll.h");
142-
cfg.header("syslog.h");
143-
cfg.header("semaphore.h");
144-
cfg.header("sys/statvfs.h");
145-
cfg.header("sys/times.h");
14682
}
83+
cfg.header("net/if.h");
84+
cfg.header("net/route.h");
85+
cfg.header("net/if_arp.h");
86+
if linux || android {
87+
cfg.header("linux/if_alg.h");
88+
}
89+
cfg.header("netdb.h");
90+
cfg.header("netinet/in.h");
91+
cfg.header("netinet/ip.h");
92+
cfg.header("netinet/tcp.h");
93+
cfg.header("netinet/udp.h");
94+
cfg.header("resolv.h");
95+
cfg.header("pthread.h");
96+
cfg.header("dlfcn.h");
97+
cfg.header("signal.h");
98+
cfg.header("string.h");
99+
cfg.header("sys/file.h");
100+
cfg.header("sys/ioctl.h");
101+
cfg.header("sys/mman.h");
102+
cfg.header("sys/resource.h");
103+
cfg.header("sys/socket.h");
104+
if linux && !musl {
105+
cfg.header("linux/if.h");
106+
cfg.header("sys/auxv.h");
107+
}
108+
cfg.header("sys/time.h");
109+
cfg.header("sys/un.h");
110+
cfg.header("sys/wait.h");
111+
cfg.header("unistd.h");
112+
cfg.header("utime.h");
113+
cfg.header("pwd.h");
114+
cfg.header("grp.h");
115+
cfg.header("sys/utsname.h");
116+
if !solaris {
117+
cfg.header("sys/ptrace.h");
118+
}
119+
cfg.header("sys/mount.h");
120+
cfg.header("sys/uio.h");
121+
cfg.header("sched.h");
122+
cfg.header("termios.h");
123+
cfg.header("poll.h");
124+
cfg.header("syslog.h");
125+
cfg.header("semaphore.h");
126+
cfg.header("sys/statvfs.h");
127+
cfg.header("sys/times.h");
147128

148129
if android {
149130
if !aarch64 && !x86_64 {
@@ -158,7 +139,7 @@ fn do_ctest() {
158139
if i686 || x86_64 {
159140
cfg.header("sys/reg.h");
160141
}
161-
} else if !windows {
142+
} else {
162143
cfg.header("glob.h");
163144
cfg.header("ifaddrs.h");
164145
cfg.header("langinfo.h");
@@ -354,33 +335,15 @@ fn do_ctest() {
354335
| "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr"
355336
| "Elf64_Chdr" => ty.to_string(),
356337

357-
// Fixup a few types on windows that don't actually exist.
358-
"time64_t" if windows => "__time64_t".to_string(),
359-
"ssize_t" if windows => "SSIZE_T".to_string(),
360-
// windows
361-
"sighandler_t" if windows && !mingw => "_crt_signal_t".to_string(),
362-
"sighandler_t" if windows && mingw => "__p_sig_fn_t".to_string(),
363338
// OSX calls this something else
364339
"sighandler_t" if bsdlike => "sig_t".to_string(),
365340

366341
t if is_union => format!("union {}", t),
367342

368343
t if t.ends_with("_t") => t.to_string(),
369344

370-
// Windows uppercase structs don't have `struct` in front, there's a
371-
// few special cases for windows, and then otherwise put `struct` in
372-
// front of everything.
373-
t if is_struct => {
374-
if windows && ty.chars().next().unwrap().is_uppercase() {
375-
t.to_string()
376-
} else if windows && t == "stat" {
377-
"struct __stat64".to_string()
378-
} else if windows && t == "utimbuf" {
379-
"struct __utimbuf64".to_string()
380-
} else {
381-
format!("struct {}", t)
382-
}
383-
}
345+
// put `struct` in front of all structs:.
346+
t if is_struct => format!("struct {}", t),
384347

385348
t => t.to_string(),
386349
}
@@ -467,27 +430,12 @@ fn do_ctest() {
467430
// mqd_t is a pointer on FreeBSD and DragonFly
468431
"mqd_t" if freebsd || dragonfly => true,
469432

470-
// windows-isms
471-
n if n.starts_with("P") => true,
472-
n if n.starts_with("H") => true,
473-
n if n.starts_with("LP") => true,
474-
"__p_sig_fn_t" if mingw => true,
475433
_ => false,
476434
}
477435
});
478436

479437
cfg.skip_const(move |name| {
480438
match name {
481-
// Apparently these don't exist in mingw headers?
482-
"MEM_RESET_UNDO"
483-
| "FILE_ATTRIBUTE_NO_SCRUB_DATA"
484-
| "FILE_ATTRIBUTE_INTEGRITY_STREAM"
485-
| "ERROR_NOTHING_TO_TERMINATE"
486-
if mingw =>
487-
{
488-
true
489-
}
490-
491439
"SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness
492440
"SIGUNUSED" => true, // removed in glibc 2.26
493441

@@ -801,15 +749,6 @@ fn do_ctest() {
801749
}
802750
});
803751

804-
cfg.skip_fn_ptrcheck(move |name| {
805-
match name {
806-
// dllimport weirdness?
807-
_ if windows => true,
808-
809-
_ => false,
810-
}
811-
});
812-
813752
cfg.skip_field_type(move |struct_, field| {
814753
// This is a weird union, don't check the type.
815754
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
@@ -847,13 +786,8 @@ fn do_ctest() {
847786
field == "ssi_arch"))
848787
});
849788

850-
cfg.fn_cname(move |name, cname| {
851-
if windows {
852-
cname.unwrap_or(name).to_string()
853-
} else {
854-
name.to_string()
855-
}
856-
});
789+
// FIXME: remove
790+
cfg.fn_cname(move |name, _cname| name.to_string());
857791

858792
cfg.generate("../src/lib.rs", "main.rs");
859793

@@ -1093,3 +1027,116 @@ fn test_apple(target: &str) {
10931027

10941028
cfg.generate("../src/lib.rs", "main.rs");
10951029
}
1030+
1031+
fn test_windows(target: &str) {
1032+
assert!(target.contains("windows"));
1033+
let gnu = target.contains("gnu");
1034+
1035+
let mut cfg = ctest::TestGenerator::new();
1036+
cfg.define("_WIN32_WINNT", Some("0x8000"));
1037+
1038+
headers! { cfg:
1039+
"direct.h",
1040+
"errno.h",
1041+
"fcntl.h",
1042+
"io.h",
1043+
"limits.h",
1044+
"locale.h",
1045+
"process.h",
1046+
"signal.h",
1047+
"stddef.h",
1048+
"stdint.h",
1049+
"stdio.h",
1050+
"stdlib.h",
1051+
"sys/stat.h",
1052+
"sys/types.h",
1053+
"sys/utime.h",
1054+
"time.h",
1055+
"wchar.h",
1056+
}
1057+
1058+
if gnu {
1059+
headers! { cfg: "ws2tcpip.h" }
1060+
} else {
1061+
headers! { cfg: "Winsock2.h" };
1062+
}
1063+
1064+
cfg.type_name(move |ty, is_struct, is_union| {
1065+
match ty {
1066+
// Just pass all these through, no need for a "struct" prefix
1067+
"FILE" | "DIR" | "Dl_info" => ty.to_string(),
1068+
1069+
// FIXME: these don't exist:
1070+
"time64_t" => "__time64_t".to_string(),
1071+
"ssize_t" => "SSIZE_T".to_string(),
1072+
1073+
"sighandler_t" if !gnu => "_crt_signal_t".to_string(),
1074+
"sighandler_t" if gnu => "__p_sig_fn_t".to_string(),
1075+
1076+
t if is_union => format!("union {}", t),
1077+
t if t.ends_with("_t") => t.to_string(),
1078+
1079+
// Windows uppercase structs don't have `struct` in front:
1080+
t if is_struct => {
1081+
if ty.clone().chars().next().unwrap().is_uppercase() {
1082+
t.to_string()
1083+
} else if t == "stat" {
1084+
"struct __stat64".to_string()
1085+
} else if t == "utimbuf" {
1086+
"struct __utimbuf64".to_string()
1087+
} else {
1088+
// put `struct` in front of all structs:
1089+
format!("struct {}", t)
1090+
}
1091+
}
1092+
t => t.to_string(),
1093+
}
1094+
});
1095+
1096+
cfg.fn_cname(move |name, cname| cname.unwrap_or(name).to_string());
1097+
1098+
cfg.skip_type(move |name| {
1099+
match name {
1100+
"SSIZE_T" if !gnu => true,
1101+
"ssize_t" if !gnu => true,
1102+
_ => false,
1103+
}
1104+
});
1105+
1106+
cfg.skip_const(move |name| {
1107+
match name {
1108+
// FIXME: API error:
1109+
// SIG_ERR type is "void (*)(int)", not "int"
1110+
"SIG_ERR" => true,
1111+
_ => false,
1112+
}
1113+
});
1114+
1115+
// FIXME: All functions point to the wrong addresses?
1116+
cfg.skip_fn_ptrcheck(|_| true);
1117+
1118+
cfg.skip_signededness(move |c| {
1119+
match c {
1120+
// windows-isms
1121+
n if n.starts_with("P") => true,
1122+
n if n.starts_with("H") => true,
1123+
n if n.starts_with("LP") => true,
1124+
"sighandler_t" if gnu => true,
1125+
_ => false,
1126+
}
1127+
});
1128+
1129+
cfg.skip_fn(move |name| {
1130+
match name {
1131+
// FIXME: API error:
1132+
"execv" |
1133+
"execve" |
1134+
"execvp" |
1135+
"execvpe" => true,
1136+
1137+
_ => false,
1138+
}
1139+
});
1140+
1141+
cfg.generate("../src/lib.rs", "main.rs");
1142+
}

0 commit comments

Comments
 (0)