-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.rs
35 lines (30 loc) · 986 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
use std::{
env,
fs::{self, File},
io::{BufWriter, Write},
path::Path,
};
fn main() {
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("svg_logos.rs");
let mut file = BufWriter::new(File::create(path).unwrap());
let mut map = phf_codegen::Map::new();
for entry in fs::read_dir(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/logos/")).unwrap() {
let entry = entry.unwrap();
let file_name = entry.file_name();
let file_name = file_name.to_string_lossy();
let Some(name) = file_name.strip_suffix(".svg") else {
panic!("expected .svg file, got {file_name}");
};
map.entry(
name.to_uppercase(),
&format!(r#"include_bytes!("{}")"#, entry.path().display()),
);
}
write!(
&mut file,
"pub(crate) static LOGOS: phf::Map<&'static str, &'static [u8]> = {}",
map.build()
)
.unwrap();
writeln!(&mut file, ";").unwrap();
}