1 use std::env;
2 use std::process::Command;
3 use std::str;
4 
5 // The rustc-cfg strings below are *not* public API. Please let us know by
6 // opening a GitHub issue if your build environment requires some way to enable
7 // these cfgs other than by executing our build script.
main()8 fn main() {
9     let minor = match rustc_minor_version() {
10         Some(minor) => minor,
11         None => return,
12     };
13 
14     // Underscore const names stabilized in Rust 1.37:
15     // https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html#using-unnamed-const-items-for-macros
16     if minor >= 37 {
17         println!("cargo:rustc-cfg=underscore_consts");
18     }
19 
20     // The ptr::addr_of! macro stabilized in Rust 1.51:
21     // https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#stabilized-apis
22     if minor >= 51 {
23         println!("cargo:rustc-cfg=ptr_addr_of");
24     }
25 }
26 
rustc_minor_version() -> Option<u32>27 fn rustc_minor_version() -> Option<u32> {
28     let rustc = env::var_os("RUSTC")?;
29     let output = Command::new(rustc).arg("--version").output().ok()?;
30     let version = str::from_utf8(&output.stdout).ok()?;
31     let mut pieces = version.split('.');
32     if pieces.next() != Some("rustc 1") {
33         return None;
34     }
35     pieces.next()?.parse().ok()
36 }
37