-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
63 lines (55 loc) · 2.05 KB
/
build.rs
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
use cmake::Config;
use std::{env, fs::File, path::PathBuf};
// print build script logs
macro_rules! p {
($($tokens: tt)*) => {
println!("cargo:warning={}", format!($($tokens)*))
}
}
const LIB_NAME: &str = "kraken";
const TARGET_NAME: &str = "kraken_static";
fn main() {
let os = env::consts::OS;
if os == "linux" {
let link_path = std::env::current_dir().unwrap().join("lib").join(os);
// link rustc
println!("cargo:rustc-link-search=native={}", link_path.display());
println!("cargo:rustc-link-lib-l=static={}", TARGET_NAME);
} else {
// cmake config
let mut cfg = Config::new(LIB_NAME);
//cfg.profile("RelWithDebInfo");
//cfg.profile("Debug");
let dst = cfg.build_target(TARGET_NAME).build();
// logging
let cmake_profile: String = cfg.get_profile().to_owned();
let rust_profile = std::env::var("PROFILE").unwrap();
p!("CMAKE_PROFILE : {}", cmake_profile);
p!("RUST_PROFILE : {}", rust_profile);
p!("DST: {}", dst.display());
// link
let mut link_path = format!("{}/build/bin/CMake", dst.display());
let mut additional_args = "".to_owned();
if cfg!(windows) {
link_path = format!("{}/{}", link_path, cmake_profile);
} else if cfg!(unix) {
additional_args = "-l".to_owned();
}
// link rustc
println!("cargo:rustc-link-search=native={}", link_path);
println!(
"cargo:rustc-link-lib{}=static={}",
additional_args, TARGET_NAME
);
}
// extract resources
let file_path = PathBuf::from("src/metadata-resources.csv");
if file_path.exists() {
p!("file exists: {}", file_path.display());
} else {
p!("extracting file: {}", file_path.display());
let f = File::open("src/metadata-resources.zip").expect("failed to open resource file");
let mut zip = zip::ZipArchive::new(f).expect("fialed to open zip file");
zip.extract("src/").expect("failed to extract zip file");
}
}