fix(rust_analyzer): resolve external crate sources via output_base, not execroot - #4212
fix(rust_analyzer): resolve external crate sources via output_base, not execroot#4212lsjostro 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)
|
Fresh datapoint on why this matters, re-measured today in our bzlmod monorepo (181 crates in Regenerating With the fix, all 556 references resolve via (Measured against a current rules_rust pin carrying the same |
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.