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