blob: 51ad9276734bd2cfe63fe3c016039e643d793dd8 [file] [log] [blame]
David Tolnaye0ba9202018-10-06 20:09:08 -07001use std::env;
2use std::process::Command;
3use 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.
8fn main() {
9 let minor = match rustc_minor_version() {
10 Some(minor) => minor,
11 None => return,
12 };
13
14 // Macro modularization allows re-exporting the `quote!` macro in 1.30+.
15 if minor >= 30 {
16 println!("cargo:rustc-cfg=syn_can_call_macro_by_path");
17 }
18}
19
20fn rustc_minor_version() -> Option<u32> {
21 let rustc = match env::var_os("RUSTC") {
22 Some(rustc) => rustc,
23 None => return None,
24 };
25
26 let output = match Command::new(rustc).arg("--version").output() {
27 Ok(output) => output,
28 Err(_) => return None,
29 };
30
31 let version = match str::from_utf8(&output.stdout) {
32 Ok(version) => version,
33 Err(_) => return None,
34 };
35
36 let mut pieces = version.split('.');
37 if pieces.next() != Some("rustc 1") {
38 return None;
39 }
40
41 let next = match pieces.next() {
42 Some(next) => next,
43 None => return None,
44 };
45
46 u32::from_str(next).ok()
47}