Skip to content

Commit

Permalink
Rollup merge of rust-lang#59879 - ebarnard:patch-1, r=alexcrichton
Browse files Browse the repository at this point in the history
Use SecRandomCopyBytes instead of /dev/urandom on MacOS

SecRandomCopyBytes is [available since MacOS 10.7](https://developer.apple.com/documentation/security/1399291-secrandomcopybytes?language=objc) which is the minimum supported version and which was suggested in rust-lang#58901 (comment) is the earliest version currently in use.

This matches the behaviour of other platforms which have a random number generator syscall available.
  • Loading branch information
Centril authored Apr 12, 2019
2 parents 1ccd4cd + 22f2afe commit 020ed28
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/libstd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() {
println!("cargo:rustc-link-lib=resolv");
} else if target.contains("apple-darwin") {
println!("cargo:rustc-link-lib=System");

println!("cargo:rustc-link-lib=framework=Security");
// res_init and friends require -lresolv on macOS/iOS.
// See #41582 and http://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html
println!("cargo:rustc-link-lib=resolv");
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/sys/unix/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn hashmap_random_keys() -> (u64, u64) {
}

#[cfg(all(unix,
not(target_os = "macos"),
not(target_os = "ios"),
not(target_os = "openbsd"),
not(target_os = "freebsd"),
Expand Down Expand Up @@ -99,7 +100,7 @@ mod imp {
}
}

#[cfg(target_os = "ios")]
#[cfg(any(target_os = "macos", target_os = "ios"))]
mod imp {
use crate::io;
use crate::ptr;
Expand Down

0 comments on commit 020ed28

Please sign in to comment.