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