Skip to content

Commit 3dbb7a5

Browse files
committed
libc-test: port windows to use ctest-next
1 parent a0c27ab commit 3dbb7a5

File tree

1 file changed

+122
-2
lines changed

1 file changed

+122
-2
lines changed

libc-test/build.rs

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ fn do_ctest() {
6565
t if t.contains("solaris") => test_solarish(t),
6666
t if t.contains("illumos") => test_solarish(t),
6767
t if t.contains("wasi") => test_wasi(t),
68-
t if t.contains("windows") => test_windows(t),
68+
t if t.contains("windows") => {
69+
test_windows_next(t);
70+
test_windows(t);
71+
}
6972
t if t.contains("vxworks") => test_vxworks(t),
7073
t if t.contains("nto-qnx") => test_neutrino(t),
7174
t if t.contains("aix") => return test_aix(t),
@@ -77,7 +80,6 @@ fn ctest_cfg() -> ctest::TestGenerator {
7780
ctest::TestGenerator::new()
7881
}
7982

80-
#[expect(unused)]
8183
fn ctest_next_cfg() -> ctest_next::TestGenerator {
8284
ctest_next::TestGenerator::new()
8385
}
@@ -957,6 +959,124 @@ fn test_windows(target: &str) {
957959
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
958960
}
959961

962+
fn test_windows_next(target: &str) {
963+
assert!(target.contains("windows"));
964+
let gnu = target.contains("gnu");
965+
let i686 = target.contains("i686");
966+
967+
let mut cfg = ctest_next_cfg();
968+
cfg.skip_private(true);
969+
if target.contains("msvc") {
970+
cfg.flag("/wd4324");
971+
}
972+
cfg.define("_WIN32_WINNT", Some("0x8000"));
973+
974+
headers! { cfg:
975+
"direct.h",
976+
"errno.h",
977+
"fcntl.h",
978+
"io.h",
979+
"limits.h",
980+
"locale.h",
981+
"process.h",
982+
"signal.h",
983+
"stddef.h",
984+
"stdint.h",
985+
"stdio.h",
986+
"stdlib.h",
987+
"sys/stat.h",
988+
"sys/types.h",
989+
"sys/utime.h",
990+
"time.h",
991+
"wchar.h",
992+
[gnu]: "ws2tcpip.h",
993+
[!gnu]: "Winsock2.h",
994+
}
995+
996+
cfg.rename_struct_ty(|ty| {
997+
match ty {
998+
// Just pass all these through, no need for a "struct" prefix
999+
"FILE" | "DIR" | "Dl_info" => ty.to_string().into(),
1000+
t if t.ends_with("_t") => t.to_string().into(),
1001+
// Windows uppercase structs don't have `struct` in fr.into()ont:
1002+
t if ty.chars().next().unwrap().is_uppercase() => t.to_string().into(),
1003+
"stat" => "struct __stat64".to_string().into(),
1004+
"utimbuf" => "struct __utimbuf64".to_string().into(),
1005+
_ => None,
1006+
}
1007+
});
1008+
cfg.rename_type(move |ty| {
1009+
match ty {
1010+
// FIXME(windows): these don't exist:
1011+
"time64_t" => "__time64_t".to_string().into(),
1012+
"ssize_t" => "SSIZE_T".to_string().into(),
1013+
1014+
"sighandler_t" if !gnu => "_crt_signal_t".to_string().into(),
1015+
"sighandler_t" if gnu => "__p_sig_fn_t".to_string().into(),
1016+
_ => None,
1017+
}
1018+
});
1019+
1020+
cfg.rename_fn(move |func| {
1021+
func.link_name()
1022+
.map(|l| l.to_string())
1023+
.or(func.ident().to_string().into())
1024+
});
1025+
1026+
cfg.skip_alias(move |alias| match alias.ident() {
1027+
"SSIZE_T" if !gnu => true,
1028+
"ssize_t" if !gnu => true,
1029+
// FIXME(windows): The size and alignment of this type are incorrect
1030+
"time_t" if gnu && i686 => true,
1031+
_ => false,
1032+
});
1033+
1034+
cfg.skip_struct(move |struct_| {
1035+
let ty = struct_.ident();
1036+
if ty.starts_with("__c_anonymous_") {
1037+
return true;
1038+
}
1039+
match ty {
1040+
// FIXME(windows): The size and alignment of this struct are incorrect
1041+
"timespec" if gnu && i686 => true,
1042+
_ => false,
1043+
}
1044+
});
1045+
cfg.skip_union(move |union_| union_.ident().starts_with("__c_anonymous_"));
1046+
1047+
cfg.skip_const(move |constant| {
1048+
match constant.ident() {
1049+
// FIXME(windows): API error:
1050+
// SIG_ERR type is "void (*)(int)", not "int"
1051+
"SIG_ERR" |
1052+
// Similar for SIG_DFL/IGN/GET/SGE/ACK
1053+
"SIG_DFL" | "SIG_IGN" | "SIG_GET" | "SIG_SGE" | "SIG_ACK" => true,
1054+
// FIXME(windows): newer windows-gnu environment on CI?
1055+
"_O_OBTAIN_DIR" if gnu => true,
1056+
_ => false,
1057+
}
1058+
});
1059+
1060+
cfg.skip_struct_field(move |s, field| s.ident() == "CONTEXT" && field.ident() == "Fp");
1061+
// FIXME(windows): All functions point to the wrong addresses?
1062+
// cfg.skip_fn_ptr_check(|_| true);
1063+
1064+
cfg.skip_signededness(move |c| {
1065+
match c {
1066+
// windows-isms
1067+
n if n.starts_with("P") => true,
1068+
n if n.starts_with("H") => true,
1069+
n if n.starts_with("LP") => true,
1070+
"sighandler_t" if gnu => true,
1071+
_ => false,
1072+
}
1073+
});
1074+
1075+
cfg.skip_fn(|_| false);
1076+
1077+
ctest_next::generate_test(&mut cfg, "../src/lib.rs", "main_next.rs").unwrap();
1078+
}
1079+
9601080
fn test_redox(target: &str) {
9611081
assert!(target.contains("redox"));
9621082

0 commit comments

Comments
 (0)