2018-10-07 03:09:08 +00:00
|
|
|
use std::env;
|
|
|
|
use std::process::Command;
|
2020-04-08 19:42:22 +00:00
|
|
|
use std::str;
|
2018-10-07 03:09:08 +00:00
|
|
|
|
|
|
|
// The rustc-cfg strings below are *not* public API. Please let us know by
|
|
|
|
// opening a GitHub issue if your build environment requires some way to enable
|
|
|
|
// these cfgs other than by executing our build script.
|
|
|
|
fn main() {
|
2019-03-10 06:58:26 +00:00
|
|
|
let compiler = match rustc_version() {
|
|
|
|
Some(compiler) => compiler,
|
2018-10-07 03:09:08 +00:00
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
2019-07-28 20:05:33 +00:00
|
|
|
if compiler.minor < 36 {
|
|
|
|
println!("cargo:rustc-cfg=syn_omit_await_from_token_macro");
|
|
|
|
}
|
|
|
|
|
2021-01-01 08:27:06 +00:00
|
|
|
if compiler.minor < 39 {
|
|
|
|
println!("cargo:rustc-cfg=syn_no_const_vec_new");
|
|
|
|
}
|
|
|
|
|
2021-09-22 02:13:01 +00:00
|
|
|
if compiler.minor < 40 {
|
|
|
|
println!("cargo:rustc-cfg=syn_no_non_exhaustive");
|
|
|
|
}
|
|
|
|
|
2021-10-26 18:12:14 +00:00
|
|
|
if compiler.minor < 56 {
|
|
|
|
println!("cargo:rustc-cfg=syn_no_negative_literal_parse");
|
|
|
|
}
|
|
|
|
|
2019-03-10 06:58:26 +00:00
|
|
|
if !compiler.nightly {
|
|
|
|
println!("cargo:rustc-cfg=syn_disable_nightly_tests");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Compiler {
|
2019-07-28 20:05:33 +00:00
|
|
|
minor: u32,
|
2019-03-10 06:58:26 +00:00
|
|
|
nightly: bool,
|
2018-10-07 03:09:08 +00:00
|
|
|
}
|
|
|
|
|
2019-03-10 06:58:26 +00:00
|
|
|
fn rustc_version() -> Option<Compiler> {
|
2020-04-08 19:38:51 +00:00
|
|
|
let rustc = env::var_os("RUSTC")?;
|
|
|
|
let output = Command::new(rustc).arg("--version").output().ok()?;
|
|
|
|
let version = str::from_utf8(&output.stdout).ok()?;
|
2019-07-28 20:05:33 +00:00
|
|
|
let mut pieces = version.split('.');
|
|
|
|
if pieces.next() != Some("rustc 1") {
|
|
|
|
return None;
|
|
|
|
}
|
2020-04-08 19:42:22 +00:00
|
|
|
let minor = pieces.next()?.parse().ok()?;
|
2021-12-29 23:26:57 +00:00
|
|
|
let nightly = version.contains("nightly") || version.ends_with("-dev");
|
2020-04-08 19:38:51 +00:00
|
|
|
Some(Compiler { minor, nightly })
|
2018-10-07 03:09:08 +00:00
|
|
|
}
|