Skip to content

Commit f333054

Browse files
committed
libc: port apple to use ctest-next
1 parent 689e54d commit f333054

File tree

2 files changed

+41
-48
lines changed

2 files changed

+41
-48
lines changed

ctest-next/src/template.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl TestTemplate {
400400
.as_ref()
401401
.is_some_and(|skip| skip(ident))
402402
};
403-
for func in helper.ffi_items.foreign_functions() {
403+
for func in helper.filtered_ffi_items.foreign_functions() {
404404
if should_skip_fn_test(func.ident()) {
405405
continue;
406406
}
@@ -423,7 +423,7 @@ impl TestTemplate {
423423
&mut self,
424424
helper: &TranslateHelper,
425425
) -> Result<(), TranslationError> {
426-
for static_ in helper.ffi_items.foreign_statics() {
426+
for static_ in helper.filtered_ffi_items.foreign_statics() {
427427
let rust_ty = static_.ty.to_token_stream().to_string().into_boxed_str();
428428

429429
let item = TestForeignStatic {

libc-test/build.rs

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ fn test_apple(target: &str) {
217217
let x86_64 = target.contains("x86_64");
218218
let i686 = target.contains("i686");
219219

220-
let mut cfg = ctest_cfg();
220+
let mut cfg = ctest_next_cfg();
221+
cfg.skip_private(true);
221222
cfg.flag("-Wno-deprecated-declarations");
222223
cfg.define("__APPLE_USE_RFC_3542", None);
223224

@@ -330,11 +331,14 @@ fn test_apple(target: &str) {
330331
[x86_64]: "crt_externs.h",
331332
}
332333

333-
cfg.skip_struct(move |ty| {
334-
if ty.starts_with("__c_anonymous_") {
335-
return true;
336-
}
337-
match ty {
334+
// Skip anonymous unions/structs.
335+
cfg.skip_union(|u| u.ident().starts_with("__c_anonymous_"));
336+
cfg.skip_struct(|s| s.ident().starts_with("__c_anonymous_"));
337+
338+
cfg.skip_struct(|s| {
339+
match s.ident() {
340+
// FIXME(union): actually a union
341+
"sigval" => true,
338342
// FIXME(macos): The size is changed in recent macOSes.
339343
"malloc_zone_t" => true,
340344
// it is a moving target, changing through versions
@@ -344,16 +348,13 @@ fn test_apple(target: &str) {
344348
"malloc_introspection_t" => true,
345349
// sonoma changes the padding `rmx_filler` field.
346350
"rt_metrics" => true,
347-
348351
_ => false,
349352
}
350353
});
351354

352-
cfg.skip_type(move |ty| {
353-
if ty.starts_with("__c_anonymous_") {
354-
return true;
355-
}
356-
match ty {
355+
cfg.skip_alias(|ty| ty.ident().starts_with("__c_anonymous_"));
356+
cfg.skip_alias(|ty| {
357+
match ty.ident() {
357358
// FIXME(macos): Requires the macOS 14.4 SDK.
358359
"os_sync_wake_by_address_flags_t" | "os_sync_wait_on_address_flags_t" => true,
359360

@@ -364,8 +365,8 @@ fn test_apple(target: &str) {
364365
}
365366
});
366367

367-
cfg.skip_const(move |name| {
368-
match name {
368+
cfg.skip_const(move |constant| {
369+
match constant.ident() {
369370
// These OSX constants are removed in Sierra.
370371
// https://developer.apple.com/library/content/releasenotes/General/APIDiffsMacOS10_12/Swift/Darwin.html
371372
"KERN_KDENABLE_BG_TRACE" | "KERN_KDDISABLE_BG_TRACE" => true,
@@ -385,9 +386,9 @@ fn test_apple(target: &str) {
385386
}
386387
});
387388

388-
cfg.skip_fn(move |name| {
389+
cfg.skip_fn(move |func| {
389390
// skip those that are manually verified
390-
match name {
391+
match func.ident() {
391392
// close calls the close_nocancel system call
392393
"close" => true,
393394

@@ -416,8 +417,10 @@ fn test_apple(target: &str) {
416417
}
417418
});
418419

419-
cfg.skip_field(move |struct_, field| {
420-
match (struct_, field) {
420+
cfg.skip_struct_field(move |struct_, field| {
421+
match (struct_.ident(), field.ident()) {
422+
// FIXME(union): actually a union
423+
("sigevent", "sigev_value") => true,
421424
// FIXME(macos): the array size has been changed since macOS 10.15 ([8] -> [7]).
422425
("statfs", "f_reserved") => true,
423426
("__darwin_arm_neon_state64", "__v") => true,
@@ -430,39 +433,28 @@ fn test_apple(target: &str) {
430433
}
431434
});
432435

433-
cfg.volatile_item(|i| {
434-
use ctest::VolatileItemKind::*;
435-
match i {
436-
StructField(ref n, ref f) if n == "aiocb" && f == "aio_buf" => true,
437-
_ => false,
438-
}
439-
});
436+
cfg.volatile_struct_field(|s, f| s.ident() == "aiocb" && f.ident() == "aio_buf");
440437

441-
cfg.type_name(move |ty, is_struct, is_union| {
442-
match ty {
443-
// Just pass all these through, no need for a "struct" prefix
444-
"FILE" | "DIR" | "Dl_info" => ty.to_string(),
445-
446-
// OSX calls this something else
447-
"sighandler_t" => "sig_t".to_string(),
448-
449-
t if is_union => format!("union {t}"),
450-
t if t.ends_with("_t") => t.to_string(),
451-
t if is_struct => format!("struct {t}"),
452-
t => t.to_string(),
453-
}
438+
cfg.rename_struct_ty(move |ty| {
439+
// Just pass all these through, no need for a "struct" prefix
440+
["FILE", "DIR", "Dl_info"]
441+
.contains(&ty)
442+
.then_some(ty.to_string())
454443
});
455-
456-
cfg.field_name(move |struct_, field| {
457-
match field {
458-
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
459-
s.replace("e_nsec", "espec.tv_nsec")
444+
cfg.rename_type(|ty| (ty == "sighandler_t").then_some("sig_t".to_string()));
445+
cfg.rename_struct_ty(|ty| ty.ends_with("_t").then_some(ty.to_string()));
446+
cfg.rename_union_ty(|ty| ty.ends_with("_t").then_some(ty.to_string()));
447+
448+
cfg.rename_struct_field(|s, f| {
449+
match f.ident() {
450+
n if n.ends_with("_nsec") && s.ident().starts_with("stat") => {
451+
n.replace("e_nsec", "espec.tv_nsec").into()
460452
}
461453
// FIXME(macos): sigaction actually contains a union with two variants:
462454
// a sa_sigaction with type: (*)(int, struct __siginfo *, void *)
463455
// a sa_handler with type sig_t
464-
"sa_sigaction" if struct_ == "sigaction" => "sa_handler".to_string(),
465-
s => s.to_string(),
456+
"sa_sigaction" if s.ident() == "sigaction" => "sa_handler".to_string().into(),
457+
_ => None,
466458
}
467459
});
468460

@@ -473,7 +465,8 @@ fn test_apple(target: &str) {
473465
"uuid_t" | "vol_capabilities_set_t" => true,
474466
_ => false,
475467
});
476-
cfg.generate(src_hotfix_dir().join("lib.rs"), "ctest_output.rs");
468+
469+
ctest_next::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap();
477470
}
478471

479472
fn test_openbsd(target: &str) {

0 commit comments

Comments
 (0)