Skip to content

Fix rustfmt silently skipping symlinked sources#4002

Open
tamasvajk wants to merge 4 commits intobazelbuild:mainfrom
tamasvajk:rustfmt-symlinked-sources
Open

Fix rustfmt silently skipping symlinked sources#4002
tamasvajk wants to merge 4 commits intobazelbuild:mainfrom
tamasvajk:rustfmt-symlinked-sources

Conversation

@tamasvajk
Copy link
Copy Markdown
Contributor

Summary

Fix rustfmt_test and rustfmt_aspect silently skipping hand-written sources that were symlinked by transform_sources().

Problem

When any compile_data entry is a generated file, transform_sources() symlinks all source files into bazel-out. After symlinking, is_source returns False for these files, so _find_rustfmtable_srcs filters them all out. The result is that rustfmt silently does nothing — no error, no formatting check.

Fix

When the aspect context is available, recover original source File objects from the rule's srcs attribute (which still references the pre-symlink originals). This preserves correct exec_path and short_path for manifests and runfiles.

Also use crate_info.srcs directly in _rustfmt_test_impl to include all sources.


Note: This PR was largely AI-generated using Claude Code, with human review and guidance throughout.

Tamas Vajk added 4 commits April 28, 2026 13:59
When transform_sources() symlinks hand-written .rs files into
bazel-out (which happens when any compile_data entry is generated),
the symlinked files are no longer is_source=True. This causes
_find_rustfmtable_srcs to filter them all out, silently skipping
formatting for the entire crate.

Fix by recovering original source files from the aspect context's
rule attributes when available. Also use crate_info.srcs directly
in rustfmt_test to include all sources.
Add a test case with an intentionally unformatted source file and
generated compile_data. This triggers transform_sources to symlink
sources into bazel-out, exercising the fix in _find_rustfmtable_srcs.

Without the fix, rustfmt silently passes (sources are skipped).
With the fix, rustfmt correctly detects the formatting issue.
The test uses an intentionally unformatted source and is expected to
fail. Including it in the test_suite causes CI to run it via //...
and report failures. The test is already exercised by the
rustfmt_failure_tester.sh script which expects exit code 3.
The unformatted source caused CI failures:
- --config=rustfmt aspect caught the formatting issue during build
- rustfmt_failure_tester.sh couldn't format it due to norustfmt tag

Use a properly formatted source instead. The test still exercises
the code path where compile_data has a generated file (triggering
transform_sources), verifying that rustfmt correctly finds and
checks the sources rather than silently skipping them.
@tamasvajk tamasvajk force-pushed the rustfmt-symlinked-sources branch from 7390345 to 34b71b4 Compare April 28, 2026 16:56
@UebelAndre
Copy link
Copy Markdown
Collaborator

@tamasvajk Does #3983 solve for your needs? This seems to be solving a similar issue to #3850

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.

2 participants