From e65e04b6a6dafa241e74adc6cef9c454c509c306 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Mon, 8 Jan 2024 13:12:16 +0000 Subject: [PATCH] proposal to separate netbsd 10 release from its predecessors which will be still used for a while. One of the visible example is the kevent using finally a void pointer like other BSD. --- build.rs | 22 ++++++++++++++++++++++ libc-test/build.rs | 22 ++++++++++++++++++++++ src/unix/bsd/netbsdlike/netbsd/mod.rs | 5 ++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index a7c34343728e..a47acc2190af 100644 --- a/build.rs +++ b/build.rs @@ -18,6 +18,7 @@ const ALLOWED_CFGS: &'static [&'static str] = &[ "libc_const_extern_fn_unstable", "libc_deny_warnings", "libc_thread_local", + "netbsd10", ]; // Extra values to allow for check-cfg. @@ -62,6 +63,12 @@ fn main() { Some(_) | None => set_cfg("freebsd11"), } + match which_netbsd() { + // TODO: to update if there is a api breaking change + Some(10..=99) => set_cfg("netbsd10"), + Some(_) | None => (), + } + match emcc_version_code() { Some(v) if (v >= 30142) => set_cfg("emscripten_new_stat_abi"), // Non-Emscripten or version < 3.1.42. @@ -183,6 +190,21 @@ fn which_freebsd() -> Option { } } +fn which_netbsd() -> Option { + let output = std::process::Command::new("uname").arg("-r").output().ok(); + if output.is_none() { + return None; + } + + let output = output.unwrap(); + let stdout = String::from_utf8(output.stdout).ok().unwrap(); + + match &stdout { + s if s.starts_with("10") => Some(10), + _ => None, + } +} + fn emcc_version_code() -> Option { let output = std::process::Command::new("emcc") .arg("-dumpversion") diff --git a/libc-test/build.rs b/libc-test/build.rs index eb04b8352e01..7a7d7cd01f21 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1044,6 +1044,13 @@ fn test_netbsd(target: &str) { assert!(target.contains("netbsd")); let mut cfg = ctest_cfg(); + let netbsd_ver = which_netbsd(); + + match netbsd_ver { + Some(10..=99) => cfg.cfg("netbsd10", None), + _ => &mut cfg, + }; + cfg.flag("-Wno-deprecated-declarations"); cfg.define("_NETBSD_SOURCE", Some("1")); @@ -4539,6 +4546,21 @@ fn which_freebsd() -> Option { } } +fn which_netbsd() -> Option { + let output = std::process::Command::new("uname").arg("-r").output().ok(); + if output.is_none() { + return None; + } + + let output = output.unwrap(); + let stdout = String::from_utf8(output.stdout).ok().unwrap(); + + match &stdout { + s if s.starts_with("10") => Some(10), + _ => None, + } +} + fn test_haiku(target: &str) { assert!(target.contains("haiku")); diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 9724cde29288..7c110f31b8b5 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -286,7 +286,10 @@ s! { pub flags: u32, pub fflags: u32, pub data: i64, - pub udata: ::intptr_t, /* FIXME: NetBSD 10.0 will finally have same layout as other BSD */ + #[cfg(netbsd10)] + pub udata: *mut ::c_void, + #[cfg(not(netbsd10))] + pub udata: ::intptr_t, } pub struct dqblk {