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

Use Rust 2018 and remove build.rs #824

Merged
merged 21 commits into from Jun 23, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 1 addition & 4 deletions Cargo.toml
Expand Up @@ -12,9 +12,9 @@ Random number generators and other randomness functionality.
"""
keywords = ["random", "rng"]
categories = ["algorithms", "no-std"]
build = "build.rs"
exclude = ["/utils/*", "/.travis.yml", "/appveyor.yml", ".gitignore"]
autobenches = true
edition = "2018"

[badges]
travis-ci = { repository = "rust-random/rand" }
Expand Down Expand Up @@ -86,8 +86,5 @@ rand_xoshiro = { path = "rand_xoshiro", version = "0.3" }
rand_isaac = { path = "rand_isaac", version = "0.2" }
rand_xorshift = { path = "rand_xorshift", version = "0.2" }

[build-dependencies]
autocfg = "0.1"

[package.metadata.docs.rs]
all-features = true
7 changes: 0 additions & 7 deletions benches/generators.rs
Expand Up @@ -10,13 +10,6 @@
#![allow(non_snake_case)]

extern crate test;
extern crate rand;
extern crate rand_isaac;
extern crate rand_chacha;
extern crate rand_hc;
extern crate rand_pcg;
extern crate rand_xorshift;
extern crate rand_xoshiro;

const RAND_BENCH_N: u64 = 1000;
const BYTES_LEN: usize = 1024;
Expand Down
14 changes: 6 additions & 8 deletions benches/misc.rs
Expand Up @@ -9,8 +9,6 @@
#![feature(test)]

extern crate test;
extern crate rand;
extern crate rand_pcg;

const RAND_BENCH_N: u64 = 1000;

Expand All @@ -25,7 +23,7 @@ fn misc_gen_bool_const(b: &mut Bencher) {
let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let mut accum = true;
for _ in 0..::RAND_BENCH_N {
for _ in 0..crate::RAND_BENCH_N {
accum ^= rng.gen_bool(0.18);
}
accum
Expand All @@ -38,7 +36,7 @@ fn misc_gen_bool_var(b: &mut Bencher) {
b.iter(|| {
let mut accum = true;
let mut p = 0.18;
for _ in 0..::RAND_BENCH_N {
for _ in 0..crate::RAND_BENCH_N {
accum ^= rng.gen_bool(p);
p += 0.0001;
}
Expand All @@ -51,7 +49,7 @@ fn misc_gen_ratio_const(b: &mut Bencher) {
let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let mut accum = true;
for _ in 0..::RAND_BENCH_N {
for _ in 0..crate::RAND_BENCH_N {
accum ^= rng.gen_ratio(2, 3);
}
accum
Expand All @@ -63,7 +61,7 @@ fn misc_gen_ratio_var(b: &mut Bencher) {
let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
b.iter(|| {
let mut accum = true;
for i in 2..(::RAND_BENCH_N as u32 + 2) {
for i in 2..(crate::RAND_BENCH_N as u32 + 2) {
accum ^= rng.gen_ratio(i, i + 1);
}
accum
Expand All @@ -76,7 +74,7 @@ fn misc_bernoulli_const(b: &mut Bencher) {
b.iter(|| {
let d = rand::distributions::Bernoulli::new(0.18).unwrap();
let mut accum = true;
for _ in 0..::RAND_BENCH_N {
for _ in 0..crate::RAND_BENCH_N {
accum ^= rng.sample(d);
}
accum
Expand All @@ -89,7 +87,7 @@ fn misc_bernoulli_var(b: &mut Bencher) {
b.iter(|| {
let mut accum = true;
let mut p = 0.18;
for _ in 0..::RAND_BENCH_N {
for _ in 0..crate::RAND_BENCH_N {
let d = Bernoulli::new(p).unwrap();
accum ^= rng.sample(d);
p += 0.0001;
Expand Down
6 changes: 2 additions & 4 deletions benches/seq.rs
Expand Up @@ -10,8 +10,6 @@
#![allow(non_snake_case)]

extern crate test;
extern crate rand;
extern crate rand_pcg;

use test::Bencher;

Expand Down Expand Up @@ -49,7 +47,7 @@ fn seq_slice_choose_1_of_1000(b: &mut Bencher) {
}
s
});
b.bytes = size_of::<usize>() as u64 * ::RAND_BENCH_N;
b.bytes = size_of::<usize>() as u64 * crate::RAND_BENCH_N;
}

macro_rules! seq_slice_choose_multiple {
Expand Down Expand Up @@ -91,7 +89,7 @@ fn seq_iter_choose_from_1000(b: &mut Bencher) {
}
s
});
b.bytes = size_of::<usize>() as u64 * ::RAND_BENCH_N;
b.bytes = size_of::<usize>() as u64 * crate::RAND_BENCH_N;
}

#[derive(Clone)]
Expand Down
11 changes: 0 additions & 11 deletions build.rs

This file was deleted.

3 changes: 0 additions & 3 deletions examples/monte-carlo.rs
Expand Up @@ -26,9 +26,6 @@

#![cfg(feature = "std")]


extern crate rand;

use rand::distributions::{Distribution, Uniform};

fn main() {
Expand Down
3 changes: 0 additions & 3 deletions examples/monty-hall.rs
Expand Up @@ -28,9 +28,6 @@

#![cfg(feature = "std")]


extern crate rand;

use rand::distributions::{Distribution, Uniform};
use rand::Rng;

Expand Down
5 changes: 1 addition & 4 deletions rand_chacha/Cargo.toml
Expand Up @@ -12,7 +12,7 @@ ChaCha random number generator
"""
keywords = ["random", "rng", "chacha"]
categories = ["algorithms", "no-std"]
build = "build.rs"
edition = "2018"

