From ff6299dd77775815a3ddd677beb5b2b4ef5e4e1d Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Tue, 18 Feb 2020 22:45:02 -0800 Subject: [PATCH] cpu: Add support for CPU-based randomness This allows freestanding targets to use getrandom. Signed-off-by: Joe Richey --- Cargo.toml | 2 ++ src/lib.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index b576b84..0488cc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,8 @@ wasi = "0.9" [features] std = [] +# Feature to enable fallback CPU-based implementation +cpu = [] # Feature to enable custom RNG implementations custom = [] # Unstable feature to support being a libstd dependency diff --git a/src/lib.rs b/src/lib.rs index a19ed71..db8665b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -185,6 +185,8 @@ cfg_if! { #[path = "rdrand.rs"] mod imp; } else if #[cfg(feature = "custom")] { use custom as imp; + } else if #[cfg(all(feature = "cpu", target_arch = "x86_64"))] { + #[path = "rdrand.rs"] mod imp; } else { compile_error!("\ target is not supported, for more information see: \