Skip to content

Commit 4adb260

Browse files
authored
Merge branch 'master' into patch-6
2 parents 2a524af + af8aa52 commit 4adb260

File tree

16 files changed

+651
-275
lines changed

16 files changed

+651
-275
lines changed

.travis.yml

Lines changed: 120 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,118 @@
11
language: rust
22
sudo: false
33

4-
# We aim to test all the following in any combination:
5-
# - standard tests, benches, documentation, all available features
6-
# - pinned stable, latest stable, beta and nightly Rust releases
7-
# - Linux, OS X, Android, iOS, bare metal (i.e. no_std)
8-
# - x86_64, ARMv7, a Big-Endian arch (MIPS)
4+
# We support too many combinations of Rust releases, crate features, operating
5+
# systems, and architectures to even remotely test all combinations.
6+
# Yet it turns out we can test most of these independent of each other, because
7+
# they serve different goals or test different pieces of code.
8+
#
9+
# RUST RELEASES
10+
# Goal: make sure we don't use language features unavailable on a certain
11+
# version, and build without warnings.
12+
# We have different builders use 4 Rust releases, a pinned stable release,
13+
# the latest stable, beta and nightly.
14+
#
15+
# ARCHITECTURES
16+
# Goal: test against issues caused by differences in endianness, pointer sizes,
17+
# etc.
18+
# We run tests on 4 different architectures.
19+
# - x64_84, default on Travis (Linux) and AppVeyor (Windows)
20+
# - i686, second AppVeyor (Windows) configuration
21+
# - MIPS, big-endian Linux emulated with QEMU (thanks to Trust)
22+
# - ARMv7, Android emulated with QEMU (thanks to Trust)
23+
#
24+
# OPERATING SYSTEMS
25+
# Goal: test on many operating systems, to verify the OsRng code, which is
26+
# mostly architecture-independent.
27+
# We run tests on Linux, OS X, Windows, Android (emulated), and Node.js (using
28+
# cargo-web).
29+
# One builder cross-compiles for many of the remaining OSes, which ensures we
30+
# keep building, but doesn't run tests.
31+
# OSes supported by Rand but which we can't cross-compile because there
32+
# is no pre-built standard library available: Dragonfly BSD, Haiku, OpenBSD.
33+
#
34+
# CRATE FEATURES, TESTS, AND SUB-CRATES
35+
# Goal: Run unit tests, doctests, examples, and test benchmarks for all crates,
36+
# in configurations that cover all interesting combinations of features.
37+
# (`--lib` only runs unit tests just like `--tests`, but the latter is not
38+
# available in Rust 1.22.0)
39+
# Tests run on rand:
40+
# - test no_std support, but only the unit tests:
41+
# `cargo test --lib --no-default-features`
42+
# - run unit tests and doctests with all features which are available on stable:
43+
# `cargo test --features=serde1,log`
44+
# - test examples:
45+
# `cargo test --examples`
46+
# Additional tests on nightly:
47+
# - run unit tests and doctests with all features which are available on nightly:
48+
# `cargo test --all-features`
49+
# - test no_std support, including the nightly alloc feature:
50+
# cargo test --lib --no-default-features --features=alloc
51+
# - run benchmarks as tests:
52+
# `cargo test --benches --features=nightly`
53+
# Tests on subcrates:
54+
# `cargo test --package rand_core`
55+
# `cargo test --package rand_core --features=alloc` (requires nightly)
56+
# `cargo test --package rand_core --no-default-features`
57+
# `cargo test --package rand_isaac --features=serde1`
58+
# `cargo test --package rand_xorshift --features=serde1`
959
matrix:
1060
include:
1161
- rust: 1.22.0
62+
env: DESCRIPTION="pinned stable Rust release"
1263
install:
1364
script:
14-
# TODO: use --tests instead of --lib on more recent compiler
1565
- cargo test --lib --no-default-features
66+
- cargo test --features=serde1,log
67+
- cargo test --examples
68+
- cargo test --package rand_core
1669
- cargo test --package rand_core --no-default-features
17-
- cargo test --package rand_isaac --features serde1
18-
- cargo test --package rand_xorshift --features serde1
19-
- cargo test --features serde1,log
70+
- cargo test --package rand_isaac --features=serde1
71+
# - cargo test --package rand_xorshift --features=serde1
72+
2073
- rust: stable
74+
env: DESCRIPTION="stable Rust release, macOS, iOS (cross-compile only)"
2175
os: osx
2276
install:
77+
- rustup target add aarch64-apple-ios
2378
script:
24-
- cargo test --tests --no-default-features
79+
- cargo test --lib --no-default-features
80+
- cargo test --features=serde1,log,i128_support
81+
- cargo test --examples
82+
- cargo test --package rand_core
2583
- cargo test --package rand_core --no-default-features
26-
- cargo test --package rand_isaac --features serde1
27-
- cargo test --package rand_xorshift --features serde1
28-
- cargo test --features serde1,log
84+
- cargo test --package rand_isaac --features=serde1
85+
- cargo test --package rand_xorshift --features=serde1
86+
- cargo build --target=aarch64-apple-ios
87+
2988
- rust: beta
89+
env: DESCRIPTION="beta Rust release"
3090
install:
3191
script:
32-
- cargo test --tests --no-default-features
92+
- cargo test --lib --no-default-features
93+
- cargo test --features=serde1,log,i128_support
94+
- cargo test --examples
95+
- cargo test --package rand_core
3396
- cargo test --package rand_core --no-default-features
34-
- cargo test --package rand_isaac --features serde1
35-
- cargo test --package rand_xorshift --features serde1
36-
- cargo test --features serde1,log
97+
- cargo test --package rand_isaac --features=serde1
98+
- cargo test --package rand_xorshift --features=serde1
99+
37100
- rust: nightly
101+
env: DESCRIPTION="nightly features, benchmarks, documentation"
38102
install:
39103
- cargo --list | egrep "^\s*deadlinks$" -q || cargo install cargo-deadlinks
104+
- cargo deadlinks -V
40105
before_script:
41106
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
42107
script:
43-
- cargo test --tests --no-default-features --features=alloc
44-
- cargo test --package rand_core --no-default-features --features=alloc,serde1
45-
- cargo test --features serde1,log,nightly,alloc
46-
- cargo test --all --benches
108+
- cargo test --lib --no-default-features --features=alloc
109+
- cargo test --all-features
110+
- cargo test --benches --features=nightly
111+
- cargo test --examples
112+
- cargo test --package rand_core
113+
- cargo test --package rand_core --no-default-features --features=alloc
114+
- cargo test --package rand_isaac --features=serde1
115+
# - cargo test --package rand_xorshift --features=serde1
47116
# remove cached documentation, otherwise files from previous PRs can get included
48117
- rm -rf target/doc
49118
- cargo doc --no-deps --all --all-features
@@ -52,52 +121,54 @@ matrix:
52121
- travis-cargo --only nightly doc-upload
53122

