Joel Galenson | 7a98302 | 2021-05-19 15:35:43 -0700 | [diff] [blame^] | 1 | #![warn(rust_2018_idioms, single_use_lifetimes)] |
| 2 | |
| 3 | use autocfg::AutoCfg; |
| 4 | use std::env; |
| 5 | |
| 6 | include!("no_atomic_cas.rs"); |
| 7 | |
| 8 | // The rustc-cfg listed below are considered public API, but it is *unstable* |
| 9 | // and outside of the normal semver guarantees: |
| 10 | // |
| 11 | // - `futures_no_atomic_cas` |
| 12 | // Assume the target does not have atomic CAS (compare-and-swap). |
| 13 | // This is usually detected automatically by the build script, but you may |
| 14 | // need to enable it manually when building for custom targets or using |
| 15 | // non-cargo build systems that don't run the build script. |
| 16 | // |
| 17 | // With the exceptions mentioned above, the rustc-cfg strings below are |
| 18 | // *not* public API. Please let us know by opening a GitHub issue if your build |
| 19 | // environment requires some way to enable these cfgs other than by executing |
| 20 | // our build script. |
| 21 | fn main() { |
| 22 | let target = match env::var("TARGET") { |
| 23 | Ok(target) => target, |
| 24 | Err(e) => { |
| 25 | println!( |
| 26 | "cargo:warning={}: unable to get TARGET environment variable: {}", |
| 27 | env!("CARGO_PKG_NAME"), |
| 28 | e |
| 29 | ); |
| 30 | return; |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | // Note that this is `no_*`, not `has_*`. This allows treating |
| 35 | // `cfg(target_has_atomic = "ptr")` as true when the build script doesn't |
| 36 | // run. This is needed for compatibility with non-cargo build systems that |
| 37 | // don't run the build script. |
| 38 | if NO_ATOMIC_CAS_TARGETS.contains(&&*target) { |
| 39 | println!("cargo:rustc-cfg=futures_no_atomic_cas"); |
| 40 | } |
| 41 | |
| 42 | let cfg = match AutoCfg::new() { |
| 43 | Ok(cfg) => cfg, |
| 44 | Err(e) => { |
| 45 | println!( |
| 46 | "cargo:warning={}: unable to determine rustc version: {}", |
| 47 | env!("CARGO_PKG_NAME"), |
| 48 | e |
| 49 | ); |
| 50 | return; |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | // Function like procedural macros in expressions patterns statements stabilized in Rust 1.45: |
| 55 | // https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#stabilizing-function-like-procedural-macros-in-expressions-patterns-and-statements |
| 56 | if cfg.probe_rustc_version(1, 45) { |
| 57 | println!("cargo:rustc-cfg=fn_like_proc_macro"); |
| 58 | } |
| 59 | |
| 60 | println!("cargo:rerun-if-changed=no_atomic_cas.rs"); |
| 61 | } |