Skip to content

Remap relative bin-dir prefix for file!() and log macros#4017

Open
tamasvajk wants to merge 1 commit intobazelbuild:mainfrom
tamasvajk:remap-file-macro-symlinked-sources
Open

Remap relative bin-dir prefix for file!() and log macros#4017
tamasvajk wants to merge 1 commit intobazelbuild:mainfrom
tamasvajk:remap-file-macro-symlinked-sources

Conversation

@tamasvajk
Copy link
Copy Markdown
Contributor

Summary

Companion to #4016. While #4016 fixes --remap-path-prefix for absolute paths in debug info (backtraces, panic locations), this PR adds a remap for the relative bazel-out/<config>/bin/ prefix so that file!(), Location::caller(), and tracing/log macros also produce clean workspace-relative paths when sources are symlinked by transform_sources().

Problem

When a target mixes generated and non-generated sources, transform_sources() symlinks all source files into bazel-out/<config>/bin/.... The existing --remap-path-prefix=${pwd}=. only affects absolute paths embedded in debug info. However, file!(), Location::caller(), and log macros embed the literal relative path that rustc received on the command line. These are not matched by the ${pwd} remap, so they produce paths like:

bazel-out/k8-fastbuild/bin/my/pkg/lib.rs

instead of:

my/pkg/lib.rs

Fix

When crate_info.root.is_source is False (symlinked sources), add a second remap that strips the relative bin-dir prefix:

--remap-path-prefix=bazel-out/<config>/bin/=

This complements the existing absolute-path remaps and ensures compile-time paths are also clean.

Tests

  • Analysis tests: Verify the relative bin-dir remap flag is present for generated-source targets and absent for plain source targets.
  • Runtime test: A library with generated sources exposes file!() and a test asserts the returned path does not contain bazel-out.

When transform_sources() symlinks sources into bazel-out/<config>/bin/,
file!(), Location::caller(), and tracing/log macros embed the literal
relative path rustc received on the command line. The existing ${pwd}
remap only matches absolute paths in debug info.

Add a second --remap-path-prefix for the relative bazel-out/<config>/bin/
prefix (without ${pwd}) so these compile-time paths are also clean.

Add analysis tests verifying the flag is present for generated sources
and absent for plain sources, plus a runtime test confirming file!()
returns a clean path.
@tamasvajk tamasvajk force-pushed the remap-file-macro-symlinked-sources branch from f0549c1 to d784ae6 Compare May 5, 2026 09:30
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