From c912ef59d15c8591c9a1bc7bd31d3d88cae9899d Mon Sep 17 00:00:00 2001 From: Michael Gieson Date: Sat, 10 Oct 2026 17:38:13 -0400 Subject: [PATCH] Build: generated sources are rewritten only when they change crates/text/build.rs (craft_fonts.rs) and crates/ui-egui/build.rs (credits.rs) wrote their output on every run. Where cargo's recorded times lose their sub-second part (an ecryptfs home directory, as Mint and Ubuntu offer at install), a file written just before its crate compiles reads as newer than that compile, so the next build compiled the crate and everything above it a second time: a full app rebuild for nothing after any build-script rerun. Unchanged output is now left alone. Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/text/build.rs | 6 ++++++ crates/ui-egui/build.rs | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/text/build.rs b/crates/text/build.rs index 73c952fa..25544a3a 100644 --- a/crates/text/build.rs +++ b/crates/text/build.rs @@ -51,6 +51,12 @@ fn main() { } let src = format!("pub static CRAFT_FONTS: &[CraftFont] = &[\n{fonts}];\npub static WEB_FONTS: &[WebFont] = &[\n{web}];\n"); let out = PathBuf::from(std::env::var_os("OUT_DIR").unwrap_or_default()).join("craft_fonts.rs"); + // Unchanged output keeps its mtime. Rewritten just before this crate compiles, it can read as + // newer than that compile where cargo's recorded times lose their sub-second part (ecryptfs + // home directories), and the next build would compile this crate and everything above it again. + if std::fs::read_to_string(&out).is_ok_and(|old| old == src) { + return; + } if let Err(e) = std::fs::write(&out, src) { println!("cargo::error=writing {}: {e}", out.display()); } diff --git a/crates/ui-egui/build.rs b/crates/ui-egui/build.rs index f40007fb..22fa00b2 100644 --- a/crates/ui-egui/build.rs +++ b/crates/ui-egui/build.rs @@ -21,7 +21,13 @@ fn main() { let people = read(&dir.join("people.toml"), "contributors are shown by username only", |t| t.parse::().map_err(|e| e.to_string())) .unwrap_or_default(); let out = std::path::PathBuf::from(std::env::var_os("OUT_DIR").unwrap_or_default()).join("credits.rs"); - if let Err(e) = std::fs::write(&out, generate(&json, &people)) { + let src = generate(&json, &people); + // Unchanged output keeps its mtime, so the next build doesn't compile this crate again + // (see crates/text/build.rs). + if std::fs::read_to_string(&out).is_ok_and(|old| old == src) { + return; + } + if let Err(e) = std::fs::write(&out, src) { println!("cargo::warning=writing {}: {e}", out.display()); } }