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

Tune platform-specific crate dependencies #724

Merged
merged 4 commits into from Feb 6, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,10 @@ 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.


## Unreleased
- Enable fork protection of ReseedingRng without `std`
- Remove dependency on `winapi`

## [0.6.5] - 2019-01-28
### Crates
- Update `rand_core` to 0.4 (#703)
Expand Down
5 changes: 1 addition & 4 deletions Cargo.toml
Expand Up @@ -65,12 +65,9 @@ optional = true
features = ["into_bits"]

[target.'cfg(unix)'.dependencies]
# Used for fork protection (reseeding.rs)
libc = { version = "0.2", default-features = false }

# TODO: check if all features are required
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["minwindef", "ntsecapi", "profileapi", "winnt"] }

[dev-dependencies]
# This has a histogram implementation used for testing uniformity.
average = "0.9.2"
Expand Down
3 changes: 3 additions & 0 deletions rand_jitter/CHANGELOG.md
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.1.3] - 2019-02-05
- Use libc in `no_std` mode to fix #723

## [0.1.2] - 2019-01-31
- Fix for older rustc compilers on Windows (#722)

Expand Down
6 changes: 4 additions & 2 deletions rand_jitter/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rand_jitter"
version = "0.1.2"
version = "0.1.3"
authors = ["The Rand Project Developers"]
license = "MIT/Apache-2.0"
readme = "README.md"
Expand All @@ -18,7 +18,9 @@ rand_core = { path = "../rand_core", version = "0.4" }
log = { version = "0.4", optional = true }

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
libc = "0.2"
# We don't need the 'use_std' feature and depending on it causes
# issues due to: https://github.com/rust-lang/cargo/issues/1197
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this statement is slightly misleading, the problem is that we use the use_std feature even for no_std builds. Would it be better if we tie libc's use_std feature to our std feature? I'm not sure how cargo works, but I imagine it might avoid recompiling the libc crate, when it is already required elsewhere with the use_std feature.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, I believe features are unified before the build takes place, so if another crate depends on libc with use_std it will just get built once with the feature enabled. We don't actually need use_std so there's no reason to depend on it.

The problem pointed out in #723 is that rand_jitter depending on libc with default features for a different target causes libc to be built with default features when depended on without by other crates in the build — obviously unintended functionality.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, then we should not use use_std in any case.

libc = { version = "0.2", default_features = false }

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["profileapi"] }
Expand Down
8 changes: 4 additions & 4 deletions src/rngs/adapter/reseeding.rs
Expand Up @@ -282,12 +282,12 @@ where R: BlockRngCore + SeedableRng + CryptoRng,
Rsdr: RngCore + CryptoRng {}


#[cfg(all(feature="std", unix, not(target_os="emscripten")))]
#[cfg(all(unix, not(target_os="emscripten")))]
mod fork {
extern crate libc;

use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT};
use core::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use core::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT};

// Fork protection
//
Expand Down Expand Up @@ -323,7 +323,7 @@ mod fork {
}
}

#[cfg(not(all(feature="std", unix, not(target_os="emscripten"))))]
#[cfg(not(all(unix, not(target_os="emscripten"))))]
mod fork {
pub fn get_fork_counter() -> usize { 0 }
pub fn register_fork_handler() {}
Expand Down