use std::env::var;
use std::io::Write;
fn main() {
use_feature_or_nothing("windows_by_handle"); use_feature_or_nothing("windows_file_type_ext");
use_feature_or_nothing("io_error_more"); use_feature_or_nothing("io_error_uncategorized");
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 out_dir = var("OUT_DIR").unwrap();
let rustc = var("RUSTC").unwrap();
let mut child = std::process::Command::new(rustc)
.arg("--crate-type=rlib") .arg("--emit=metadata") .arg("--out-dir")
.arg(out_dir) .arg("-") .stdin(std::process::Stdio::piped()) .spawn()
.unwrap();
writeln!(child.stdin.take().unwrap(), "#![feature({})]", feature).unwrap();
child.wait().unwrap().success()
}