-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathbuild.rs
36 lines (31 loc) · 1.33 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
use std::io::Write;
fn main() {
let syscall_in = match std::env::var("CARGO_CFG_TARGET_ARCH") {
Ok(s) if s == "riscv64" => "src/riscv64_syscall.h.in",
Ok(s) if s == "aarch64" => "src/aarch64_syscall.h.in",
_ => "src/syscall.h.in",
};
println!("cargo:rerun-if-changed={}", syscall_in);
let mut fout = std::fs::File::create(std::env::var("OUT_DIR").unwrap() + "/consts.rs").unwrap();
writeln!(fout, "// Generated by build.rs. DO NOT EDIT.").unwrap();
writeln!(fout, "use numeric_enum_macro::numeric_enum;\n").unwrap();
writeln!(fout, "numeric_enum! {{").unwrap();
writeln!(fout, "#[repr(u32)]").unwrap();
writeln!(fout, "#[derive(Debug, Eq, PartialEq)]").unwrap();
writeln!(fout, "#[allow(non_camel_case_types)]").unwrap();
writeln!(fout, "pub enum SyscallType {{").unwrap();
let data = std::fs::read_to_string(syscall_in).unwrap();
for line in data.lines() {
if !line.starts_with("#define") {
continue;
}
let mut iter = line.split_whitespace();
let _ = iter.next().unwrap();
let name = iter.next().unwrap();
let id = iter.next().unwrap();
let name = &name[5..].to_uppercase();
writeln!(fout, " {} = {},", name, id).unwrap();
}
writeln!(fout, "}}").unwrap();
writeln!(fout, "}}").unwrap();
}