//! Embeds the client's Lucide icons: `crates/voelin-ui/ui/assets/icons/*.svg` //! (Lucide 1.48, the set the Slint front end draws) become a sorted table of //! `include_bytes!` in `$OUT_DIR/icons.rs`, which `assets.rs` serves as //! gpui-component's `icons/.svg` paths before gpui-kit-assets' own //! (Lucide 1.43) catalogue. No dependency: the directory is read and the //! table written with `std`. use std::fmt::Write as _; use std::path::PathBuf; fn main() { let manifest = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR")); let dir = manifest.join("../voelin-ui/ui/assets/icons"); println!("cargo:rerun-if-changed={}", dir.display()); let mut names: Vec = std::fs::read_dir(&dir) .unwrap_or_else(|e| panic!("the client's icons are at {}: {e}", dir.display())) .filter_map(|entry| entry.ok()?.file_name().into_string().ok()) .filter(|name| name.ends_with(".svg")) .collect(); names.sort(); assert!(!names.is_empty(), "no icons in {}", dir.display()); let mut table = String::from( "/// The client's icons by file name, sorted.\npub static ICONS: &[(&str, &[u8])] = &[\n", ); for name in &names { let path = dir.join(name); let path = path.canonicalize().unwrap_or(path); let _ = writeln!(table, "\t({name:?}, include_bytes!({:?})),", path.display().to_string()); } table.push_str("];\n"); let out = PathBuf::from(std::env::var_os("OUT_DIR").expect("OUT_DIR")).join("icons.rs"); std::fs::write(out, table).expect("write icons.rs"); }