From 0218ace91c2bb6038fe47bc3e6ac8a86cc578ff3 Mon Sep 17 00:00:00 2001 From: Sebastian Neubauer Date: Fri, 16 Aug 2024 21:06:14 +0200 Subject: [PATCH] fix(android): avoid rebuilds if nothing changed (#1342) * fix(android): avoid rebuilds if nothing changed Unconditionally overwriting files where the build reruns if they changed leads to rebuilds every time. Only overwrite a file if its content is different to not rebuild in such a case. * Update build.rs --------- Co-authored-by: Lucas Fernandes Nogueira --- build.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 712a9e7a9..c977e2dfb 100644 --- a/build.rs +++ b/build.rs @@ -92,7 +92,10 @@ fn main() { out.push_str(&content); let out_path = kotlin_out_dir.join(file.file_name()); - fs::write(&out_path, out).expect("Failed to write kotlin file"); + // Overwrite only if changed to not trigger rebuilds + if fs::read_to_string(&out_path).map_or(true, |o| o != out) { + fs::write(&out_path, out).expect("Failed to write kotlin file"); + } println!("cargo:rerun-if-changed={}", out_path.display()); } }