-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.rs
53 lines (46 loc) · 1.53 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
use proc_macro2::Literal;
use std::collections::HashMap;
use std::env;
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::Path;
fn parse(errcodes: &str) -> impl DoubleEndedIterator<Item = (u32, &str)> {
let from_start = errcodes
.splitn(2, "switch_known_errcodes = {")
.nth(1)
.unwrap();
let region = from_start.split("}\n").next().unwrap().trim();
region
.lines()
.filter(|line| line.len() > 0 && !line.trim().starts_with("#"))
.map(|line| {
let mut fields = line.splitn(2, ":");
let code = u32::from_str_radix(&fields.next().unwrap().trim()[2..], 16).unwrap();
let message = fields
.next()
.unwrap()
.trim_matches(&[' ', '"', ',', '\''] as &[char]);
(code, message)
})
}
fn main() {
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs");
let mut file = BufWriter::new(File::create(&path).unwrap());
let mut map = phf_codegen::Map::new();
let deduped: HashMap<_, _> = parse(include_str!("assets/errcodes.py")).rev().collect();
for (k, v) in deduped {
map.entry(k, &Literal::string(v).to_string());
}
writeln!(
&mut file,
"static ERROR_CODES: phf::Map<u32, &'static str> = \n{};\n",
map.build(),
)
.unwrap();
drop(file);
let include_path = "/opt/devkitpro/libnx/include/";
cpp_build::Config::new()
.flag("-isystem")
.flag(include_path)
.build("src/main.rs");
}