Skip to content

Commit 0e72a76

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 f7253f2 commit 0e72a76

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/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
#[cfg(not(target_os = "freebsd"))]
6868
use libc::getrandom;
@@ -82,7 +82,8 @@ mod imp {
8282
target_os = "android",
8383
target_os = "espidf",
8484
target_os = "horizon",
85-
target_os = "freebsd"
85+
target_os = "freebsd",
86+
netbsd10
8687
)))]
8788
fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool {
8889
false
@@ -93,7 +94,8 @@ mod imp {
9394
target_os = "android",
9495
target_os = "espidf",
9596
target_os = "horizon",
96-
target_os = "freebsd"
97+
target_os = "freebsd",
98+
netbsd10
9799
))]
98100
fn getrandom_fill_bytes(v: &mut [u8]) -> bool {
99101
use crate::sync::atomic::{AtomicBool, Ordering};
@@ -229,7 +231,7 @@ mod imp {
229231
}
230232

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

src/bootstrap/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const EXTRA_CHECK_CFGS: &[(Option<Mode>, &str, Option<&[&'static str]>)] = &[
8383
(Some(Mode::Std), "no_global_oom_handling", None),
8484
(Some(Mode::Std), "no_rc", None),
8585
(Some(Mode::Std), "no_sync", None),
86+
(Some(Mode::Std), "netbsd10", None),
8687
(Some(Mode::Std), "backtrace_in_libstd", None),
8788
/* Extra values not defined in the built-in targets yet, but used in std */
8889
(Some(Mode::Std), "target_env", Some(&["libnx"])),

0 commit comments

Comments
 (0)