• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     println!("cargo:rerun-if-changed=build.rs");
10 
11     let minor = match rustc_minor_version() {
12         Some(minor) => minor,
13         None => return,
14     };
15 
16     // Underscore const names stabilized in Rust 1.37:
17     // https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html#using-unnamed-const-items-for-macros
18     if minor < 37 {
19         println!("cargo:rustc-cfg=no_underscore_consts");
20     }
21 
22     // The ptr::addr_of! macro stabilized in Rust 1.51:
23     // https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#stabilized-apis
24     if minor < 51 {
25         println!("cargo:rustc-cfg=no_ptr_addr_of");
26     }
27 }
28 
rustc_minor_version() -> Option<u32>29 fn rustc_minor_version() -> Option<u32> {
30     let rustc = env::var_os("RUSTC")?;
31     let output = Command::new(rustc).arg("--version").output().ok()?;
32     let version = str::from_utf8(&output.stdout).ok()?;
33     let mut pieces = version.split('.');
34     if pieces.next() != Some("rustc 1") {
35         return None;
36     }
37     pieces.next()?.parse().ok()
38 }
39