blob: c705fc50fd69e2933186c0fe43e644224a6c384c [file] [log] [blame]
David Tolnaye0ba9202018-10-06 20:09:08 -07001use std::env;
2use std::process::Command;
Haibo Huang3588bff2020-04-23 15:44:10 -07003use std::str;
David Tolnaye0ba9202018-10-06 20:09:08 -07004
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() {
David Tolnayf83b6c92019-03-09 22:58:26 -08009 let compiler = match rustc_version() {
10 Some(compiler) => compiler,
David Tolnaye0ba9202018-10-06 20:09:08 -070011 None => return,
12 };
13
Chih-Hung Hsieh467ea212019-10-31 17:36:47 -070014 if compiler.minor < 36 {
15 println!("cargo:rustc-cfg=syn_omit_await_from_token_macro");
David Tolnaye0ba9202018-10-06 20:09:08 -070016 }
David Tolnayf83b6c92019-03-09 22:58:26 -080017
Haibo Huangec2e2eb2021-01-05 21:38:44 -080018 if compiler.minor < 39 {
19 println!("cargo:rustc-cfg=syn_no_const_vec_new");
20 }
21
David LeGareec387692022-03-02 16:21:07 +000022 if compiler.minor < 56 {
23 println!("cargo:rustc-cfg=syn_no_negative_literal_parse");
24 }
25
David Tolnayf83b6c92019-03-09 22:58:26 -080026 if !compiler.nightly {
27 println!("cargo:rustc-cfg=syn_disable_nightly_tests");
28 }
David Tolnaye0ba9202018-10-06 20:09:08 -070029}
30
David Tolnayf83b6c92019-03-09 22:58:26 -080031struct Compiler {
32 minor: u32,
33 nightly: bool,
34}
35
36fn rustc_version() -> Option<Compiler> {
Haibo Huang3588bff2020-04-23 15:44:10 -070037 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 Tolnaye0ba9202018-10-06 20:09:08 -070040 let mut pieces = version.split('.');
41 if pieces.next() != Some("rustc 1") {
42 return None;
43 }
Haibo Huang3588bff2020-04-23 15:44:10 -070044 let minor = pieces.next()?.parse().ok()?;
David LeGareec387692022-03-02 16:21:07 +000045 let nightly = version.contains("nightly") || version.ends_with("-dev");
Haibo Huang3588bff2020-04-23 15:44:10 -070046 Some(Compiler { minor, nightly })
David Tolnaye0ba9202018-10-06 20:09:08 -070047}