• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! This build script detects target platforms that lack proper support for
2 //! atomics and sets `cfg` flags accordingly.
3 
4 use std::env;
5 use std::str;
6 
main()7 fn 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 
target_has_atomic_cas(target: &str) -> bool24 fn 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 
target_has_atomics(target: &str) -> bool34 fn target_has_atomics(target: &str) -> bool {
35     match &target[..] {
36         "msp430-none-elf" | "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => false,
37         _ => true,
38     }
39 }
40 
rustc_target() -> Option<String>41 fn rustc_target() -> Option<String> {
42     env::var("TARGET").ok()
43 }
44