use std::env;
use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
if env::var_os("CARGO_FEATURE_ILP64").is_some() {
panic!(
"{}",
concat!(
"the `ilp64` feature of `onemkl` is not supported yet: the safe wrappers are ",
"written for the LP64 interface (`MKL_INT` = `int`) and do not type-check ",
"against ILP64 bindings. Use the default `lp64` feature, or use `onemkl-sys` ",
"directly with `ilp64`."
)
);
}
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
if target_os != "linux" {
return;
}
if env::var_os("CARGO_FEATURE_LINK_DYNAMIC").is_none() {
return;
}
println!("cargo:rerun-if-env-changed=DEP_MKL_LIB");
let lib_dir = match env::var_os("DEP_MKL_LIB") {
Some(v) => PathBuf::from(v),
None => return,
};
let interface = if env::var_os("CARGO_FEATURE_ILP64").is_some() {
"mkl_intel_ilp64"
} else {
"mkl_intel_lp64"
};
let threading = if env::var_os("CARGO_FEATURE_THREADING_INTEL_OPENMP").is_some() {
"mkl_intel_thread"
} else if env::var_os("CARGO_FEATURE_THREADING_TBB").is_some() {
"mkl_tbb_thread"
} else {
"mkl_sequential"
};
println!("cargo:rustc-link-arg=-Wl,--no-as-needed");
for name in [interface, threading, "mkl_core"] {
let so = lib_dir.join(format!("lib{name}.so"));
println!("cargo:rustc-link-arg={}", so.display());
}
for sys_lib in ["m", "pthread", "dl"] {
println!("cargo:rustc-link-arg=-l{sys_lib}");
}
println!("cargo:rustc-link-arg=-Wl,--as-needed");
}