use std::env;
use rustc_version::Channel;
use rustc_version::version_meta;
const F16_FEATURE_ATTR: &str = "-Zcrate-attr=feature(f16)";
pub fn main() {
println!("cargo::rustc-check-cfg=cfg(nightly)");
if env::var("CARGO_FEATURE_F16").is_ok() {
match version_meta().unwrap().channel {
Channel::Nightly => {
match env::var("CARGO_ENCODED_RUSTFLAGS") {
Ok(mut rustflags) => check_rustflags(&mut rustflags),
Err(_) => rustflag_error()
}
println!("cargo::rustc-cfg=nightly");
},
_ => nightly_error()
}
}
}
fn nightly_error() -> ! {
panic!("ERROR: `f16` feature currently requires the nightly build of the rust compiler.")
}
fn rustflag_error() -> ! {
panic!("ERROR: `f16` feature requires the '{}' option to be set in the RUSTFLAGS environment variable.", F16_FEATURE_ATTR)
}
fn check_rustflags(rustflags: &mut String) {
remove_whitespace(rustflags);
if !rustflags.contains(F16_FEATURE_ATTR)
{
rustflag_error();
}
}
fn remove_whitespace(s: &mut String) {
s.retain(|c| !(c.is_whitespace() || c == '\u{1f}'));
}