Skip to content

Commit 197f08d

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

File tree

1 file changed

+37
-47
lines changed

1 file changed

+37
-47
lines changed

libc-test/build.rs

Lines changed: 37 additions & 47 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,12 @@ fn test_apple(target: &str) {
382380
}
383381
});
384382

385-
cfg.skip_const(move |name| {
383+
cfg.skip_const(move |constant| {
386384
// They're declared via `deprecated_mach` and we don't support it anymore.
387385
if name.starts_with("VM_FLAGS_") {
388386
return true;
389387
}
390-
match name {
388+
match constant.ident() {
391389
// These OSX constants are removed in Sierra.
392390
// https://developer.apple.com/library/content/releasenotes/General/APIDiffsMacOS10_12/Swift/Darwin.html
393391
"KERN_KDENABLE_BG_TRACE" | "KERN_KDDISABLE_BG_TRACE" => true,
@@ -407,12 +405,11 @@ fn test_apple(target: &str) {
407405
}
408406
});
409407

410-
cfg.skip_fn(move |name| {
408+
cfg.skip_fn(move |func| {
411409
// skip those that are manually verified
412-
match name {
410+
match func.ident() {
413411
// FIXME: https://github.com/rust-lang/libc/issues/1272
414412
"execv" | "execve" | "execvp" => true,
415-
416413
// close calls the close_nocancel system call
417414
"close" => true,
418415

@@ -441,8 +438,8 @@ fn test_apple(target: &str) {
441438
}
442439
});
443440

444-
cfg.skip_field(move |struct_, field| {
445-
match (struct_, field) {
441+
cfg.skip_struct_field(move |struct_, field| {
442+
match (struct_.ident(), field.ident()) {
446443
// FIXME(macos): the array size has been changed since macOS 10.15 ([8] -> [7]).
447444
("statfs", "f_reserved") => true,
448445
("__darwin_arm_neon_state64", "__v") => true,
@@ -467,39 +464,31 @@ fn test_apple(target: &str) {
467464
}
468465
});
469466

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-
}
467+
cfg.volatile_struct_field(|s, f| s.ident() == "aiocb" && f.ident() == "aio_buf");
468+
469+
cfg.rename_struct_ty(move |ty| {
470+
// Just pass all these through, no need for a "struct" prefix
471+
["FILE", "DIR", "Dl_info"]
472+
.contains(&ty)
473+
.then_some(ty.to_string())
476474
});
477475

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(),
476+
// OSX calls this something else
477+
cfg.rename_type(|ty| (ty == "sighandler_t").then_some("sig_t".to_string()));
482478

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

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")
482+
cfg.rename_struct_field(|s, f| {
483+
match f.ident() {
484+
n if n.ends_with("_nsec") && s.ident().starts_with("stat") => {
485+
Some(n.replace("e_nsec", "espec.tv_nsec"))
497486
}
498487
// FIXME(macos): sigaction actually contains a union with two variants:
499488
// a sa_sigaction with type: (*)(int, struct __siginfo *, void *)
500489
// a sa_handler with type sig_t
501-
"sa_sigaction" if struct_ == "sigaction" => "sa_handler".to_string(),
502-
s => s.to_string(),
490+
"sa_sigaction" if s.ident() == "sigaction" => Some("sa_handler".to_string()),
491+
_ => None,
503492
}
504493
});
505494

@@ -510,7 +499,8 @@ fn test_apple(target: &str) {
510499
"uuid_t" | "vol_capabilities_set_t" => true,
511500
_ => false,
512501
});
513-
cfg.generate(src_hotfix_dir().join("lib.rs"), "ctest_output.rs");
502+
503+
ctest_next::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap();
514504
}
515505

516506
fn test_openbsd(target: &str) {
@@ -881,7 +871,7 @@ fn test_windows(target: &str) {
881871
let i686 = target.contains("i686");
882872

883873
let mut cfg = ctest_next_cfg();
884-
cfg.skip_private(true);
874+
885875
if target.contains("msvc") {
886876
cfg.flag("/wd4324");
887877
}

0 commit comments

Comments
 (0)