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