use std::{env, error::Error};
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
struct Atomics {
has_8: bool,
has_16: bool,
has_32: bool,
has_64: bool,
has_ptr: bool,
}
impl Atomics {
const ALL: Self = Self {
has_8: true,
has_16: true,
has_32: true,
has_64: true,
has_ptr: true,
};
const NONE: Self = Self {
has_8: false,
has_16: false,
has_32: false,
has_64: false,
has_ptr: false,
};
}
fn main() -> Result<(), Box<dyn Error>> {
let mut atomics = Atomics::ALL;
let target = env::var("TARGET")?;
#[allow(clippy::match_single_binding, clippy::single_match)]
match &*target {
"arm-linux-androideabi" => atomics.has_64 = false,
_ => {}
}
let tgt_arch = target.split("-").next().unwrap_or(&target);
let env_arch = env::var("CARGO_CFG_TARGET_ARCH")?;
#[allow(clippy::match_single_binding, clippy::single_match)]
match tgt_arch {
"armv5te" | "mips" | "mipsel" | "powerpc" | "riscv32imac" | "thumbv7em" | "thumbv7m"
| "thumbv8m.base" | "thumbv8m.main" | "armebv7r" | "armv7r" => atomics.has_64 = false,
"armv7" | "armv7a" | "armv7s" => atomics.has_64 = true,
"riscv32i" | "riscv32imc" | "thumbv6m" => atomics = Atomics::NONE,
_ => {}
}
#[allow(clippy::match_single_binding, clippy::single_match)]
match &*env_arch {
"avr" => atomics = Atomics::NONE,
_ => {}
}
if atomics.has_8 {
println!("cargo:rustc-cfg=radium_atomic_8");
}
if atomics.has_16 {
println!("cargo:rustc-cfg=radium_atomic_16");
}
if atomics.has_32 {
println!("cargo:rustc-cfg=radium_atomic_32");
}
if atomics.has_64 {
println!("cargo:rustc-cfg=radium_atomic_64");
}
if atomics.has_ptr {
println!("cargo:rustc-cfg=radium_atomic_ptr");
}
Ok(())
}