-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
45 lines (37 loc) · 1.54 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
use std::fs;
use std::{env, path::Path};
use xmltree::Element;
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("xtlid.rs");
let input = fs::read_to_string("src/xtlid.xml").unwrap();
let xtlid_element = Element::parse(input.as_bytes()).unwrap();
let mut output = String::new();
output.push_str("use phf::phf_map;\n\n");
output.push_str("pub static XTLIDS: phf::Map<u32, &str> = phf_map! {\n");
for lib_node in xtlid_element.children.iter() {
match lib_node {
xmltree::XMLNode::Element(child_element) => {
if child_element.name == "lib" {
for func_node in child_element.children.iter() {
match func_node {
xmltree::XMLNode::Element(func_node) => {
if func_node.name == "func" {
let id = func_node.attributes.get("id").unwrap();
let name = func_node.attributes.get("name").unwrap();
output.push_str(&format!(" {}u32 => \"{}\",\n", id, name));
}
}
_ => {}
}
}
}
}
_ => {}
}
}
output.push_str("};\n");
fs::write(dest_path, output).unwrap();
println!("cargo:rerun-if-changed=src/xtlid.xml");
println!("cargo:rerun-if-changed=build.rs");
}