diff --git a/libc-test/build.rs b/libc-test/build.rs index 885befea66c6b..97c83ec542fe8 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -473,7 +473,7 @@ fn test_apple(target: &str) { fn test_openbsd(target: &str) { assert!(target.contains("openbsd")); - let mut cfg = ctest_cfg(); + let mut cfg = ctest_next_cfg(); cfg.flag("-Wno-deprecated-declarations"); let x86_64 = target.contains("x86_64"); @@ -563,64 +563,76 @@ fn test_openbsd(target: &str) { "sys/param.h", } - cfg.skip_const(move |name| { - match name { - // Removed in OpenBSD 7.8 - "CTL_FS" | "SO_NETPROC" => true, + cfg.rename_type(|ty| match ty { + // FIXME(openbsd): https://github.com/rust-lang/libc/issues/1273 + "sighandler_t" => Some("sig_t".to_string()), + _ => None, + }); - _ => false, + cfg.rename_struct_ty(move |ty| { + match ty { + // Just pass all these through, no need for a "struct" prefix + "FILE" | "DIR" | "Dl_info" | "Elf32_Phdr" | "Elf64_Phdr" => Some(ty.to_string()), + + _ => None, } }); - cfg.skip_fn(move |name| { - match name { - // futex() has volatile arguments, but that doesn't exist in Rust. - "futex" => true, + cfg.rename_struct_field(|struct_, field_| { + let struct_ = struct_.ident(); + let replacement = match field_.ident() { + "st_birthtime" if struct_.starts_with("stat") => "__st_birthtime".to_string(), + "st_birthtime_nsec" if struct_.starts_with("stat") => "__st_birthtimensec".to_string(), - _ => false, - } + // Our stat *_nsec fields normally don't actually exist but are part + // of a timeval struct + s if s.ends_with("_nsec") && struct_.starts_with("stat") => { + s.replace("e_nsec", ".tv_nsec") + } + + "sa_sigaction" if struct_ == "sigaction" => "sa_handler".to_string(), + + _ => return None, + }; + Some(replacement) }); - cfg.type_name(move |ty, is_struct, is_union| { - match ty { - // Just pass all these through, no need for a "struct" prefix - "FILE" | "DIR" | "Dl_info" | "Elf32_Phdr" | "Elf64_Phdr" => ty.to_string(), + cfg.skip_const(move |constant| { + match constant.ident() { + // Removed in OpenBSD 7.7 (unused since 1991) + "ATF_COM" | "ATF_PERM" | "ATF_PUBL" | "ATF_USETRAILERS" => true, - // OSX calls this something else - "sighandler_t" => "sig_t".to_string(), + // Removed in OpenBSD 7.8 + "CTL_FS" | "SO_NETPROC" => true, - t if is_union => format!("union {t}"), - t if t.ends_with("_t") => t.to_string(), - t if is_struct => format!("struct {t}"), - t => t.to_string(), + _ => false, } }); - cfg.field_name(move |struct_, field| match field { - "st_birthtime" if struct_.starts_with("stat") => "__st_birthtime".to_string(), - "st_birthtime_nsec" if struct_.starts_with("stat") => "__st_birthtimensec".to_string(), - s if s.ends_with("_nsec") && struct_.starts_with("stat") => s.replace("e_nsec", ".tv_nsec"), - "sa_sigaction" if struct_ == "sigaction" => "sa_handler".to_string(), - s => s.to_string(), - }); + // Skip anonymous unions/structs. + cfg.skip_union(|u| u.ident().starts_with("__c_anonymous_")); + cfg.skip_struct(|s| s.ident().starts_with("__c_anonymous_")); - cfg.skip_field_type(move |struct_, field| { - // type siginfo_t.si_addr changed from OpenBSD 6.0 to 6.1 - struct_ == "siginfo_t" && field == "si_addr" - }); + cfg.rename_struct_ty(|ty| ty.ends_with("_t").then_some(ty.to_string())); + cfg.rename_union_ty(|ty| ty.ends_with("_t").then_some(ty.to_string())); - cfg.skip_field(|struct_, field| { - match (struct_, field) { + cfg.skip_struct_field(move |struct_, field| { + match (struct_.ident(), field.ident()) { // conflicting with `p_type` macro from . ("Elf32_Phdr", "p_type") => true, ("Elf64_Phdr", "p_type") => true, - // ifr_ifru is defined is an union + + // type siginfo_t.si_addr changed from OpenBSD 6.0 to 6.1 + ("siginfo_t", "si_addr") => true, + + // ifr_ifru is an union ("ifreq", "ifr_ifru") => true, + _ => false, } }); - cfg.generate(src_hotfix_dir().join("lib.rs"), "ctest_output.rs"); + ctest_next::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap(); } fn test_cygwin(target: &str) {