Skip to content

Re-invalidate build.rs when extracted CLI cache is removed#1480

Merged
SteveSandersonMS merged 2 commits into
mainfrom
tclem/cli-cache-rerun-if-changed
May 28, 2026
Merged

Re-invalidate build.rs when extracted CLI cache is removed#1480
SteveSandersonMS merged 2 commits into
mainfrom
tclem/cli-cache-rerun-if-changed

Conversation

@tclem
Copy link
Copy Markdown
Member

@tclem tclem commented May 28, 2026

When bundled-cli is OFF, build.rs downloads and extracts the Copilot CLI binary to a platform cache directory at build time, then emits cargo:rustc-cfg=has_extracted_cli so the runtime resolver knows where to look.

Problem: no rerun-if-changed directive watches the extracted binary itself. If the file disappears between builds (cache GC, rm -rf ~/Library/Caches, switching COPILOT_CLI_EXTRACT_DIR) and no other watched input changes, cargo treats the build script as up-to-date, replays the cached has_extracted_cli cfg, and the runtime resolver hits BinaryNotFound despite a "successful" build.

Fix:

  1. Add rerun-if-changed=<final_path> pointing at the extracted binary. Cargo's semantics for a missing path are "always rerun" — exactly the right behavior here.
  2. Only emit rustc-cfg=has_extracted_cli when final_path.is_file() holds after extraction, making the cfg honest about ground truth.

The bundled-cli ON path (embed mode) is unchanged.

  Generated via Copilot (Claude Opus 4.6) on behalf of @tclem

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>
Copilot AI review requested due to automatic review settings May 28, 2026 04:57
@tclem tclem requested a review from a team as a code owner May 28, 2026 04:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Rust SDK build-script cache invalidation for unbundled CLI builds, ensuring Cargo reruns build.rs when the extracted CLI binary cache is removed so runtime resolution stays consistent with build output.

Changes:

  • Adds a rerun-if-changed directive for the extracted CLI binary path.
  • Emits has_extracted_cli only when the expected extracted binary exists after the build-script extraction step.
Show a summary per file
File Description
rust/build.rs Updates unbundled CLI extraction invalidation and cfg emission logic.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@SteveSandersonMS SteveSandersonMS merged commit 986015b into main May 28, 2026
19 checks passed
@SteveSandersonMS SteveSandersonMS deleted the tclem/cli-cache-rerun-if-changed branch May 28, 2026 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants