35 lines
1.1 KiB
Rust
35 lines
1.1 KiB
Rust
fn main() {
|
|
use std::{fs, path::Path};
|
|
|
|
let webroot = Path::new("webroot");
|
|
if !webroot.exists() {
|
|
fs::create_dir_all(webroot).expect("create fallback webroot");
|
|
fs::write(
|
|
webroot.join("index.html"),
|
|
"<!doctype html><title>Avida-ED assets not injected</title><p>Run make fetch-v4 build-linux.</p>\n",
|
|
)
|
|
.expect("write fallback webroot index");
|
|
}
|
|
|
|
println!("cargo:rerun-if-changed=webroot");
|
|
print_rerun_files(webroot);
|
|
println!("cargo:rerun-if-env-changed=AVIDA_ED_DEFAULT_PATH");
|
|
let default_path = std::env::var("AVIDA_ED_DEFAULT_PATH")
|
|
.unwrap_or_else(|_| "/index.html".to_string());
|
|
println!("cargo:rustc-env=AVIDA_ED_DEFAULT_PATH={default_path}");
|
|
}
|
|
|
|
fn print_rerun_files(path: &std::path::Path) {
|
|
let Ok(entries) = std::fs::read_dir(path) else {
|
|
return;
|
|
};
|
|
for entry in entries.flatten() {
|
|
let path = entry.path();
|
|
if path.is_dir() {
|
|
print_rerun_files(&path);
|
|
} else {
|
|
println!("cargo:rerun-if-changed={}", path.display());
|
|
}
|
|
}
|
|
}
|