-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
48 lines (38 loc) · 1.1 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
use std::{
ffi::OsStr,
fs::{create_dir, read_dir},
io,
path::{Path, PathBuf},
process::Command,
};
fn assemble_tests(
platform: &'static str,
tests_path: &Path,
output_path: &Path,
) -> Result<(), io::Error> {
let src_path = tests_path.join(platform);
println!("cargo:rerun-if-changed={}", src_path.display());
if !output_path.exists() {
create_dir(&output_path)?;
}
for result in read_dir(src_path)? {
let file_path = result?.path();
if file_path.extension() == Some(OsStr::new("asm")) {
let file_name = file_path.file_name().unwrap();
let out = output_path.join(file_name).with_extension(platform);
Command::new("nasm")
.arg(&file_path)
.arg("-O0")
.arg("-o")
.arg(out)
.output()?;
}
}
Ok(())
}
fn main() -> Result<(), io::Error> {
let tests_path = PathBuf::from_iter(["tests", "asm"]);
let output_path = tests_path.join("out");
assemble_tests("x86_64", &tests_path, &output_path)?;
Ok(())
}