Skip to content

Commit

Permalink
Disable std feature by default in rand_core and rand_jitter
Browse files Browse the repository at this point in the history
Implements #702
Resolves #645
  • Loading branch information
dhardy committed Jan 23, 2019
1 parent 6f3875f commit 67c856b
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Expand Up @@ -46,9 +46,9 @@ members = [
]

[dependencies]
rand_core = { path = "rand_core", version = "0.3", default-features = false }
rand_core = { path = "rand_core", version = "0.4" }
rand_pcg = { path = "rand_pcg", version = "0.1" }
rand_jitter = { path = "rand_jitter", version = "0.1", default-features = false }
rand_jitter = { path = "rand_jitter", version = "0.1" }
rand_os = { path = "rand_os", version = "0.1", optional = true }
# only for deprecations and benches:
rand_isaac = { path = "rand_isaac", version = "0.1" }
Expand Down Expand Up @@ -84,4 +84,4 @@ autocfg = "0.1"
all-features = true

[patch.crates-io]
rand_core = { path = "rand_core", version = "0.3", default-features = false }
rand_core = { path = "rand_core", version = "0.4" }
2 changes: 1 addition & 1 deletion rand_chacha/Cargo.toml
Expand Up @@ -19,7 +19,7 @@ travis-ci = { repository = "rust-random/rand" }
appveyor = { repository = "rust-random/rand" }

[dependencies]
rand_core = { path = "../rand_core", version = ">=0.2, <0.4", default-features=false }
rand_core = { path = "../rand_core", version = "0.4" }

