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

Update: getrandom v0.3.0 rc.0 #1541

Merged
merged 8 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ A [separate changelog is kept for rand_core](rand_core/CHANGELOG.md).

You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.html) useful.

## [0.9.0-beta.1] - 2024-11-30
- Bump `rand_core` version

## [0.9.0-beta.0] - 2024-11-25
This is a pre-release. To depend on this version, use `rand = "=0.9.0-beta.0"` to prevent automatic updates (which can be expected to include breaking changes).

Expand Down Expand Up @@ -65,6 +68,7 @@ This is a pre-release. To depend on this version, use `rand = "=0.9.0-beta.0"` t
- Distribution `Uniform` implements `TryFrom` instead of `From` for ranges (#1229)
- Optimize distribution `Uniform`: use Canon's method (single sampling) / Lemire's method (distribution sampling) for faster sampling (breaks value stability; #1287)
- Add `UniformUsize` and use to make `Uniform` for `usize` portable (#1487)
- Remove support for generating `isize` and `usize` values with `Standard`, `Uniform` (except via `UniformUsize`) and `Fill` and usage as a `WeightedAliasIndex` weight (#1487)
- Optimize fn `sample_single_inclusive` for floats (+~20% perf) (#1289)
- Allow `UniformFloat::new` samples and `UniformFloat::sample_single` to yield `high` (#1462)
- Add impl `DistString` for distributions `Slice<char>` and `Uniform<char>` (#1315)
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rand"
version = "0.9.0-beta.0"
version = "0.9.0-beta.1"
authors = ["The Rand Project Developers", "The Rust Project Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down Expand Up @@ -37,7 +37,7 @@ serde = ["dep:serde", "rand_core/serde"]
std = ["rand_core/std", "rand_chacha?/std", "alloc"]

# Option: "alloc" enables support for Vec and Box when not using "std"
alloc = ["rand_core/alloc"]
alloc = []

# Option: enable OsRng
os_rng = ["rand_core/os_rng"]
Expand Down Expand Up @@ -69,14 +69,14 @@ members = [
exclude = ["benches", "distr_test"]

[dependencies]
rand_core = { path = "rand_core", version = "=0.9.0-beta.0", default-features = false }
rand_core = { path = "rand_core", version = "=0.9.0-beta.1", default-features = false }
log = { version = "0.4.4", optional = true }
serde = { version = "1.0.103", features = ["derive"], optional = true }
rand_chacha = { path = "rand_chacha", version = "=0.9.0-beta.0", default-features = false, optional = true }
rand_chacha = { path = "rand_chacha", version = "=0.9.0-beta.1", default-features = false, optional = true }
zerocopy = { version = "0.8.0", default-features = false, features = ["simd"] }

[dev-dependencies]
rand_pcg = { path = "rand_pcg", version = "=0.9.0-beta.0" }
rand_pcg = { path = "rand_pcg", version = "=0.9.0-beta.1" }
# Only to test serde
bincode = "1.2.1"
rayon = "1.7"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ rand = "0.8.5"
Or, to try the 0.9.0 beta release:
```toml
[dependencies]
rand = "=0.9.0-beta.0"
rand = "=0.9.0-beta.1"
```

To get started using Rand, see [The Book](https://rust-random.github.io/book).
Expand Down
2 changes: 1 addition & 1 deletion distr_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish = false

[dev-dependencies]
rand_distr = { path = "../rand_distr", version = "=0.5.0-beta.1", default-features = false, features = ["alloc"] }
rand = { path = "..", version = "=0.9.0-beta.0", features = ["small_rng"] }
rand = { path = "..", version = "=0.9.0-beta.1", features = ["small_rng"] }
num-traits = "0.2.19"
# Special functions for testing distributions
special = "0.11.0"
Expand Down
3 changes: 3 additions & 0 deletions rand_chacha/CHANGELOG.md
Original file line number Diff line number Diff line change
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.9.0-beta.1] - 2024-11-30
- Bump `rand_core` version

## [0.9.0-beta.0] - 2024-11-25
This is a pre-release. To depend on this version, use `rand_chacha = "=0.9.0-beta.0"` to prevent automatic updates (which can be expected to include breaking changes).

Expand Down
6 changes: 3 additions & 3 deletions rand_chacha/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rand_chacha"
version = "0.9.0-beta.0"
version = "0.9.0-beta.1"
authors = ["The Rand Project Developers", "The Rust Project Developers", "The CryptoCorrosion Contributors"]
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand All @@ -20,14 +20,14 @@ all-features = true
rustdoc-args = ["--generate-link-to-definition"]

[dependencies]
rand_core = { path = "../rand_core", version = "=0.9.0-beta.0" }
rand_core = { path = "../rand_core", version = "=0.9.0-beta.1" }
ppv-lite86 = { version = "0.2.14", default-features = false, features = ["simd"] }
serde = { version = "1.0", features = ["derive"], optional = true }

[dev-dependencies]
# Only to test serde
serde_json = "1.0"
rand_core = { path = "../rand_core", version = "=0.9.0-beta.0", features = ["os_rng"] }
rand_core = { path = "../rand_core", version = "=0.9.0-beta.1", features = ["os_rng"] }

[features]
default = ["std"]
Expand Down
3 changes: 3 additions & 0 deletions rand_core/CHANGELOG.md
Original file line number Diff line number Diff line change
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.9.0-beta.1] - 2024-11-30
- Update to `getrandom` v0.3.0-rc.0

## [0.9.0-beta.0] - 2024-11-25
This is a pre-release. To depend on this version, use `rand_core = "=0.9.0-beta.0"` to prevent automatic updates (which can be expected to include breaking changes).

Expand Down
7 changes: 3 additions & 4 deletions rand_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rand_core"
version = "0.9.0-beta.0"
version = "0.9.0-beta.1"
authors = ["The Rand Project Developers", "The Rust Project Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand All @@ -25,12 +25,11 @@ rustdoc-args = ["--generate-link-to-definition"]
all-features = true

[features]
std = ["alloc", "getrandom?/std"]
alloc = [] # enables Vec and Box support without std
std = ["getrandom?/std"]
os_rng = ["dep:getrandom"]
serde = ["dep:serde"] # enables serde for BlockRng wrapper

[dependencies]
serde = { version = "1", features = ["derive"], optional = true }
getrandom = { version = "0.2", optional = true }
getrandom = { version = "0.3.0-rc.0", optional = true }
zerocopy = { version = "0.8.0", default-features = false }
27 changes: 1 addition & 26 deletions rand_core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,9 @@ The traits and error types are also available via `rand`.

The current version is:
```
rand_core = "0.6.4"
rand_core = "=0.9.0-beta.1"
```

Rand libs have inter-dependencies and make use of the
[semver trick](https://github.com/dtolnay/semver-trick/) in order to make traits
compatible across crate versions. (This is especially important for `RngCore`
and `SeedableRng`.) A few crate releases are thus compatibility shims,
depending on the *next* lib version (e.g. `rand_core` versions `0.2.2` and
`0.3.1`). This means, for example, that `rand_core_0_4_0::SeedableRng` and
`rand_core_0_3_0::SeedableRng` are distinct, incompatible traits, which can
cause build errors. Usually, running `cargo update` is enough to fix any issues.

## Crate Features

`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`,
`std::io::Read` support for types supporting `RngCore`, and
extensions to the `Error` type's functionality.

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 `serde` feature can be used to derive `Serialize` and `Deserialize` for RNG
implementations that use the `BlockRng` or `BlockRng64` wrappers.


# License

Expand Down
4 changes: 1 addition & 3 deletions rand_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![no_std]

#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

Expand Down Expand Up @@ -512,7 +510,7 @@ pub trait SeedableRng: Sized {
#[cfg(feature = "os_rng")]
fn try_from_os_rng() -> Result<Self, getrandom::Error> {
let mut seed = Self::Seed::default();
getrandom::getrandom(seed.as_mut())?;
getrandom::fill(seed.as_mut())?;
let res = Self::from_seed(seed);
Ok(res)
}
Expand Down
16 changes: 3 additions & 13 deletions rand_core/src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
//! Interface to the random number generator of the operating system.

use crate::{TryCryptoRng, TryRngCore};
use getrandom::getrandom;

/// An interface over the operating-system's random data source
///
Expand Down Expand Up @@ -79,15 +78,6 @@ impl OsError {
pub fn raw_os_error(self) -> Option<i32> {
self.0.raw_os_error()
}

/// Extract the bare error code.
///
/// This code can either come from the underlying OS, or be a custom error.
/// Use [`OsError::raw_os_error()`] to disambiguate.
#[inline]
pub const fn code(self) -> core::num::NonZeroU32 {
self.0.code()
}
}

impl TryRngCore for OsRng {
Expand All @@ -96,20 +86,20 @@ impl TryRngCore for OsRng {
#[inline]
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
let mut buf = [0u8; 4];
getrandom(&mut buf).map_err(OsError)?;
getrandom::fill(&mut buf).map_err(OsError)?;
dhardy marked this conversation as resolved.
Show resolved Hide resolved
Ok(u32::from_ne_bytes(buf))
}

#[inline]
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
let mut buf = [0u8; 8];
getrandom(&mut buf).map_err(OsError)?;
getrandom::fill(&mut buf).map_err(OsError)?;
Ok(u64::from_ne_bytes(buf))
}

#[inline]
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> {
getrandom(dest).map_err(OsError)?;
getrandom::fill(dest).map_err(OsError)?;
Ok(())
}
}
Expand Down
3 changes: 3 additions & 0 deletions rand_distr/CHANGELOG.md
Original file line number Diff line number Diff line change
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.5.0-beta.2] - 2024-11-30
- Bump `rand` version

## [0.5.0-beta.1] - 2024-11-27
- Fix docs.rs build (#1539)

Expand Down
8 changes: 4 additions & 4 deletions rand_distr/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rand_distr"
version = "0.5.0-beta.1"
version = "0.5.0-beta.2"
authors = ["The Rand Project Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down Expand Up @@ -33,15 +33,15 @@ std_math = ["num-traits/std"]
serde = ["dep:serde", "dep:serde_with", "rand/serde"]

[dependencies]
rand = { path = "..", version = "=0.9.0-beta.0", default-features = false }
rand = { path = "..", version = "=0.9.0-beta.1", default-features = false }
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
serde = { version = "1.0.103", features = ["derive"], optional = true }
serde_with = { version = ">= 3.0, <= 3.11", optional = true }

[dev-dependencies]
rand_pcg = { version = "=0.9.0-beta.0", path = "../rand_pcg" }
rand_pcg = { version = "=0.9.0-beta.1", path = "../rand_pcg" }
# For inline examples
rand = { path = "..", version = "=0.9.0-beta.0", features = ["small_rng"] }
rand = { path = "..", version = "=0.9.0-beta.1", features = ["small_rng"] }
# Histogram implementation for testing uniformity
average = { version = "0.15", features = [ "std" ] }
# Special functions for testing distributions
Expand Down
3 changes: 3 additions & 0 deletions rand_pcg/CHANGELOG.md
Original file line number Diff line number Diff line change
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.9.0-beta.1] - 2024-11-30
- Bump `rand_core` version

## [0.9.0-beta.0] - 2024-11-25
This is a pre-release. To depend on this version, use `rand_chacha = "=0.9.0-beta.0"` to prevent automatic updates (which can be expected to include breaking changes).

Expand Down
6 changes: 3 additions & 3 deletions rand_pcg/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rand_pcg"
version = "0.9.0-beta.0"
version = "0.9.0-beta.1"
authors = ["The Rand Project Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand All @@ -24,12 +24,12 @@ serde = ["dep:serde"]
os_rng = ["rand_core/os_rng"]

[dependencies]
rand_core = { path = "../rand_core", version = "=0.9.0-beta.0" }
rand_core = { path = "../rand_core", version = "=0.9.0-beta.1" }
serde = { version = "1", features = ["derive"], 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
# Versions prior to 1.1.4 had incorrect minimal dependencies.
bincode = { version = "1.1.4" }
rand_core = { path = "../rand_core", version = "=0.9.0-beta.0", features = ["os_rng"] }
rand_core = { path = "../rand_core", version = "=0.9.0-beta.1", features = ["os_rng"] }
Loading