From 515d63712a4b4451631f019f73e586c68c2af2bd Mon Sep 17 00:00:00 2001 From: Toby Lawrence Date: Fri, 3 Dec 2021 13:47:57 -0500 Subject: [PATCH] Amend build script to handle more platforms. Signed-off-by: Toby Lawrence --- bytecheck/build.rs | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/bytecheck/build.rs b/bytecheck/build.rs index 68ab8fc..9dd3c51 100644 --- a/bytecheck/build.rs +++ b/bytecheck/build.rs @@ -1,19 +1,33 @@ use std::env; fn main() { + let mut has_atomic32 = true; + let mut has_atomic64 = true; + let target = env::var("TARGET").unwrap(); - let is_wasm = target == "asmjs-unknown-emscripten" - || target == "wasm32-unknown-emscripten" - || target == "wasm32-unknown-unknown"; + // Full target triples that have specific limitations: + match target.as_str() { + "arm-linux-androideabi" + | "asmjs-unknown-emscripten" + | "wasm32-unknown-emscripten" + | "wasm32-unknown-unknown" => has_atomic64 = false, + _ => {} + } - let has_atomic64 = target.starts_with("x86_64") - || target.starts_with("i686") - || target.starts_with("aarch64") - || target.starts_with("powerpc64") - || target.starts_with("sparc64") - || target.starts_with("mips64el"); - let has_atomic32 = has_atomic64 || is_wasm; + // Architecture-specific limitations: + let arch = target.split("-").next().unwrap_or(&target); + match arch { + // NOTE: Not all ARMv7 variants are listed here, as certain variants do actually provide + // 64-bit atomics. (`armv7`, `armv7a`, and `armv7s`, specifically) + "armv5te" | "mips" | "mipsel" | "powerpc" | "riscv32imac" | "thumbv7em" | "thumbv7m" + | "thumbv8m.base" | "thumbv8m.main" | "armebv7r" | "armv7r" => has_atomic64 = false, + "avr" | "riscv32i" | "riscv32imc" | "thumbv6m" => { + has_atomic32 = false; + has_atomic64 = false; + } + _ => {} + } if has_atomic64 { println!("cargo:rustc-cfg=has_atomics_64");