From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793816533; b=Vd5Cv3zXXzfCNSdEwKSqbrfjj+yr9kbG/FEsCgoPe178RuN2Vj5M2qglG9Yhw/sqPNCb elSFmKMMY1IjSscW08EtfmFN7TXldv9cMx/sK1Bm3soc3Zcl11ku37BoEWdShlkIcHwHe TIT02TFfVzEzCWr1HqP4KYVuzB6Fx2gft02tV5jnEU2cskDFMfE19ryNc0xi+CrPZf/K2 +BWI63ugtRnIjmhyJMmZv1HPQCkxJNVx7CIJSPwYCR7+xuB+JnKbtUNxHLusubMISuXPh Yo3/KDuvT9MzJX4hIM6/HoRaAwexLazlCOvmVMTbHoUVhVC4Cc1xKK+XxYAnisPitnQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793816533; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=Ae44f96zItRoMnEuDxqCncdEeGbSJAWzgR3XJgNUP70=; b=46m2GwE2YtzGbwajKu8FMdTZ6tODjMhI8qhwYdSSPdBWfzbFZ8L9gGoAxjrNl/H805pD JAhDTfse08X/559MJsqZTdl4RMa085XuSfwbsiDzpciXxGDatwQybhF8B24XsaFKfxvVW U2KWyVwHajlAUOeCkpdU5CBa22VgMZZzhLuP3gg+GO/xtTqJtzG3XCkRMaq91ttHAy73a YTnhbL9WoQEMpOsZX8JaW8MGs6/zsGjIk8rVLiiok/6yrDjI8EaHidaDulU7mT2ZWZ8Q3 KGt3SuCJhrDatxLA16uVT6x8G4tb+df0e05llILngj5e+UgSgXfOBji0ILq0wznJKng== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hs59Teb0; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBFFB606D2E3; Wed, 4 Nov 2026 18:22:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hs59Teb0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D60F31F00919; Wed, 4 Nov 2026 18:22:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793816532; bh=Ae44f96zItRoMnEuDxqCncdEeGbSJAWzgR3XJgNUP70=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=hs59Teb0yhtPbZ/h74PFv9MW9QEiSmAVJZFS1FTYTU7wnnWhQ+xAbwgVbAYow8NOK kNm7m5LEEPXZwIL3/mFGDobzskJxK93M/N0b/q2Ca8BpaZt//spk3eeIvY9G++OZcw 4rpVhepNM/4W5zzyt6cV96z1fU2SOzl5M4QgB3PJpff+AVM3eg5Xw1WjNf33AkG6Wv nv0dT4p3APoOknaWM0NYIgd5mwZPN4gfBuBv83NtoAIOe+pzo09qaH2QvYZh6he+yY CUfaQFr7NBy1yH99osmwcdRkn/gfT+i+2lUCsssJUpEWPGgVLdD010bnqXQANuhAI5 agXgV8P4XmsUQ== From: "Lorenzo Stoakes (ARM)" Date: Wed, 04 Nov 2026 18:20:29 +0000 Subject: [PATCH v5 11/11] kbuild: build rust crates in parallel with the rest of the build X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261104-build-speedup-v5-11-0f6018be8dae@kernel.org> References: <20261104-build-speedup-v5-0-0f6018be8dae@kernel.org> In-Reply-To: <20261104-build-speedup-v5-0-0f6018be8dae@kernel.org> To: Linus Torvalds , Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Geert Uytterhoeven , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Josh Poimboeuf , Peter Zijlstra , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= Cc: ljs@kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4608; i=ljs@kernel.org; h=from:subject:message-id; bh=FgSgFDAAcTPCFUAL+8odpu2fPm2OKUlCsBm/ENgnc8s=; b=owGbwMvMwCV2fu7ZrsZH9SKMp9WSGLJel+dt0LuyaXfbNOY9pR3zHT59b3wuq7N+5vIGXd416 /y27p2zsqOUhUGMi0FWTJHl+Rfx/UEiYfM6L/i7wcxhZQIZwsDFKQAT0bnPyPDKR156gdy8xyn+ XOs3/2qaNFnmS1Okr+/+sssq67LnHuxj+Kfd4V8/8eaSHOESDtVr3Llfb9WalTZuZey8J2rfyPJ Thg0A X-Developer-Key: i=ljs@kernel.org; a=openpgp; fpr=E7F417BF5214569E89D04F46CF9DCD8A81E27F14 When CONFIG_RUST is specified make prepare builds all of the rust components before descending into the tree. This means nothing can be done until all of these are compiled, resulting in a stall at the start of every clean CONFIG_RUST build. This also implicitly slows down every rust-capable LLVM allmodconfig build as this enables the CONFIG_RUST option. Fix this by allowing rust crates to be built alongside the C code. Remove the rust build from the make prepare step, then establish a dependency between rust code located elsewhere in the tree upon rust components contained in rust/. Do this by establishing a top-level list of directories containing rust code, KBUILD_RUST_DIRS, upon which the dependency is expressed. Finally, ensure that no rust code is located elsewhere and fail the build if any is found to ensure that nothing is missed in future. Care is taken to ensure the rust/ dependency is also established for any module being built to account for external rust modules which rely upon it, and that only one rust/ build will be performed at any one time. External rust modules builds are unaffected - make modules_prepare ... (where ... are other goals) will build rust/ first. The rustdoc and rusttest goals invoke rust/ directly rather than via Kbuild, so build rust/ first there too. Every Rust and C object was confirmed to be byte-for-byte identical after this change. Whole build, 128-thread Threadripper 9980X, best of N runs: before after delta ------------------------------- x86 defconfig+RUST, clean 36.5s 32.6s -3.9s (-11%) x86 allmodconfig, clean 297.0s 278.3s -18.7s (-6%) Signed-off-by: Lorenzo Stoakes (ARM) --- Kbuild | 5 +++++ Makefile | 17 ++++++++++++++++- scripts/Makefile.build | 5 ++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Kbuild b/Kbuild index a6a0192dea08..9670556059dd 100644 --- a/Kbuild +++ b/Kbuild @@ -115,3 +115,8 @@ obj-$(CONFIG_NET) += net/ obj-y += virt/ obj-y += $(ARCH_DRIVERS) obj-$(CONFIG_DRM_HEADER_TEST) += include/ + +# Rust code elsewhere in the tree depends upon rust/. +ifdef CONFIG_RUST +$(KBUILD_RUST_DIRS): | rust +endif diff --git a/Makefile b/Makefile index 7c254b8657a3..de4cc052af03 100644 --- a/Makefile +++ b/Makefile @@ -1416,11 +1416,14 @@ prepare0: archprepare $(Q)$(MAKE) $(build)=. prepare $(Q)$(MAKE) $(build)=scripts/mod +ifdef CONFIG_RUST +export KBUILD_RUST_DIRS := drivers lib mm samples +endif + # All the preparing.. prepare: prepare0 ifdef CONFIG_RUST +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh - $(Q)$(MAKE) $(build)=rust endif PHONY += remove-stale-files @@ -1767,6 +1770,14 @@ modules: modules_prepare # Target to prepare building external modules modules_prepare: prepare $(Q)$(MAKE) $(build)=scripts scripts/module.lds +ifdef CONFIG_RUST +# Avoid two instances of rust/ being built at any one time. +ifneq ($(filter modules_prepare,$(MAKECMDGOALS)),) +ifeq ($(filter all vmlinux modules %Image% dtbs rustdoc rusttest,$(MAKECMDGOALS)),) + $(Q)$(MAKE) $(build)=rust +endif +endif +endif endif # CONFIG_MODULES @@ -2035,13 +2046,17 @@ rustavailable: # Documentation target # # Using the singular to avoid running afoul of `no-dot-config-targets`. +# +# rust/ is built alongside the rest of the tree, so must be built first here. PHONY += rustdoc rustdoc: prepare + $(Q)$(MAKE) $(build)=rust $(Q)$(MAKE) $(build)=rust $@ # Testing target PHONY += rusttest rusttest: prepare + $(Q)$(MAKE) $(build)=rust $(Q)$(MAKE) $(build)=rust $@ # Formatting targets diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 7b652f169a8f..ec4e220d6831 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -381,8 +381,11 @@ quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ $(cmd_ld_single)) \ $(cmd_objtool) +rust-dir-ok = $(or $(KBUILD_EXTMOD),$(filter rust $(KBUILD_RUST_DIRS),$(firstword $(subst /, ,$@)))) + +# Ensure that any rust code located elsewhere from rust/ is listed in KBUILD_RUST_DIRS. define rule_rustc_o_rs - $(call cmd_and_fixdep,rustc_o_rs) + $(if $(rust-dir-ok),,$(error $@: Rust code in a directory not listed in KBUILD_RUST_DIRS, see the top Makefile))$(call cmd_and_fixdep,rustc_o_rs) $(call cmd,gen_objtooldep) endef -- 2.56.0