summaryrefslogtreecommitdiffstats
path: root/icons/build.rs
diff options
context:
space:
mode:
Diffstat (limited to 'icons/build.rs')
-rw-r--r--icons/build.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/icons/build.rs b/icons/build.rs
new file mode 100644
index 0000000..a9ae2de
--- /dev/null
+++ b/icons/build.rs
@@ -0,0 +1,52 @@
+use std::hash::{Hash, Hasher};
+use std::io::Write;
+
+fn main() {
+ println!("cargo:rerun-if-changed=res");
+ let mut file =
+ std::fs::File::create(format!("{}/icons.rs", std::env::var("OUT_DIR").unwrap())).unwrap();
+ let mut mapping = Vec::new();
+
+ writeln!(file, "use super::Icon;").unwrap();
+
+ for res in std::fs::read_dir("res").unwrap() {
+ let path = res.unwrap().path();
+ if path.is_dir() {
+ continue;
+ }
+
+ println!("{:?}", path);
+
+ let content = std::fs::read(&path).unwrap();
+
+ let mut hasher = std::collections::hash_map::DefaultHasher::new();
+ content.hash(&mut hasher);
+ let hash = hasher.finish();
+
+ let key = format!("{}.svg", hash);
+
+ let name = path.file_name().unwrap().to_str().unwrap();
+ let name = (&name[0..name.len() - 4]).to_ascii_uppercase();
+
+ writeln!(
+ file,
+ "pub const {}: Icon=Icon{{path:\"{}\",content:include_str!(\"{}\")}};",
+ name,
+ key,
+ path.canonicalize().unwrap().to_str().unwrap()
+ )
+ .unwrap();
+
+ mapping.push((key, name));
+ }
+
+ writeln!(
+ file,
+ "pub const ICONS_MAP: phf::Map<&'static str, &'static Icon> = phf::phf_map! {{"
+ )
+ .unwrap();
+ for (key, name) in mapping {
+ writeln!(file, "\"{}\" => &{},", key, name).unwrap();
+ }
+ writeln!(file, "}};").unwrap();
+}