-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
39 lines (33 loc) · 1.22 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
use std::{env, fs, path::Path};
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo::rerun-if-changed=..");
let target = env::var("TARGET").unwrap();
let host = env::var("HOST").unwrap();
let profile = env::var("PROFILE").unwrap();
let packer_bin_name = "packer.exe";
let agent_bin_name = "agent.exe";
let packer_path = if target == host {
format!("../target/{profile}/{packer_bin_name}")
} else {
format!("../target/{target}/{profile}/{packer_bin_name}")
};
let agent_path = if target == host {
format!("../target/{profile}/{agent_bin_name}")
} else {
format!("../target/{target}/{profile}/{agent_bin_name}")
};
let out_dir = env::var_os("OUT_DIR").expect("OUT_DIR env var not set");
let out_dir = Path::new(&out_dir);
if !std::path::Path::new(&packer_path).is_file() {
panic!("File not found '{packer_path}'");
}
if !std::path::Path::new(&agent_path).is_file() {
panic!("File not found '{agent_path}'");
}
fs::write(out_dir.join("packer.exe"), fs::read(packer_path)?)?;
fs::write(
out_dir.join("agent.pack"),
common::pack_to_vec(&fs::read(agent_path)?),
)?;
Ok(())
}