Skip to content

Commit 80a2055

Browse files
committed
cpu: Add support for CPU-based randomness
This allows freestanding targets to use getrandom. Signed-off-by: Joe Richey <joerichey@google.com>
1 parent 7aed17e commit 80a2055

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ libc = { version = "0.2.64", default-features = false }
3434
wasi = "0.9"
3535

3636
[features]
37+
default = ["cpu"]
3738
std = []
39+
# Feature to enable fallback CPU-based implementation
40+
cpu = []
3841
# Feature to enable custom RNG implementations
3942
custom = []
4043
# Unstable feature to support being a libstd dependency

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ cfg_if! {
185185
#[path = "rdrand.rs"] mod imp;
186186
} else if #[cfg(feature = "custom")] {
187187
use custom as imp;
188+
} else if #[cfg(all(feature = "cpu", target_arch = "x86_64"))] {
189+
#[path = "rdrand.rs"] mod imp;
188190
} else {
189191
compile_error!("\
190192
target is not supported, for more information see: \

0 commit comments

Comments
 (0)