[PATCH] kbuild, rust: use -fremap-path-prefix to make paths relative

From: Thomas Weißschuh
Date: Mon Feb 10 2025 - 12:11:24 EST


Remap source path prefixes in all output, including compiler
diagnostics, debug information, macro expansions, etc.
This removes a few absolute paths from the binary and also makes it
possible to use core::panic::Location properly.

Equivalent to the same configuration done for C sources in
commit 1d3730f0012f ("kbuild: support -fmacro-prefix-map for external modules")
and commit a73619a845d5 ("kbuild: use -fmacro-prefix-map to make __FILE__ a relative path").

Link: https://doc.rust-lang.org/rustc/command-line-arguments.html#--remap-path-prefix-remap-source-names-in-output
Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
---
Makefile | 1 +
1 file changed, 1 insertion(+)

diff --git a/Makefile b/Makefile
index 9e0d63d9d94b90672f91929e5e148e5a0c346cb6..ac35083180c825b72f13149ec3acfd7d6d74ef98 100644
--- a/Makefile
+++ b/Makefile
@@ -1068,6 +1068,7 @@ endif
# change __FILE__ to the relative path to the source directory
ifdef building_out_of_srctree
KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srcroot)/=)
+KBUILD_RUSTFLAGS += $(call rustc-option,--remap-path-prefix=$(srcroot)/=)
endif

# include additional Makefiles when needed

---
base-commit: beeb78d46249cab8b2b8359a2ce8fa5376b5ad2d
change-id: 20250210-rust-path-remap-e97cec71e61a

Best regards,
--
Thomas Weißschuh <linux@xxxxxxxxxxxxxx>