-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
36 lines (30 loc) · 1.02 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
fn execute(command: &str, args: &[&str]) -> Result<(), Box<dyn std::error::Error>> {
let output = std::process::Command::new(command).args(args).output()?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
return Err(stderr.into());
}
Ok(())
}
fn move_file(from: &str, to: &str) -> std::io::Result<()> {
std::fs::copy(from, to)?;
std::fs::remove_file(from)?;
Ok(())
}
fn main() {
println!("cargo:rerun-if-changed=src/air/opcode.opcodes");
println!("cargo:rerun-if-changed=src/air/opcode_generator.rb");
let out_dir = std::env::var("OUT_DIR").unwrap();
execute(
"ruby",
&["src/air/opcode_generator.rb", "src/air/opcode.opcodes"],
)
.unwrap();
move_file(
"opcode_generated.rs",
&format!("{}/opcode_generated.rs", out_dir),
)
.unwrap();
move_file("opcode_utils.rs", &format!("{}/opcode_utils.rs", out_dir)).unwrap();
move_file("opcode.rs", &format!("{}/opcode.rs", out_dir)).unwrap();
}