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) <[email protected]>
This commit is contained in:
Michael GiesonandClaude Opus 5.5 authored and bflatastic committed 2026-10-11 07:13:32 +07:00
1 parent af505b197a
commit c912ef59d1
2 files changed
+13 -1

No files matched your search

+6
View File
@@ -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());
}
+7 -1
View File
@@ -21,7 +21,13 @@ fn main() {
let people = read(&dir.join("people.toml"), "contributors are shown by username only", |t| t.parse::<toml::Table>().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());
}
}