From 67c856bfe9f8dc38d5822172817dc368b4e25acc Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Wed, 23 Jan 2019 12:43:33 +0000 Subject: [PATCH 1/2] Disable std feature by default in rand_core and rand_jitter Implements #702 Resolves #645 --- Cargo.toml | 6 +++--- rand_chacha/Cargo.toml | 2 +- rand_core/CHANGELOG.md | 3 +++ rand_core/Cargo.toml | 3 +-- rand_core/README.md | 11 ++++++----- rand_hc/Cargo.toml | 2 +- rand_isaac/Cargo.toml | 2 +- rand_jitter/CHANGELOG.md | 2 +- rand_jitter/Cargo.toml | 6 ++---- rand_jitter/README.md | 6 ++++++ rand_jitter/tests/mod.rs | 2 ++ rand_os/Cargo.toml | 2 +- rand_pcg/Cargo.toml | 2 +- rand_xorshift/Cargo.toml | 2 +- rand_xoshiro/Cargo.toml | 2 +- 15 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ba750895295..ccdc008cec7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } @@ -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" } diff --git a/rand_chacha/Cargo.toml b/rand_chacha/Cargo.toml index 028428ce6d5..f8cbe7f9ac1 100644 --- a/rand_chacha/Cargo.toml +++ b/rand_chacha/Cargo.toml @@ -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" diff --git a/rand_core/CHANGELOG.md b/rand_core/CHANGELOG.md index 2cbb2596f52..7f2d7978fdc 100644 --- a/rand_core/CHANGELOG.md +++ b/rand_core/CHANGELOG.md @@ -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) diff --git a/rand_core/Cargo.toml b/rand_core/Cargo.toml index 1678773447b..340fb3a40a5 100644 --- a/rand_core/Cargo.toml +++ b/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" @@ -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 diff --git a/rand_core/README.md b/rand_core/README.md index dee65048210..ef076b99d82 100644 --- a/rand_core/README.md +++ b/rand_core/README.md @@ -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` types where `R: RngCore`, as well as +comprising `RngCore` support for `Box` 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. diff --git a/rand_hc/Cargo.toml b/rand_hc/Cargo.toml index ed5dd5b9355..b4aa08ecfa0 100644 --- a/rand_hc/Cargo.toml +++ b/rand_hc/Cargo.toml @@ -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" } diff --git a/rand_isaac/Cargo.toml b/rand_isaac/Cargo.toml index b35d0ab6f2e..16d0cab905a 100644 --- a/rand_isaac/Cargo.toml +++ b/rand_isaac/Cargo.toml @@ -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 } diff --git a/rand_jitter/CHANGELOG.md b/rand_jitter/CHANGELOG.md index b23c9904901..1e399169a2d 100644 --- a/rand_jitter/CHANGELOG.md +++ b/rand_jitter/CHANGELOG.md @@ -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. diff --git a/rand_jitter/Cargo.toml b/rand_jitter/Cargo.toml index 22cc80e73cf..e04dcc141dc 100644 --- a/rand_jitter/Cargo.toml +++ b/rand_jitter/Cargo.toml @@ -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] @@ -24,6 +24,4 @@ libc = "0.2" winapi = { version = "0.3", features = ["profileapi"] } [features] -default = ["std"] -std = [] - +std = ["rand_core/std"] diff --git a/rand_jitter/README.md b/rand_jitter/README.md index 4da9d3e0605..cda5d62ad3a 100644 --- a/rand_jitter/README.md +++ b/rand_jitter/README.md @@ -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 diff --git a/rand_jitter/tests/mod.rs b/rand_jitter/tests/mod.rs index ba7e54cfc66..6820c2080a5 100644 --- a/rand_jitter/tests/mod.rs +++ b/rand_jitter/tests/mod.rs @@ -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 diff --git a/rand_os/Cargo.toml b/rand_os/Cargo.toml index 2f9224a082c..6673a76a981 100644 --- a/rand_os/Cargo.toml +++ b/rand_os/Cargo.toml @@ -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] diff --git a/rand_pcg/Cargo.toml b/rand_pcg/Cargo.toml index c2fcb7d543e..5ebf2db69d0 100644 --- a/rand_pcg/Cargo.toml +++ b/rand_pcg/Cargo.toml @@ -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 } diff --git a/rand_xorshift/Cargo.toml b/rand_xorshift/Cargo.toml index 114fee95ab8..e01ddc233f0 100644 --- a/rand_xorshift/Cargo.toml +++ b/rand_xorshift/Cargo.toml @@ -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 } diff --git a/rand_xoshiro/Cargo.toml b/rand_xoshiro/Cargo.toml index 8d174c74e0e..c518baaec53 100644 --- a/rand_xoshiro/Cargo.toml +++ b/rand_xoshiro/Cargo.toml @@ -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 From 77e952f01ac1a3289562f3b9048ebead2ba6f46d Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Wed, 23 Jan 2019 15:53:25 +0000 Subject: [PATCH 2/2] AppVeyor: use --manifest-path over --package in tests --package causes problems where multiple versions exist (an issue since rdrand depends on rand_core:0.3). Also, we definitely don't need both. --- appveyor.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 70e4326e204..70a8cada336 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -37,13 +37,6 @@ test_script: - cargo test --features=serde1,log - cargo test --benches --features=nightly - cargo test --examples - - cargo test --package rand_core - - cargo test --package rand_core --no-default-features --features=alloc - - cargo test --package rand_isaac --features=serde1 - - cargo test --package rand_xorshift --features=serde1 - - cargo test --package rand_xoshiro - - cargo test --package rand_chacha - - cargo test --package rand_hc - cargo test --manifest-path rand_core/Cargo.toml - cargo test --manifest-path rand_core/Cargo.toml --no-default-features --features=alloc - cargo test --manifest-path rand_isaac/Cargo.toml --features=serde1