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 compiler = match rustc_version() {
10         Some(compiler) => compiler,
11         None => return,
12     };
13 
14     if compiler.minor < 36 {
15         println!("cargo:rustc-cfg=syn_omit_await_from_token_macro");
16     }
17 
18     if !compiler.nightly {
19         println!("cargo:rustc-cfg=syn_disable_nightly_tests");
20     }
21 }
22 
23 struct Compiler {
24     minor: u32,
25     nightly: bool,
26 }
27 
rustc_version() -> Option<Compiler>28 fn rustc_version() -> Option<Compiler> {
29     let rustc = env::var_os("RUSTC")?;
30     let output = Command::new(rustc).arg("--version").output().ok()?;
31     let version = str::from_utf8(&output.stdout).ok()?;
32     let mut pieces = version.split('.');
33     if pieces.next() != Some("rustc 1") {
34         return None;
35     }
36     let minor = pieces.next()?.parse().ok()?;
37     let nightly = version.contains("nightly");
38     Some(Compiler { minor, nightly })
39 }
40