fn main() {
#[cfg(feature = "dev_lapack")]
dev_lapack::compile();
#[cfg(not(feature = "dev_lapack"))]
{
println!("cargo:rerun-if-changed=build.rs");
}
}
#[cfg(feature = "dev_lapack")]
mod dev_lapack {
use std::path::Path;
pub fn compile() {
let root = std::env::var("ALGEBRA_LINEAR_DEV_LAPACK_ROOT").unwrap_or_else(|_| {
panic!(
"algebra_linear: the `dev_lapack` feature needs ALGEBRA_LINEAR_DEV_LAPACK_ROOT set \
to the CMake build directory of a LAPACK 3.12.1 build (the one containing include/ \
and lib/)"
)
});
let include = Path::new(&root).join("include");
let lib = Path::new(&root).join("lib");
if !include.join("lapack.h").is_file() {
panic!(
"algebra_linear: the `dev_lapack` feature needs {}/lapack.h; set \
ALGEBRA_LINEAR_DEV_LAPACK_ROOT to the CMake build directory of a LAPACK 3.12.1 build",
include.display()
);
}
if !lib.join("liblapack.so").is_file() {
panic!(
"algebra_linear: the `dev_lapack` feature needs {}/liblapack.so; set \
ALGEBRA_LINEAR_DEV_LAPACK_ROOT to the CMake build directory of a LAPACK 3.12.1 build",
lib.display()
);
}
cc::Build::new()
.file("c_code/reference_lapack.c")
.include("c_code")
.include(&include)
.warnings(false)
.compile("reference_lapack");
println!("cargo:rustc-link-search=native={}", lib.display());
for lib_name in ["lapack", "blas"] {
println!("cargo:rustc-link-lib=dylib={lib_name}");
}
println!("cargo:rustc-link-lib=dylib=gfortran");
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", lib.display());
println!("cargo:rerun-if-env-changed=ALGEBRA_LINEAR_DEV_LAPACK_ROOT");
println!("cargo:rerun-if-changed=c_code/reference.h");
println!("cargo:rerun-if-changed=c_code/reference_lapack.c");
}
}