use rustflags::Flag;
fn check_supported_archs() {
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
if !["x86_64", "x86", "aarch64", "arm"].contains(&arch.as_str()) {
println!("cargo::error=closure-ffi does not support the '{arch}' target architecture.");
}
}
fn set_thumb_mode_cfg() {
println!("cargo::rustc-check-cfg=cfg(thumb_mode)");
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
if arch != "arm" {
return;
}
if std::env::var("CARGO_CFG_TARGET_FEATURE")
.map(|f| f.contains("thumb-mode"))
.unwrap_or_else(|_| {
let target = std::env::var("TARGET").unwrap();
if target.to_lowercase().ends_with(".json") {
println!(
"cargo::warning=Custom ARM target file detected. If using the Thumb ISA by \
default, use nightly and add 'thumb-mode' to the feature list."
);
false
}
else {
target.starts_with("thumb")
}
})
{
println!("cargo::rustc-cfg=thumb_mode")
}
}
fn check_coverage_supported() {
if std::env::var("CARGO_FEATURE_COVERAGE").is_ok() {
return;
}
if rustflags::from_env()
.any(|f| matches!(f, Flag::Codegen { opt, value: _ } if opt == "instrument-coverage"))
{
println!(
"cargo::error=closure-ffi requires a nightly compiler and the 'coverage' crate feature \
to be enabled for '-C instrument-coverage' support."
);
}
}
fn main() {
check_supported_archs();
check_coverage_supported();
set_thumb_mode_cfg();
}