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