use std::env::var;
use std::io::Write;
fn main() {
use_feature_or_nothing("rustc_attrs");
println!("cargo:rerun-if-changed=build.rs");
}
fn use_feature_or_nothing(feature: &str) {
if has_feature(feature) {
use_feature(feature);
}
}
fn use_feature(feature: &str) {
println!("cargo:rustc-cfg={}", feature);
}
fn has_feature(feature: &str) -> bool {
let rustc = var("RUSTC").unwrap();
#[cfg(not(windows))]
let dev_null = "/dev/null";
#[cfg(windows)]
let dev_null = "NUL";
let mut child = std::process::Command::new(rustc)
.arg("--crate-type=rlib") .arg("--emit=dep-info") .arg("-o")
.arg(dev_null) .arg("-") .stdin(std::process::Stdio::piped()) .spawn()
.unwrap();
writeln!(child.stdin.take().unwrap(), "#![feature({})]", feature).unwrap();
child.wait().unwrap().success()
}