use std::io::Write;
const FEATURES: [&str; 7] = [
"dev",
"beta",
"debug",
"stable",
"nightly",
"release",
"bootstrap",
];
pub fn app() -> Result<(), Box<dyn std::error::Error>> {
let mut stdout = std::io::stdout();
for f in FEATURES {
write!(stdout, "cargo::rustc-check-cfg=cfg({f})\n")?;
}
match rustc_version::version_meta()?.channel {
rustc_version::Channel::Dev => {
write!(stdout, "cargo::rustc-cfg=dev\n")?;
write!(stdout, "cargo::rustc-cfg=beta\n")?;
write!(stdout, "cargo::rustc-cfg=stable\n")?;
write!(stdout, "cargo::rustc-cfg=nightly\n")?;
},
rustc_version::Channel::Beta => {
write!(stdout, "cargo::rustc-cfg=beta\n")?;
write!(stdout, "cargo::rustc-cfg=stable\n")?;
},
rustc_version::Channel::Stable => {
write!(stdout, "cargo::rustc-cfg=stable\n")?;
},
rustc_version::Channel::Nightly => {
write!(stdout, "cargo::rustc-cfg=beta\n")?;
write!(stdout, "cargo::rustc-cfg=stable\n")?;
write!(stdout, "cargo::rustc-cfg=nightly\n")?;
},
}
if let Ok(env) = std::env::var("RUSTC_BOOTSTRAP") {
if env.trim() == "1" {
write!(stdout, "cargo::rustc-cfg=bootstrap\n")?;
}
}
if cfg!(debug_assertions) {
write!(stdout, "cargo::rustc-cfg=debug\n")?;
} else {
write!(stdout, "cargo::rustc-cfg=release\n")?;
}
Ok(stdout.flush()?)
}
pub fn checked_app() -> bool {
match app() {
Ok(_) => true,
Err(_) => false,
}
}
pub fn wrapping_app(expect_msg: Option<&str>) {
if let Some(expect_msg) = expect_msg {
app().expect(expect_msg)
} else {
app().unwrap()
}
}