-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
52 lines (43 loc) · 1.44 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
use std::path::{Path, PathBuf};
use std::{env, fs};
fn get_output_path() -> PathBuf {
/* <root or manifest path>/target/<profile>/ */
let manifest_dir_string = env::var("CARGO_MANIFEST_DIR").unwrap();
let build_type = env::var("PROFILE").unwrap();
let path = Path::new(&manifest_dir_string)
.join("target")
.join(build_type);
return PathBuf::from(path);
}
fn main() {
println!("cargo:rerun-if-env-changed=DV_DIR");
let env_dv_dir = env::var("DV_DIR").unwrap();
let target_dir = get_output_path();
let dv_dir = Path::new(&env_dv_dir);
let tt_dir = Path::new(&target_dir);
println!("DV_DIR: {}", dv_dir.display());
println!("TARGET_DIR: {}", tt_dir.display());
let (src, dst);
if cfg!(windows) {
src = dv_dir.join("bin/differvoid.dll");
dst = tt_dir.join("differvoid.dll");
} else if cfg!(unix) {
src = dv_dir.join("lib/libdiffervoid.so");
dst = tt_dir.join("libdiffervoid.so");
} else {
panic!("OS not supported.");
}
println!("cargo:rerun-if-changed={}", src.display());
match fs::copy(&src, &dst) {
Err(_) => {
println!(
"cargo:warning=Failed to copy {} to {}",
src.display(),
dst.display()
);
}
_ => {}
}
println!("cargo:rustc-link-search=native={}/lib", dv_dir.display());
println!("cargo:rustc-link-lib=dylib=differvoid");
}