Skip to content

Commit

Permalink
Don't recompile dpe every single time
Browse files Browse the repository at this point in the history
The build script always writes to `arbitrary_max_handles.rs`, which
means that a recompile is always required.

This then triggers a rebuild of any project (i.e., Caliptra) that uses
this.

This fixes is so that we only write the file if the contents need to be
changed, so the build can be cached.
  • Loading branch information
swenson committed Feb 3, 2025
1 parent 7679315 commit afcecc1
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions dpe/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Licensed under the Apache-2.0 license

use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

fn main() {
let default_value: usize = 24;
Expand All @@ -18,13 +17,13 @@ fn main() {
println!("cargo:rerun-if-env-changed=ARBITRARY_MAX_HANDLES");
println!("cargo:rerun-if-changed=build.rs");

let mut file = File::create(&dest_path).unwrap();
write!(
file,
"pub const MAX_HANDLES: usize = {};",
arbitrary_max_handles
)
.unwrap();
let max_handles_str = format!("pub const MAX_HANDLES: usize = {};", arbitrary_max_handles);

println!("cargo:rerun-if-changed={}", dest_path);
let dest_path = PathBuf::from(&dest_path);
if dest_path.exists() {
if std::fs::read_to_string(&dest_path).unwrap_or_default() != max_handles_str {
std::fs::write(&dest_path, max_handles_str).unwrap();
}
}
println!("cargo:rerun-if-changed={}", dest_path.display());
}

0 comments on commit afcecc1

Please sign in to comment.