Skip to content

fix(xtask): stop the Windows bundle script from re-entering cargo - #256

Merged
66HEX merged 2 commits into
66HEX:masterfrom
CSEliot:fix/xtask-bundle-windows-reentry
Nov 21, 2026
Merged

66HEX merged 2 commits into
66HEX:masterfrom
CSEliot:fix/xtask-bundle-windows-reentry

Conversation

@CSEliot

@CSEliot CSEliot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #254.

cargo xtask bundle windows could not complete on Windows. The bundle command spawns script/bundle-windows.ps1 while the xtask.exe image is still running, and the script's first cargo step re-enters cargo with cargo xtask setup-ffmpeg. cargo run exports CARGO_MANIFEST_DIR and the other package variables into the child; ring fingerprints CARGO_MANIFEST_DIR through cargo:rerun-if-env-changed, so the nested build saw a different value, rebuilt the TLS stack, and tried to relink the running xtask.exe. Windows rejects that with failed to remove file ... Access is denied (os error 5).

Changes

  • tooling/xtask/src/main.rs
    • bundle windows runs setup_ffmpeg in-process before spawning the script and forwards -SkipSetupFfmpeg. Setup is skipped for -Help, -PackageOnly, an explicit -SkipSetupFfmpeg, and any -Architecture/-a value other than x86_64 (space-separated, -Architecture:value, and a dangling switch included), so those invocations reach the script's own diagnostic without touching the binary cache. A non-Windows host gets the existing Windows-only usage error before any download.
    • run_command strips the cargo run package environment (CARGO_MANIFEST_DIR, CARGO_MANIFEST_PATH, CARGO_PKG_*) from child processes, so cargo builds inside the script fingerprint the same as a plain-shell run. Without that, the documented command and a direct script run would keep invalidating each other's fingerprints, including a full release-profile rebuild.
    • Five unit tests for the argument plumbing, the architecture/skip predicate, and the environment predicate.
  • script/bundle-windows.ps1
    • New -SkipSetupFfmpeg switch, documented in -Help, with an early existence check for both runtime binaries. The runtime binary paths are now resolved by one helper shared with Prepare-BundleDirectory.
    • Default behavior is unchanged: without the switch the script still runs cargo xtask setup-ffmpeg, which is how CI and direct script runs invoke it.

Testing

  • cargo xtask bundle windows completes end to end on Windows 11 (rustc/cargo 1.95.0, Inno Setup 6.7.1): exit 0, Successful compile (108.359 sec), target/Frame-x86_64.exe written. The log shows the script launched with -SkipSetupFfmpeg and no nested cargo xtask.
  • -Help, -Architecture arm64, -Architecture:arm64, and a dangling -Architecture all reach their diagnostics with no Detected Windows ... Preparing FFmpeg line.
  • script/bundle-windows.ps1 -Architecture x86_64 -PrepareOnly still runs cargo xtask setup-ffmpeg, stages the same inputs, and exits 0.
  • cargo fmt --manifest-path tooling/xtask/Cargo.toml --check passes; the five new unit tests pass.
  • The new code is clean under cargo clippy --all-targets -- -D warnings. A bare run on Windows still fails on pre-existing lints only (frame-updater dead code and the non-Unix make_file_executable variant, both present on 8fe5aa1); with those allowed, clippy exits 0. The full xtask test suite has four pre-existing failures on this CRLF checkout (workflow/dependabot string assertions and bash-mock tests), also present on 8fe5aa1.
  • Fingerprint check after the run: ring's CARGO_MANIFEST_DIR entry is null in target/x86_64-pc-windows-msvc/release, i.e. the scrubbed child build matches a plain-shell invocation. The target/debug entry is also null, but that build came from a plain-shell invocation, so it says nothing about the bundle path.

Notes

  • No workflow changes; .github/workflows is generated by cargo xtask workflows and untouched.
  • bundle-linux and bundle-mac still call cargo xtask setup-ffmpeg, but the env scrub means that nested build no longer sees a spurious environment difference; on Unix a running binary can be replaced, so the failure mode there is only wasted rebuild time.

@CSEliot
CSEliot requested a review from 66HEX as a code owner November 14, 2026 13:36
@CSEliot
CSEliot force-pushed the fix/xtask-bundle-windows-reentry branch from 1374932 to a426f32 Compare November 14, 2026 13:46
@CSEliot CSEliot changed the title fix(xtask): prepare Windows FFmpeg binaries before the bundle script fix(xtask): stop the Windows bundle script from re-entering cargo Nov 14, 2026
`cargo xtask bundle windows` spawned script/bundle-windows.ps1 while the
xtask process was still mapped, and the script re-entered cargo through
`cargo xtask setup-ffmpeg`. `cargo run` exports package variables into
the child, so the nested build recorded a different CARGO_MANIFEST_DIR
for ring, rebuilt the TLS stack, and tried to relink the running
xtask.exe, which Windows rejects with `Access is denied` (os error 5).

Run setup_ffmpeg inside xtask before spawning the script, forward
-SkipSetupFfmpeg so the script does not re-enter cargo, and strip the
cargo run package environment from child processes so cargo builds
inside the script match a plain-shell invocation. setup_ffmpeg is
skipped for -Help, -PackageOnly, an explicit -SkipSetupFfmpeg and any
architecture other than x86_64, so those paths keep their existing
diagnostics without touching the binary cache. Direct script runs and CI
keep their current behavior because the switch defaults to off.

Fixes 66HEX#254.

@66HEX 66HEX left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the thorough diagnosis and clean fix! The in-process setup_ffmpeg handling, env scrubbing, and unit tests all look solid.

@66HEX
66HEX merged commit 2d031aa into 66HEX:master Nov 21, 2026
9 checks passed
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.

[Bug]: cargo xtask bundle windows fails on Windows: nested cargo cannot replace the running xtask.exe

2 participants