diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index d6e1faa28c58eb..adda3497250853 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -241,6 +241,10 @@ config ARCH_DEFCONFIG default "arch/x86/configs/i386_defconfig" if X86_32 default "arch/x86/configs/x86_64_defconfig" if X86_64 +config ARCH_RUST_TARGET + string + default "x86_64-linux-kernel" if X86_64 + config LOCKDEP_SUPPORT def_bool y diff --git a/init/Kconfig b/init/Kconfig index b4daad2bac233c..cd16edd51fdc02 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1951,6 +1951,32 @@ config PROFILING config TRACEPOINTS bool +config HAS_RUST + def_bool $(success,rustc --version) + +config HAS_CARGO + def_bool $(success,cargo --version) + +config MENU_RUST + bool "Enables building kernel modules written in Rust" + depends on HAS_RUST + depends on HAS_CARGO + help + Whether to support building modules written in Rust. + +config RUST_DISABLE + bool + depends on RUST_MENU + help + This option disables the support for Rust, so that make + allyesconfig and make allmodconfig will not enable it. To + build modules written in Rust, leave this option set to 'n'. + +config RUST + bool + default y + depends on RUST_MENU && !RUST_DISABLE + endmenu # General setup source "arch/Kconfig" diff --git a/scripts/Makefile.build b/scripts/Makefile.build index f72aba64d611d2..9515eca591fc1e 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -283,6 +283,19 @@ quiet_cmd_cc_lst_c = MKLST $@ $(obj)/%.lst: $(src)/%.c FORCE $(call if_changed_dep,cc_lst_c) +# Compile Rust sources +# -------------------- + +ifdef CONFIG_RUST +CARGO ?= cargo + +# TODO: release/debug +$(obj)/%.rust.o: $(src)/Cargo.toml $(src)/Cargo.lock $(wildcard $(src)/src/*.rs) FORCE + cd $(src); env -u MAKE -u MAKEFLAGS KDIR="$(CURDIR)/$(srctree)" $(CARGO) build -Z build-std=core,alloc --target=$(CONFIG_ARCH_RUST_TARGET) + $(LD) -r -o $@ --whole-archive $(src)/target/$(CONFIG_ARCH_RUST_TARGET)/debug/lib$(patsubst %.rust.o,%.a,$(@F)) + +endif + # header test (header-test-y, header-test-m target) # ---------------------------------------------------------------------------