fn main() -> Result<(), cc::Error> {
let mut build = cc::Build::new();
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let numa_feature_enabled = std::env::var("CARGO_FEATURE_NUMA").is_ok();
let enable_numa = target_os == "linux" && numa_feature_enabled;
build
.cpp(true) .std("c++17") .file("c/lib.cpp")
.include("include")
.define("FU_ENABLE_NUMA", if enable_numa { "1" } else { "0" })
.opt_level(2) .flag_if_supported("-pedantic") .warnings(false);
if let Err(e) = build.try_compile("fork_union") {
print!("cargo:warning={e}");
return Err(e);
}
if enable_numa {
println!("cargo:rustc-link-lib=numa");
println!("cargo:rustc-link-lib=pthread");
}
println!("cargo:rerun-if-changed=c/lib.cpp");
println!("cargo:rerun-if-changed=rust/lib.rs");
println!("cargo:rerun-if-changed=include/fork_union.h");
println!("cargo:rerun-if-changed=include/fork_union.hpp");
Ok(())
}