Skip to content

Commit

Permalink
Use a runtime-rng feature flag instead of using OS detection (#82)
Browse files Browse the repository at this point in the history
* Use a runtime-rng feature flag instead of using OS detection
* Use --no-default-features on WASM
* Update Cargo.toml

Co-authored-by: bl-ue <[email protected]>

Co-authored-by: Tom Kaitchuck <[email protected]>
Co-authored-by: bl-ue <[email protected]>
  • Loading branch information
3 people authored Oct 22, 2021
1 parent c0efa32 commit 3b9d761
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,4 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: check
args: --target wasm32-unknown-unknown
args: --target wasm32-unknown-unknown --no-default-features
22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ bench = true
doc = true

[features]
default = ["std"]
default = ["std", "runtime-rng"]

# Enabling this will enable `AHashMap` and `AHashSet`.
std = []

# This is an alternitive to runtime key generation which does compile time key generation if getrandom is not available.
# (If getrandom is available this does nothing.)
# If this is on (and getrandom is off) it implies the produced binary will not be identical.
# If this is disabled and gerrandom is unavailable constant keys are used.
# Runtime random key generation using getrandom.
runtime-rng = ["getrandom", "once_cell"]

# This is an alternative to runtime key generation which does compile time key generation if runtime-rng is not available.
# (If runtime-rng is available this does nothing.)
# If this is on (and runtime-rng is off) it implies the produced binary will not be identical.
# If this is disabled and runtime-rng is unavailable constant keys are used.
compile-time-rng = ["const-random"]

[[bench]]
Expand Down Expand Up @@ -64,12 +67,9 @@ codegen-units = 1
[build-dependencies]
version_check = "0.9"

[target.'cfg(any(target_os = "linux", target_os = "android", target_os = "windows", target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "dragonfly", target_os = "solaris", target_os = "illumos", target_os = "fuchsia", target_os = "redox", target_os = "cloudabi", target_os = "haiku", target_os = "vxworks", target_os = "emscripten", target_os = "wasi"))'.dependencies]
getrandom = { version = "0.2.3" }
const-random = { version = "0.1.12", optional = true }
serde = { version = "1.0.117", optional = true }

[target.'cfg(not(any(target_os = "linux", target_os = "android", target_os = "windows", target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "dragonfly", target_os = "solaris", target_os = "illumos", target_os = "fuchsia", target_os = "redox", target_os = "cloudabi", target_os = "haiku", target_os = "vxworks", target_os = "emscripten", target_os = "wasi")))'.dependencies]
[dependencies]
once_cell = { version = "1.8", default-features = false, features = ["unstable", "alloc"], optional = true }
getrandom = { version = "0.2.3", optional = true }
const-random = { version = "0.1.12", optional = true }
serde = { version = "1.0.117", optional = true }

Expand Down
21 changes: 0 additions & 21 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,6 @@ fn main() {
println!("cargo:rustc-cfg=feature=\"stdsimd\"");
}
}
let os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS was not set");
if os.eq_ignore_ascii_case("linux")
|| os.eq_ignore_ascii_case("android")
|| os.eq_ignore_ascii_case("windows")
|| os.eq_ignore_ascii_case("macos")
|| os.eq_ignore_ascii_case("ios")
|| os.eq_ignore_ascii_case("freebsd")
|| os.eq_ignore_ascii_case("openbsd")
|| os.eq_ignore_ascii_case("dragonfly")
|| os.eq_ignore_ascii_case("solaris")
|| os.eq_ignore_ascii_case("illumos")
|| os.eq_ignore_ascii_case("fuchsia")
|| os.eq_ignore_ascii_case("redox")
|| os.eq_ignore_ascii_case("cloudabi")
|| os.eq_ignore_ascii_case("haiku")
|| os.eq_ignore_ascii_case("vxworks")
|| os.eq_ignore_ascii_case("emscripten")
|| os.eq_ignore_ascii_case("wasi")
{
println!("cargo:rustc-cfg=feature=\"runtime-rng\"");
}
let arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH was not set");
if arch.eq_ignore_ascii_case("x86_64")
|| arch.eq_ignore_ascii_case("aarch64")
Expand Down

0 comments on commit 3b9d761

Please sign in to comment.