Skip to content

Commit

Permalink
Amend build script to handle more platforms.
Browse files Browse the repository at this point in the history
Signed-off-by: Toby Lawrence <[email protected]>
  • Loading branch information
tobz committed Dec 3, 2021
1 parent 20ed257 commit 515d637
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions bytecheck/build.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down

0 comments on commit 515d637

Please sign in to comment.