diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index e1b34b5..45e04cf 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -21,7 +21,7 @@ jobs: run: cargo build --release - name: Test - run: cargo test --release --lib + run: cargo test --release build_test_x86_avx2: name: Build & Test X86 AVX2 @@ -37,7 +37,7 @@ jobs: run: cargo build --release - name: Test - run: cargo test --release --lib + run: cargo test --release build_test_arm: name: Build & Test ARM @@ -50,4 +50,4 @@ jobs: run: cargo build --release - name: Test - run: cargo test --release --lib \ No newline at end of file + run: cargo test --release \ No newline at end of file diff --git a/build.rs b/build.rs index dd11580..6216fff 100644 --- a/build.rs +++ b/build.rs @@ -2,10 +2,40 @@ extern crate rustc_version; use rustc_version::{version_meta, Channel}; fn main() { + + if let Err(e) = check_hardware_support() { + panic!("Gxhash build failed: {}", e); + } + if version_meta().unwrap().channel == Channel::Nightly && cfg!(target_arch = "x86_64") && cfg!(target_feature = "avx2") && cfg!(target_feature = "vaes") { println!("cargo:rustc-cfg=hybrid"); } +} + +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +fn check_hardware_support() -> Result<(), Box> { + if !std::is_x86_feature_detected!("aes") { + return Result::Err("CPU feature 'aes' is required")?; + } + if !std::is_x86_feature_detected!("sse2") { + return Result::Err("CPU feature 'sse2' is required")?; + } + return Ok(()); +} + +#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] +fn check_hardware_support() -> Result<(), Box> { + if cfg!(any(target_arch = "arm", target_arch = "aarch64")) { + if cfg!(not(target_feature = "aes")) { + return Result::Err("CPU feature 'aes' is required")?; + } + if cfg!(not(target_feature = "neon")) { + return Result::Err("CPU feature 'neon' is required")?; + } + return Ok(()); + } + return Result::Err(format!("Target arch '{}' is not supported", std::env::consts::ARCH))?; } \ No newline at end of file diff --git a/src/gxhash/platform/mod.rs b/src/gxhash/platform/mod.rs index 0feb928..d08d22b 100644 --- a/src/gxhash/platform/mod.rs +++ b/src/gxhash/platform/mod.rs @@ -1,8 +1,8 @@ -#[cfg(all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "aes", target_feature = "neon"))] +#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] #[path = "arm.rs"] mod platform; -#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", target_feature = "sse2"))] +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[path = "x86.rs"] mod platform;