From patchwork Thu Aug 8 22:11: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: 13758237 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 B691415FA73; Thu, 8 Aug 2024 22:12:01 +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=1723155121; cv=none; b=gRltGD2Wt3PY/RLG+av98jdZZuNuZ7Yir3L3zGXO+Etwhd2cYklKMhlrqThn/giBc5y9NPDnnZX1H2NVuq5IZmfZJsmmdzi5TajhvGnjoOLhYNrCrai3LdYgXQPQheMsOWTcwfRTOEfLg3EnwHdn6V36Zob8zDXBnSWklcp27xQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723155121; c=relaxed/simple; bh=dyjEI+qN7UE6T5JZLmW51Kukg6KdxKj+Q9Udid5aCvM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cmUatzkNnJBH/wQl/bsCCGtboPbckZ27Aj0pKqvU2ltd+6X0oFWo9DW+z69lRCoItAf448hgU6qFcPYqhL/6BzTUMKV9bZ39mX2jVR87Us7w3h5tW8pg46zUT3Cd8HfDOoHC+pOtDvddX4Ri5p4+nEhv5ejmHV155l6FrawYiuM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SXtyBSAe; 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="SXtyBSAe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B2C0C4AF09; Thu, 8 Aug 2024 22:11:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723155121; bh=dyjEI+qN7UE6T5JZLmW51Kukg6KdxKj+Q9Udid5aCvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SXtyBSAet2dLZe3YiuPEOINhNkdMmW8ohKVhr7NP/FadhWLFG+DfUcy8zNv8IfyuJ 8wu5Ae4c21JpuN7jqCd3AaCKzdpgtJQ3uQ6X4utrTwrEtzCqxT4vT+S0cidlNekH8y pJ9zmq8LOu03GJ244P3wwW3Ur/VvoU7mojFv2lbK+DAN6HQOkLpYTveqgIrD2IFD8B FDjPFUYkW12ciEff7504MocOxMPp0pN2pIAWxzjWtg9crVfLUM3RjmsRF/bPe9lOTI bDI3sJ2Z2+AEKt3FeKgzRMs90BQidgMItC6j+gYR8EscHcg0kDA6DGlg3qxriE4aWs eb6DB41pEkhYw== 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 1/6] kbuild: rust: add `CONFIG_RUSTC_VERSION` Date: Fri, 9 Aug 2024 00:11:33 +0200 Message-ID: <20240808221138.873750-2-ojeda@kernel.org> In-Reply-To: <20240808221138.873750-1-ojeda@kernel.org> References: <20240808221138.873750-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 has also been 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] Signed-off-by: Miguel Ojeda Reviewed-by: Nicolas Schier --- 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 3ada33b1d681..47e2c3227b99 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 Thu Aug 8 22:11:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13758238 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 0372615DBB6; Thu, 8 Aug 2024 22:12:05 +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=1723155126; cv=none; b=BBWyp3anI9Iz3EjYX7tFrFjbTFZUX0iPSFQzdogsVWAnGQzQjz2H26gpFJw5TttqmXgWDUWaYE98TaU3zIxlfDkdha7mOai3BPWDPUzmZKCsPHLbuxITi42F2C5O3iI6xy/BjhV9NI1DBSV9f0xyv0i8MLD3Olr/TybGDUa5sFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723155126; c=relaxed/simple; bh=O4Sm2YagEseSl4nGQCa4p4TK8SrCAz9AxT6GFG1stRw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SqlsQMlI3Dylo65bzg1FJw0rWSDQn/PpU/LfOeTwaOnlfi8xS8MejL6vBGNzQ4L9Mc8uitF/yiofhqtO8LTSOgOWLFYv2pCO+dAWk+jcpGVnRZgRF2sW5ZW2yQk0wf0O0o5vi4vY7jtIORtkleK4ao/UwFGbbDHqs+jL8MIL3Ao= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CZSNj4E8; 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="CZSNj4E8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3AFCC32782; Thu, 8 Aug 2024 22:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723155125; bh=O4Sm2YagEseSl4nGQCa4p4TK8SrCAz9AxT6GFG1stRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CZSNj4E8cKyHA0M4BmAqRq5dL4M22Jm906xGP8Qqqo7IEXPpIEWYWRbP+imLtPbC+ TYyQ+07kG+rOQ8b8uzqRH1E/k1i/7aEIBmky8nDJu7D7z53LvUx+oJ7qsCD+/1FGsC uW2JB2MuQCI7I85hEDgjBo/i7HWDLJ9nEChV61mM5o7w/E60tcDYtIqm1ScLLf35n+ w4yQiZpGRn5qv4Dgy1ZkkcbihtSbwS5UVq/Kl9XG1rqtohXZgJrnRVcvRTZXrDPUsk zzUqBL+irqZgp9eDCZT1V2wGiKs3kjPGyndUvjWMqvBqsW+mrQYq10e3apGekYeyTn b+17TwDiRQyhw== 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 2/6] kbuild: rust: make command for `RUSTC_VERSION_TEXT` closer to the `CC` one Date: Fri, 9 Aug 2024 00:11:34 +0200 Message-ID: <20240808221138.873750-3-ojeda@kernel.org> In-Reply-To: <20240808221138.873750-1-ojeda@kernel.org> References: <20240808221138.873750-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 `CC_VERSION_TEXT` is defined as: CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1)) Make `RUSTC_VERSION_TEXT` closer to that, i.e. add `LC_ALL=C` and `| head -n 1` in case it matters in the future, and for consistency. This reduces the difference in the next commit. Signed-off-by: Miguel Ojeda --- init/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/Kconfig b/init/Kconfig index 47e2c3227b99..2f974f412374 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1926,7 +1926,7 @@ config RUST config RUSTC_VERSION_TEXT string depends on RUST - default "$(shell,$(RUSTC) --version 2>/dev/null)" + default "$(shell,LC_ALL=C $(RUSTC) --version 2>/dev/null | head -n 1)" config BINDGEN_VERSION_TEXT string From patchwork Thu Aug 8 22:11:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13758239 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 7EF1815DBB6; Thu, 8 Aug 2024 22:12:10 +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=1723155130; cv=none; b=a7zH+Dq1OoQyJmCXwLdf9Up3Tt5XuF3n9iB3fR+BVZ+wksbwoFx82dFPbXUHOzXhDvF5YYyvINt18pxrLKhNm43bOvhW4QrwOccwpO1Uap0Ndmllykzrk68x6ck2insDE0MLx0RYlEnKFcP8LzcmJZLMHNBQIwx85FlFPryX1CQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723155130; c=relaxed/simple; bh=eMcrbKMzXg14IvqJEdwphrNH5oXng/0pxQDFBFqyhJM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mgSSFj6CSIL8bRqoDwKlBAWMIWjqFRhrudOEV5SqwiQzIWrRn9J0c5j+EJr7zKqHBDscsOdM19wIXExKbxHJVQuBp7U2pYtrWyV3dpM/94o3aK+K57bqEOne4sVUH/pZU4dlMbgstcaDFLrRPzP0CEEW4+9NIo+6B66SszgF7wM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Gj9h9Gix; 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="Gj9h9Gix" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 362B7C32782; Thu, 8 Aug 2024 22:12:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723155130; bh=eMcrbKMzXg14IvqJEdwphrNH5oXng/0pxQDFBFqyhJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gj9h9GixbdlI1aJLW7/1WfMWb21t9bIecPEeihj2PiGhjid3YWsqSHkowuheQhRFj pvcVf96hI2zX8kBiYkQl6m00pnrOGqn7/MFiZUfnpoUfEhH7lIt73l5zmMBQ+P+0SV bc1PheUkxIoe9Bkevym33o7uKi0ZPCAr8CQpktzYwT1EUfZO8tCON3fzQKolMQfVu5 fxR/xnIv4yLSj+n8dA1phDlkFnLJV7v3X3uhJ8QE1ZRaEdnZ5vcVpK7Tw5jtccPdvo aUH4JEWsVWGeE8r3fliPG6Sp/spc2pYNMXQKLB44BZBo0ZPUxG2OVpn3+CRuLPZgNz 1wHFeyVImGRwQ== 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 3/6] kbuild: rust: re-run Kconfig if the version text changes Date: Fri, 9 Aug 2024 00:11:35 +0200 Message-ID: <20240808221138.873750-4-ojeda@kernel.org> In-Reply-To: <20240808221138.873750-1-ojeda@kernel.org> References: <20240808221138.873750-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 Reviewed-by: Nicolas Schier --- Masahiro: I think leaving the `depends on RUST` in `RUSTC_VERSION` is OK, but since this is different from the C side, please let me know if you prefer otherwise. Thanks! Makefile | 5 +++-- init/Kconfig | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) -- 2.46.0 diff --git a/Makefile b/Makefile index 8ad55d6e7b60..2b5f9f098b6f 100644 --- a/Makefile +++ b/Makefile @@ -648,9 +648,10 @@ 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), +# 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 LC_ALL=C $(RUSTC) --version 2>/dev/null | head -n 1)) ifneq ($(findstring clang,$(CC_VERSION_TEXT)),) include $(srctree)/scripts/Makefile.clang @@ -671,7 +672,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 2f974f412374..b0238c4b6e79 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1926,7 +1926,9 @@ config RUST config RUSTC_VERSION_TEXT string depends on RUST - default "$(shell,LC_ALL=C $(RUSTC) --version 2>/dev/null | head -n 1)" + default "$(RUSTC_VERSION_TEXT)" + help + See `CC_VERSION_TEXT`. config BINDGEN_VERSION_TEXT string From patchwork Thu Aug 8 22:11:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13758240 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 9E71115DBB6; Thu, 8 Aug 2024 22:12:14 +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=1723155134; cv=none; b=cfq0pStkjV5U/igHJvR3kzGwy1Nw2ch9TI3Rli2FmUK8D24+YRUkrZdyQtfXLAGgH/H65+GnOF9l0OGFY0ZB8tHPT0ulHXzlv+SaijGIFOBxdAQj3Sd+86DxNF6LLuX9+5iUmNbgZzYnftiEPvVK066LFMLZJh1uBeeim7kBbYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723155134; c=relaxed/simple; bh=a07yMugK1+zuRaVA+o2s+/N2A/1oN9fyVOt7k3dxEq4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bwz1jmj1VHaVMwJdT2r9TdBn0+pxGbIdfBZKq74w7PwzZNk666WdrzJgVLfYRPHREouwmoB892WfkZJiowcvrhArtqpw8sGjepEvcFHTqdoA1Di4Q5cqOmy5CKBql2qrfJdWH+LBjtuc20syd+W0IZj/eD1ILQeTSYWLtDjB6+o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YzwuFsCb; 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="YzwuFsCb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CA86C4AF0D; Thu, 8 Aug 2024 22:12:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723155134; bh=a07yMugK1+zuRaVA+o2s+/N2A/1oN9fyVOt7k3dxEq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YzwuFsCbLdyYLszA5900E5UeebrPPMkIEPhaZLrGLtvD2m7WRoBvWvBDZ0rXDXf9k 3ujDeoP0vBUFdIopTBlIad+Mu3YlbdFM+1m/CHMWmmQD4vc3hplY6UVmttEYKhr9jV uFOtdh1gFFaBXupt/sA8GDQoysoErvvkofL2y98qlNiOkYlHcU4EKWTwdycVeWRm92 EQSnrgTlEkHkq5Q70gm2eQLRfnHaWCDGmbu/yBmAJ5Il+yQO4gXbAKAqN5MAqMaJzs z+dKg6imBF06+EqLJ4QYrjbegjVVhXGwIpxETNcZWovIz6H1pN8vgZpDJOYe2MIwug e0/F94/R11XNQ== 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 4/6] kbuild: rust: rebuild if the version text changes Date: Fri, 9 Aug 2024 00:11:36 +0200 Message-ID: <20240808221138.873750-5-ojeda@kernel.org> In-Reply-To: <20240808221138.873750-1-ojeda@kernel.org> References: <20240808221138.873750-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`. Signed-off-by: Miguel Ojeda --- Masahiro: I used `$(objtree)` here since we still use it in the rest of this `Makefile`, but please let me know if you prefer otherwise. Thanks! rust/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.46.0 diff --git a/rust/Makefile b/rust/Makefile index 6c0644b6090c..966743a9ee25 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -370,7 +370,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_dep,rustc_library) ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),) $(obj)/core.o: scripts/target.json From patchwork Thu Aug 8 22:11:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13758241 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 4818C15EFA3; Thu, 8 Aug 2024 22:12:18 +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=1723155139; cv=none; b=iOhLNYY/zL4kFUfq24ucRsMXjErAKKXN5bK89PsFrqfXST5EeRPfT2WO2xs3kenIiKK7ZRlsOlTG53/r1pj9hEQaObbIVyzXbxlSJJ6AN1hxnlz7giQCjfySoDIcBw1PgMtTewT2FdhrUVkauQAoGOEGCLu7x679ZZ+tFihu+Yk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723155139; c=relaxed/simple; bh=qASlKvmzFWrXL4Fx7wsh+J7JNlB35sjrOi18fXWXpKk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=duxsWx2YspTynfGl+snSoOW1qFFzrIUDYNcu7I/SU5i8NEcpMFvvTG/oN5Zn0pLweRBoR35TZSh18Buo+aEPjtUg9rT8yju45OmNY5rKaHkXSb+VEw8O86eoo7Tw2Fjow+unaWlmmPW0tCh42hihF6hz9XhKLRpiuxEVbz9OVIY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EBlbva0V; 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="EBlbva0V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C184C32782; Thu, 8 Aug 2024 22:12:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723155138; bh=qASlKvmzFWrXL4Fx7wsh+J7JNlB35sjrOi18fXWXpKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EBlbva0VzqiGmBnX/N5DCgSE/4V2oNfC065MEbyoRR/Dr9UW/sUCmOy9NSOnhG2Gr ztq5/yEtIeX4x0p3VA0mjzAZHPF4c5vvni5IiPutosVplg1t1Y7Ywk+xYyPuFGt6v0 tQzUVl3XRD86txFwxJHVWHYIEsJf4LEKRJW2HB4HpxKFjPG5k5J3RfoHpzJxXZzwfT kWz2Zz+grKK+vmYtwc37VgZbiT0WYJSis0lohQBuOgNB/JTBamnNczanOnEdwZT+OM BtQjNvslnOAoNo381aBWXLz3hv0Uw2fuo/ivpKFZM6BNtmoblFIq05CHAe7+muscy2 Ur71DpNQlnwBA== 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 5/6] kbuild: rust: replace proc macros dependency on `core.o` with the version text Date: Fri, 9 Aug 2024 00:11:37 +0200 Message-ID: <20240808221138.873750-6-ojeda@kernel.org> In-Reply-To: <20240808221138.873750-1-ojeda@kernel.org> References: <20240808221138.873750-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. Signed-off-by: Miguel Ojeda --- rust/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rust/Makefile b/rust/Makefile index 966743a9ee25..40c8d2c57024 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -329,9 +329,8 @@ 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 \ + $(wildcard $(objtree)/include/config/RUSTC_VERSION_TEXT) FORCE +$(call if_changed_dep,rustc_procmacro) quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@ From patchwork Thu Aug 8 22:11:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13758242 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 AE8F615EFA3; Thu, 8 Aug 2024 22:12:23 +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=1723155143; cv=none; b=LyYn68OO8LcuXXd+1oJrEpcHEZ9foOAts/cx8rP+iDYppOqRxH2yiRv80PYEEAMtPdW6qV5Oe7VeyL1HrOEWRTzW4diHDI2x0+P4oGzCKCBtQoJiTD6YQn9DYX8ywzG2nhIzbB9pdrk5qhsSs8JdnX8Zh0nCjmZ/AYGjXqohEHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723155143; c=relaxed/simple; bh=Dd+AEbTggXStEdSEmha1BZG1604nKY6E7BJ1Ers8Xg8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JPL6kXlBDy8UfOrUQthNSJpwxERR/JbPthzFMFX27IIR8kKH5ef08H9a7FLYs/GqnUnrK8oaVTWBS/wMp/gSfAcgk5acUo/0M5byoolxurjeMWlHguRAdFOj/VEe4E+bL81VTSABvvXVpF4PM5crWaNYHyAK5rQZMt9wU8o2Ars= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SGmtupP7; 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="SGmtupP7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63A50C4AF0C; Thu, 8 Aug 2024 22:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723155143; bh=Dd+AEbTggXStEdSEmha1BZG1604nKY6E7BJ1Ers8Xg8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SGmtupP7vC2I1Rz0y72beEuKjy7ao5c5zZ0/GBwzGdTnECfOx7ztRX6M4dcJCO+Jv ZR+VFVJeENtfffM9cqyxHPOMOmY0byYitIFgeb5+ubeyklDz6kAmNjyS1YYCH5ZPtR H800xsWsYxPaakivRIRWleNtUfKfc/UwpHTQTys9jEKeJPfYqgd9bOk70qvnMi4DjR xMTtYAtPz0Kxu9fDZcZi7SDXbzVhvKojGx7GH1NnHv1GWByWJhHLMTE1/5JhvgPZqn DtGuQ4l/dGd8H6X1ct6zCy3hzgLYtyXxDTroTYgV/uRKzHHk42rC5/Z8+9VIdmwouw GwOjUEUkA+fgg== 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 6/6] docs: rust: include other expressions in conditional compilation section Date: Fri, 9 Aug 2024 00:11:38 +0200 Message-ID: <20240808221138.873750-7-ojeda@kernel.org> In-Reply-To: <20240808221138.873750-1-ojeda@kernel.org> References: <20240808221138.873750-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 e3f388ef4ee4..071c5bafd668 100644 --- a/Documentation/rust/general-information.rst +++ b/Documentation/rust/general-information.rst @@ -142,3 +142,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