Revision control
Copy as Markdown
Other Tools
use std::env;
use std::process::Command;
use std::str;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let compiler = match rustc_minor_version() {
Some(compiler) => compiler,
None => return,
};
if compiler < 33 {
// Exhaustive integer patterns. On older compilers, a final `_` arm is
// required even if every possible integer value is otherwise covered.
println!("cargo:rustc-cfg=no_exhaustive_int_match");
}
if compiler < 36 {
// extern crate alloc.
println!("cargo:rustc-cfg=no_alloc_crate");
}
if compiler < 39 {
// const Vec::new.
println!("cargo:rustc-cfg=no_const_vec_new");
}
if compiler < 40 {
// #[non_exhaustive].
println!("cargo:rustc-cfg=no_non_exhaustive");
}
if compiler < 45 {
// String::strip_prefix.
println!("cargo:rustc-cfg=no_str_strip_prefix");
}
if compiler < 46 {
// #[track_caller].
println!("cargo:rustc-cfg=no_track_caller");
}
if compiler < 52 {
// #![deny(unsafe_op_in_unsafe_fn)].
println!("cargo:rustc-cfg=no_unsafe_op_in_unsafe_fn_lint");
}
if compiler < 53 {
// Efficient intrinsics for count-leading-zeros and count-trailing-zeros
// on NonZero integers stabilized in 1.53.0. On many architectures these
// are more efficient than counting zeros on ordinary zeroable integers.
println!("cargo:rustc-cfg=no_nonzero_bitscan");
}
}
fn rustc_minor_version() -> Option<u32> {
let rustc = env::var_os("RUSTC")?;
let output = Command::new(rustc).arg("--version").output().ok()?;
let version = str::from_utf8(&output.stdout).ok()?;
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
pieces.next()?.parse().ok()
}