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

Move XorShiftRng to its own crate #557

Merged
merged 15 commits into from Jul 24, 2018
8 changes: 4 additions & 4 deletions Cargo.toml
Expand Up @@ -20,20 +20,20 @@ appveyor = { repository = "alexcrichton/rand" }
[features]
default = ["std" ] # without "std" rand uses libcore
nightly = ["i128_support", "simd_support"] # enables all features requiring nightly rust
std = ["rand_core/std", "alloc", "libc", "winapi", "cloudabi", "fuchsia-zircon"]
std = ["rand_core/std", "rand_isaac/std", "rand_xorshift/std", "alloc", "libc", "winapi", "cloudabi", "fuchsia-zircon"]
alloc = ["rand_core/alloc"] # enables Vec and Box support (without std)
i128_support = [] # enables i128 and u128 support
simd_support = [] # enables SIMD support
serde1 = ["serde", "serde_derive", "rand_core/serde1"] # enables serialization for PRNGs
serde1 = ["serde", "serde_derive", "rand_core/serde1", "rand_isaac/serde1", "rand_xorshift/serde1"] # enables serialization for PRNGs

[workspace]
members = ["rand_core", "rand_isaac", "rand_xorshift"]

[dependencies]
rand_core = { path = "rand_core", version = "0.2", default-features = false }
# only for deprecations and benches:
rand_isaac = { path = "rand_isaac", version = "0.1", default-features = false }
rand_xorshift = { path = "rand_xorshift", version = "0.1", default-features = false }
rand_isaac = { path = "rand_isaac", version = "0.1" }
rand_xorshift = { path = "rand_xorshift", version = "0.1" }
log = { version = "0.4", optional = true }
serde = { version = "1", optional = true }
serde_derive = { version = "1", optional = true }
Expand Down
8 changes: 7 additions & 1 deletion rand_isaac/Cargo.toml
Expand Up @@ -18,9 +18,15 @@ travis-ci = { repository = "rust-lang-nursery/rand" }
appveyor = { repository = "alexcrichton/rand" }

[features]
serde1 = ["serde", "serde_derive"] # enables serde for BlockRng wrapper
serde1 = ["serde", "serde_derive", "rand_core/serde1"]
Copy link
Member

Choose a reason for hiding this comment

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

Feature serde1 implicitly implies std — should probably be documented with a comment here and in the README

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Feature serde1 implicitly implies std

What do you mean? We don't require std for the serde1 feature, and Serde works without std. We only need std for the tests.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, sorry. I mis-understood the double-negative conditional no_std attribute.

std = []
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't follow why you added an extra std feature... Or does testing serialization need std?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, exactly. The test uses BufWriter, BufReader and bincode, all requiring std.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about only enabling std when testing, or even only when testing in combination with serde? Than we don't need the otherwise useless feature flag.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems a bit fragile. What if you want to test Serde without std? Anyway, this is not possible AFAIK.


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

[dev-dependencies]
# This is for testing serde, unfortunately we can't specify feature-gated dev
# deps yet, see: https://github.com/rust-lang/cargo/issues/1596
bincode = "1"
5 changes: 3 additions & 2 deletions rand_isaac/src/lib.rs
Expand Up @@ -18,11 +18,12 @@
#![deny(missing_debug_implementations)]
#![doc(test(attr(allow(unused_variables), deny(warnings))))]

#![no_std]
#![cfg_attr(not(feature="std"), no_std)]

#[cfg(feature="std")] extern crate std as core;
extern crate rand_core;

#[cfg(test)] #[cfg(feature="serde1")] extern crate bincode;
#[cfg(all(feature="serde1", test))] extern crate bincode;
#[cfg(feature="serde1")] extern crate serde;
#[cfg(feature="serde1")] #[macro_use] extern crate serde_derive;

Expand Down
8 changes: 7 additions & 1 deletion rand_xorshift/Cargo.toml
Expand Up @@ -18,9 +18,15 @@ travis-ci = { repository = "rust-lang-nursery/rand" }
appveyor = { repository = "alexcrichton/rand" }

[features]
serde1 = ["serde", "serde_derive"] # enables serde for BlockRng wrapper
serde1 = ["serde", "serde_derive"]
Copy link
Member

Choose a reason for hiding this comment

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

Same as for rand_isaac

std = []

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

[dev-dependencies]
# This is for testing serde, unfortunately we can't specify feature-gated dev
# deps yet, see: https://github.com/rust-lang/cargo/issues/1596
bincode = "1"
5 changes: 3 additions & 2 deletions rand_xorshift/src/lib.rs
Expand Up @@ -18,13 +18,14 @@
#![deny(missing_debug_implementations)]
#![doc(test(attr(allow(unused_variables), deny(warnings))))]

#![no_std]
#![cfg_attr(not(feature="std"), no_std)]

#[cfg(feature="std")] extern crate std as core;
extern crate rand_core;

#[cfg(test)] #[cfg(feature="serde1")] extern crate bincode;
#[cfg(feature="serde1")] extern crate serde;
#[cfg(feature="serde1")] #[macro_use] extern crate serde_derive;
#[cfg(all(feature="serde1", test))] extern crate bincode;

mod xorshift;

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -237,7 +237,7 @@
#[cfg(feature="std")] extern crate std as core;
#[cfg(all(feature = "alloc", not(feature="std")))] extern crate alloc;

#[cfg(test)] #[cfg(feature="serde1")] extern crate bincode;
#[cfg(all(feature="serde1", test))] extern crate bincode;
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment does not really belong to this PR, but does rand still need bincode as dependency, or do all tests now live in external crates?

Copy link
Collaborator Author

@vks vks Jul 20, 2018

Choose a reason for hiding this comment

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

Actually, after this PR rand does not depend directly on serde or bincode anymore. I removed them.

We might want to implement Serde support for StdRngand SmallRng. The serialization stability guarantees could be the same as for value stability.

#[cfg(feature="serde1")] extern crate serde;

#[cfg(all(target_arch="wasm32", not(target_os="emscripten"), feature="stdweb"))]
Expand Down