use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let target_dir = out_dir
.parent() .and_then(|p| p.parent()) .and_then(|p| p.parent()) .expect("Could not find target directory");
let direct_lib = target_dir.join("libseq_runtime.a");
let runtime_lib = if direct_lib.exists() {
direct_lib
} else {
let deps_dir = target_dir.join("deps");
find_runtime_in_deps(&deps_dir).unwrap_or_else(|| {
panic!(
"Runtime library not found.\n\
Looked in: {}\n\
And deps: {}\n\
OUT_DIR was: {}",
direct_lib.display(),
deps_dir.display(),
out_dir.display()
)
})
};
println!(
"cargo:rustc-env=SEQ_RUNTIME_LIB_PATH={}",
runtime_lib.display()
);
println!("cargo:rerun-if-changed={}", runtime_lib.display());
}
fn find_runtime_in_deps(deps_dir: &PathBuf) -> Option<PathBuf> {
if !deps_dir.exists() {
return None;
}
fs::read_dir(deps_dir).ok()?.find_map(|entry| {
let entry = entry.ok()?;
let name = entry.file_name();
let name_str = name.to_string_lossy();
if name_str.starts_with("libseq_runtime") && name_str.ends_with(".a") {
Some(entry.path())
} else {
None
}
})
}