use std::path::Path;
use std::time::SystemTime;
fn main() {
println!("cargo:rerun-if-changed=web/dist");
println!("cargo:rerun-if-changed=web/src");
let dist = Path::new("web/dist");
let src = Path::new("web/src");
match (newest_mtime(dist), newest_mtime(src)) {
(None, _) => {
println!(
"cargo:warning=web/dist is missing or empty; the binary will ship without the web UI (run `bun run build` in web/)"
);
}
(Some(dist_mtime), Some(src_mtime)) if src_mtime > dist_mtime => {
println!(
"cargo:warning=web/src is newer than web/dist; the embedded frontend is stale (run `bun run build` in web/)"
);
}
_ => {}
}
}
fn newest_mtime(dir: &Path) -> Option<SystemTime> {
let mut newest: Option<SystemTime> = None;
let entries = std::fs::read_dir(dir).ok()?;
for entry in entries.flatten() {
let path = entry.path();
let candidate = if path.is_dir() {
newest_mtime(&path)
} else {
entry.metadata().ok().and_then(|m| m.modified().ok())
};
if let Some(t) = candidate
&& newest.is_none_or(|n| t > n)
{
newest = Some(t);
}
}
newest
}