1 parent
d55640d37a
commit
fff8521a17
67 files changed
+11016
-16763
No files matched your search
@@ -1,35 +1,31 @@
|
||||
use std::{env, fs, path::PathBuf};
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let root = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
|
||||
let out = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR"));
|
||||
let css_dir = root.join("src/web/css");
|
||||
let manifest = css_dir.join("manifest.txt");
|
||||
fn fnv1a64(parts: &[&[u8]]) -> u64 {
|
||||
let mut hash = 0xcbf29ce484222325u64;
|
||||
for part in parts {
|
||||
for byte in *part {
|
||||
hash ^= u64::from(*byte);
|
||||
hash = hash.wrapping_mul(0x100000001b3);
|
||||
}
|
||||
}
|
||||
hash
|
||||
}
|
||||
|
||||
fn bundle_manifest(
|
||||
root: &Path,
|
||||
directory: &Path,
|
||||
manifest: &Path,
|
||||
extension: &str,
|
||||
banner: &str,
|
||||
) -> String {
|
||||
println!("cargo:rerun-if-changed={}", manifest.display());
|
||||
println!(
|
||||
"cargo:rerun-if-changed={}",
|
||||
root.join("src/web/index.html").display()
|
||||
);
|
||||
println!(
|
||||
"cargo:rerun-if-changed={}",
|
||||
root.join("src/web/app.js").display()
|
||||
);
|
||||
println!(
|
||||
"cargo:rerun-if-changed={}",
|
||||
root.join("src/web/icons.svg").display()
|
||||
);
|
||||
println!(
|
||||
"cargo:rerun-if-changed={}",
|
||||
root.join("src/web/i18n/en.json").display()
|
||||
);
|
||||
println!(
|
||||
"cargo:rerun-if-changed={}",
|
||||
root.join("src/web/i18n/pl.json").display()
|
||||
);
|
||||
|
||||
let manifest_text = fs::read_to_string(&manifest).expect("read src/web/css/manifest.txt");
|
||||
let mut bundle = String::from("/* RustBox UI bundle - generated by build.rs */\n");
|
||||
let manifest_text = fs::read_to_string(manifest)
|
||||
.unwrap_or_else(|error| panic!("{}: {error}", manifest.display()));
|
||||
let mut bundle = String::from(banner);
|
||||
bundle.push('\n');
|
||||
|
||||
for raw in manifest_text.lines() {
|
||||
let name = raw.trim();
|
||||
@@ -37,22 +33,66 @@ fn main() {
|
||||
continue;
|
||||
}
|
||||
assert!(
|
||||
name.ends_with(".css")
|
||||
name.ends_with(extension)
|
||||
&& !name.contains('/')
|
||||
&& !name.contains('\\')
|
||||
&& !name.contains(".."),
|
||||
"invalid CSS manifest entry: {name}"
|
||||
"invalid {extension} manifest entry: {name}"
|
||||
);
|
||||
let path = directory.join(name);
|
||||
assert!(
|
||||
path.starts_with(root),
|
||||
"asset path escaped project root: {}",
|
||||
path.display()
|
||||
);
|
||||
let path = css_dir.join(name);
|
||||
println!("cargo:rerun-if-changed={}", path.display());
|
||||
let css =
|
||||
let source =
|
||||
fs::read_to_string(&path).unwrap_or_else(|error| panic!("{}: {error}", path.display()));
|
||||
bundle.push_str("\n/* ");
|
||||
bundle.push_str("\n/* ---- ");
|
||||
bundle.push_str(name);
|
||||
bundle.push_str(" */\n");
|
||||
bundle.push_str(&css);
|
||||
bundle.push('\n');
|
||||
bundle.push_str(" ---- */\n");
|
||||
bundle.push_str(&source);
|
||||
if !source.ends_with('\n') {
|
||||
bundle.push('\n');
|
||||
}
|
||||
}
|
||||
|
||||
fs::write(out.join("rustbox-ui.css"), bundle).expect("write RustBox CSS bundle");
|
||||
bundle
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let root = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
|
||||
let out = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR"));
|
||||
let css_dir = root.join("src/web/css");
|
||||
let js_dir = root.join("src/web/js");
|
||||
|
||||
for path in [
|
||||
root.join("src/web/index.html"),
|
||||
root.join("src/web/icons.svg"),
|
||||
root.join("src/web/i18n/en.json"),
|
||||
root.join("src/web/i18n/pl.json"),
|
||||
] {
|
||||
println!("cargo:rerun-if-changed={}", path.display());
|
||||
}
|
||||
|
||||
let css_bundle = bundle_manifest(
|
||||
&root,
|
||||
&css_dir,
|
||||
&css_dir.join("manifest.txt"),
|
||||
".css",
|
||||
"/* RustBox UI CSS bundle - generated by build.rs */",
|
||||
);
|
||||
let js_bundle = bundle_manifest(
|
||||
&root,
|
||||
&js_dir,
|
||||
&js_dir.join("manifest.txt"),
|
||||
".js",
|
||||
"/* RustBox UI JavaScript bundle - generated by build.rs; edit src/web/js/*.js */",
|
||||
);
|
||||
|
||||
let asset_id = fnv1a64(&[css_bundle.as_bytes(), js_bundle.as_bytes()]);
|
||||
println!("cargo:rustc-env=RUSTBOX_ASSET_ID={asset_id:016x}");
|
||||
|
||||
fs::write(out.join("rustbox-ui.css"), css_bundle).expect("write RustBox CSS bundle");
|
||||
fs::write(out.join("rustbox-ui.js"), js_bundle).expect("write RustBox JavaScript bundle");
|
||||
}
|
||||
Reference in new issue
Block a user