From dcaee4dcfc08428dcce08dc34941763daedb5b20 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Wed, 27 May 2026 21:56:50 -0700 Subject: [PATCH 1/2] Re-invalidate build.rs when extracted CLI cache is removed Add rerun-if-changed for the extracted binary path so cargo re-runs build.rs when the cached CLI disappears (cache GC, manual rm, OS reset, switching COPILOT_CLI_EXTRACT_DIR). Without this, cargo replays the saved has_extracted_cli cfg from its build-script output cache even when the file is gone, causing runtime BinaryNotFound failures despite a successful cargo build. Also gate the cfg emission on final_path.is_file() so the cfg is only set when the binary actually exists post-extraction. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- rust/build.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rust/build.rs b/rust/build.rs index 64659107e..e6512675b 100644 --- a/rust/build.rs +++ b/rust/build.rs @@ -106,6 +106,13 @@ fn main() { let install_dir = extracted_install_dir(&version); let final_path = install_dir.join(platform.binary_name); + // Invalidate build.rs whenever the cached binary disappears (cache GC, + // manual rm, OS reset, switching extract dir). Without this, cargo + // replays the saved `has_extracted_cli` cfg from its build-script + // output cache even when the file is gone, and runtime resolution + // fails with BinaryNotFound. + println!("cargo:rerun-if-changed={}", final_path.display()); + if !final_path.is_file() { let archive = cached_download( &format!("{base_url}/{}", platform.asset_name), @@ -117,7 +124,9 @@ fn main() { extract_to_cache(&archive, &install_dir, platform); } - println!("cargo:rustc-cfg=has_extracted_cli"); + if final_path.is_file() { + println!("cargo:rustc-cfg=has_extracted_cli"); + } } } From f68a6d1c09ccdd24c5983258eca133e27c02ef8c Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Wed, 27 May 2026 22:02:51 -0700 Subject: [PATCH 2/2] Add comment clarifying post-condition check on extracted binary Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- rust/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rust/build.rs b/rust/build.rs index e6512675b..630a0d100 100644 --- a/rust/build.rs +++ b/rust/build.rs @@ -124,6 +124,8 @@ fn main() { extract_to_cache(&archive, &install_dir, platform); } + // Re-check after potential download+extract above; not an `else` + // because we need to verify the extraction actually produced the file. if final_path.is_file() { println!("cargo:rustc-cfg=has_extracted_cli"); }