Skip to content

Commit

Permalink
fix(android): avoid rebuilds if nothing changed (#1342)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Flakebi and lucasfernog authored Aug 16, 2024
1 parent 38abcb9 commit 0218ace
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down

0 comments on commit 0218ace

Please sign in to comment.