2019-03-18 23:03:11 +01:00
|
|
|
//! This build script detects target platforms that lack proper support for
|
|
|
|
//! atomics and sets `cfg` flags accordingly.
|
|
|
|
|
|
|
|
use std::env;
|
2020-10-14 10:05:02 -07:00
|
|
|
use std::str;
|
2020-08-03 18:05:15 +10:00
|
|
|
|
2019-03-18 23:03:11 +01:00
|
|
|
fn main() {
|
2020-08-03 18:05:15 +10:00
|
|
|
let target = match rustc_target() {
|
|
|
|
Some(target) => target,
|
|
|
|
None => return,
|
|
|
|
};
|
2019-03-18 23:03:11 +01:00
|
|
|
|
2020-09-22 12:06:47 -07:00
|
|
|
if target_has_atomic_cas(&target) {
|
|
|
|
println!("cargo:rustc-cfg=atomic_cas");
|
|
|
|
}
|
2020-09-11 11:35:14 -07:00
|
|
|
|
2020-09-22 12:06:47 -07:00
|
|
|
if target_has_atomics(&target) {
|
|
|
|
println!("cargo:rustc-cfg=has_atomics");
|
|
|
|
}
|
2020-09-11 11:35:14 -07:00
|
|
|
|
2019-03-18 23:03:11 +01:00
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
}
|
2020-08-03 18:05:15 +10:00
|
|
|
|
2020-09-22 12:06:47 -07:00
|
|
|
fn target_has_atomic_cas(target: &str) -> bool {
|
|
|
|
match &target[..] {
|
|
|
|
"thumbv6m-none-eabi"
|
|
|
|
| "msp430-none-elf"
|
|
|
|
| "riscv32i-unknown-none-elf"
|
|
|
|
| "riscv32imc-unknown-none-elf" => false,
|
|
|
|
_ => true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn target_has_atomics(target: &str) -> bool {
|
|
|
|
match &target[..] {
|
2022-02-27 11:36:27 -06:00
|
|
|
"thumbv4t-none-eabi"
|
|
|
|
| "msp430-none-elf"
|
|
|
|
| "riscv32i-unknown-none-elf"
|
|
|
|
| "riscv32imc-unknown-none-elf" => false,
|
2020-09-22 12:06:47 -07:00
|
|
|
_ => true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:05:15 +10:00
|
|
|
fn rustc_target() -> Option<String> {
|
|
|
|
env::var("TARGET").ok()
|
|
|
|
}
|