-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.rs
47 lines (42 loc) · 1.79 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
use std::env;
use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changes=build.rs");
let target = env::var("TARGET").expect("valid TARGET defined");
if target.contains("pc-windows-msvc") {
let manifest_dir = PathBuf::from(
env::var("CARGO_MANIFEST_DIR").expect("valid CARGO_MANIFEST_DIR defined"),
);
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("valid CARGO_OUT_DIR defined"));
let mut lib_dir = manifest_dir.join("lib").join("msvc").join("lib");
let mut dll_dir = manifest_dir.join("lib").join("msvc").join("dll");
if target.contains("x86_64") {
lib_dir.push("64");
dll_dir.push("64");
} else {
lib_dir.push("32");
dll_dir.push("32");
}
println!("cargo:rustc-link-search=native={}", out_dir.display());
for dir in [lib_dir, dll_dir] {
for entry in std::fs::read_dir(&dir)
.unwrap_or_else(|err| panic!("can't read directory: {}, {}", dir.display(), err))
{
let entry_path = entry.expect("invalid fs entry").path();
let file_name_result = entry_path.file_name();
if let Some(file_name) = file_name_result {
let file_name = file_name.to_str().expect("valid filename");
let new_file_path = out_dir.join(file_name);
std::fs::copy(&entry_path, &new_file_path).unwrap_or_else(|err| {
panic!(
"can't copy directory: {} to {}, {}",
entry_path.display(),
new_file_path.display(),
err
)
});
}
}
}
}
}