Skip to content

Commit

Permalink
Check at build-time if aes feature is enabled (and panic otherwise)
Browse files Browse the repository at this point in the history
  • Loading branch information
ogxd committed Jan 21, 2024
1 parent 559b565 commit cadcfc6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
File renamed without changes.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "gxhash"
authors = ["Olivier Giniaux"]
version = "3.1.0"
version = "3.1.1"
edition = "2021"
description = "GxHash non-cryptographic algorithm"
license = "MIT"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Check out the [paper](https://github.com/ogxd/gxhash-rust/blob/main/article/arti

## Portability

> **Important**
> Because GxHash relies on `aes` hardware acceleration, you must make sure the `aes` feature is enabled when building (otherwise it won't build). This can be done by setting the `RUSTFLAGS` environment variable to `-C target-feature=+aes` or `-C target-cpu=native` (the latter should work if your CPU is properly recognized by rustc, which is the case most of the time).
### Architecture Compatibility
GxHash is compatible with:
- X86 processors with `AES-NI` & `SSE2` intrinsics
Expand Down
8 changes: 8 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ 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.");
}
}

0 comments on commit cadcfc6

Please sign in to comment.