-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Right now we only have a single option `Option::DEFAULT`. However, in the future, we could add options to: - guarantee the function doesn't block - use a insecure but quicker system source (for seeding hashmaps). - not use a fallback mechanism - never use the custom RNG source - always prefere the custom RNG source if it exists Not all of these are things we should _necessarily_ do, but this gives us the flexibility to add such options in the future. Signed-off-by: Joe Richey <[email protected]>
- Loading branch information
Showing
3 changed files
with
108 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::env; | ||
use std::process::Command; | ||
use std::str; | ||
|
||
fn main() { | ||
let minor_ver = rustc_minor().expect("failed to get rustc version"); | ||
|
||
if minor_ver >= 40 { | ||
println!("cargo:rustc-cfg=getrandom_non_exhaustive"); | ||
} | ||
} | ||
|
||
// Based on libc's implementation: | ||
// https://github.com/rust-lang/libc/blob/74e81a50c2528b01507e9d03f594949c0f91c817/build.rs#L168-L205 | ||
fn rustc_minor() -> Option<u32> { | ||
let rustc = env::var_os("RUSTC")?; | ||
let output = Command::new(rustc).arg("--version").output().ok()?.stdout; | ||
let version = str::from_utf8(&output).ok()?; | ||
let mut pieces = version.split('.'); | ||
if pieces.next()? != "rustc 1" { | ||
return None; | ||
} | ||
let minor = pieces.next()?; | ||
minor.parse().ok() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters