use glob::glob;
use std::env;
use std::path::PathBuf;
fn main() {
#[cfg(docsrs)]
let cplex_include_path = Path::from(env!("CARGO_MANIFEST_DIR"))
.join("include")
.join("22010000");
#[cfg(not(docsrs))]
let cplex_include_path = {
let cplex_installation_path = env::var("CPLEX_PATH")
.map(PathBuf::from)
.unwrap_or_else(|_| {
glob("/opt/ibm/ILOG/*/cplex")
.expect("Invalid glob pattern")
.filter_map(|path| path.ok())
.next()
.expect("No valid CPLEX installation path found. Please set the env variable 'CPLEX_PATH' with the CPLEX installation directory or install CPLEX in the default location.")
});
let cplex_lib_path = cplex_installation_path.join("lib/x86-64_linux/static_pic");
println!(
"cargo:rustc-link-search={}",
cplex_lib_path.as_os_str().to_string_lossy()
);
println!("cargo:rustc-link-lib=cplex");
cplex_installation_path.join("include")
};
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.clang_arg(format!(
"-F{}",
cplex_include_path.as_os_str().to_string_lossy()
))
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.allowlist_item("CPX.*")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}