From patchwork Mon Sep 2 16:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13787526 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF49718028; Mon, 2 Sep 2024 16:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725296163; cv=none; b=kYjr3gBLeRANj94KeN+luWzdbiX/5xUn5lvbphAMXJn5PT9cQbtTN7ZzGbkkw34QfKlu/sRK57adWqNfGybTyBK9gts+n4RCKkzoO6WHR44J4SveZI9J41mZj8s+VPsFm3ypXnpbvwTFZxGvnC2gxYOHwGnVJPK+HF5BGTMLY0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725296163; c=relaxed/simple; bh=OPfqn3z0R6G80BF+F0Is94BhMTckTTROfEsTDwttcwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ctpPz90Z/fhu7xSprEFd80pqPlr4vcEhuNv8GFlHAZUeijBxrMa742tKfF0WRwmcchJqYF06HRsKjnbCskXi20XOkWc2hI7RIFEg8EXSEBuAmPUgXzZCNlGGnN8hYnN2/8uvdp6Mdk0h95cDbxe38E91Ip7QQpeJ0/r4JGusj18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O1/XA2T+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O1/XA2T+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 463B9C4CEC4; Mon, 2 Sep 2024 16:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725296162; bh=OPfqn3z0R6G80BF+F0Is94BhMTckTTROfEsTDwttcwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O1/XA2T+iWYzGRceF4UMC9ztBvI1WXW6LESJX6N5HL5uGF4UC59qf3hX3cYUe3ixn lUIAYgydwC098my2ArigaMCyHiN0HaJg5h+dfNm3WUqbRYhx97MVQbCPC6XBsYftrO 0Mk5pMHpTKDA2dKNgYGTKsZI49cPxGEonWMC/iFV2f4us7SV1ZYTVrznIM5755sTSK bEn4//mADwR5sKkdF0UAKU3p5LoUFFstZgDVfjy9OLIctcMj+B6XZbIneg5HIJNFtp CIBl1dpbpSkerSvdzuHG5hkGVb1IxqjJCyRpbs1Qxza3q2Mc1GbTMa8N8KyaQDCX4h hC3na/kevgCvQ== From: Miguel Ojeda To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Masahiro Yamada Cc: Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, Nathan Chancellor , Nicolas Schier , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH v2 1/6] kbuild: rust: add `CONFIG_RUSTC_VERSION` Date: Mon, 2 Sep 2024 18:55:28 +0200 Message-ID: <20240902165535.1101978-2-ojeda@kernel.org> In-Reply-To: <20240902165535.1101978-1-ojeda@kernel.org> References: <20240902165535.1101978-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that we support several Rust versions, introduce `CONFIG_RUSTC_VERSION` so that it can be used in Kconfig to enable and disable configuration options based on the `rustc` version. The approach taken resembles `pahole`'s -- see commit 613fe1692377 ("kbuild: Add CONFIG_PAHOLE_VERSION"), i.e. a simple version parsing without trying to identify several kinds of compilers, since so far there is only one (`rustc`). However, unlike `pahole`'s, we also print a zero if executing failed for any reason, rather than checking if the command is found and executable (which still leaves things like a file that exists and is executable, but e.g. is built for another platform [1]). An equivalent approach to the one here was also submitted for `pahole` [2]. Link: https://lore.kernel.org/rust-for-linux/CANiq72=4vX_tJMJLE6e+bg7ZECHkS-AQpm8GBzuK75G1EB7+Nw@mail.gmail.com/ [1] Link: https://lore.kernel.org/linux-kbuild/20240728125527.690726-1-ojeda@kernel.org/ [2] Reviewed-by: Nicolas Schier Tested-by: Alice Ryhl Signed-off-by: Miguel Ojeda --- init/Kconfig | 7 +++++++ scripts/rustc-version.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100755 scripts/rustc-version.sh diff --git a/init/Kconfig b/init/Kconfig index 839c83034006..38c1cfcce821 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -60,6 +60,13 @@ config LLD_VERSION default $(ld-version) if LD_IS_LLD default 0 +config RUSTC_VERSION + int + default $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC)) + help + It does not depend on `RUST` since that one may need to use the version + in a `depends on`. + config RUST_IS_AVAILABLE def_bool $(success,$(srctree)/scripts/rust_is_available.sh) help diff --git a/scripts/rustc-version.sh b/scripts/rustc-version.sh new file mode 100755 index 000000000000..62ea510be71b --- /dev/null +++ b/scripts/rustc-version.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Usage: $ ./rustc-version.sh rustc +# +# Print the Rust compiler name and its version in a 6 or 7-digit form. + +# Convert the version string x.y.z to a canonical up-to-7-digits form. +# +# Note that this function uses one more digit (compared to other +# instances in other version scripts) to give a bit more space to +# `rustc` since it will reach 1.100.0 in late 2026. +get_canonical_version() +{ + IFS=. + set -- $1 + echo $((100000 * $1 + 100 * $2 + $3)) +} + +if output=$("$@" --version 2>/dev/null); then + set -- $output + get_canonical_version $2 +else + echo 0 + exit 1 +fi From patchwork Mon Sep 2 16:55:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13787527 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A868E1AB6E8; Mon, 2 Sep 2024 16:56:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725296167; cv=none; b=Wz+eo7g/1rLgWJ6XyL3z33oRPHjWR5xueSFpjY7Q5Jz4iTdq6wBS9x9deXeVD8prh7mwnepPPmZMz6b71KhXXmNVf6Xd8mX+r5U1yCS6umLZolcY8al0VYEXRGY/eLpSJYKHLPKNpBRtpKWuyje3k1MkcgMcWAe+U25oJeyFKTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725296167; c=relaxed/simple; bh=6+P3G2uD3pU9h/ana8iXMMrjSzmZVYjkyTEYm9ga1t8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IVPMkktFzz0MIYNmSV3Lei25eVtFYzesM1ehDZVqWswSJ7L8tGiLh1CPbfGZWe2Ethdm/HWlScLZnLDdW5ig//LUgrkdhk/mq5qenuSyVO+1jrSN+M5hclJ1zqs4P6GsEqGZfq0/t1JN6VWKHPpJChSzTpDCzbo4md/srUdxWfw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fpMpWZ3a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fpMpWZ3a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 092E3C4CEC2; Mon, 2 Sep 2024 16:56:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725296167; bh=6+P3G2uD3pU9h/ana8iXMMrjSzmZVYjkyTEYm9ga1t8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fpMpWZ3amZnsYF+/Hq6C7vvIZQcT6puXcP8Z4IH6bOZg+GfiQM0RI/NyhIbaZ0TVm BXP44wKSXyHA02RSHnbkBY8qxHtpK1s9LxkFERwZZXejzv6cY17ZGlqDJYH5xWe5Ly fQMr1rVU349JahUPvZIbUbS7HgyEWysYKtk2Vr7Jf6Pt9FallMDQQD3IN5f4jxuS9L lEdb2eHS5L/mOQyJObzjJtbBwEKEDinc1xAb5Ks8i5scDCTha3j7O/rDkyzXBCsME9 O0mGaEBT1s9f149N0ktdfGv+2gJh4Yr9bbLl6ijHBVTRT4QKw6c9sdUSquNyxzvd+Z XaRVP8nifz6zQ== From: Miguel Ojeda To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Masahiro Yamada Cc: Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, Nathan Chancellor , Nicolas Schier , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH v2 2/6] kbuild: rust: re-run Kconfig if the version text changes Date: Mon, 2 Sep 2024 18:55:29 +0200 Message-ID: <20240902165535.1101978-3-ojeda@kernel.org> In-Reply-To: <20240902165535.1101978-1-ojeda@kernel.org> References: <20240902165535.1101978-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Re-run Kconfig if we detect the Rust compiler has changed via the version text, like it is done for C. Unlike C, and unlike `RUSTC_VERSION`, the `RUSTC_VERSION_TEXT` is kept under `depends on RUST`, since it should not be needed unless `RUST` is enabled. Signed-off-by: Miguel Ojeda --- Makefile | 8 +++++--- init/Kconfig | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 68ebd6d6b444..1883aeb919a4 100644 --- a/Makefile +++ b/Makefile @@ -648,9 +648,11 @@ endif # The expansion should be delayed until arch/$(SRCARCH)/Makefile is included. # Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile. -# CC_VERSION_TEXT is referenced from Kconfig (so it needs export), -# and from include/config/auto.conf.cmd to detect the compiler upgrade. +# CC_VERSION_TEXT and RUSTC_VERSION_TEXT are referenced from Kconfig (so they +# need export), and from include/config/auto.conf.cmd to detect the compiler +# upgrade. CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1)) +RUSTC_VERSION_TEXT = $(subst $(pound),,$(shell $(RUSTC) --version 2>/dev/null)) ifneq ($(findstring clang,$(CC_VERSION_TEXT)),) include $(srctree)/scripts/Makefile.clang @@ -671,7 +673,7 @@ ifdef config-build # KBUILD_DEFCONFIG may point out an alternative default configuration # used for 'make defconfig' include $(srctree)/arch/$(SRCARCH)/Makefile -export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT +export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT RUSTC_VERSION_TEXT config: outputmakefile scripts_basic FORCE $(Q)$(MAKE) $(build)=scripts/kconfig $@ diff --git a/init/Kconfig b/init/Kconfig index 38c1cfcce821..c6b744a48dcc 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1927,7 +1927,9 @@ config RUST config RUSTC_VERSION_TEXT string depends on RUST - default "$(shell,$(RUSTC) --version 2>/dev/null)" + default "$(RUSTC_VERSION_TEXT)" + help + See `CC_VERSION_TEXT`. config BINDGEN_VERSION_TEXT string From patchwork Mon Sep 2 16:55:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13787528 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 638951AB6E8; Mon, 2 Sep 2024 16:56:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725296172; cv=none; b=NERD7RQ48gEfXigxdrJiuDA7s63RzEIzEUtStl7rcHkyVRiVFn5yJnIKPdGEGKfZuVrqgrNpRixthfVMrPbHlFfxG7ldwOn1A3cJj0TrXD4G2GpNCnF2VmZ0uiijrw8uq6L3/io2sDGx34UNH6PcMQD6VKuIgCURsWDvze25vjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725296172; c=relaxed/simple; bh=Py8aXDwihPSg2fJ40DevYcamcRTgb64eTsUQY/xmr6Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WdF/f/xxBeWvGKFD0cM8vs1dGGXxJlLKMiG/LOsuaOBCx0zdYrltVv8c80Kk55lJ/9lNnchixKHJGRzCn0HamGLK3JIJ10XjMoQAWPrgy3sr2jaBe8mEwe+qq7toXWMjH88hbq1kPU9VX9Q9lZ+ZTsgFGkfOzdK5msDZrFdwOAs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kKxBx91f; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kKxBx91f" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF4ADC4CEC7; Mon, 2 Sep 2024 16:56:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725296171; bh=Py8aXDwihPSg2fJ40DevYcamcRTgb64eTsUQY/xmr6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kKxBx91flDChNZo/qI/zDXN+iFkvr4fJ38taaQ0lsNqxzBu4XVZh/Fscl59ttHewm Tb99CuciXKvLjFLFjQuDjJ7urgDIlPJYItr9sEFCysJbqTSnbYnS+CNWpOZCK4NTlS u0Z5ez9jvwULsDfIfkQjiJ2M7AwdQMeskeX+bWsO8o6FeoRQKdDAdSq/81r4V9g4vT nkm4yZg5xw/kRJEpgp+pnvW4GMLRHft4mBl5SWHrxm8Xth5kD7Pw0IcaPchRW1MpQA obNDnaxA6nrAfhWRgH4ydA6gAF93FsgLRLDer1Cz2TChwanGYmqvk1C+mYajtnEC9Q B5o5CgfO64iZQ== From: Miguel Ojeda To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Masahiro Yamada Cc: Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, Nathan Chancellor , Nicolas Schier , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH v2 3/6] kbuild: rust: rebuild if the version text changes Date: Mon, 2 Sep 2024 18:55:30 +0200 Message-ID: <20240902165535.1101978-4-ojeda@kernel.org> In-Reply-To: <20240902165535.1101978-1-ojeda@kernel.org> References: <20240902165535.1101978-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that `RUSTC_VERSION_TEXT` exists, use it to rebuild `core` when the version text changes (which in turn will trigger a rebuild of all the kernel Rust code). This also applies to proc macros (which only work with the `rustc` that compiled them), via the already existing dependency on `core.o`. That is cleaned up in the next commit. However, this does not cover host programs written in Rust, which is the same case in the C side. This is accomplished by referencing directly the generated file, instead of using the `fixdep` header trick, since we cannot change the Rust standard library sources. This is not too much of a burden, since it only needs to be done for `core`. Tested-by: Alice Ryhl Signed-off-by: Miguel Ojeda --- rust/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rust/Makefile b/rust/Makefile index e13d14ec5fe7..bb57a7c30f1a 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -389,7 +389,8 @@ $(obj)/core.o: private skip_clippy = 1 $(obj)/core.o: private skip_flags = -Wunreachable_pub $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym)) $(obj)/core.o: private rustc_target_flags = $(core-cfgs) -$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE +$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs \ + $(wildcard $(objtree)/include/config/RUSTC_VERSION_TEXT) FORCE +$(call if_changed_rule,rustc_library) ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),) $(obj)/core.o: scripts/target.json From patchwork Mon Sep 2 16:55:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13787529 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CFE92139C7; Mon, 2 Sep 2024 16:56:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725296177; cv=none; b=D1UhlHN792o/hqJY1QPR794PXwhDRBcpBSBj6uByrzmTqnB08wEGCyhOU9UKl3g9HEdqYltNS9DuO628reOcJW8D4osKdAYZywgi/qx2GFL5rBm9PjWxR02EZC+0jEeC1MShHSm0M71zPsHryM98m8Oo7Pyb5YLTbHlwh44yjlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725296177; c=relaxed/simple; bh=6U2O9UkpXcwVcGaoZPhOeZwiwv01xDuO6fgQ9kL3ZIY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GpdT82pwkGgGrlCTODceHVclPZEDij9hhUZ4QEgFejeVcUxuKA7Oiim3JT+JfpF2bpZw8L0k4OD1S4wu/2ujlsZaWjMmoxrJs3yOSiPd6SR33KMuVcdQjTyBP3wfNAuhXk/2VOpOCqk+mXpClAtnpgIZAeC/lMgDI5IEb3tN6Hc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S2MkbGFW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S2MkbGFW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80433C4CEC4; Mon, 2 Sep 2024 16:56:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725296176; bh=6U2O9UkpXcwVcGaoZPhOeZwiwv01xDuO6fgQ9kL3ZIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S2MkbGFWV/b1bWzstYhJ+FETznpvRzt/sLOetwFtCLTACYyp1JrcXVevUKh5hyEXc XYRxcAOe0BunBJOzHmWGPMjIFxr+RUOR6opb0WENAMbkt0en2GKFTskWvO33qBcprr 8dz33LEuL5TDZn7YZ6gtUF4JhbT4F8+OFc0FBpfIcl8LcZ8prvP4fg5ntwwLMNXg8C GhqiqLESM2elgnEhRde6u6CPD8fFA+aJMYzUW6vZcBJ9rmevnCBUBt7xrpBhGUy5Yz oRcfqKO0Pc7fLRjBEEX2ANESDliOcnclj3AJ9IcQa7djoicn0UtWD2XyOC+EmP6Pdi 8DhDB3OLYj6gw== From: Miguel Ojeda To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Masahiro Yamada Cc: Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, Nathan Chancellor , Nicolas Schier , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH v2 4/6] kbuild: rust: replace proc macros dependency on `core.o` with the version text Date: Mon, 2 Sep 2024 18:55:31 +0200 Message-ID: <20240902165535.1101978-5-ojeda@kernel.org> In-Reply-To: <20240902165535.1101978-1-ojeda@kernel.org> References: <20240902165535.1101978-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With the `RUSTC_VERSION_TEXT` rebuild support in place, now proc macros can depend on that instead of `core.o`. This means that both the `core` and `macros` crates can be built in parallel, and that touching `core.o` does not trigger a rebuild of the proc macros. This could be accomplished using the same approach as for `core` (i.e. depending directly on `include/config/RUSTC_VERSION_TEXT`). However, that is considered an implementation detail [1], and thus it is best to avoid it. Instead, let fixdep find a string that we explicitly write down in the source code for this purpose (like it is done for `include/linux/compiler-version.h`), which we can easily do (unlike for `core`) since this is our own source code. Suggested-by: Masahiro Yamada Link: https://lore.kernel.org/rust-for-linux/CAK7LNAQBG0nDupXSgAAk-6nOqeqGVkr3H1RjYaqRJ1OxmLm6xA@mail.gmail.com/ [1] Signed-off-by: Miguel Ojeda --- rust/Makefile | 4 +--- rust/macros/lib.rs | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/rust/Makefile b/rust/Makefile index bb57a7c30f1a..4eae318f36ff 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -342,9 +342,7 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@ --crate-name $(patsubst lib%.so,%,$(notdir $@)) $< # Procedural macros can only be used with the `rustc` that compiled it. -# Therefore, to get `libmacros.so` automatically recompiled when the compiler -# version changes, we add `core.o` as a dependency (even if it is not needed). -$(obj)/libmacros.so: $(src)/macros/lib.rs $(obj)/core.o FORCE +$(obj)/libmacros.so: $(src)/macros/lib.rs FORCE +$(call if_changed_dep,rustc_procmacro) quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@ diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs index 5be0cb9db3ee..a626b1145e5c 100644 --- a/rust/macros/lib.rs +++ b/rust/macros/lib.rs @@ -2,6 +2,10 @@ //! Crate for all kernel procedural macros. +// When fixdep scans this, it will find this string `CONFIG_RUSTC_VERSION_TEXT` +// and thus add a dependency on `include/config/RUSTC_VERSION_TEXT`, which is +// touched by Kconfig when the version string from the compiler changes. + #[macro_use] mod quote; mod concat_idents; From patchwork Mon Sep 2 16:55:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13787530 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F21A321C16C; Mon, 2 Sep 2024 16:56:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725296182; cv=none; b=tqAZAydTQv/kCHL+fsuIO0qJIG2rMTJhbnI+Qlt4BwskgpNJTs8/eLx2HRrIEOSdmQxe7FyliVqBcvHmPZN9Zw54uRSe2iC9s5hsN56gt574aJdLpW3LtO2yGwUjlXRTUHZjY5wGhQO/CZRCPftN/GvWmVEAzjfcDkKK+OVNzZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725296182; c=relaxed/simple; bh=RzgZlfDyLil5uBN/RYf7XolTsi7y3Begl7ZXdDPw9L8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NglJYN+PEX/CLiLRdxFlg21iI7mEPDDgiKhG9bkeH6Mlmnyfxmams2tx8JA0grkllSSMgBOklEHHY4DdtwyQSjbyNgKiWX97zr6EY9TpWnX6XO6jVfPKMWJHbU6lJjkfQhh06aBYerVCjMSl/dhf92OgrHIC8ODm9O6LcKmLUFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W99fTCkD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W99fTCkD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4209CC4CEC2; Mon, 2 Sep 2024 16:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725296181; bh=RzgZlfDyLil5uBN/RYf7XolTsi7y3Begl7ZXdDPw9L8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W99fTCkD2FCF+aKv8y2iAJhZVEcRNTxJzBpCFpswxHC3a7Uw3UjdWZtS6IXtsCBxd 6yas9AJoTiRFY75kOV3P0+piEJez/qVWBqlgs/F47Y637ktrf9bB0bAiE5NxXZfyga p+EKPM8gPucv1BmMXv20L6dkj7tLaQQmnDBcwA6rwqafJu0nkehDY5fTokJu3rInW0 jvLCimNRR/iI8ziVOqUUfJV7vStm0Mu9zp5uPBzYtdz5Fq8hsd+Cb8r5S6ZZnFazYJ ctsKYWIHy+C+wHMmrGaLDFmbGERllojQdyrNF6fSiU2ybapH7cPck/pvKdYHkB1ZIb 5SIxSf4fgzkwg== From: Miguel Ojeda To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Masahiro Yamada Cc: Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, Nathan Chancellor , Nicolas Schier , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH v2 5/6] kbuild: rust: warn if the out-of-tree compiler differs from the kernel one Date: Mon, 2 Sep 2024 18:55:32 +0200 Message-ID: <20240902165535.1101978-6-ojeda@kernel.org> In-Reply-To: <20240902165535.1101978-1-ojeda@kernel.org> References: <20240902165535.1101978-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For out-of-tree modules, in the C side, Kbuild warns if the C compiler differs from the one used to build the kernel. Do the same for Rust, except that we add the extra condition that Rust support was enabled in the kernel. For instance, the output will look like: warning: the Rust compiler differs from the one used to build the kernel The kernel was built by: rustc 1.78.0 (9b00956e5 2024-04-29) You are using: rustc 1.79.0 (129f3b996 2024-06-10) Note that the build will fail later anyway in such a case, since the Rust compiler checks for incompatible Rust versions, e.g.: RUSTC [M] rust-out-of-tree-module/rust_out_of_tree.o error[E0514]: found crate `core` compiled by an incompatible version of rustc | = note: the following crate versions were found: crate `core` compiled by rustc 1.78.0 (9b00956e5 2024-04-29): rust/libcore.rmeta = help: please recompile that crate using this compiler (rustc 1.79.0 (129f3b996 2024-06-10)) (consider running `cargo clean` first) Nevertheless, the added warning at the top should hopefully make the situation clearer. The extra condition on `CONFIG_RUST=y` is added since otherwise users would get warnings when a Rust compiler is reachable, e.g. the most likely case today is that they are building a C module for a kernel that does not have Rust enabled. However, if Rust was indeed enabled, then we do print the warning in all cases, e.g. even if they are building a C module. While it may not matter in some cases, it may still be a sign that something unexpectedly changed in the environment they may want to be aware of: warning: the Rust compiler differs from the one used to build the kernel The kernel was built by: rustc 1.78.0 (9b00956e5 2024-04-29) You are using: rustc 1.79.0 (129f3b996 2024-06-10) CC [M] c-out-of-tree-module/c_out_of_tree.o Note that the check will also trigger for cases where the user does not have the Rust compiler installed, including when building a C module: warning: the Rust compiler differs from the one used to build the kernel The kernel was built by: rustc 1.78.0 (9b00956e5 2024-04-29) You are using: CC [M] c-out-of-tree-module/c_out_of_tree.o Suggested-by: Nicolas Schier Link: https://lore.kernel.org/rust-for-linux/20240817-heavy-dancing-whale-6ae13d@lindesnes/ Signed-off-by: Miguel Ojeda --- Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1883aeb919a4..e3fcc7028c5f 100644 --- a/Makefile +++ b/Makefile @@ -1794,14 +1794,20 @@ clean: private rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modu $(KBUILD_EXTMOD)/compile_commands.json PHONY += prepare -# now expand this into a simple variable to reduce the cost of shell evaluations +# now expand these into simple variables to reduce the cost of shell evaluations prepare: CC_VERSION_TEXT := $(CC_VERSION_TEXT) +prepare: RUSTC_VERSION_TEXT := $(RUSTC_VERSION_TEXT) prepare: @if [ "$(CC_VERSION_TEXT)" != "$(CONFIG_CC_VERSION_TEXT)" ]; then \ - echo >&2 "warning: the compiler differs from the one used to build the kernel"; \ + echo >&2 "warning: the C compiler differs from the one used to build the kernel"; \ echo >&2 " The kernel was built by: $(CONFIG_CC_VERSION_TEXT)"; \ echo >&2 " You are using: $(CC_VERSION_TEXT)"; \ fi + @if [ "$(CONFIG_RUST)" = "y" -a "$(RUSTC_VERSION_TEXT)" != "$(CONFIG_RUSTC_VERSION_TEXT)" ]; then \ + echo >&2 "warning: the Rust compiler differs from the one used to build the kernel"; \ + echo >&2 " The kernel was built by: $(CONFIG_RUSTC_VERSION_TEXT)"; \ + echo >&2 " You are using: $(RUSTC_VERSION_TEXT)"; \ + fi PHONY += help help: From patchwork Mon Sep 2 16:55:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13787531 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 949051C62C2; Mon, 2 Sep 2024 16:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725296187; cv=none; b=m0gtRNK3r8lLwQZWxKvAi4YOY3P9tTc+EKiNmYw/OrbApifg/aU3HzdD2C+CsDWWqx8D9X00DqSNpNXDT5e5jp+ZxNtxQ3pVrGC4/P5Rxxi8yfYvfNSR4ZuBww8NDoM8pT49h0DYfbdrfnCnp1+WAp2CYYo+L1hXRfQMRNConrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725296187; c=relaxed/simple; bh=EQDbaMna4Ean8/5H5hVqMKDCp1htA8sUKuu5IvS7JnA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KN1fImQui454O3OkW/D8e0hRsw/woJ/MXGo9CwKVva2Pmn/f5VKxD8/IsMaMwo11Ql3kydlHY99+6efn+yuIavZc5X7l1Uqbhcat3GmCJCwYKl/W7ucrLeLtHORwsrBpZq2YA30tn8xBWP8+pTlCf4M2gaob52x8lphY0jpCBrQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DhV9QAuM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DhV9QAuM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0759AC4CECB; Mon, 2 Sep 2024 16:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725296186; bh=EQDbaMna4Ean8/5H5hVqMKDCp1htA8sUKuu5IvS7JnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DhV9QAuMAexluc+NmF+GNVpPnho0V4yVjEBbQP44bHXYuV8p8nfcsLPSMtJ8exhvR XJR+KbFetLZ3mDiw+jAy3amRt2hFasj/17i38HhDP1bmn2/9oqICsqEkSWSHMjl2HJ NiQ1EJUgu3O2IQrWQBJ4lBrMxYvaVzCvrBIfbjngLHWidWo4NinTl7CCJhZRB0lbYY tlg2A8PbLsdUiVutJHgDJEWiWgTF8EYUQ9gbSFhCFZzTVXe16++SRxd0v27tii/A6q LBe6n2HS0bS+9gpnt8WMh+qtk6+fbZMPa+DjDjugRCDAgRpcuZAAsbf2KtbjnZtRES znOLWbwPw88Yw== From: Miguel Ojeda To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Masahiro Yamada Cc: Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, Nathan Chancellor , Nicolas Schier , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH v2 6/6] docs: rust: include other expressions in conditional compilation section Date: Mon, 2 Sep 2024 18:55:33 +0200 Message-ID: <20240902165535.1101978-7-ojeda@kernel.org> In-Reply-To: <20240902165535.1101978-1-ojeda@kernel.org> References: <20240902165535.1101978-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Expand the conditional compilation section to explain how to support other expressions, such as testing whether `RUSTC_VERSION` is at least a given version, which requires a numerical comparison that Rust's `cfg` predicates do not support (yet?). Signed-off-by: Miguel Ojeda --- Documentation/rust/general-information.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/rust/general-information.rst b/Documentation/rust/general-information.rst index 2d76e09da121..6146b49b6a98 100644 --- a/Documentation/rust/general-information.rst +++ b/Documentation/rust/general-information.rst @@ -151,3 +151,11 @@ configuration: #[cfg(CONFIG_X="y")] // Enabled as a built-in (`y`) #[cfg(CONFIG_X="m")] // Enabled as a module (`m`) #[cfg(not(CONFIG_X))] // Disabled + +For other predicates that Rust's ``cfg`` does not support, e.g. expressions with +numerical comparisons, one may define a new Kconfig symbol: + +.. code-block:: kconfig + + config RUSTC_VERSION_MIN_107900 + def_bool y if RUSTC_VERSION >= 107900