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     // Function-like procedural macros in expressions, patterns, and statements
15     // stabilized in Rust 1.45:
16     // https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#stabilizing-function-like-procedural-macros-in-expressions-patterns-and-statements
17     if minor < 45 {
18         println!("cargo:rustc-cfg=need_proc_macro_hack");
19     }
20 }
21 
rustc_minor_version() -> Option<u32>22 fn rustc_minor_version() -> Option<u32> {
23     let rustc = env::var_os("RUSTC")?;
24     let output = Command::new(rustc).arg("--version").output().ok()?;
25     let version = str::from_utf8(&output.stdout).ok()?;
26     let mut pieces = version.split('.');
27     if pieces.next() != Some("rustc 1") {
28         return None;
29     }
30     pieces.next()?.parse().ok()
31 }
32