2023-11-14 04:13:38 +00:00
|
|
|
const MSRV_MINOR: u64 = 56;
|
2023-10-28 09:41:27 +00:00
|
|
|
|
2022-09-08 14:50:24 +00:00
|
|
|
fn main() {
|
2023-10-28 09:41:27 +00:00
|
|
|
let rustc = std::env::var_os("RUSTC");
|
|
|
|
let rustc = rustc.as_ref().map(std::path::Path::new).unwrap_or_else(|| "rustc".as_ref());
|
2022-09-08 14:50:24 +00:00
|
|
|
let output = std::process::Command::new(rustc)
|
|
|
|
.arg("--version")
|
|
|
|
.output()
|
2023-10-28 09:41:27 +00:00
|
|
|
.unwrap_or_else(|error| panic!("Failed to run `{:?} --version`: {:?}", rustc, error));
|
|
|
|
assert!(output.status.success(), "{:?} -- version returned non-zero exit code", rustc);
|
2022-09-08 14:50:24 +00:00
|
|
|
let stdout = String::from_utf8(output.stdout).expect("rustc produced non-UTF-8 output");
|
|
|
|
let version_prefix = "rustc ";
|
|
|
|
if !stdout.starts_with(version_prefix) {
|
|
|
|
panic!("unexpected rustc output: {}", stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
let version = &stdout[version_prefix.len()..];
|
|
|
|
let end = version.find(&[' ', '-'] as &[_]).unwrap_or(version.len());
|
|
|
|
let version = &version[..end];
|
|
|
|
let mut version_components = version.split('.');
|
|
|
|
let major = version_components.next().unwrap();
|
2023-10-28 09:41:27 +00:00
|
|
|
assert_eq!(major, "1", "Unexpected Rust major version");
|
2022-09-08 14:50:24 +00:00
|
|
|
let minor = version_components
|
|
|
|
.next()
|
|
|
|
.unwrap_or("0")
|
|
|
|
.parse::<u64>()
|
|
|
|
.expect("invalid Rust minor version");
|
|
|
|
|
2023-10-28 09:41:27 +00:00
|
|
|
// print cfg for all interesting versions less than or equal to minor
|
|
|
|
for version in MSRV_MINOR..=minor {
|
|
|
|
println!("cargo:rustc-cfg=rust_v_1_{}", version);
|
2022-09-08 14:50:24 +00:00
|
|
|
}
|
|
|
|
}
|