-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.rs
More file actions
70 lines (59 loc) · 2.11 KB
/
Copy pathbuild.rs
File metadata and controls
70 lines (59 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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");
// Only rerun if specific files change
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");
// Check if the library already exists
if find_static_lib(ncbi_dir, "libncbi-vdb.a").is_none() {
// Run configure
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");
}
// Run make with optimal thread count
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");
}
}
// Find the static library
let lib_path =
find_static_lib(ncbi_dir, "libncbi-vdb.a").expect("Could not find libncbi-vdb.a");
// Tell cargo about the library
println!(
"cargo:rustc-link-search=native={}",
lib_path.parent().unwrap().display()
);
println!("cargo:rustc-link-lib=static=ncbi-vdb");
// Add the c++ standard library
if cfg!(target_os = "macos") {
println!("cargo:rustc-link-lib=c++");
} else {
println!("cargo:rustc-link-lib=stdc++");
}
}