|
| 1 | +fn main() { |
| 2 | + // generate sha256 files |
| 3 | + // this avoids having to perform hashing at runtime |
| 4 | + let files = &[ |
| 5 | + "static/css/rustdoc.css", |
| 6 | + "static/css/noscript.css", |
| 7 | + "static/css/normalize.css", |
| 8 | + "static/js/main.js", |
| 9 | + "static/js/search.js", |
| 10 | + "static/js/settings.js", |
| 11 | + "static/js/src-script.js", |
| 12 | + "static/js/storage.js", |
| 13 | + "static/js/scrape-examples.js", |
| 14 | + "static/COPYRIGHT.txt", |
| 15 | + "static/LICENSE-APACHE.txt", |
| 16 | + "static/LICENSE-MIT.txt", |
| 17 | + "static/images/rust-logo.svg", |
| 18 | + "static/images/favicon.svg", |
| 19 | + "static/images/favicon-32x32.png", |
| 20 | + "static/fonts/FiraSans-Regular.woff2", |
| 21 | + "static/fonts/FiraSans-Medium.woff2", |
| 22 | + "static/fonts/FiraSans-LICENSE.txt", |
| 23 | + "static/fonts/SourceSerif4-Regular.ttf.woff2", |
| 24 | + "static/fonts/SourceSerif4-Bold.ttf.woff2", |
| 25 | + "static/fonts/SourceSerif4-It.ttf.woff2", |
| 26 | + "static/fonts/SourceSerif4-LICENSE.md", |
| 27 | + "static/fonts/SourceCodePro-Regular.ttf.woff2", |
| 28 | + "static/fonts/SourceCodePro-Semibold.ttf.woff2", |
| 29 | + "static/fonts/SourceCodePro-It.ttf.woff2", |
| 30 | + "static/fonts/SourceCodePro-LICENSE.txt", |
| 31 | + "static/fonts/NanumBarunGothic.ttf.woff2", |
| 32 | + "static/fonts/NanumBarunGothic-LICENSE.txt", |
| 33 | + ]; |
| 34 | + let out_dir = std::env::var("OUT_DIR").expect("standard Cargo environment variable"); |
| 35 | + for path in files { |
| 36 | + let inpath = format!("html/{path}"); |
| 37 | + println!("cargo::rerun-if-changed={inpath}"); |
| 38 | + let bytes = std::fs::read(inpath).expect("static path exists"); |
| 39 | + use sha2::Digest; |
| 40 | + let bytes = sha2::Sha256::digest(bytes); |
| 41 | + let mut digest = format!("-{bytes:x}"); |
| 42 | + digest.truncate(9); |
| 43 | + let outpath = std::path::PathBuf::from(format!("{out_dir}/{path}.sha256")); |
| 44 | + std::fs::create_dir_all(outpath.parent().expect("all file paths are in a directory")) |
| 45 | + .expect("should be able to write to out_dir"); |
| 46 | + std::fs::write(&outpath, digest.as_bytes()).expect("write to out_dir"); |
| 47 | + } |
| 48 | +} |
0 commit comments