Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 49 additions & 37 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 <resolve.h>.
("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) {
Expand Down