summaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
authorJack O'Connor <oconnor663@gmail.com>2020-01-11 10:40:44 -0500
committerJack O'Connor <oconnor663@gmail.com>2020-01-13 13:34:06 -0500
commitb9b1d485457f3ed1b113537e79448df9c56d5d25 (patch)
tree8c01f07f757753a37deac3a0eb4f25e6decf8b9e /build.rs
parent5c7004c518f3b5e5a4b61e632a6ba5da6631b7c2 (diff)
avoid using MSVC-style flags with the GNU toolchain on Windows
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs34
1 files changed, 17 insertions, 17 deletions
diff --git a/build.rs b/build.rs
index 3611258..14c054c 100644
--- a/build.rs
+++ b/build.rs
@@ -4,33 +4,33 @@ fn defined(var: &str) -> bool {
env::var_os(var).is_some()
}
-fn target_arch() -> String {
+fn target_components() -> Vec<String> {
let target = env::var("TARGET").unwrap();
- let target_components: Vec<&str> = target.split("-").collect();
- target_components[0].to_string()
-}
-
-fn target_os() -> String {
- let target = env::var("TARGET").unwrap();
- let target_components: Vec<&str> = target.split("-").collect();
- target_components[2].to_string()
-}
-
-fn is_windows() -> bool {
- target_os() == "windows"
+ target.split("-").map(|s| s.to_string()).collect()
}
fn is_x86_64() -> bool {
- target_arch() == "x86_64"
+ target_components()[0] == "x86_64"
}
fn is_armv7() -> bool {
- target_arch() == "armv7"
+ target_components()[0] == "armv7"
+}
+
+// Windows targets may be using the MSVC toolchain or the GNU toolchain. The
+// right compiler flags to use depend on the toolchain. (And we don't want to
+// use flag_if_supported, because we don't want features to be silently
+// disabled by old compilers.)
+fn is_windows_msvc() -> bool {
+ // Some targets are only two components long, so check in steps.
+ target_components()[1] == "pc"
+ && target_components()[2] == "windows"
+ && target_components()[3] == "msvc"
}
fn new_build() -> cc::Build {
let mut build = cc::Build::new();
- if !is_windows() {
+ if !is_windows_msvc() {
build.flag("-std=c11");
}
build
@@ -45,7 +45,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
if defined("CARGO_FEATURE_C_AVX512") && is_x86_64() {
let mut build = new_build();
build.file("c/blake3_avx512.c");
- if is_windows() {
+ if is_windows_msvc() {
// Note that a lot of versions of MSVC don't support /arch:AVX512,
// and they'll discard it with a warning, hopefully leading to a
// build error.