eth2_hashing: make cpufeatures
dep optional (#3309)
## Issue Addressed #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>
This commit is contained in:
parent
d5e2d98970
commit
5dbfb37d74
@ -8,9 +8,9 @@ description = "Hashing primitives used in Ethereum 2.0"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lazy_static = { version = "1.4.0", optional = true }
|
lazy_static = { version = "1.4.0", optional = true }
|
||||||
|
cpufeatures = { version = "0.2.2", optional = true }
|
||||||
ring = "0.16.19"
|
ring = "0.16.19"
|
||||||
sha2 = "0.10.2"
|
sha2 = "0.10.2"
|
||||||
cpufeatures = "0.2.2"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rustc-hex = "2.1.0"
|
rustc-hex = "2.1.0"
|
||||||
@ -19,5 +19,6 @@ rustc-hex = "2.1.0"
|
|||||||
wasm-bindgen-test = "0.3.18"
|
wasm-bindgen-test = "0.3.18"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["zero_hash_cache"]
|
default = ["zero_hash_cache", "detect-cpufeatures"]
|
||||||
zero_hash_cache = ["lazy_static"]
|
zero_hash_cache = ["lazy_static"]
|
||||||
|
detect-cpufeatures = ["cpufeatures"]
|
||||||
|
@ -127,15 +127,15 @@ pub enum DynamicImpl {
|
|||||||
// Runtime latch for detecting the availability of SHA extensions on x86_64.
|
// Runtime latch for detecting the availability of SHA extensions on x86_64.
|
||||||
//
|
//
|
||||||
// Inspired by the runtime switch within the `sha2` crate itself.
|
// 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");
|
cpufeatures::new!(x86_sha_extensions, "sha", "sse2", "ssse3", "sse4.1");
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn have_sha_extensions() -> bool {
|
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();
|
return x86_sha_extensions::get();
|
||||||
|
|
||||||
#[cfg(not(target_arch = "x86_64"))]
|
#[cfg(not(all(feature = "detect-cpufeatures", target_arch = "x86_64")))]
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user