act on japaric's requests using techniques from Rahix to more generically support AVR

This commit is contained in:
Robert Forsman 2022-06-14 13:47:05 -04:00
parent 2150effc73
commit c8e6dcc3da
2 changed files with 27 additions and 19 deletions

View File

@ -36,10 +36,7 @@ atomic-polyfill = { version = "0.1.4" }
[target.riscv32imc-unknown-none-elf.dependencies]
atomic-polyfill = { version = "0.1.4" }
[target.avr-atmega328p.dependencies]
atomic-polyfill = { version = "0.1.8", optional = true }
[target.avr-atmega2560.dependencies]
[target.'cfg(target_arch = "avr")'.dependencies]
atomic-polyfill = { version = "0.1.8", optional = true }

View File

@ -23,10 +23,15 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("cargo:rustc-cfg=armv7a");
}
let is_avr = env::var("CARGO_CFG_TARGET_ARCH") == Ok("avr".to_string());
// built-in targets with no atomic / CAS support as of nightly-2022-01-13
// AND not supported by the atomic-polyfill crate
// see the `no-atomics.sh` / `no-cas.sh` script sitting next to this file
match &target[..] {
if is_avr {
// lacks cas
} else {
match &target[..] {
"avr-unknown-gnu-atmega328"
| "bpfeb-unknown-none"
| "bpfel-unknown-none"
@ -40,11 +45,14 @@ fn main() -> Result<(), Box<dyn Error>> {
_ => {
println!("cargo:rustc-cfg=has_cas");
}
}
};
match &target[..] {
"avr-unknown-gnu-atmega328"
| "msp430-none-elf"
if is_avr {
// lacks atomics
} else {
match &target[..] {
"msp430-none-elf"
// | "riscv32i-unknown-none-elf" // supported by atomic-polyfill
// | "riscv32imc-unknown-none-elf" // supported by atomic-polyfill
=> {}
@ -52,23 +60,26 @@ fn main() -> Result<(), Box<dyn Error>> {
_ => {
println!("cargo:rustc-cfg=has_atomics");
}
}
};
// Let the code know if it should use atomic-polyfill or not, and what aspects
// of polyfill it requires
match &target[..] {
"riscv32i-unknown-none-elf"
| "riscv32imc-unknown-none-elf"
| "avr-atmega328p"
| "avr-atmega2560" => {
println!("cargo:rustc-cfg=full_atomic_polyfill");
println!("cargo:rustc-cfg=cas_atomic_polyfill");
}
if is_avr {
println!("cargo:rustc-cfg=full_atomic_polyfill");
println!("cargo:rustc-cfg=cas_atomic_polyfill");
} else {
match &target[..] {
"riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {
println!("cargo:rustc-cfg=full_atomic_polyfill");
println!("cargo:rustc-cfg=cas_atomic_polyfill");
}
"thumbv6m-none-eabi" => {
println!("cargo:rustc-cfg=cas_atomic_polyfill");
"thumbv6m-none-eabi" => {
println!("cargo:rustc-cfg=cas_atomic_polyfill");
}
_ => {}
}
_ => {}
}
if !matches!(