Skip to content

Commit

Permalink
Fix build issue on ARM
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Kaitchuck <Tom.Kaitchuck@gmail.com>
  • Loading branch information
tkaitchuck committed Jul 17, 2021
1 parent 8781819 commit 8066e02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ edition = "2018"
readme = "README.md"
build = "./build.rs"
exclude = ["/smhasher"]
resolver = "2"

This comment has been minimized.

Copy link
@extrawurst

extrawurst Oct 11, 2021

this significantly raises the minimum required rust version of this crate and it now got shipped as a patch release. @tkaitchuck was that intended?

This comment has been minimized.

Copy link
@stephank

stephank Oct 12, 2021

Seconding this, and adding a little more context:

I believe this Cargo option was introduced in Rust 1.51.0 (2021-03-25), and I maintain a project that currently has a minimum required Rust version 1.46.0 (2020-08-27), so ahash was compatible with at least that version.

This crate is very popular and pulled in via h2 (hyper), rusqlite, mongodb, to name a few. It's not a huge deal for me personally (I can raise the Rust requirement), but possibly other projects have to deal with distribution packaging or other reasons that require building with an older Rust.

This comment has been minimized.

Copy link
@tkaitchuck

tkaitchuck Oct 15, 2021

Author Owner

I was not aware of that effect. The intention was to remove the dependencies from the targets where it is not required...
Perhaps this will have to wait.


[lib]
name = "ahash"
Expand Down Expand Up @@ -73,7 +74,7 @@ serde = { version = "1.0.117", optional = true }
const-random = { version = "0.1.12", optional = true }
serde = { version = "1.0.117", optional = true }

[dependencies]
[target.'cfg(not(all(target_arch = "arm", target_os = "none")))'.dependencies]
once_cell = { version = "1.8", default-features = false, features = ["alloc"] }

[dev-dependencies]
Expand Down
17 changes: 17 additions & 0 deletions src/random_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern crate std as alloc;

use alloc::boxed::Box;
use core::sync::atomic::{AtomicUsize, Ordering};
#[cfg(not(all(target_arch = "arm", target_os = "none")))]
use once_cell::race::OnceBox;

#[cfg(any(
Expand All @@ -44,6 +45,7 @@ use crate::aes_hash::*;
)))]
use crate::fallback_hash::*;

#[cfg(not(all(target_arch = "arm", target_os = "none")))]
static RAND_SOURCE: OnceBox<Box<dyn RandomSource + Send + Sync>> = OnceBox::new();

/// A supplier of Randomness used for different hashers.
Expand Down Expand Up @@ -80,6 +82,12 @@ impl DefaultRandomSource {
counter: AtomicUsize::new(&PI as *const _ as usize),
}
}

const fn default() -> DefaultRandomSource {
DefaultRandomSource {
counter: AtomicUsize::new(PI[3] as usize),
}
}
}

impl RandomSource for DefaultRandomSource {
Expand Down Expand Up @@ -165,15 +173,24 @@ impl RandomState {
/// The source of randomness can only be set once, and must be set before the first RandomState is created.
/// If the source has already been specified `Err` is returned with a `bool` indicating if the set failed because
/// method was previously invoked (true) or if the default source is already being used (false).
#[cfg(not(all(target_arch = "arm", target_os = "none")))]
pub fn set_random_source(source: impl RandomSource + Send + Sync + 'static) -> Result<(), bool> {
RAND_SOURCE.set(Box::new(Box::new(source))).map_err(|s| s.as_ref().type_id() != TypeId::of::<&DefaultRandomSource>())
}

#[inline]
#[cfg(not(all(target_arch = "arm", target_os = "none")))]
fn get_src() -> &'static dyn RandomSource {
RAND_SOURCE.get_or_init(|| Box::new(Box::new(DefaultRandomSource::new()))).as_ref()
}

#[inline]
#[cfg(all(target_arch = "arm", target_os = "none"))]
fn get_src() -> &'static dyn RandomSource {
static RAND_SOURCE: DefaultRandomSource = DefaultRandomSource::default();
&RAND_SOURCE
}

/// Use randomly generated keys
#[inline]
pub fn new() -> RandomState {
Expand Down

0 comments on commit 8066e02

Please sign in to comment.