Skip to content

Commit

Permalink
Use compile_error macro to replace build script
Browse files Browse the repository at this point in the history
  • Loading branch information
ogxd committed May 16, 2024
1 parent c9c9f61 commit 6793257
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: rustup default nightly

- name: Benchmark
run: cargo bench --bench throughput --features bench-plot
run: cargo bench --bench throughput --features bench-plot hybrid

- uses: actions/upload-artifact@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:
run: cargo rustc -- --version

- name: Build
run: cargo build --release
run: cargo build --release --features hybrid

- name: Test
run: cargo test --release --lib
run: cargo test --release --lib --features hybrid

build_test_arm:
name: Build & Test ARM
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exclude = ["article/*"]
bench-csv = []
bench-md = []
bench-plot = []
hybrid = []

[dependencies]
rand = "0.8"
Expand Down
13 changes: 0 additions & 13 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,5 @@ extern crate rustc_version;
use rustc_version::{version_meta, Channel};

fn main() {
// When conditions permits, enable hybrid feature to leverage wider intrinsics for even more throughput
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");
}

// If not cross compiling, make sure the aes feature is available
if std::env::var("HOST").unwrap_or_default() == std::env::var("TARGET").unwrap_or_default()
&& cfg!(not(target_feature = "aes")) {
panic!("| GxHash requires target-feature 'aes' to be enabled.\n\
| Build with RUSTFLAGS=\"-C target-cpu=native\" or RUSTFLAGS=\"-C target-feature=+aes\" to enable.");
}
}
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Hybrid SIMD width usage currently requires unstable 'stdsimd'
#![cfg_attr(hybrid, feature(stdarch_x86_avx512))]

#[cfg(all(feature = "hybrid", not(any(target_arch = "x86_64", target_feature = "avx2", target_feature = "vaes"))))]
compile_error!{"Hybrid feature is only available on x86 processors with avx2 and vaes intrinsics."}

#[cfg(not(target_feature = "aes"))]
compile_error!{"Gxhash requires aes intrinsics. Make sure the processor supports it and build with RUSTFLAGS=\"-C target-cpu=native\" or RUSTFLAGS=\"-C target-feature=+aes\"."}

#[rustfmt::skip]
mod gxhash;
mod hasher;
Expand Down

0 comments on commit 6793257

Please sign in to comment.