54123
- rust: nightly
124+
env: DESCRIPTION="WASM via emscripten, stdweb and wasm-bindgen"
55125
install:
56126
- rustup target add wasm32-unknown-unknown
57-
# Use cargo-update since we need a real update-or-install command
58-
# Only install if not already installed:
59-
#- cargo --list | egrep "\binstall-update$" -q || cargo install cargo-update
60-
#- cargo install-update -i cargo-web
61-
# Cargo has errors with sub-commands so ignore updating for now:
127+
- rustup target add wasm32-unknown-emscripten
128+
# cargo-web takes ±10 min. to install, and cargo and cargo-update offer
129+
# no reliable update-or-install command. We ignore updating for now
130+
# (just drop the Travis' caches when necessary)
62131
- cargo --list | egrep "^\s*web$" -q || cargo install cargo-web
132+
- cargo web -V
133+
addons:
134+
chrome: stable
63135
script:
64-
- cargo web test --target wasm32-unknown-unknown --nodejs --features=stdweb
65-
66-
- rust: nightly
67-
install:
68-
- rustup target add wasm32-unknown-unknown
69-
script:
70-
- cargo build --target wasm32-unknown-unknown --features wasm-bindgen
136+
# testing wasm32-unknown-emscripten fails because of rust-lang/rust#49877
137+
- cargo build --target wasm32-unknown-emscripten
138+
#- cargo web test --target wasm32-unknown-emscripten
139+
#- cargo web test --nodejs --target wasm32-unknown-emscripten
140+
- cargo build --target wasm32-unknown-unknown # without any features
141+
- cargo web test --nodejs --target wasm32-unknown-unknown --features=stdweb
142+
- cargo build --target wasm32-unknown-unknown --features=wasm-bindgen
71143

72144
- rust: nightly
145+
env: DESCRIPTION="cross-platform builder (doesn't run tests)"
73146
install:
74-
- rustup target add thumbv6m-none-eabi
147+
- rustup target add x86_64-sun-solaris
148+
- rustup target add x86_64-unknown-cloudabi
149+
- rustup target add x86_64-unknown-freebsd
150+
#- rustup target add x86_64-unknown-fuchsia
151+
- rustup target add x86_64-unknown-netbsd
152+
- rustup target add x86_64-unknown-redox
75153
script:
76-
# Bare metal target; no std; only works on nightly
77-
- cargo build --no-default-features --target thumbv6m-none-eabi --release
154+
- cargo build --target=x86_64-sun-solaris --all-features
155+
- cargo build --target=x86_64-unknown-cloudabi --all-features
156+
- cargo build --target=x86_64-unknown-freebsd --all-features
157+
#- cargo build --target=x86_64-unknown-fuchsia --all-features
158+
- cargo build --target=x86_64-unknown-netbsd --all-features
159+
- cargo build --target=x86_64-unknown-redox --all-features
78160

