David Tolnay | e0ba920 | 2018-10-06 20:09:08 -0700 | [diff] [blame] | 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. |
| 8 | fn main() { |
| 9 | let minor = match rustc_minor_version() { |
| 10 | Some(minor) => minor, |
| 11 | None => return, |
| 12 | }; |
| 13 | |
David Tolnay | 3287480 | 2018-11-11 08:52:19 -0800 | [diff] [blame^] | 14 | if minor >= 19 { |
| 15 | println!("cargo:rustc-cfg=syn_can_use_thread_id"); |
| 16 | } |
| 17 | |
David Tolnay | e0ba920 | 2018-10-06 20:09:08 -0700 | [diff] [blame] | 18 | // 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 | |
| 24 | fn 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 | } |