Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add std_rng feature, remove deprecations #948

Merged
merged 6 commits into from Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 19 additions & 19 deletions Cargo.toml
Expand Up @@ -22,23 +22,28 @@ appveyor = { repository = "rust-random/rand" }

[features]
# Meta-features:
default = ["std"] # without "std" rand uses libcore
default = ["std", "std_rng"]
nightly = ["simd_support"] # enables all features requiring nightly rust
serde1 = [] # does nothing, deprecated

# Optional dependencies:
# Option: without "std" rand uses libcore; this option enables functionality
# expected to be available on a standard platform.
dhardy marked this conversation as resolved.
Show resolved Hide resolved
std = ["rand_core/std", "rand_chacha/std", "alloc", "getrandom", "libc"]
alloc = ["rand_core/alloc"] # enables Vec and Box support (without std)
# re-export optional WASM dependencies to avoid breakage:
# Warning: wasm-bindgen and stdweb features will be removed in rand 0.8;
# recommended to activate via the getrandom crate instead.
wasm-bindgen = ["getrandom_package/wasm-bindgen"]
stdweb = ["getrandom_package/stdweb"]
getrandom = ["getrandom_package", "rand_core/getrandom"]

# Configuration:
simd_support = ["packed_simd"] # enables SIMD support
small_rng = ["rand_pcg"] # enables SmallRng
# Option: "alloc" enables support for Vec and Box when not using "std"
alloc = ["rand_core/alloc"]

# Option: use getrandom package for seeding
getrandom = ["rand_core/getrandom"]

# Option: experimental SIMD support
dhardy marked this conversation as resolved.
Show resolved Hide resolved
simd_support = ["packed_simd"]

# Option: enable StdRng (enabled by default)
std_rng = ["rand_chacha", "rand_hc"]

# Option: enable SmallRng
small_rng = ["rand_pcg"]

[workspace]
members = [
Expand All @@ -47,16 +52,11 @@ members = [
"rand_chacha",
"rand_hc",
"rand_pcg",
"tests/wasm_bindgen",
]

[dependencies]
rand_core = { path = "rand_core", version = "0.5.1" }
rand_pcg = { path = "rand_pcg", version = "0.2", optional = true }
# Do not depend on 'getrandom_package' directly; use the 'getrandom' feature!
# This is a dependency because: we forward wasm feature flags
# This is renamed because: we need getrandom to depend on rand_core/getrandom
getrandom_package = { version = "0.1.1", package = "getrandom", optional = true }
log = { version = "0.4.4", optional = true }

[dependencies.packed_simd]
Expand All @@ -73,9 +73,9 @@ libc = { version = "0.2.22", optional = true, default-features = false }
# Emscripten does not support 128-bit integers, which are used by ChaCha code.
# We work around this by using a different RNG.
[target.'cfg(not(target_os = "emscripten"))'.dependencies]
rand_chacha = { path = "rand_chacha", version = "0.2.1", default-features = false }
rand_chacha = { path = "rand_chacha", version = "0.2.1", default-features = false, optional = true }
[target.'cfg(target_os = "emscripten")'.dependencies]
rand_hc = { path = "rand_hc", version = "0.2" }
rand_hc = { path = "rand_hc", version = "0.2", optional = true }

[dev-dependencies]
rand_pcg = { path = "rand_pcg", version = "0.2" }
Expand Down
14 changes: 6 additions & 8 deletions README.md
Expand Up @@ -90,19 +90,17 @@ Rand release if required, but the change must be noted in the changelog.
Rand is built with these features enabled by default:

- `std` enables functionality dependent on the `std` lib
- `alloc` (implied by `std`) enables functionality requiring an allocator (when using this feature in `no_std`, Rand requires Rustc version 1.36 or greater)
- `alloc` (implied by `std`) enables functionality requiring an allocator
(when using this feature in `no_std`, Rand requires Rustc version 1.36 or
greater)
- `getrandom` (implied by `std`) is an optional dependency providing the code
behind `rngs::OsRng`
- `std_rng` enables inclusion of `StdRng`, `thread_rng` and `random`
(the latter two *also* require that `std` be enabled)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add std as requirement for std_rng in Cargo.toml?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Perhaps utility is limited, but this still passes:

$ cargo test --no-default-features --features std_rng --tests
...
test rngs::std::test::test_stdrng_construction ... ok
...


Optionally, the following dependencies can be enabled:

- `log` enables logging via the `log` crate
- `stdweb` implies `getrandom/stdweb` to enable
`getrandom` support on `wasm32-unknown-unknown`
(will be removed in rand 0.8; activate via `getrandom` crate instead)
- `wasm-bindgen` implies `getrandom/wasm-bindgen` to enable
`getrandom` support on `wasm32-unknown-unknown`
(will be removed in rand 0.8; activate via `getrandom` crate instead)
- `log` enables logging via the `log` crate` crate

Additionally, these features configure Rand:

Expand Down