79161
# Trust cross-built/emulated targets. We must repeat all non-default values.
80162
- rust: stable
81163
sudo: required
82164
dist: trusty
83165
services: docker
84-
env: TARGET=x86_64-unknown-freebsd DISABLE_TESTS=1
166+
env: DESCRIPTION="Linux (MIPS, big-endian)" TARGET=mips-unknown-linux-gnu
85167
- rust: stable
86168
sudo: required
87169
dist: trusty
88170
services: docker
89-
env: TARGET=mips-unknown-linux-gnu
90-
- rust: stable
91-
sudo: required
92-
dist: trusty
93-
services: docker
94-
env: TARGET=armv7-linux-androideabi DISABLE_TESTS=1
95-
- rust: stable
96-
os: osx
97-
sudo: required
98-
dist: trusty
99-
services: docker
100-
env: TARGET=armv7-apple-ios DISABLE_TESTS=1
171+
env: DESCRIPTION="Android (ARMv7)" TARGET=armv7-linux-androideabi
101172

102173
before_install:
103174
- set -e

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ A [separate changelog is kept for rand_core](rand_core/CHANGELOG.md).
88

99
You may also find the [Update Guide](UPDATING.md) useful.
1010

11+
## [0.6.0] - Unreleased
12+
13+
### Crate features and organisation
14+
- The ISAAC and Xorshift RNGs have been moved to their own crates: `rand_isaac`
15+
and `rand_xorshift`. (#551, #557)
16+
- `Uniform` supports inclusive ranges: `Uniform::from(a..=b)`. This is
17+
automatically enabled for Rust >= 1.27. (#566)
18+
- Support for `i128` and `u128` is automatically enabled for Rust >= 1.26. This
19+
renders the `i128_support` feature obsolete. It still exists for backwards
20+
compatibility but does not have any effect. This breaks programs using Rand
21+
with `i128_support` on nightlies older than Rust 1.26. (#571)
22+
23+
### New distributions
24+
- Added sampling from the unit sphere and circle. (#567)
25+
26+
### Sequences module
27+
- Optimised and changed return type of the `sample_indices` function. (#479)
28+
- Added weighted sampling. (#518)
29+
30+
### Platform support
31+
- Added support for wasm-bindgen. (#541)
32+
- Added basic SIMD support. (#523)
33+
1134
## [0.5.4] - 2018-07-11
1235
### Platform support
1336
- Make `OsRng` work via WASM/stdweb for WebWorkers

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ appveyor = { repository = "alexcrichton/rand" }
2020

2121
[features]
2222
default = ["std" ] # without "std" rand uses libcore
23-
nightly = ["i128_support", "simd_support"] # enables all features requiring nightly rust
23+
nightly = ["simd_support"] # enables all features requiring nightly rust
2424
std = ["rand_core/std", "alloc", "libc", "winapi", "cloudabi", "fuchsia-zircon"]
2525
alloc = ["rand_core/alloc"] # enables Vec and Box support (without std)
26-
i128_support = [] # enables i128 and u128 support
26+
i128_support = [] # dummy feature for backwards compatibility
2727
simd_support = ["packed_simd"] # enables SIMD support
2828
serde1 = ["rand_core/serde1", "rand_isaac/serde1", "rand_xorshift/serde1"] # enables serialization for PRNGs
2929

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ Rand is built with only the `std` feature enabled by default. The following
115115
optional features are available:
116116

117117
- `alloc` can be used instead of `std` to provide `Vec` and `Box`.
118-
- `i128_support` enables support for generating `u128` and `i128` values.
119118
- `log` enables some logging via the `log` crate.
120-
- `nightly` enables all unstable features (`i128_support`, `simd_support`).
119+
- `nightly` enables all unstable features (`simd_support`).
121120
- `serde1` enables serialization for some types, via Serde version 1.
122121
- `simd_support` enables uniform sampling of SIMD types (integers and floats).
123122
- `stdweb` enables support for `OsRng` on `wasm32-unknown-unknown` via `stdweb`

appveyor.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ install:
3232
build: false
3333

3434
test_script:
35-
- cargo test --all # cannot use --all and --features together
36-
- cargo test --all --benches
37-
- cargo test --features serde1,log,nightly
38-
- cargo test --tests --no-default-features --features=alloc,serde1
39-
- cargo test --package rand_core --no-default-features --features=alloc,serde1
35+
- cargo test --lib --no-default-features --features alloc
36+
- cargo test --all-features
37+
- cargo test --benches --features=nightly
38+
- cargo test --examples
39+
- cargo test --package rand_core
40+
- cargo test --package rand_core --no-default-features --features=alloc
41+
- cargo test --package rand_isaac --features=serde1
42+
- cargo test --package rand_xorshift --features=serde1

benches/seq.rs

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(test)]
2+
#![allow(non_snake_case)]
23

34
extern crate test;
45
extern crate rand;
@@ -27,28 +28,31 @@ fn seq_slice_choose_1_of_1000(b: &mut Bencher) {
2728
})
2829
}
2930

30-
#[bench]
31-
fn seq_slice_choose_multiple_1_of_1000(b: &mut Bencher) {
32-
let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
33-
let x : &[usize] = &[1; 1000];
34-
b.iter(|| {
35-
x.choose_multiple(&mut rng, 1).cloned().next()
36-
})
37-
}
38-
39-
#[bench]
40-
fn seq_slice_choose_multiple_10_of_100(b: &mut Bencher) {
41-
let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
42-
let x : &[usize] = &[1; 100];
43-
let mut buf = [0; 10];
44-
b.iter(|| {
45-
for (v, slot) in x.choose_multiple(&mut rng, buf.len()).zip(buf.iter_mut()) {
46-
*slot = *v;
31+
macro_rules! seq_slice_choose_multiple {
32+
($name:ident, $amount:expr, $length:expr) => {
33+
#[bench]
34+
fn $name(b: &mut Bencher) {
35+
let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
36+
let x : &[i32] = &[$amount; $length];
37+
let mut result = [0i32; $amount];
38+
b.iter(|| {
39+
// Collect full result to prevent unwanted shortcuts getting
40+
// first element (in case sample_indices returns an iterator).
41+
for (slot, sample) in result.iter_mut().zip(
42+
x.choose_multiple(&mut rng, $amount)) {
43+
*slot = *sample;
44+
}
45+
result[$amount-1]
46+
})
4747
}
48-
buf
49-
})
48+
}
5049
}
5150

51+
seq_slice_choose_multiple!(seq_slice_choose_multiple_1_of_1000, 1, 1000);
52+
seq_slice_choose_multiple!(seq_slice_choose_multiple_950_of_1000, 950, 1000);
53+
seq_slice_choose_multiple!(seq_slice_choose_multiple_10_of_100, 10, 100);
54+
seq_slice_choose_multiple!(seq_slice_choose_multiple_90_of_100, 90, 100);
55+
5256
#[bench]
5357
fn seq_iter_choose_from_100(b: &mut Bencher) {
5458
let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
@@ -78,17 +82,22 @@ fn seq_iter_choose_multiple_fill_10_of_100(b: &mut Bencher) {
7882
}
7983

8084
macro_rules! sample_indices {
81-
($name:ident, $amount:expr, $length:expr) => {
85+
($name:ident, $fn:ident, $amount:expr, $length:expr) => {
8286
#[bench]
8387
fn $name(b: &mut Bencher) {
8488
let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
8589
b.iter(|| {
86-
sample_indices(&mut rng, $length, $amount)
90+
index::$fn(&mut rng, $length, $amount)
8791
})
8892
}
8993
}
9094
}
9195

92-
sample_indices!(seq_sample_indices_10_of_1k, 10, 1000);
93-
sample_indices!(seq_sample_indices_50_of_1k, 50, 1000);
94-
sample_indices!(seq_sample_indices_100_of_1k, 100, 1000);
96+
sample_indices!(misc_sample_indices_1_of_1k, sample, 1, 1000);
97+
sample_indices!(misc_sample_indices_10_of_1k, sample, 10, 1000);
98+
sample_indices!(misc_sample_indices_100_of_1k, sample, 100, 1000);
99+
sample_indices!(misc_sample_indices_100_of_1M, sample, 100, 1000_000);
100+
sample_indices!(misc_sample_indices_100_of_1G, sample, 100, 1000_000_000);
101+
sample_indices!(misc_sample_indices_200_of_1G, sample, 200, 1000_000_000);
102+
sample_indices!(misc_sample_indices_400_of_1G, sample, 400, 1000_000_000);
103+
sample_indices!(misc_sample_indices_600_of_1G, sample, 600, 1000_000_000);

build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ extern crate rustc_version;
22
use rustc_version::{version, Version};
33

44
fn main() {
5+
if version().unwrap() >= Version::parse("1.26.0").unwrap() {
6+
println!("cargo:rustc-cfg=rust_1_26");
7+
}
58
if version().unwrap() >= Version::parse("1.27.0").unwrap() {
69
println!("cargo:rustc-cfg=rust_1_27");
710
}

0 commit comments

Comments
 (0)