Skip to content

Commit

Permalink
std: enabling new netbsd (10) calls.
Browse files Browse the repository at this point in the history
Introducing a new config for this purpose as NetBSD 9 or 8 will be still around
for a good while. For now, we re finally enabling sys::unix::rand::getrandom.
  • Loading branch information
devnexen committed Jan 13, 2024
1 parent c6c4abf commit 8eabfdf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use std::env;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let target = env::var("TARGET").expect("TARGET was not set");
if target.contains("netbsd") && env::var("RUST_STD_NETBSD10").is_ok() {
println!("cargo:rust-cfg=netbsd10");
}
if target.contains("linux")
|| target.contains("netbsd")
|| target.contains("dragonfly")
Expand Down
10 changes: 6 additions & 4 deletions library/std/src/sys/pal/unix/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod imp {
unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), libc::GRND_NONBLOCK) }
}

#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "freebsd"))]
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "freebsd", netbsd10))]
fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
unsafe { libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
}
Expand All @@ -72,7 +72,8 @@ mod imp {
target_os = "android",
target_os = "espidf",
target_os = "horizon",
target_os = "freebsd"
target_os = "freebsd",
netbsd10
)))]
fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool {
false
Expand All @@ -83,7 +84,8 @@ mod imp {
target_os = "android",
target_os = "espidf",
target_os = "horizon",
target_os = "freebsd"
target_os = "freebsd",
netbsd10
))]
fn getrandom_fill_bytes(v: &mut [u8]) -> bool {
use crate::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -219,7 +221,7 @@ mod imp {
}

// FIXME: once the 10.x release becomes the minimum, this can be dropped for simplification.
#[cfg(target_os = "netbsd")]
#[cfg(all(target_os = "netbsd", not(netbsd10)))]
mod imp {
use crate::ptr;

Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const EXTRA_CHECK_CFGS: &[(Option<Mode>, &str, Option<&[&'static str]>)] = &[
(Some(Mode::Std), "no_global_oom_handling", None),
(Some(Mode::Std), "no_rc", None),
(Some(Mode::Std), "no_sync", None),
(Some(Mode::Std), "netbsd10", None),
(Some(Mode::Std), "backtrace_in_libstd", None),
/* Extra values not defined in the built-in targets yet, but used in std */
(Some(Mode::Std), "target_env", Some(&["libnx"])),
Expand Down

0 comments on commit 8eabfdf

Please sign in to comment.