use std::{env, path::Path};
fn main() {
let lib = match build_probe_mpi::probe() {
Ok(lib) => lib,
Err(errs) => {
println!("This library checks multiple methods to find an MPI library on your system. This process has failed to find an MPI library for various reasons:\n");
for (i, err) in errs.iter().enumerate() {
println!("Reason #{}:\n{}\n", i + 1, err);
}
panic!();
}
};
let mut builder = cc::Build::new();
builder.file("src/rsmpi.c");
if let Some(mpicc) = lib.mpicc {
builder.compiler(mpicc);
} else {
for inc in &lib.include_paths {
builder.include(inc);
}
}
let compiler = builder.try_get_compiler();
builder.compile("rsmpi");
for dir in &lib.lib_paths {
println!("cargo:rustc-link-search=native={}", dir.display());
}
for lib in &lib.libs {
println!("cargo:rustc-link-lib={}", lib);
}
let mut builder = bindgen::builder();
for dir in &lib.include_paths {
builder = builder.clang_arg(format!("-I{}", dir.display()));
}
if let Ok(compiler) = compiler {
let include_env = compiler.env().iter().find(|(key, _)| key == "INCLUDE");
if let Some((_, include_paths)) = include_env {
if let Some(include_paths) = include_paths.to_str() {
builder = builder.clang_args(include_paths.split(';').map(|i| format!("-I{}", i)));
}
}
}
let mpi_opaque_types =
"MPI_(Comm|Datatype|Errhandler|Group|Info|Message|Op|Request|Session|Win)";
let bindings = builder
.header("src/rsmpi.h")
.new_type_alias(mpi_opaque_types)
.derive_partialeq(true)
.emit_builtins()
.generate()
.unwrap();
let out_dir = env::var("OUT_DIR").expect("cargo did not set OUT_DIR");
let out_file = Path::new(&out_dir).join("functions_and_types.rs");
bindings.write_to_file(out_file).unwrap();
}