generated from napi-rs/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
42 lines (35 loc) · 928 Bytes
/
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
extern crate napi_build;
use std::{
env,
fs::File,
io::{BufWriter, Write},
path::Path,
};
fn main() {
napi_build::setup();
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::<char>::new();
let data = include_str!("./data/confusables.txt")
.lines()
.filter(|l| !l.is_empty())
.map(|l| l.split_whitespace().collect::<Vec<_>>())
.map(|l| (l[0], l[1]))
.map(|(target, characters)| {
let characters = characters.chars().collect::<Vec<_>>();
(characters, target)
});
for (source, target) in data {
let target = &format!("r\"{target}\"");
for source in source {
let _ = map.entry(source, target);
}
}
write!(
&mut file,
"#[allow(clippy::unicode_not_nfc, clippy::unreadable_literal)]
static KEYWORDS: phf::Map<char, &'static str> = {};",
map.build()
)
.unwrap();
}