blob: 6ab40985b60bc2f8b39559409735c4eaf25f36be [file] [log] [blame]
Haibo Huangb0dbc762020-10-28 22:33:04 -07001use std::env;
2use std::process::Command;
3use 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.
8fn 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
22fn 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}