-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
88 lines (73 loc) · 2.18 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use std::{
env,
error::Error,
fs::{self, read_dir},
path::{Path, PathBuf},
process::{Command, Stdio},
};
fn main() -> Result<(), Box<dyn Error>> {
let tools = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tools");
let dd = tools.join("DepotDownloader/DepotDownloader.exe");
let files = tools.join("files");
let out = PathBuf::from("target/vendor");
println!("cargo:rustc-link-search=native={}/bin", out.display());
println!(
"cargo:rustc-link-search=native={}/garrysmod/bin",
out.display()
);
println!("cargo:rustc-cdylib-link-arg=-Wl,-rpath,./garrysmod/bin,-rpath,{}/bin,-rpath,{}/garrysmod/bin",
out.display(),
out.display()
);
println!("cargo:rustc-cdylib-link-arg=-l:lua_shared.so");
println!("cargo:rustc-cdylib-link-arg=-l:libtier0.so");
println!("cargo:rustc-cdylib-link-arg=-l:libvstdlib.so");
println!("cargo:rustc-cdylib-link-arg=-l:libsteam_api.so");
println!("cargo:rerun-if-changed=tools/files");
download_depot(&dd, &files, 4022, &out)?;
download_depot(&dd, &files, 4023, &out)?;
Ok(())
}
fn download_depot(
dd: &Path,
files: &Path,
depot: u32,
out: &Path,
) -> Result<(), Box<dyn Error>> {
// Update lua_shared libraries
let tmp = out.join("tmp");
let output = Command::new(dd)
.args(&["-app", "4020"])
.args(&["-depot", &depot.to_string()])
.args(&["-filelist", files.to_str().unwrap()])
.args(&["-dir", tmp.to_str().unwrap()])
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?
.wait_with_output()?;
//
if !output.status.success() {
panic!(
"DepotDownloader failed with `{}`",
String::from_utf8_lossy(&output.stdout)
);
}
copy_binaries(&tmp, out)?;
Ok(())
}
fn copy_binaries(from: &Path, to: &Path) -> std::io::Result<()> {
for entry in read_dir(from)? {
let entry = entry?;
let entry_type = entry.file_type()?;
let entry_name = entry.file_name();
let entry_name = entry_name.to_string_lossy();
if !entry_type.is_file() {
copy_binaries(&entry.path(), to)?;
}
if !entry_name.ends_with(".dll") || !entry_name.ends_with(".so") {
continue;
}
fs::copy(entry.path(), to.join(entry.file_name()))?;
}
Ok(())
}