1 use std::env;
2 use std::process::Command;
3 use std::str::{self, FromStr};
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 = match env::var_os("RUSTC") {
30 Some(rustc) => rustc,
31 None => return None,
32 };
33
34 let output = match Command::new(rustc).arg("--version").output() {
35 Ok(output) => output,
36 Err(_) => return None,
37 };
38
39 let version = match str::from_utf8(&output.stdout) {
40 Ok(version) => version,
41 Err(_) => return None,
42 };
43
44 let mut pieces = version.split('.');
45 if pieces.next() != Some("rustc 1") {
46 return None;
47 }
48
49 let next = match pieces.next() {
50 Some(next) => next,
51 None => return None,
52 };
53
54 let minor = match u32::from_str(next) {
55 Ok(minor) => minor,
56 Err(_) => return None,
57 };
58
59 Some(Compiler {
60 minor: minor,
61 nightly: version.contains("nightly"),
62 })
63 }
64