Skip to content

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

Closed

Description

@CSEliot

Frame version

0.34.0, built from source at 66HEX/frame 8fe5aa1

Operating system

Windows

Operating system version

Windows 11, 10.0.26200.9711

Source media details

git clone of https://github.com/66HEX/frame, built from source; Inno Setup 6.7.1 installed machine-wide via Chocolatey; rustc/cargo 1.95.0 with the toolchain pinned by rust-toolchain.toml

Steps to reproduce

  1. Clone the repo and confirm rustup target add x86_64-pc-windows-msvc succeeds.
  2. Install Inno Setup 6.
  3. Run cargo xtask bundle windows.

Expected behavior

The Windows installer is built at target\Frame-x86_64.exe.

Actual behavior

The command fails before packaging, on every attempt (2 of 2 here):

error: failed to remove file `C:\...\frame\target\debug\xtask.exe`

Caused by:
  Access is denied. (os error 5)
cargo exited with status 101

Running the underlying script directly succeeds and produces target\Frame-x86_64.exe:

powershell -NoProfile -ExecutionPolicy Bypass -File .\script\bundle-windows.ps1

Details

The bundle path re-enters cargo while the xtask process that spawned it is still running:

  1. .cargo/config.toml aliases xtask to run --package xtask --, so cargo builds and starts target\debug\xtask.exe.
  2. bundle("windows") (tooling/xtask/src/main.rs:185) spawns script/bundle-windows.ps1 through run_script (:1690) and run_command (:1714). run_command uses Command::status() with inherited stdio, so it blocks until the script exits, and the xtask.exe image stays mapped the whole time.
  3. script/bundle-windows.ps1:123 runs cargo xtask setup-ffmpeg ..., a nested cargo build in the same target directory. It decides xtask must be relinked, but Windows will not replace a running image, hence os error 5.

Why the nested build is always dirty: cargo run injects CARGO_MANIFEST_DIR, CARGO_MANIFEST_PATH and CARGO_PKG_* into the process it starts. Verified with a minimal binary: under cargo run those variables are set to the crate's own values; the same exe run directly has them unset.

ring's build script declares cargo:rerun-if-env-changed=CARGO_MANIFEST_DIR itself (ring-0.17.14/build.rs:38, read at :272). Cargo records the value from its own process environment, not from the build script's environment: the script always sees its own crate directory (ring's build.rs calls .expect("CARGO_MANIFEST_DIR should always be set")), yet the stored fingerprint value is null in a plain-shell build.

The two contexts therefore disagree, with this trace from the nested case:

dirty: EnvVarChanged { name: "CARGO_MANIFEST_DIR",
  old_value: None,
  new_value: Some("C:\\Users\\Eliot\\Applications\\frame\\tooling\\xtask") }

(CARGO_LOG=cargo::core::compiler::fingerprint=trace with that variable exported; the following plain build reports the reverse, Some -> None.) Each attempt flips the recorded value, so one of the two contexts is always dirty and re-running cannot get further. In the failing logs the rebuild covers ring, rustls, rustls-webpki, tokio-rustls, ureq, hyper-rustls, reqwest, frame-updater, and finally xtask, whose relink fails.

Minimal reproduction without ring, in a crate whose build.rs only prints cargo:rerun-if-env-changed=CARGO_MANIFEST_DIR:

  • cargo build (first): compiles
  • cargo build (again): clean
  • CARGO_MANIFEST_DIR=<any path> cargo build: compiles
  • cargo build (plain again): compiles

The same recursion exists on the other platforms: script/bundle-linux:110 and script/bundle-mac:77 also call cargo xtask setup-ffmpeg. On Unix a running binary can be replaced, so the expected cost there is rebuild time instead of a hard failure (reasoning; not tested on a Unix host).

This is the documented release path (README.md:305-317, CONTRIBUTING.md:194-196, frame-app/README.md:24). CI does not hit it because the workflows call the scripts directly (release.yml:446, run_bundling.yml), so the failure is invisible there.

The direct-script workaround works because no xtask.exe image is mapped when the nested cargo run builds and runs it, which is also the control experiment for this diagnosis.

Suggested fix

  1. Run setup-ffmpeg inside xtask before spawning the script, then pass a flag so the script skips its own cargo xtask setup-ffmpeg step. The script's remaining cargo calls build release binaries for the target triple, not host xtask, so no running image is relinked. Note that .github/workflows are generated (cargo xtask workflows), so CI-side changes belong in the generator.
  2. Alternatively, have the script call target\debug\xtask.exe setup-ffmpeg ..., but only as a fast path with a cargo run --package xtask -- fallback: CI and the documented script path start from a bare checkout where that binary does not exist, and a stale binary would silently run old code.
  3. As a mitigation, scrub CARGO_MANIFEST_DIR, CARGO_MANIFEST_PATH and CARGO_PKG_* when spawning the script. That removes this flip but not environment changes the script makes itself (the dev shell import sets variables ring also tracks), so it is not sufficient alone.

Activity

  1. added 2 commits that reference this issue on Nov 14, 2026
    a426f32
    2435533
  2. added a commit that references this issue on Nov 21, 2026
    2d031aa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions