#[allow(clippy::disallowed_methods)]
fn main() {
println!("cargo:rustc-env=TARGET={}", std::env::var("TARGET").unwrap());
println!("cargo:rustc-env=RUSTC_VERSION_TEXT={}", get_rustc_version());
set_wasm_backend_cfg();
set_windows_delay_load_dlls();
}
#[allow(clippy::disallowed_methods)]
fn set_wasm_backend_cfg() {
println!("cargo:rustc-check-cfg=cfg(use_pulley)");
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let use_pulley = matches!(arch.as_str(), "powerpc64" | "loongarch64") || os == "android";
if use_pulley {
println!("cargo:rustc-cfg=use_pulley");
}
}
#[allow(clippy::disallowed_methods)]
fn set_windows_delay_load_dlls() {
let is_windows_msvc = std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") && std::env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc");
if !is_windows_msvc {
return;
}
let dlls = [
"ws2_32", "crypt32", "combase", "oleaut32", "pdh", "powrprof", "psapi", ];
for dll in dlls {
println!("cargo:rustc-link-arg-bin=dprint=/delayload:{dll}.dll");
}
println!("cargo:rustc-link-arg-bin=dprint=delayimp.lib");
}
fn get_rustc_version() -> String {
let output = std::process::Command::new("rustc").arg("-V").output().unwrap();
String::from_utf8(output.stdout).unwrap().trim().to_string()
}