forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
48 lines (48 loc) · 2.02 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
fn main() {
// generate sha256 files
// this avoids having to perform hashing at runtime
let files = &[
"static/css/rustdoc.css",
"static/css/noscript.css",
"static/css/normalize.css",
"static/js/main.js",
"static/js/search.js",
"static/js/settings.js",
"static/js/src-script.js",
"static/js/storage.js",
"static/js/scrape-examples.js",
"static/COPYRIGHT.txt",
"static/LICENSE-APACHE.txt",
"static/LICENSE-MIT.txt",
"static/images/rust-logo.svg",
"static/images/favicon.svg",
"static/images/favicon-32x32.png",
"static/fonts/FiraSans-Regular.woff2",
"static/fonts/FiraSans-Medium.woff2",
"static/fonts/FiraSans-LICENSE.txt",
"static/fonts/SourceSerif4-Regular.ttf.woff2",
"static/fonts/SourceSerif4-Bold.ttf.woff2",
"static/fonts/SourceSerif4-It.ttf.woff2",
"static/fonts/SourceSerif4-LICENSE.md",
"static/fonts/SourceCodePro-Regular.ttf.woff2",
"static/fonts/SourceCodePro-Semibold.ttf.woff2",
"static/fonts/SourceCodePro-It.ttf.woff2",
"static/fonts/SourceCodePro-LICENSE.txt",
"static/fonts/NanumBarunGothic.ttf.woff2",
"static/fonts/NanumBarunGothic-LICENSE.txt",
];
let out_dir = std::env::var("OUT_DIR").expect("standard Cargo environment variable");
for path in files {
let inpath = format!("html/{path}");
println!("cargo::rerun-if-changed={inpath}");
let bytes = std::fs::read(inpath).expect("static path exists");
use sha2::Digest;
let bytes = sha2::Sha256::digest(bytes);
let mut digest = format!("-{bytes:x}");
digest.truncate(9);
let outpath = std::path::PathBuf::from(format!("{out_dir}/{path}.sha256"));
std::fs::create_dir_all(outpath.parent().expect("all file paths are in a directory"))
.expect("should be able to write to out_dir");
std::fs::write(&outpath, digest.as_bytes()).expect("write to out_dir");
}
}