Adjust --remap-path-prefix for targets with generated sources#4016
Open
tamasvajk wants to merge 3 commits intobazelbuild:mainfrom
Open
Adjust --remap-path-prefix for targets with generated sources#4016tamasvajk wants to merge 3 commits intobazelbuild:mainfrom
--remap-path-prefix for targets with generated sources#4016tamasvajk wants to merge 3 commits intobazelbuild:mainfrom
Conversation
added 3 commits
May 5, 2026 08:00
When transform_sources() symlinks source files into bazel-out/<config>/bin
(due to mixed generated and non-generated sources), the crate root path
starts with ctx.bin_dir.path. The existing --remap-path-prefix=${pwd}=.
only strips the exec root, leaving bazel-out/.../bin/ in diagnostics,
file!(), panic locations, and backtraces.
Use crate_info.root.is_source to detect symlinked sources and remap
${pwd}/<bin_dir> instead, producing clean workspace-relative paths.
Apply the same fix to ${exec_root} and macOS -oso_prefix.
Update analysis tests to cover both source and generated-source cases.
Use prefix/suffix matching instead of hardcoding k8-fastbuild in the bin dir path, so tests pass on macOS (darwin_arm64-fastbuild) too.
Update the comment to accurately list what --remap-path-prefix affects: debug info, dep-info, panic locations, and backtraces.
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.
Summary
Adjust
--remap-path-prefixto produce clean workspace-relative paths when a target has mixed generated and non-generated sources.Problem
When a Rust target mixes generated and non-generated source files (e.g. generated
compile_data),transform_sources()symlinks all source files intobazel-out/<config>/bin/...so they sit next to the generated files. The existing--remap-path-prefix=${pwd}=.only strips the exec root prefix, leavingbazel-out/k8-fastbuild/bin/in:For example,
./bazel-out/k8-fastbuild/bin/my/pkg/lib.rsinstead of./my/pkg/lib.rs.Fix
Detect symlinked sources via
crate_info.root.is_sourceand remap${pwd}/<bin_dir>(e.g.${pwd}/bazel-out/k8-fastbuild/bin) instead of just${pwd}, stripping the bin-dir component to produce clean workspace-relative paths. The same fix is applied to:${exec_root}remapping (canonicalized exec root paths, added in Remap path prefixes for canonicalized paths #3903)-oso_prefix(N_OSO stab entries, also added in Remap path prefixes for canonicalized paths #3903)Tests
Updated the analysis tests in
remap_path_prefix_test.bzlto cover both cases:${pwd}=./${exec_root}=.remapping${pwd}/<bin_dir>=./${exec_root}/<bin_dir>=.remapping