use std::env;
use std::path::Path;
fn main() {
let lib = match build_probe_mpi::probe() {
Ok(lib) => lib,
Err(errs) => {
println!("Could not find MPI library for various reasons:\n");
for (i, err) in errs.iter().enumerate() {
println!("Reason #{}:\n{}\n", i, err);
}
panic!();
}
};
let mut builder = cc::Build::new();
builder.file("src/rsmpi.c");
if cfg!(windows) {
println!("cargo:rustc-cfg=msmpi");
}
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 bindings = builder
.header("src/rsmpi.h")
.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();
}