[build-dependencies]
autocfg = "0.1"
3 changes: 3 additions & 0 deletions rand_core/CHANGELOG.md
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.0] - 2019-01-24
- Disable the `std` feature by default (#702)

## [0.3.0] - 2018-09-24
- Add `SeedableRng::seed_from_u64` for convenient seeding. (#537)

Expand Down
3 changes: 1 addition & 2 deletions rand_core/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rand_core"
version = "0.3.0"
version = "0.4.0"
authors = ["The Rand Project Developers", "The Rust Project Developers"]
license = "MIT/Apache-2.0"
readme = "README.md"
Expand All @@ -18,7 +18,6 @@ travis-ci = { repository = "rust-random/rand" }
appveyor = { repository = "rust-random/rand" }

[features]
default = ["std"]
std = ["alloc"] # use std library; should be default but for above bug
alloc = [] # enables Vec and Box support without std
serde1 = ["serde", "serde_derive"] # enables serde for BlockRng wrapper
Expand Down
11 changes: 6 additions & 5 deletions rand_core/README.md
Expand Up @@ -44,13 +44,14 @@ The traits and error types are also available via `rand`.

`rand_core` supports `no_std` and `alloc`-only configurations, as well as full
`std` functionality. The differences between `no_std` and full `std` are small,
comprising `RngCore` support for `Box<R>` types where `R: RngCore`, as well as
comprising `RngCore` support for `Box<R>` types where `R: RngCore`,
`std::io::Read` support for types supporting `RngCore`, and
extensions to the `Error` type's functionality.

Due to [rust-lang/cargo#1596](https://github.com/rust-lang/cargo/issues/1596),
`rand_core` is built without `std` support by default. Since features are
unioned across the whole dependency tree, any crate using `rand` with its
default features will also enable `std` support in `rand_core`.
The `std` feature is *not enabled by default*. This is primarily to avoid build
problems where one crate implicitly requires `rand_core` with `std` support and
another crate requires `rand` *without* `std` support. However, the `rand` crate
continues to enable `std` support by default, both for itself and `rand_core`.

The `serde1` feature can be used to derive `Serialize` and `Deserialize` for RNG
implementations that use the `BlockRng` or `BlockRng64` wrappers.
Expand Down
2 changes: 1 addition & 1 deletion rand_hc/Cargo.toml
Expand Up @@ -18,4 +18,4 @@ travis-ci = { repository = "rust-random/rand" }
appveyor = { repository = "rust-random/rand" }

[dependencies]
rand_core = { path = "../rand_core", version = ">=0.2, <0.4", default-features=false }
rand_core = { path = "../rand_core", version = "0.4" }
2 changes: 1 addition & 1 deletion rand_isaac/Cargo.toml
Expand Up @@ -21,7 +21,7 @@ appveyor = { repository = "rust-random/rand" }
serde1 = ["serde", "serde_derive", "rand_core/serde1"]

[dependencies]
rand_core = { path = "../rand_core", version = "0.3", default-features=false }
rand_core = { path = "../rand_core", version = "0.4" }
serde = { version = "1", optional = true }
serde_derive = { version = "^1.0.38", optional = true }

Expand Down
2 changes: 1 addition & 1 deletion rand_jitter/CHANGELOG.md
Expand Up @@ -4,5 +4,5 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2019-01-04
## [0.1.0] - 2019-01-24
Initial release.
6 changes: 2 additions & 4 deletions rand_jitter/Cargo.toml
Expand Up @@ -14,7 +14,7 @@ travis-ci = { repository = "rust-random/rand" }
appveyor = { repository = "rust-random/rand" }

[dependencies]
rand_core = { path = "../rand_core", version = "0.3", default-features = false }
rand_core = { path = "../rand_core", version = "0.4" }
log = { version = "0.4", optional = true }

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
Expand All @@ -24,6 +24,4 @@ libc = "0.2"
winapi = { version = "0.3", features = ["profileapi"] }

[features]
default = ["std"]
std = []

std = ["rand_core/std"]
6 changes: 6 additions & 0 deletions rand_jitter/README.md
Expand Up @@ -22,6 +22,12 @@ Links:
- [API documentation (docs.rs)](https://docs.rs/rand_jitter)
- [Changelog](CHANGELOG.md)

## Features

This crate has optional `std` support which is *disabled by default*;
this feature is required to provide the `JitterRng::new` function;
without `std` support a timer must be supplied via `JitterRng::new_with_timer`.

## Quality testing

`JitterRng::new()` has build-in, but limited, quality testing, however
Expand Down
2 changes: 2 additions & 0 deletions rand_jitter/tests/mod.rs
Expand Up @@ -2,8 +2,10 @@ extern crate rand_jitter;
extern crate rand_core;

use rand_jitter::JitterRng;
#[cfg(feature = "std")]
use rand_core::RngCore;

#[cfg(feature = "std")]
#[test]
fn test_jitter_init() {
// Because this is a debug build, measurements here are not representive
Expand Down
2 changes: 1 addition & 1 deletion rand_os/Cargo.toml
Expand Up @@ -15,7 +15,7 @@ travis-ci = { repository = "rust-random/rand" }
appveyor = { repository = "rust-random/rand" }

[dependencies]
rand_core = { path = "../rand_core", version = "0.3", default-features = false }
rand_core = { path = "../rand_core", version = "0.4", features = ["std"] }
log = { version = "0.4", optional = true }

[target.'cfg(unix)'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion rand_pcg/Cargo.toml
Expand Up @@ -22,7 +22,7 @@ appveyor = { repository = "rust-random/rand" }
serde1 = ["serde", "serde_derive"]

[dependencies]
rand_core = { path = "../rand_core", version = "0.3", default-features=false }
rand_core = { path = "../rand_core", version = "0.4" }
serde = { version = "1", optional = true }
serde_derive = { version = "^1.0.38", optional = true }

Expand Down
2 changes: 1 addition & 1 deletion rand_xorshift/Cargo.toml
Expand Up @@ -21,7 +21,7 @@ appveyor = { repository = "rust-random/rand" }
serde1 = ["serde", "serde_derive"]

[dependencies]
rand_core = { path = "../rand_core", version = ">=0.2, <0.4", default-features=false }
rand_core = { path = "../rand_core", version = "0.4" }
serde = { version = "1", optional = true }
serde_derive = { version = "^1.0.38", optional = true }

Expand Down
2 changes: 1 addition & 1 deletion rand_xoshiro/Cargo.toml
Expand Up @@ -13,7 +13,7 @@ categories = ["algorithms"]

[dependencies]
byteorder = { version = "1", default-features=false }
rand_core = { path = "../rand_core", version = "0.3", default-features=false }
rand_core = { path = "../rand_core", version = "0.4" }

[dev-dependencies]
rand = { path = "..", version = "0.6", default-features=false } # needed for doctests

4 comments on commit 67c856b

@Eijebong
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to release the subcrates with the rand_core update to avoid duping rand_core everywhere :)

@dhardy
Copy link
Member Author

@dhardy dhardy commented on 67c856b Feb 21, 2019

Choose a reason for hiding this comment

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

Yes, agreed. It's blocked by #663 which was waiting on bincode, but maybe the latest release has solved that now.

@dhardy
Copy link
Member Author

@dhardy dhardy commented on 67c856b Feb 23, 2019

Choose a reason for hiding this comment

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

rand_pcg has now been updated; this leaves rand_hc, rand_chacha, rand_isaac, rand_xorshift and rdrand all still depending on rand_core 0.3. I guess we need more updates. @nagisa can you update rdrand?

@dhardy
Copy link
Member Author

@dhardy dhardy commented on 67c856b Feb 23, 2019

Choose a reason for hiding this comment

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

Actually, all other mentioned crates explicitly disable the default features of rand_core, thus should not be a problem here.

Please sign in to comment.