From 9b2e9d093c0596baa7a42328314af9799f863c83 Mon Sep 17 00:00:00 2001 From: Carl Lundin Date: Thu, 20 Feb 2025 12:52:44 -0800 Subject: [PATCH] Fix caliptra-sw cold build [Commit](https://github.com/chipsalliance/caliptra-dpe/commit/387034197f091694610c09548b2513731101ea54) improves the DPE build by checking if arbitrary_handles.rs has changed. Caliptra-sw fails to compile after this change if the build is cold, since the arbitrary_handles.rs file is never written to if it does not yet exist. --- dpe/build.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dpe/build.rs b/dpe/build.rs index 53c244da..69062feb 100644 --- a/dpe/build.rs +++ b/dpe/build.rs @@ -20,10 +20,16 @@ fn main() { let max_handles_str = format!("pub const MAX_HANDLES: usize = {};", arbitrary_max_handles); let dest_path = PathBuf::from(&dest_path); - if dest_path.exists() - && std::fs::read_to_string(&dest_path).unwrap_or_default() != max_handles_str - { - std::fs::write(&dest_path, max_handles_str).unwrap(); + match std::fs::read_to_string(&dest_path) { + // arbitrary_max_handles.rs changed so overwrite it's contents. + Ok(handles) if handles != max_handles_str => { + std::fs::write(&dest_path, max_handles_str).unwrap(); + } + // arbitrary_max_handles.rs does not exist. + Err(_) => { + std::fs::write(&dest_path, max_handles_str).unwrap(); + } + _ => (), } println!("cargo:rerun-if-changed={}", dest_path.display()); }