[badges]
travis-ci = { repository = "rust-random/rand" }
Expand All @@ -22,9 +22,6 @@ appveyor = { repository = "rust-random/rand" }
rand_core = { path = "../rand_core", version = "0.5" }
c2-chacha = { version = "0.2.2", default-features = false }

[build-dependencies]
autocfg = "0.1"

[features]
default = ["std", "simd"]
std = ["c2-chacha/std"]
Expand Down
7 changes: 0 additions & 7 deletions rand_chacha/build.rs

This file was deleted.

5 changes: 2 additions & 3 deletions rand_chacha/src/lib.rs
Expand Up @@ -18,12 +18,11 @@

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

extern crate c2_chacha;
pub extern crate rand_core;
pub use rand_core;

mod chacha;

pub use chacha::{ChaCha12Core, ChaCha12Rng, ChaCha20Core, ChaCha20Rng, ChaCha8Core, ChaCha8Rng};
pub use crate::chacha::{ChaCha12Core, ChaCha12Rng, ChaCha20Core, ChaCha20Rng, ChaCha8Core, ChaCha8Rng};

/// ChaCha with 20 rounds
pub type ChaChaRng = ChaCha20Rng;
Expand Down
6 changes: 3 additions & 3 deletions rand_core/Cargo.toml
Expand Up @@ -12,6 +12,7 @@ Core random number generator traits and tools for implementation.
"""
keywords = ["random", "rng"]
categories = ["algorithms", "no-std"]
edition = "2018"

[badges]
travis-ci = { repository = "rust-random/rand" }
Expand All @@ -20,9 +21,8 @@ appveyor = { repository = "rust-random/rand" }
[features]
std = ["alloc", "getrandom", "getrandom/std"] # 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
serde1 = ["serde"] # enables serde for BlockRng wrapper

[dependencies]
serde = { version = "1", optional = true }
serde_derive = { version = "^1.0.38", optional = true }
serde = { version = "1", features = ["derive"], optional = true }
getrandom = { version = "0.1", optional = true }
5 changes: 3 additions & 2 deletions rand_core/src/block.rs
Expand Up @@ -52,8 +52,9 @@

use core::convert::AsRef;
use core::{fmt, ptr};
use {RngCore, CryptoRng, SeedableRng, Error};
use impls::{fill_via_u32_chunks, fill_via_u64_chunks};
#[cfg(feature="serde1")] use serde::{Serialize, Deserialize};
use crate::{RngCore, CryptoRng, SeedableRng, Error};
use crate::impls::{fill_via_u32_chunks, fill_via_u64_chunks};

/// A trait for RNGs which do not generate random numbers individually, but in
/// blocks (typically `[u32; N]`). This technique is commonly used by
Expand Down
2 changes: 1 addition & 1 deletion rand_core/src/impls.rs
Expand Up @@ -22,7 +22,7 @@ use core::ptr::copy_nonoverlapping;
use core::slice;
use core::cmp::min;
use core::mem::size_of;
use RngCore;
use crate::RngCore;


/// Implement `next_u64` via `next_u32`, little-endian order.
Expand Down
8 changes: 2 additions & 6 deletions rand_core/src/lib.rs
Expand Up @@ -38,16 +38,12 @@
#![cfg_attr(not(feature="std"), no_std)]
#![cfg_attr(all(feature="alloc", not(feature="std")), feature(alloc))]

#[cfg(feature="std")] extern crate core;
#[cfg(all(feature = "alloc", not(feature="std")))] extern crate alloc;
#[cfg(feature="serde1")] extern crate serde;
#[cfg(feature="serde1")] #[macro_use] extern crate serde_derive;


use core::default::Default;
use core::convert::AsMut;
use core::ptr::copy_nonoverlapping;

#[cfg(all(feature="alloc", not(feature="std")))] extern crate alloc;
#[cfg(all(feature="alloc", not(feature="std")))] use alloc::boxed::Box;

pub use error::Error;
Expand Down Expand Up @@ -435,7 +431,7 @@ impl<R: RngCore + ?Sized> RngCore for Box<R> {
}

#[cfg(feature="std")]
impl std::io::Read for RngCore {
impl std::io::Read for dyn RngCore {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
self.try_fill_bytes(buf)?;
Ok(buf.len())
Expand Down
2 changes: 0 additions & 2 deletions rand_distr/benches/distributions.rs
Expand Up @@ -8,8 +8,6 @@

#![feature(test)]

extern crate test;

const RAND_BENCH_N: u64 = 1000;

use std::mem::size_of;
Expand Down
1 change: 1 addition & 0 deletions rand_jitter/Cargo.toml
Expand Up @@ -8,6 +8,7 @@ repository = "https://github.com/rust-random/rand"
documentation = "https://docs.rs/rand_jitter"
description = "Random number generator based on timing jitter"
keywords = ["random", "rng", "os"]
edition = "2018"

[badges]
travis-ci = { repository = "rust-random/rand" }
Expand Down
3 changes: 1 addition & 2 deletions rand_jitter/benches/mod.rs
@@ -1,6 +1,5 @@
#![feature(test)]
extern crate test;
extern crate rand_jitter;
#![cfg(std)]

use test::Bencher;
use rand_jitter::rand_core::RngCore;
Expand Down
10 changes: 0 additions & 10 deletions rand_jitter/src/dummy_log.rs

This file was deleted.

50 changes: 35 additions & 15 deletions rand_jitter/src/lib.rs
Expand Up @@ -54,15 +54,10 @@
// compiler not optimize out code which does influence timing jitter, but is
// technically dead code.
#![no_std]
pub extern crate rand_core;
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "log")]
#[macro_use] extern crate log;
#[cfg(any(target_os = "macos", target_os = "ios"))]
extern crate libc;
#[cfg(target_os = "windows")]
extern crate winapi;

pub use rand_core;

// Coming from https://crates.io/crates/doc-comment
#[cfg(test)]
Expand All @@ -76,21 +71,47 @@ macro_rules! doc_comment {
#[cfg(test)]
doc_comment!(include_str!("../README.md"));

#[cfg(not(feature = "log"))]
#[macro_use] mod dummy_log;
#[allow(unused)]
macro_rules! trace { ($($x:tt)*) => (
#[cfg(feature = "log")] {
log::trace!($($x)*)
}
) }
#[allow(unused)]
macro_rules! debug { ($($x:tt)*) => (
#[cfg(feature = "log")] {
log::debug!($($x)*)
}
) }
#[allow(unused)]
macro_rules! info { ($($x:tt)*) => (
#[cfg(feature = "log")] {
log::info!($($x)*)
}
) }
#[allow(unused)]
macro_rules! warn { ($($x:tt)*) => (
#[cfg(feature = "log")] {
log::warn!($($x)*)
}
) }
#[allow(unused)]
macro_rules! error { ($($x:tt)*) => (
#[cfg(feature = "log")] {
log::error!($($x)*)
}
) }

#[cfg(feature = "std")]
mod platform;
mod error;

use rand_core::{RngCore, Error, impls};
pub use error::TimerError;
pub use crate::error::TimerError;

use core::{fmt, mem, ptr};
#[cfg(feature = "std")]
use std::sync::atomic::{AtomicUsize, Ordering};
#[cfg(feature = "std")]
#[allow(deprecated)] // Required for compatibility with Rust < 1.24.
use std::sync::atomic::ATOMIC_USIZE_INIT;

const MEMORY_BLOCKS: usize = 64;
const MEMORY_BLOCKSIZE: usize = 32;
Expand Down Expand Up @@ -185,8 +206,7 @@ impl Clone for JitterRng {

// Initialise to zero; must be positive
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
#[allow(deprecated)]
static JITTER_ROUNDS: AtomicUsize = ATOMIC_USIZE_INIT;
static JITTER_ROUNDS: AtomicUsize = AtomicUsize::new(0);

impl JitterRng {
/// Create a new `JitterRng`. Makes use of `std::time` for a timer, or a
Expand Down
3 changes: 0 additions & 3 deletions rand_jitter/tests/mod.rs
@@ -1,6 +1,3 @@
extern crate rand_jitter;
extern crate rand_core;

use rand_jitter::JitterRng;
#[cfg(feature = "std")]
use rand_core::RngCore;
Expand Down
3 changes: 0 additions & 3 deletions rand_pcg/Cargo.toml
Expand Up @@ -30,6 +30,3 @@ serde = { version = "1", features = ["derive"], optional = true }
# deps yet, see: https://github.com/rust-lang/cargo/issues/1596
# We require at least 1.1.2 for i128 auto-detection
bincode = { version = "1.1.2" }

[build-dependencies]
autocfg = "0.1"