fix(rust_analyzer): resolve external crate sources via output_base, not execroot - #4212
Open
lsjostro wants to merge 1 commit into
Open
fix(rust_analyzer): resolve external crate sources via output_base, not execroot#4212lsjostro wants to merge 1 commit into
lsjostro wants to merge 1 commit into
Conversation
…ot execroot
gen_rust_project emits external crate paths through the execution root
(__EXEC_ROOT__/external/...). The execroot's external/ symlinks are
ephemeral -- only guaranteed to exist while a build action is running --
so once the build finishes those paths dangle and rust-analyzer cannot
read any external crate sources. The result is no completions, no
go-to-definition, and no docs for third-party dependencies.
The real, stable location of external repository sources is
{output_base}/external/. Rewrite {execution_root}/external/ prefixes to
{output_base}/external/ during template substitution, while leaving
bazel-out/ paths (generated files) under the execution root where they
belong.
Fixes the first bug described in bazelbuild#4057.
Assisted-by: Claude (Anthropic AI assistant)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the first bug described in #4057 (as requested by @UebelAndre there, this PR covers Bug 1 only; Bug 2 will get its own issue).
Problem
gen_rust_projectemits external crate paths through the execution root:The execroot's
external/symlinks are ephemeral — they are only guaranteed to exist while a build action is running — so once the build finishes these paths dangle. rust-analyzer then cannot read any external crate sources: no completions, no go-to-definition, no inline docs for third-party dependencies (anyhow,serde,clap, …).The stable location of external repository sources is
{output_base}/external/.Fix
In
deserialize_with_substitution, rewrite{execution_root}/external/prefixes to{output_base}/external/after the existing template substitutions.bazel-out/paths (generated files) are unaffected and stay under the execution root where they belong.Testing
Added a unit test covering the four path shapes (external via
__EXEC_ROOT__, generated file underbazel-out/,__OUTPUT_BASE__, and__WORKSPACE__); it fails without the fix and passes with it. We have also been running this fix as a patch on top of rules_rust in our bzlmod monorepo, where it restores full rust-analyzer IDE support for external crates.Per the AI tools policy: this change was prepared with LLM assistance (see
Assisted-bycommit trailer), reviewed and tested by me.