use std::path::{Path, PathBuf};
use std::process::Command;
use walkdir::WalkDir;
fn find_static_lib(start_dir: &Path, lib_name: &str) -> Option<PathBuf> {
WalkDir::new(start_dir)
.into_iter()
.filter_map(|e| e.ok())
.find(|e| e.file_name().to_string_lossy() == lib_name)
.map(|e| e.path().to_path_buf())
}
fn main() {
if std::env::var("DOCS_RS").is_ok() {
return;
}
let ncbi_dir = Path::new("vendor/ncbi-vdb");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=vendor/ncbi-vdb/libs");
println!("cargo:rerun-if-changed=vendor/ncbi-vdb/interfaces");
println!("cargo:rerun-if-changed=vendor/ncbi-vdb/setup/konfigure.perl");
println!("cargo:rerun-if-changed=vendor/ncbi-vdb/Makefile.env");
if find_static_lib(ncbi_dir, "libncbi-vdb.a").is_none() {
let configure_status = Command::new("./configure")
.current_dir(ncbi_dir)
.arg("--build-prefix=comp")
.status()
.expect("Failed to run configure");
if !configure_status.success() {
panic!("Configure failed");
}
let threads = num_cpus::get();
let make_status = Command::new("make")
.current_dir(ncbi_dir)
.arg(format!("-j{}", threads))
.status()
.expect("Failed to run make");
if !make_status.success() {
panic!("Make failed");
}
}
let lib_path =
find_static_lib(ncbi_dir, "libncbi-vdb.a").expect("Could not find libncbi-vdb.a");
println!(
"cargo:rustc-link-search=native={}",
lib_path.parent().unwrap().display()
);
println!("cargo:rustc-link-lib=static=ncbi-vdb");
if cfg!(target_os = "macos") {
println!("cargo:rustc-link-lib=c++");
} else {
println!("cargo:rustc-link-lib=stdc++");
}
}