VectorCraft: An open-source, vector art tool written by scratch in pure Rust
Build: generated sources are rewritten only when they change
Michael Giesonc912ef59d15c
diff --git a/crates/text/build.rs b/crates/text/build.rsindex 73c952faf..25544a3a6 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.rsindex f40007fb2..22fa00b26 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::<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());}}