-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
68 lines (63 loc) · 2.41 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
64
65
66
67
68
use std::env;
use std::path::PathBuf;
fn main() {
let target = env::var("TARGET").unwrap();
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("Failed to find target dir"));
// Horrible brittle hack to allow me to send the game to friends
let mut build_output_dir = out_dir;
build_output_dir.pop();
build_output_dir.pop();
build_output_dir.pop();
let mut src_resource_dir = manifest_dir.clone();
src_resource_dir.push("resources");
let mut dst_target_resource_dir = build_output_dir.clone();
dst_target_resource_dir.push("resources");
if !dst_target_resource_dir.exists() {
std::fs::create_dir(dst_target_resource_dir.clone()).unwrap();
}
copy(&src_resource_dir, &dst_target_resource_dir, ".png");
if target.contains("pc-windows") {
let mut lib_dir = manifest_dir.clone();
let mut dll_dir = manifest_dir.clone();
if target.contains("msvc") {
lib_dir.push("msvc");
dll_dir.push("msvc");
} else {
lib_dir.push("gnu-mingw");
dll_dir.push("gnu-mingw");
}
lib_dir.push("lib");
dll_dir.push("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=all={}", lib_dir.display());
copy(&dll_dir, &manifest_dir, ".dll");
copy(&dll_dir, &build_output_dir, ".dll");
}
}
fn copy(src_dir: &PathBuf, dst_dir: &PathBuf, file_type: &str) {
println!("{:?}", src_dir);
println!("{:?}", dst_dir);
for entry in
std::fs::read_dir(src_dir).unwrap_or_else(|_| panic!("Can't read dir {:?}", src_dir))
{
let entry_path = entry.expect("Invalid fs entry").path();
let file_name_result = entry_path.file_name();
let mut new_file_path = dst_dir.clone();
if let Some(file_name) = file_name_result {
let file_name = file_name.to_str().unwrap();
if file_name.ends_with(file_type) {
new_file_path.push(file_name);
std::fs::copy(&entry_path, new_file_path.as_path()).unwrap_or_else(|_| {
panic!("Can't copy from dir {:?} to {:?}", src_dir, dst_dir)
});
}
}
}
}