Skip to content

Keep retained runfiles when draining on Windows without symlinks - #4429

Open
Mattbusel wants to merge 1 commit into
bazelbuild:mainfrom
Mattbusel:fix/windows-drain-retained-runfiles
Open

Mattbusel wants to merge 1 commit into
bazelbuild:mainfrom
Mattbusel:fix/windows-drain-retained-runfiles

Conversation

@Mattbusel

Copy link
Copy Markdown

Fixes #4266.

RunfilesMaker::drain_runfiles_dir_windows had its guard backwards. Its doc comment says only the non-retained entries are deleted, but the code skipped every entry that did not match a retain suffix and deleted the ones that did. On a Windows host where the Bazel server can't create symlinks, create_runfiles_dir copies every runfile into the tree, and then the drain removed exactly the .lib/.so files that were supposed to stay. Links that used those paths then failed with LNK1181.

What changed:

  • The Windows drain now skips retained entries and deletes the rest.
  • After deleting an entry it also removes the parent directories that are now empty, the same as drain_runfiles_dir_unix. That loop moved into a small remove_empty_parent_dirs helper so both paths share it, plus an is_retained helper for the suffix check.
  • New unit test drain_runfiles_dir_windows_keeps_retained_files builds a RunfilesMaker with a .lib and a .rs entry already copied into the output dir, drains it, and checks that only the .lib is left and the empty src/ dir is gone. The function isn't cfg-gated, so the test runs on Linux and macOS CI too.

Testing: I didn't have Bazel on this machine, so I compiled the crate directly with rustc --edition 2018 --test (it has no deps) and ran it with TEST_TMPDIR set.

  • Linux (WSL): all 13 lib tests and the 7 bin.rs tests pass. Clippy is clean.
  • Windows 11 without symlink privilege (the setup from the issue): the new test passes. With the old guard put back, it fails on the .lib assert. The existing replace_symlinks_in_out_dir test fails there with os error 1314 both before and after this change, because that test creates symlinks.

I used Claude (AI) to help write this change, per the AI tool policy in CONTRIBUTING. I read and checked all of it myself, and the commit has an Assisted-by: Claude trailer.

`drain_runfiles_dir_windows` skipped the entries that did not match a
retained suffix and deleted the ones that did, the opposite of its doc
comment. On Windows hosts without symlink privilege this removed the
`.lib`/`.so` files from the `cargo_runfiles` tree, so links against
them failed with LNK1181.

Delete the non-retained entries instead, and remove the directories
they leave empty, the same way the Unix drain does. The empty-parent
cleanup is moved into a shared helper.

Fixes bazelbuild#4266

Assisted-by: Claude

This branch has not been deployed

No deployments
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.

Windows (no-symlink path): drain_runfiles_dir_windows deletes retained runfiles — inverted filename_suffixes_to_retain condition

1 participant