Skip to content

Adjust --remap-path-prefix for targets with generated sources#4016

Open
tamasvajk wants to merge 3 commits intobazelbuild:mainfrom
tamasvajk:remap-symlinked-sources
Open

Adjust --remap-path-prefix for targets with generated sources#4016
tamasvajk wants to merge 3 commits intobazelbuild:mainfrom
tamasvajk:remap-symlinked-sources

Conversation

@tamasvajk
Copy link
Copy Markdown
Contributor

@tamasvajk tamasvajk commented May 5, 2026

Summary

Adjust --remap-path-prefix to 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 into bazel-out/<config>/bin/... so they sit next to the generated files. The existing --remap-path-prefix=${pwd}=. only strips the exec root prefix, leaving bazel-out/k8-fastbuild/bin/ in:

  • Diagnostics and compiler errors
  • Panic locations and backtraces
  • macOS N_OSO linker entries

For example, ./bazel-out/k8-fastbuild/bin/my/pkg/lib.rs instead of ./my/pkg/lib.rs.

Fix

Detect symlinked sources via crate_info.root.is_source and 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:

Tests

Updated the analysis tests in remap_path_prefix_test.bzl to cover both cases:

  • Source files: plain ${pwd}=. / ${exec_root}=. remapping
  • Generated sources: ${pwd}/<bin_dir>=. / ${exec_root}/<bin_dir>=. remapping

Tamas Vajk 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.
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.

1 participant