use std::{env, process::Command, str};
fn main() {
let compiler = match rustc_version() {
Some(compiler) => compiler,
None => return,
};
if (compiler.minor >= 51
&& (compiler.channel == ReleaseChannel::Stable || compiler.channel == ReleaseChannel::Beta))
|| compiler.minor >= 52
{
println!("cargo:rustc-cfg=seek_convenience");
}
if (compiler.minor >= 61
&& (compiler.channel == ReleaseChannel::Stable || compiler.channel == ReleaseChannel::Beta))
|| compiler.minor >= 62
{
println!("cargo:rustc-cfg=const_fn_trait_bounds");
}
}
struct Compiler {
minor: u32,
channel: ReleaseChannel,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum ReleaseChannel {
Stable,
Beta,
Nightly,
}
fn rustc_version() -> Option<Compiler> {
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;
}
let minor = pieces.next()?.parse().ok()?;
let channel = if version.contains("nightly") {
ReleaseChannel::Nightly
} else if version.contains("beta") {
ReleaseChannel::Beta
} else {
ReleaseChannel::Stable
};
Some(Compiler { minor, channel })
}