aboutsummaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2020-01-11 20:13:08 -0500
committerJack O'Connor <[email protected]>2020-01-13 14:34:27 -0500
commitcaa6622afadea443cc125a3b5d9990d32d366f71 (patch)
tree165bf4cfd9ba763aed9a0f218c3d8fa8244070f9 /build.rs
parentb9b1d485457f3ed1b113537e79448df9c56d5d25 (diff)
explicitly check for -mavx512f or /arch:AVX512 support
If AVX-512 is enabled, and the local C compiler doesn't support it, the build is going to fail. However, if we check for this explicitly, we can give a better error message. Fixes https://github.com/BLAKE3-team/BLAKE3/issues/6.
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/build.rs b/build.rs
index 14c054c..67fe3fc 100644
--- a/build.rs
+++ b/build.rs
@@ -36,6 +36,38 @@ fn new_build() -> cc::Build {
build
}
+const WINDOWS_MSVC_ERROR: &str = r#"
+The "c_avx512" feature is enabled, but your version of the MSVC C compiler does
+not support the "/arch:AVX512" flag. If you are building the "b3sum" or
+"bao_bin" crates, you can disable AVX-512 with Cargo's "--no-default-features"
+flag. (Note that this also disables other default features like Rayon-based
+multithreading, which you can re-enable with "--features=rayon".) Other crates
+might or might not support this workaround.
+"#;
+
+const GNU_ERROR: &str = r#"
+The "c_avx512" feature is enabled, but your C compiler does not support the
+"-mavx512f" flag. If you are building the "b3sum" or "bao_bin" crates, you can
+disable AVX-512 with Cargo's "--no-default-features" flag. (Note that this also
+disables other default features like Rayon-based multithreading, which you can
+re-enable with "--features=rayon".) Other crates might or might not support
+this workaround.
+"#;
+
+fn check_for_avx512_compiler_support(build: &cc::Build) {
+ if is_windows_msvc() {
+ if !build.is_flag_supported("/arch:AVX512").unwrap() {
+ eprintln!("{}", WINDOWS_MSVC_ERROR.trim());
+ std::process::exit(1);
+ }
+ } else {
+ if !build.is_flag_supported("-mavx512f").unwrap() {
+ eprintln!("{}", GNU_ERROR.trim());
+ std::process::exit(1);
+ }
+ }
+}
+
fn main() -> Result<(), Box<dyn std::error::Error>> {
// "c_avx512' is a no-op for non-x86_64 targets. It also participates in
// dynamic CPU feature detection, so it's generally safe to enable.
@@ -44,6 +76,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// reason.
if defined("CARGO_FEATURE_C_AVX512") && is_x86_64() {
let mut build = new_build();
+ check_for_avx512_compiler_support(&build);
build.file("c/blake3_avx512.c");
if is_windows_msvc() {
// Note that a lot of versions of MSVC don't support /arch:AVX512,