Skip to content

Commit 8eabfdf

Browse files
committed
std: enabling new netbsd (10) calls.
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.
1 parent c6c4abf commit 8eabfdf

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

library/std/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ use std::env;
33
fn main() {
44
println!("cargo:rerun-if-changed=build.rs");
55
let target = env::var("TARGET").expect("TARGET was not set");
6+
if target.contains("netbsd") && env::var("RUST_STD_NETBSD10").is_ok() {
7+
println!("cargo:rust-cfg=netbsd10");
8+
}
69
if target.contains("linux")
710
|| target.contains("netbsd")
811
|| target.contains("dragonfly")

library/std/src/sys/pal/unix/rand.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mod imp {
6262
unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), libc::GRND_NONBLOCK) }
6363
}
6464

65-
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "freebsd"))]
65+
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "freebsd", netbsd10))]
6666
fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
6767
unsafe { libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
6868
}
@@ -72,7 +72,8 @@ mod imp {
7272
target_os = "android",
7373
target_os = "espidf",
7474
target_os = "horizon",
75-
target_os = "freebsd"
75+
target_os = "freebsd",
76+
netbsd10
7677
)))]
7778
fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool {
7879
false
@@ -83,7 +84,8 @@ mod imp {
8384
target_os = "android",
8485
target_os = "espidf",
8586
target_os = "horizon",
86-
target_os = "freebsd"
87+
target_os = "freebsd",
88+
netbsd10
8789
))]
8890
fn getrandom_fill_bytes(v: &mut [u8]) -> bool {
8991
use crate::sync::atomic::{AtomicBool, Ordering};
@@ -219,7 +221,7 @@ mod imp {
219221
}
220222

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

src/bootstrap/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const EXTRA_CHECK_CFGS: &[(Option<Mode>, &str, Option<&[&'static str]>)] = &[
8686
(Some(Mode::Std), "no_global_oom_handling", None),
8787
(Some(Mode::Std), "no_rc", None),
8888
(Some(Mode::Std), "no_sync", None),
89+
(Some(Mode::Std), "netbsd10", None),
8990
(Some(Mode::Std), "backtrace_in_libstd", None),
9091
/* Extra values not defined in the built-in targets yet, but used in std */
9192
(Some(Mode::Std), "target_env", Some(&["libnx"])),

0 commit comments

Comments
 (0)