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:
Kirill
2022-07-06 22:00:58 +00:00
parent d5e2d98970
commit 5dbfb37d74
2 changed files with 6 additions and 5 deletions

View File

@@ -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;
}