xref: /third_party/rust/crates/log/build.rs (revision 2d8ae3ab)
1//! This build script detects target platforms that lack proper support for
2//! atomics and sets `cfg` flags accordingly.
3
4use std::env;
5use std::str;
6
7fn main() {
8    let target = match rustc_target() {
9        Some(target) => target,
10        None => return,
11    };
12
13    if target_has_atomic_cas(&target) {
14        println!("cargo:rustc-cfg=atomic_cas");
15    }
16
17    if target_has_atomics(&target) {
18        println!("cargo:rustc-cfg=has_atomics");
19    }
20
21    println!("cargo:rerun-if-changed=build.rs");
22}
23
24fn target_has_atomic_cas(target: &str) -> bool {
25    match &target[..] {
26        "thumbv6m-none-eabi"
27        | "msp430-none-elf"
28        | "riscv32i-unknown-none-elf"
29        | "riscv32imc-unknown-none-elf" => false,
30        _ => true,
31    }
32}
33
34fn target_has_atomics(target: &str) -> bool {
35    match &target[..] {
36        "thumbv4t-none-eabi"
37        | "msp430-none-elf"
38        | "riscv32i-unknown-none-elf"
39        | "riscv32imc-unknown-none-elf" => false,
40        _ => true,
41    }
42}
43
44fn rustc_target() -> Option<String> {
45    env::var("TARGET").ok()
46}
47