Skip to content

Commit b2aa153

Browse files
committed
rust: kbuild: support global per-version flags
Sometimes it is useful to gate global Rust flags per compiler version. For instance, we may want to disable a lint that has false positives in a single version [1]. We already had helpers like `rustc-min-version` for that, which we use elsewhere, but we cannot currently use them for `rust_common_flags`, which contains the global flags for all Rust code (kernel and host), because `rustc-min-version` depends on `CONFIG_RUSTC_VERSION`, which does not exist when `rust_common_flags` is defined. Thus, to support that, introduce `rust_common_flags_per_version`, defined after the `include/config/auto.conf` inclusion (where `CONFIG_RUSTC_VERSION` becomes available), and append it to `rust_common_flags`, `KBUILD_HOSTRUSTFLAGS` and `KBUILD_RUSTFLAGS`. In addition, move the expansion of `HOSTRUSTFLAGS` to the same place, so that users can also override per-version flags [2]. Link: https://lore.kernel.org/rust-for-linux/CANiq72mWdFU11GcCZRchzhy0Gi1QZShvZtyRkHV2O+WA2uTdVQ@mail.gmail.com/ [1] Link: https://lore.kernel.org/rust-for-linux/CANiq72mTaA2tjhkLKf0-2hrrrt9rxWPgy6SfNSbponbGOegQvA@mail.gmail.com/ [2] Link: https://patch.msgid.link/20260307170929.153892-1-ojeda@kernel.org Link: https://patch.msgid.link/20260405235309.418950-33-ojeda@kernel.org Reviewed-by: Tamir Duberstein <tamird@kernel.org> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 9e5946d commit b2aa153

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) \
506506
KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) \
507507
-I $(srctree)/scripts/include
508508
KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \
509-
-Zallow-features= $(HOSTRUSTFLAGS)
509+
-Zallow-features=
510510
KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
511511
KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
512512
KBUILD_PROCMACROLDFLAGS := $(or $(PROCMACROLDFLAGS),$(KBUILD_HOSTLDFLAGS))
@@ -836,6 +836,14 @@ endif # CONFIG_TRACEPOINTS
836836

837837
export WARN_ON_UNUSED_TRACEPOINTS
838838

839+
# Per-version Rust flags. These are like `rust_common_flags`, but may
840+
# depend on the Rust compiler version (e.g. using `rustc-min-version`).
841+
rust_common_flags_per_version :=
842+
843+
rust_common_flags += $(rust_common_flags_per_version)
844+
KBUILD_HOSTRUSTFLAGS += $(rust_common_flags_per_version) $(HOSTRUSTFLAGS)
845+
KBUILD_RUSTFLAGS += $(rust_common_flags_per_version)
846+
839847
include $(srctree)/arch/$(SRCARCH)/Makefile
840848

841849
ifdef need-config

0 commit comments

Comments
 (0)