kernel: support building Rust in the kernel

With CONFIG_KERNEL_RUST pass RUSTC, BINDGEN, RUST_LIB_SRC and
LIBCLANG_PATH to the kernel build. These are the variables
scripts/rust_is_available.sh checks.

KERNEL_RUST is enabled by default with any Rust toolchain, selects
bindgen and follows the kernel's architecture requirements: ARM32 needs
little-endian ARMv7, and ARM32 and LoongArch require KASAN to be
disabled.

CONFIG_RUST makes further symbols visible, which kconfig asks for
because the generic configuration does not answer them. Answer them in
the generic configuration so that targets need no changes. Filter the
rustc and bindgen version texts out of the kernel configuration
comparison.

Suggested-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
This commit is contained in:
Daniel Golle committed 2026-10-30 12:06:08 +02:00
1 parent c59b9de355
commit 8ce797daed
4 files changed
+38 -1

No files matched your search

+10
View File
@@ -134,6 +134,16 @@ ifeq ($(call qstrip,$(CONFIG_EXTERNAL_KERNEL_TREE))$(call qstrip,$(CONFIG_KERNEL
KERNELRELEASE=$(LINUX_VERSION)
endif
ifdef CONFIG_KERNEL_RUST
include $(INCLUDE_DIR)/rust-values.mk
KERNEL_MAKE_FLAGS += \
RUSTC="$(RUSTC)" \
BINDGEN="$(STAGING_DIR_HOST)/bin/bindgen" \
RUST_LIB_SRC="$(STAGING_DIR_HOST)/lib/rustlib/src/rust/library" \
LIBCLANG_PATH="$(RUST_LIBCLANG_PATH)"
endif
KERNEL_MAKEOPTS = -C $(LINUX_DIR) $(KERNEL_MAKE_FLAGS)
ifdef CONFIG_USE_SPARSE
+11
View File
@@ -223,6 +223,7 @@ CONFIG_ALLOW_DEV_COREDUMP=y
# CONFIG_AMPERE_ERRATUM_AC04_CPU_23 is not set
# CONFIG_AMT is not set
# CONFIG_ANDROID_BINDER_IPC is not set
# CONFIG_ANDROID_BINDER_IPC_RUST is not set
# CONFIG_ANON_VMA_NAME is not set
# CONFIG_AOSONG_AGS02MA is not set
# CONFIG_APDS9160 is not set
@@ -717,6 +718,7 @@ CONFIG_BLK_DEV_LOOP_MIN_COUNT=8
# CONFIG_BLK_DEV_PMEM is not set
# CONFIG_BLK_DEV_RAM is not set
# CONFIG_BLK_DEV_RBD is not set
# CONFIG_BLK_DEV_RUST_NULL is not set
# CONFIG_BLK_DEV_SD is not set
# CONFIG_BLK_DEV_SR is not set
# CONFIG_BLK_DEV_THROTTLING is not set
@@ -1085,6 +1087,7 @@ CONFIG_CONSTRUCTORS=y
# CONFIG_CPUFREQ_ARCH_CUR_FREQ is not set
# CONFIG_CPUFREQ_DT is not set
# CONFIG_CPUFREQ_DT_PLATDEV is not set
# CONFIG_CPUFREQ_DT_RUST is not set
# CONFIG_CPUFREQ_VIRT is not set
# CONFIG_CPU_BIG_ENDIAN is not set
# CONFIG_CPU_BPREDICT_DISABLE is not set
@@ -2306,6 +2309,7 @@ CONFIG_FIB_RULES=y
# CONFIG_FIELDBUS_DEV is not set
CONFIG_FILE_LOCKING=y
# CONFIG_FIND_BIT_BENCHMARK is not set
# CONFIG_FIND_BIT_BENCHMARK_RUST is not set
# CONFIG_FIREWIRE is not set
# CONFIG_FIREWIRE_NOSY is not set
# CONFIG_FIRMWARE_EDID is not set
@@ -4814,6 +4818,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
# CONFIG_NOA1305 is not set
# CONFIG_NOP_USB_XCEIV is not set
# CONFIG_NOTIFIER_ERROR_INJECTION is not set
# CONFIG_NOVA_CORE is not set
# CONFIG_NOZOMI is not set
# CONFIG_NO_HZ is not set
# CONFIG_NO_HZ_FULL is not set
@@ -5731,6 +5736,12 @@ CONFIG_RTC_SYSTOHC_DEVICE="rtc0"
CONFIG_RT_MUTEXES=y
CONFIG_RUNTIME_TESTING_MENU=y
# CONFIG_RUST is not set
# CONFIG_RUST_BITMAP_HARDENED is not set
# CONFIG_RUST_BUILD_ASSERT_ALLOW is not set
# CONFIG_RUST_DEBUG_ASSERTIONS is not set
# CONFIG_RUST_FW_LOADER_ABSTRACTIONS is not set
CONFIG_RUST_OVERFLOW_CHECKS=y
# CONFIG_RUST_PHYLIB_ABSTRACTIONS is not set
# CONFIG_RV is not set
# CONFIG_RXGK is not set
CONFIG_RXKAD=y
+2
View File
@@ -26,7 +26,9 @@ CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES=.*
CONFIG_RUSTC_LLVM_VERSION=.*
CONFIG_RUSTC_SUPPORTS_.*=.*
CONFIG_RUSTC_VERSION=.*
CONFIG_RUSTC_VERSION_TEXT=.*
CONFIG_RUST_IS_AVAILABLE=.*
CONFIG_BINDGEN_VERSION_TEXT=.*
# CONFIG_SET_FS is not set
# CONFIG_TASKS_.* is not set
CONFIG_TOOLS_SUPPORT_RELR=.*
+15 -1
View File
@@ -416,6 +416,19 @@ config RUST_PANIC_IMMEDIATE_ABORT
all crates of a program, the standard library included, so this
applies to the whole build.
config KERNEL_RUST
bool
prompt "Enable Rust in the kernel" if RUST_TOOLCHAINOPTS
depends on USE_RUST_TOOLCHAIN
depends on aarch64 || (arm && arm_v7 && !BIG_ENDIAN && !KERNEL_KASAN) \
|| (loongarch64 && !KERNEL_KASAN) || x86_64
select BUILD_BINDGEN
default y
help
Builds bindgen and passes RUSTC/BINDGEN/RUST_LIB_SRC to the kernel
Kbuild, enabling CONFIG_RUST to be selected in the kernel .config.
riscv64 is excluded: kernel Rust on riscv64 requires CC_IS_CLANG.
config BUILD_BINDGEN
bool
prompt "Build bindgen (C-header to Rust bindings)" if RUST_TOOLCHAINOPTS
@@ -423,7 +436,8 @@ config BUILD_BINDGEN
select USE_LLVM_BUILD if !USE_LLVM_HOST && !USE_LLVM_PREBUILT
default y
help
Installs bindgen-cli to the host toolchain.
Installs bindgen-cli to the host toolchain. Required for kernel Rust.
Automatically selected by KERNEL_RUST.
config USE_CBINDGEN
bool