Skip to content

Commit d730bc3

Browse files
mbyxtgross35
authored andcommitted
libc: port apple to use ctest-next
(backport <#4610>) (cherry picked from commit 1e8377c)
1 parent 3a650df commit d730bc3

File tree

1 file changed

+41
-53
lines changed

1 file changed

+41
-53
lines changed

libc-test/build.rs

Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ fn test_apple(target: &str) {
226226
let x86_64 = target.contains("x86_64");
227227
let i686 = target.contains("i686");
228228

229-
let mut cfg = ctest_cfg();
229+
let mut cfg = ctest_next_cfg();
230+
230231
cfg.flag("-Wno-deprecated-declarations");
231232
cfg.define("__APPLE_USE_RFC_3542", None);
232233

@@ -347,31 +348,28 @@ fn test_apple(target: &str) {
347348
[x86_64]: "crt_externs.h",
348349
}
349350

350-
cfg.skip_struct(move |ty| {
351-
if ty.starts_with("__c_anonymous_") {
352-
return true;
353-
}
354-
match ty {
351+
// Skip anonymous unions/structs.
352+
cfg.skip_union(|u| u.ident().starts_with("__c_anonymous_"));
353+
cfg.skip_struct(|s| s.ident().starts_with("__c_anonymous_"));
354+
355+
cfg.skip_struct(|s| {
356+
match s.ident() {
355357
// FIXME(union): actually a union
356358
"sigval" => true,
357-
358359
// FIXME(macos): The size is changed in recent macOSes.
359360
"malloc_zone_t" => true,
360361
// it is a moving target, changing through versions
361362
// also contains bitfields members
362363
"tcp_connection_info" => true,
363364
// FIXME(macos): The size is changed in recent macOSes.
364365
"malloc_introspection_t" => true,
365-
366366
_ => false,
367367
}
368368
});
369369

370-
cfg.skip_type(move |ty| {
371-
if ty.starts_with("__c_anonymous_") {
372-
return true;
373-
}
374-
match ty {
370+
cfg.skip_alias(|ty| ty.ident().starts_with("__c_anonymous_"));
371+
cfg.skip_alias(|ty| {
372+
match ty.ident() {
375373
// FIXME(macos): Requires the macOS 14.4 SDK.
376374
"os_sync_wake_by_address_flags_t" | "os_sync_wait_on_address_flags_t" => true,
377375

@@ -382,12 +380,10 @@ fn test_apple(target: &str) {
382380
}
383381
});
384382

385-
cfg.skip_const(move |name| {
386-
// They're declared via `deprecated_mach` and we don't support it anymore.
387-
if name.starts_with("VM_FLAGS_") {
388-
return true;
389-
}
390-
match name {
383+
cfg.skip_const(move |constant| {
384+
match constant.ident() {
385+
// They're declared via `deprecated_mach` and we don't support it anymore.
386+
x if x.starts_with("VM_FLAGS_") => true,
391387
// These OSX constants are removed in Sierra.
392388
// https://developer.apple.com/library/content/releasenotes/General/APIDiffsMacOS10_12/Swift/Darwin.html
393389
"KERN_KDENABLE_BG_TRACE" | "KERN_KDDISABLE_BG_TRACE" => true,
@@ -407,12 +403,11 @@ fn test_apple(target: &str) {
407403
}
408404
});
409405

410-
cfg.skip_fn(move |name| {
406+
cfg.skip_fn(move |func| {
411407
// skip those that are manually verified
412-
match name {
408+
match func.ident() {
413409
// FIXME: https://github.com/rust-lang/libc/issues/1272
414410
"execv" | "execve" | "execvp" => true,
415-
416411
// close calls the close_nocancel system call
417412
"close" => true,
418413

@@ -441,8 +436,8 @@ fn test_apple(target: &str) {
441436
}
442437
});
443438

444-
cfg.skip_field(move |struct_, field| {
445-
match (struct_, field) {
439+
cfg.skip_struct_field(move |struct_, field| {
440+
match (struct_.ident(), field.ident()) {
446441
// FIXME(macos): the array size has been changed since macOS 10.15 ([8] -> [7]).
447442
("statfs", "f_reserved") => true,
448443
("__darwin_arm_neon_state64", "__v") => true,
@@ -459,47 +454,39 @@ fn test_apple(target: &str) {
459454
}
460455
});
461456

462-
cfg.skip_field_type(move |struct_, field| {
463-
match (struct_, field) {
457+
cfg.skip_struct_field_type(move |struct_, field| {
458+
match (struct_.ident(), field.ident()) {
464459
// FIXME(union): actually a union
465460
("sigevent", "sigev_value") => true,
466461
_ => false,
467462
}
468463
});
469464

470-
cfg.volatile_item(|i| {
471-
use ctest::VolatileItemKind::*;
472-
match i {
473-
StructField(ref n, ref f) if n == "aiocb" && f == "aio_buf" => true,
474-
_ => false,
475-
}
465+
cfg.volatile_struct_field(|s, f| s.ident() == "aiocb" && f.ident() == "aio_buf");
466+
467+
cfg.rename_struct_ty(move |ty| {
468+
// Just pass all these through, no need for a "struct" prefix
469+
["FILE", "DIR", "Dl_info"]
470+
.contains(&ty)
471+
.then_some(ty.to_string())
476472
});
477473

478-
cfg.type_name(move |ty, is_struct, is_union| {
479-
match ty {
480-
// Just pass all these through, no need for a "struct" prefix
481-
"FILE" | "DIR" | "Dl_info" => ty.to_string(),
474+
// OSX calls this something else
475+
cfg.rename_type(|ty| (ty == "sighandler_t").then_some("sig_t".to_string()));
482476

483-
// OSX calls this something else
484-
"sighandler_t" => "sig_t".to_string(),
477+
cfg.rename_struct_ty(|ty| ty.ends_with("_t").then_some(ty.to_string()));
478+
cfg.rename_union_ty(|ty| ty.ends_with("_t").then_some(ty.to_string()));
485479

486-
t if is_union => format!("union {t}"),
487-
t if t.ends_with("_t") => t.to_string(),
488-
t if is_struct => format!("struct {t}"),
489-
t => t.to_string(),
490-
}
491-
});
492-
493-
cfg.field_name(move |struct_, field| {
494-
match field {
495-
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
496-
s.replace("e_nsec", "espec.tv_nsec")
480+
cfg.rename_struct_field(|s, f| {
481+
match f.ident() {
482+
n if n.ends_with("_nsec") && s.ident().starts_with("stat") => {
483+
Some(n.replace("e_nsec", "espec.tv_nsec"))
497484
}
498485
// FIXME(macos): sigaction actually contains a union with two variants:
499486
// a sa_sigaction with type: (*)(int, struct __siginfo *, void *)
500487
// a sa_handler with type sig_t
501-
"sa_sigaction" if struct_ == "sigaction" => "sa_handler".to_string(),
502-
s => s.to_string(),
488+
"sa_sigaction" if s.ident() == "sigaction" => Some("sa_handler".to_string()),
489+
_ => None,
503490
}
504491
});
505492

@@ -510,7 +497,8 @@ fn test_apple(target: &str) {
510497
"uuid_t" | "vol_capabilities_set_t" => true,
511498
_ => false,
512499
});
513-
cfg.generate(src_hotfix_dir().join("lib.rs"), "ctest_output.rs");
500+
501+
ctest_next::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap();
514502
}
515503

516504
fn test_openbsd(target: &str) {
@@ -881,7 +869,7 @@ fn test_windows(target: &str) {
881869
let i686 = target.contains("i686");
882870

883871
let mut cfg = ctest_next_cfg();
884-
cfg.skip_private(true);
872+
885873
if target.contains("msvc") {
886874
cfg.flag("/wd4324");
887875
}

0 commit comments

Comments
 (0)