Skip to content

Commit

Permalink
eth2_hashing: make cpufeatures dep optional (sigp#3309)
Browse files Browse the repository at this point in the history
## Issue Addressed

sigp#3308 

## Proposed Changes

* add `cpufeatures` feature.
* make `cpufeature` default feature to preserve the compatibility;
* hide all `cpufeature`-related code with `cpufeatures` feature.

Co-authored-by: Kirill <kirill@aurora.dev>
  • Loading branch information
sept-en and sept-en committed Jul 6, 2022
1 parent d5e2d98 commit 5dbfb37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions crypto/eth2_hashing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ description = "Hashing primitives used in Ethereum 2.0"

[dependencies]
lazy_static = { version = "1.4.0", optional = true }
cpufeatures = { version = "0.2.2", optional = true }
ring = "0.16.19"
sha2 = "0.10.2"
cpufeatures = "0.2.2"

[dev-dependencies]
rustc-hex = "2.1.0"
Expand All @@ -19,5 +19,6 @@ rustc-hex = "2.1.0"
wasm-bindgen-test = "0.3.18"

[features]
default = ["zero_hash_cache"]
default = ["zero_hash_cache", "detect-cpufeatures"]
zero_hash_cache = ["lazy_static"]
detect-cpufeatures = ["cpufeatures"]
6 changes: 3 additions & 3 deletions crypto/eth2_hashing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ pub enum DynamicImpl {
// Runtime latch for detecting the availability of SHA extensions on x86_64.
//
// Inspired by the runtime switch within the `sha2` crate itself.
#[cfg(target_arch = "x86_64")]
#[cfg(all(feature = "detect-cpufeatures", target_arch = "x86_64"))]
cpufeatures::new!(x86_sha_extensions, "sha", "sse2", "ssse3", "sse4.1");

#[inline(always)]
pub fn have_sha_extensions() -> bool {
#[cfg(target_arch = "x86_64")]
#[cfg(all(feature = "detect-cpufeatures", target_arch = "x86_64"))]
return x86_sha_extensions::get();

#[cfg(not(target_arch = "x86_64"))]
#[cfg(not(all(feature = "detect-cpufeatures", target_arch = "x86_64")))]
return false;
}

Expand Down

0 comments on commit 5dbfb37

Please sign in to comment.