Skip to content

Commit 8516849

Browse files
mbyxtgross35
authored andcommitted
libc: port windows to use ctest-next
(backport <rust-lang#4600>) (cherry picked from commit acd869f)
1 parent ec1573c commit 8516849

File tree

4 files changed

+36
-58
lines changed

4 files changed

+36
-58
lines changed

libc-test/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ name = "ctest"
3737
path = "test/ctest.rs"
3838
harness = false
3939

40-
[[test]]
41-
name = "ctest_next"
42-
path = "test/ctest_next.rs"
43-
harness = false
44-
4540
[[test]]
4641
name = "linux-fcntl"
4742
path = "test/linux_fcntl.rs"

libc-test/build.rs

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ fn ctest_cfg() -> ctest::TestGenerator {
8484
cfg
8585
}
8686

87-
#[expect(unused)]
8887
fn ctest_next_cfg() -> ctest_next::TestGenerator {
8988
ctest_next::TestGenerator::new()
9089
}
@@ -176,14 +175,6 @@ fn main() {
176175
let re = regex::bytes::Regex::new(r"(?-u:\b)crate::").unwrap();
177176
copy_dir_hotfix(Path::new("../src"), &hotfix_dir, &re, b"::");
178177

179-
// FIXME(ctest): Only needed until ctest-next supports all tests.
180-
// Provide a default for targets that don't yet use `ctest-next`.
181-
std::fs::write(
182-
format!("{}/main_next.rs", std::env::var("OUT_DIR").unwrap()),
183-
"\nfn main() { println!(\"test result: ok\"); }\n",
184-
)
185-
.unwrap();
186-
187178
do_cc();
188179
do_ctest();
189180
do_semver();
@@ -887,7 +878,8 @@ fn test_windows(target: &str) {
887878
let gnu = target.contains("gnu");
888879
let i686 = target.contains("i686");
889880

890-
let mut cfg = ctest_cfg();
881+
let mut cfg = ctest_next_cfg();
882+
cfg.skip_private(true);
891883
if target.contains("msvc") {
892884
cfg.flag("/wd4324");
893885
}
@@ -915,49 +907,46 @@ fn test_windows(target: &str) {
915907
[!gnu]: "Winsock2.h",
916908
}
917909

918-
cfg.type_name(move |ty, is_struct, is_union| {
910+
cfg.rename_struct_ty(|ty| {
919911
match ty {
920912
// Just pass all these through, no need for a "struct" prefix
921-
"FILE" | "DIR" | "Dl_info" => ty.to_string(),
922-
913+
"FILE" | "DIR" | "Dl_info" => ty.to_string().into(),
914+
t if t.ends_with("_t") => t.to_string().into(),
915+
// Windows uppercase structs don't have `struct` in fr.into()ont:
916+
t if ty.chars().next().unwrap().is_uppercase() => t.to_string().into(),
917+
"stat" => "struct __stat64".to_string().into(),
918+
"utimbuf" => "struct __utimbuf64".to_string().into(),
919+
_ => None,
920+
}
921+
});
922+
cfg.rename_type(move |ty| {
923+
match ty {
923924
// FIXME(windows): these don't exist:
924-
"time64_t" => "__time64_t".to_string(),
925-
"ssize_t" => "SSIZE_T".to_string(),
926-
927-
"sighandler_t" if !gnu => "_crt_signal_t".to_string(),
928-
"sighandler_t" if gnu => "__p_sig_fn_t".to_string(),
929-
930-
t if is_union => format!("union {t}"),
931-
t if t.ends_with("_t") => t.to_string(),
925+
"time64_t" => "__time64_t".to_string().into(),
926+
"ssize_t" => "SSIZE_T".to_string().into(),
932927

933-
// Windows uppercase structs don't have `struct` in front:
934-
t if is_struct => {
935-
if ty.chars().next().unwrap().is_uppercase() {
936-
t.to_string()
937-
} else if t == "stat" {
938-
"struct __stat64".to_string()
939-
} else if t == "utimbuf" {
940-
"struct __utimbuf64".to_string()
941-
} else {
942-
// put `struct` in front of all structs:
943-
format!("struct {t}")
944-
}
945-
}
946-
t => t.to_string(),
928+
"sighandler_t" if !gnu => "_crt_signal_t".to_string().into(),
929+
"sighandler_t" if gnu => "__p_sig_fn_t".to_string().into(),
930+
_ => None,
947931
}
948932
});
949933

950-
cfg.fn_cname(move |name, cname| cname.unwrap_or(name).to_string());
934+
cfg.rename_fn(move |func| {
935+
func.link_name()
936+
.map(|l| l.to_string())
937+
.or(func.ident().to_string().into())
938+
});
951939

952-
cfg.skip_type(move |name| match name {
940+
cfg.skip_alias(move |alias| match alias.ident() {
953941
"SSIZE_T" if !gnu => true,
954942
"ssize_t" if !gnu => true,
955943
// FIXME(windows): The size and alignment of this type are incorrect
956944
"time_t" if gnu && i686 => true,
957945
_ => false,
958946
});
959947

960-
cfg.skip_struct(move |ty| {
948+
cfg.skip_struct(move |struct_| {
949+
let ty = struct_.ident();
961950
if ty.starts_with("__c_anonymous_") {
962951
return true;
963952
}
@@ -967,9 +956,10 @@ fn test_windows(target: &str) {
967956
_ => false,
968957
}
969958
});
959+
cfg.skip_union(move |union_| union_.ident().starts_with("__c_anonymous_"));
970960

971-
cfg.skip_const(move |name| {
972-
match name {
961+
cfg.skip_const(move |constant| {
962+
match constant.ident() {
973963
// FIXME(windows): API error:
974964
// SIG_ERR type is "void (*)(int)", not "int"
975965
"SIG_ERR" |
@@ -981,10 +971,7 @@ fn test_windows(target: &str) {
981971
}
982972
});
983973

984-
cfg.skip_field(move |s, field| match s {
985-
"CONTEXT" if field == "Fp" => true,
986-
_ => false,
987-
});
974+
cfg.skip_struct_field(move |s, field| s.ident() == "CONTEXT" && field.ident() == "Fp");
988975
// FIXME(windows): All functions point to the wrong addresses?
989976
cfg.skip_fn_ptrcheck(|_| true);
990977

@@ -999,16 +986,16 @@ fn test_windows(target: &str) {
999986
}
1000987
});
1001988

1002-
cfg.skip_fn(move |name| {
1003-
match name {
989+
cfg.skip_fn(move |func| {
990+
match func.ident() {
1004991
// FIXME: https://github.com/rust-lang/libc/issues/1272
1005992
"execv" | "execve" | "execvp" | "execvpe" => true,
1006993

1007994
_ => false,
1008995
}
1009996
});
1010997

1011-
cfg.generate(src_hotfix_dir().join("lib.rs"), "ctest_output.rs");
998+
ctest_next::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap();
1012999
}
10131000

10141001
fn test_redox(target: &str) {

libc-test/test/ctest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![allow(bad_style, improper_ctypes, deprecated)]
1+
#![allow(deprecated)]
22

3+
#[allow(unused_imports)]
34
use libc::*;
45

56
include!(concat!(env!("OUT_DIR"), "/ctest_output.rs"));

libc-test/test/ctest_next.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)