Skip to content

Commit

Permalink
Merge pull request #16 from tobz/tobz/add-more-atomic-support-to-buil…
Browse files Browse the repository at this point in the history
…d-script

Amend build script to handle more platforms.
  • Loading branch information
djkoloski authored Dec 3, 2021
2 parents 20ed257 + 515d637 commit 0ea4a1a
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 0ea4a1a

Please sign in to comment.