David Tolnay | e0ba920 | 2018-10-06 20:09:08 -0700 | [diff] [blame] | 1 | use std::env; |
| 2 | use std::process::Command; |
Haibo Huang | 3588bff | 2020-04-23 15:44:10 -0700 | [diff] [blame] | 3 | use std::str; |
David Tolnay | e0ba920 | 2018-10-06 20:09:08 -0700 | [diff] [blame] | 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() { |
David Tolnay | f83b6c9 | 2019-03-09 22:58:26 -0800 | [diff] [blame] | 9 | let compiler = match rustc_version() { |
| 10 | Some(compiler) => compiler, |
David Tolnay | e0ba920 | 2018-10-06 20:09:08 -0700 | [diff] [blame] | 11 | None => return, |
| 12 | }; |
| 13 | |
Chih-Hung Hsieh | 467ea21 | 2019-10-31 17:36:47 -0700 | [diff] [blame] | 14 | if compiler.minor < 36 { |
| 15 | println!("cargo:rustc-cfg=syn_omit_await_from_token_macro"); |
David Tolnay | e0ba920 | 2018-10-06 20:09:08 -0700 | [diff] [blame] | 16 | } |
David Tolnay | f83b6c9 | 2019-03-09 22:58:26 -0800 | [diff] [blame] | 17 | |
Haibo Huang | ec2e2eb | 2021-01-05 21:38:44 -0800 | [diff] [blame] | 18 | if compiler.minor < 39 { |
| 19 | println!("cargo:rustc-cfg=syn_no_const_vec_new"); |
| 20 | } |
| 21 | |
David LeGare | ec38769 | 2022-03-02 16:21:07 +0000 | [diff] [blame] | 22 | if compiler.minor < 56 { |
| 23 | println!("cargo:rustc-cfg=syn_no_negative_literal_parse"); |
| 24 | } |
| 25 | |
David Tolnay | f83b6c9 | 2019-03-09 22:58:26 -0800 | [diff] [blame] | 26 | if !compiler.nightly { |
| 27 | println!("cargo:rustc-cfg=syn_disable_nightly_tests"); |
| 28 | } |
David Tolnay | e0ba920 | 2018-10-06 20:09:08 -0700 | [diff] [blame] | 29 | } |
| 30 | |
David Tolnay | f83b6c9 | 2019-03-09 22:58:26 -0800 | [diff] [blame] | 31 | struct Compiler { |
| 32 | minor: u32, |
| 33 | nightly: bool, |
| 34 | } |
| 35 | |
| 36 | fn rustc_version() -> Option<Compiler> { |
Haibo Huang | 3588bff | 2020-04-23 15:44:10 -0700 | [diff] [blame] | 37 | let rustc = env::var_os("RUSTC")?; |
| 38 | let output = Command::new(rustc).arg("--version").output().ok()?; |
| 39 | let version = str::from_utf8(&output.stdout).ok()?; |
David Tolnay | e0ba920 | 2018-10-06 20:09:08 -0700 | [diff] [blame] | 40 | let mut pieces = version.split('.'); |
| 41 | if pieces.next() != Some("rustc 1") { |
| 42 | return None; |
| 43 | } |
Haibo Huang | 3588bff | 2020-04-23 15:44:10 -0700 | [diff] [blame] | 44 | let minor = pieces.next()?.parse().ok()?; |
David LeGare | ec38769 | 2022-03-02 16:21:07 +0000 | [diff] [blame] | 45 | let nightly = version.contains("nightly") || version.ends_with("-dev"); |
Haibo Huang | 3588bff | 2020-04-23 15:44:10 -0700 | [diff] [blame] | 46 | Some(Compiler { minor, nightly }) |
David Tolnay | e0ba920 | 2018-10-06 20:09:08 -0700 | [diff] [blame] | 47 | } |