-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.rs
50 lines (41 loc) · 1.3 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
use std::{
env,
fs::{self, File},
io::BufWriter,
io::Write,
path::Path,
};
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("stationpedia.rs");
let mut map_builder = ::phf_codegen::Map::new();
let mut set_builder = ::phf_codegen::Set::new();
let mut check_set = std::collections::HashSet::new();
let infile = Path::new("stationpedia.txt");
let contents = fs::read_to_string(infile).unwrap();
for line in contents.lines() {
let mut it = line.splitn(2, ' ');
let hash = it.next().unwrap();
let name = it.next().unwrap();
map_builder.entry(hash, &format!("\"{}\"", name));
if !check_set.contains(name) {
set_builder.entry(name);
check_set.insert(name);
}
}
let output_file = File::create(dest_path).unwrap();
let mut writer = BufWriter::new(&output_file);
write!(
&mut writer,
"pub(crate) const HASH_NAME_LOOKUP: phf::Map<&'static str, &'static str> = {};\n",
map_builder.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const HASH_NAMES: phf::Set<&'static str> = {};\n",
set_builder.build()
)
.unwrap();
println!("cargo:rerun-if-changed=stationpedia.txt");
}