GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — WineXP/build.rs at master · shitastical/WineXP Expand file tree/ Copy pathbuild.rsMore file actions 52 lines (45 loc) · 1.77 KB / Copy pathbuild.rsFile metadata and controls52 lines (45 loc) · 1.77 KB 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 51 52 //! Embeds every file under `assets/` into the binary and generates a lookup //! function keyed by the asset's path relative to `assets/` (with forward //! slashes), e.g. `windowsIcons/start.png`. use std::env; use std::fs; use std::path::{Path, PathBuf}; fn main() { let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); let assets = Path::new(&manifest_dir).join("assets"); let mut keys: Vec<String> = Vec::new(); walk(&assets, &assets, &mut keys); keys.sort(); let mut code = String::new(); code.push_str("/// Look up an embedded asset by its path relative to `assets/`.\n"); code.push_str("pub fn asset_bytes(path: &str) -> Option<&'static [u8]> {\n"); code.push_str(" match path {\n"); for key in &keys { // Skip fonts; they are loaded directly via include_bytes! in fonts.rs. if key.starts_with("fonts/") { continue; } code.push_str(&format!( " {key:?} => Some(include_bytes!(concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/assets/{key}\"))),\n" )); } code.push_str(" _ => None,\n"); code.push_str(" }\n"); code.push_str("}\n"); let out = Path::new(&env::var("OUT_DIR").unwrap()).join("assets_gen.rs"); fs::write(out, code).unwrap(); println!("cargo:rerun-if-changed=assets"); println!("cargo:rerun-if-changed=build.rs"); } fn walk(root: &Path, dir: &Path, out: &mut Vec<String>) { let Ok(read) = fs::read_dir(dir) else { return }; for entry in read.flatten() { let path: PathBuf = entry.path(); if path.is_dir() { walk(root, &path, out); } else if let Ok(rel) = path.strip_prefix(root) { let rel = rel.to_string_lossy().replace('\\', "/"); out.push(rel); } } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |