* [PATCH 1/6] kbuild: rust: add `CONFIG_RUSTC_VERSION`
2024-08-08 22:11 [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support Miguel Ojeda
@ 2024-08-08 22:11 ` Miguel Ojeda
2024-08-17 12:42 ` Nicolas Schier
2024-08-08 22:11 ` [PATCH 2/6] kbuild: rust: make command for `RUSTC_VERSION_TEXT` closer to the `CC` one Miguel Ojeda
` (5 subsequent siblings)
6 siblings, 1 reply; 25+ messages in thread
From: Miguel Ojeda @ 2024-08-08 22:11 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, rust-for-linux, Nathan Chancellor,
Nicolas Schier, linux-kbuild, linux-kernel, patches
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 <ojeda@kernel.org>
---
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
--
2.46.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH 1/6] kbuild: rust: add `CONFIG_RUSTC_VERSION`
2024-08-08 22:11 ` [PATCH 1/6] kbuild: rust: add `CONFIG_RUSTC_VERSION` Miguel Ojeda
@ 2024-08-17 12:42 ` Nicolas Schier
0 siblings, 0 replies; 25+ messages in thread
From: Nicolas Schier @ 2024-08-17 12:42 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, rust-for-linux, Nathan Chancellor, linux-kbuild,
linux-kernel, patches
On Fri, Aug 09, 2024 at 12:11:33AM +0200, Miguel Ojeda wrote:
> 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 <ojeda@kernel.org>
> ---
> 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
> --
> 2.46.0
>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH 2/6] kbuild: rust: make command for `RUSTC_VERSION_TEXT` closer to the `CC` one
2024-08-08 22:11 [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support Miguel Ojeda
2024-08-08 22:11 ` [PATCH 1/6] kbuild: rust: add `CONFIG_RUSTC_VERSION` Miguel Ojeda
@ 2024-08-08 22:11 ` Miguel Ojeda
2024-08-09 17:52 ` Masahiro Yamada
2024-08-10 13:44 ` Björn Roy Baron
2024-08-08 22:11 ` [PATCH 3/6] kbuild: rust: re-run Kconfig if the version text changes Miguel Ojeda
` (4 subsequent siblings)
6 siblings, 2 replies; 25+ messages in thread
From: Miguel Ojeda @ 2024-08-08 22:11 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, rust-for-linux, Nathan Chancellor,
Nicolas Schier, linux-kbuild, linux-kernel, patches
`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 <ojeda@kernel.org>
---
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
--
2.46.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH 2/6] kbuild: rust: make command for `RUSTC_VERSION_TEXT` closer to the `CC` one
2024-08-08 22:11 ` [PATCH 2/6] kbuild: rust: make command for `RUSTC_VERSION_TEXT` closer to the `CC` one Miguel Ojeda
@ 2024-08-09 17:52 ` Masahiro Yamada
2024-08-10 11:37 ` Miguel Ojeda
2024-08-10 13:44 ` Björn Roy Baron
1 sibling, 1 reply; 25+ messages in thread
From: Masahiro Yamada @ 2024-08-09 17:52 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
rust-for-linux, Nathan Chancellor, Nicolas Schier, linux-kbuild,
linux-kernel, patches
On Fri, Aug 9, 2024 at 7:12 AM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> `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.
Even if "rustc --version" starts to print multiple lines,
it will not cause an immediate problem.
$(shell ... ) (both Makefile and Kconfig) replaces a new line
with a space.
CONFIG_RUSTC_VERSION_TEXT is not broken in any way.
It would be just longer than we would expect.
>
> This reduces the difference in the next commit.
>
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
> ---
> 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
> --
> 2.46.0
>
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 2/6] kbuild: rust: make command for `RUSTC_VERSION_TEXT` closer to the `CC` one
2024-08-09 17:52 ` Masahiro Yamada
@ 2024-08-10 11:37 ` Miguel Ojeda
0 siblings, 0 replies; 25+ messages in thread
From: Miguel Ojeda @ 2024-08-10 11:37 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, rust-for-linux, Nathan Chancellor, Nicolas Schier,
linux-kbuild, linux-kernel, patches
On Fri, Aug 9, 2024 at 7:53 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Even if "rustc --version" starts to print multiple lines,
> it will not cause an immediate problem.
>
> $(shell ... ) (both Makefile and Kconfig) replaces a new line
> with a space.
>
> CONFIG_RUSTC_VERSION_TEXT is not broken in any way.
> It would be just longer than we would expect.
+1, I will update the commit message when I apply it (or if you prefer
a v2 if you are taking it, or if you want to drop this commit, please
let me know!).
Thanks for taking a look, Masahiro.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 2/6] kbuild: rust: make command for `RUSTC_VERSION_TEXT` closer to the `CC` one
2024-08-08 22:11 ` [PATCH 2/6] kbuild: rust: make command for `RUSTC_VERSION_TEXT` closer to the `CC` one Miguel Ojeda
2024-08-09 17:52 ` Masahiro Yamada
@ 2024-08-10 13:44 ` Björn Roy Baron
2024-08-10 14:45 ` Miguel Ojeda
1 sibling, 1 reply; 25+ messages in thread
From: Björn Roy Baron @ 2024-08-10 13:44 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada, Boqun Feng,
Gary Guo, Benno Lossin, Andreas Hindborg, Alice Ryhl,
rust-for-linux, Nathan Chancellor, Nicolas Schier, linux-kbuild,
linux-kernel, patches
On Friday, August 9th, 2024 at 00:11, Miguel Ojeda <ojeda@kernel.org> wrote:
> `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.
Cargo depends on the rustc version string not getting localized. Or to be precise it depends on the version string being fixed for a given rustc version, which would not be the case if the value of LC_ALL could change the version string. If the version string changes, cargo will rebuild everything from scratch. There is also not really anything to localize in the non-verbose version string. I guess setting LC_ALL doesn't hurt either though.
>
> This reduces the difference in the next commit.
>
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
> ---
> 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
> --
> 2.46.0
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 2/6] kbuild: rust: make command for `RUSTC_VERSION_TEXT` closer to the `CC` one
2024-08-10 13:44 ` Björn Roy Baron
@ 2024-08-10 14:45 ` Miguel Ojeda
0 siblings, 0 replies; 25+ messages in thread
From: Miguel Ojeda @ 2024-08-10 14:45 UTC (permalink / raw)
To: Björn Roy Baron
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada,
Boqun Feng, Gary Guo, Benno Lossin, Andreas Hindborg, Alice Ryhl,
rust-for-linux, Nathan Chancellor, Nicolas Schier, linux-kbuild,
linux-kernel, patches
On Sat, Aug 10, 2024 at 3:44 PM Björn Roy Baron
<bjorn3_gh@protonmail.com> wrote:
>
> Cargo depends on the rustc version string not getting localized. Or to be precise it depends on the version string being fixed for a given rustc version, which would not be the case if the value of LC_ALL could change the version string. If the version string changes, cargo will rebuild everything from scratch. There is also not really anything to localize in the non-verbose version string. I guess setting LC_ALL doesn't hurt either though.
Thanks Björn -- yeah, I agree it works either way (also for `head` as
Masahiro mentioned).
I made this commit to make it as close as possible to the C one, since
in the next patch it gets moved to another place where both commands
go together.
It is reasonable to argue that it makes it more complex and slower, so
I am happy dropping it.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH 3/6] kbuild: rust: re-run Kconfig if the version text changes
2024-08-08 22:11 [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support Miguel Ojeda
2024-08-08 22:11 ` [PATCH 1/6] kbuild: rust: add `CONFIG_RUSTC_VERSION` Miguel Ojeda
2024-08-08 22:11 ` [PATCH 2/6] kbuild: rust: make command for `RUSTC_VERSION_TEXT` closer to the `CC` one Miguel Ojeda
@ 2024-08-08 22:11 ` Miguel Ojeda
2024-08-17 12:58 ` Nicolas Schier
2024-08-08 22:11 ` [PATCH 4/6] kbuild: rust: rebuild " Miguel Ojeda
` (3 subsequent siblings)
6 siblings, 1 reply; 25+ messages in thread
From: Miguel Ojeda @ 2024-08-08 22:11 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, rust-for-linux, Nathan Chancellor,
Nicolas Schier, linux-kbuild, linux-kernel, patches
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 <ojeda@kernel.org>
---
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(-)
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
--
2.46.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH 3/6] kbuild: rust: re-run Kconfig if the version text changes
2024-08-08 22:11 ` [PATCH 3/6] kbuild: rust: re-run Kconfig if the version text changes Miguel Ojeda
@ 2024-08-17 12:58 ` Nicolas Schier
2024-08-17 13:28 ` Miguel Ojeda
0 siblings, 1 reply; 25+ messages in thread
From: Nicolas Schier @ 2024-08-17 12:58 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, rust-for-linux, Nathan Chancellor, linux-kbuild,
linux-kernel, patches
On Fri, Aug 09, 2024 at 12:11:35AM +0200, Miguel Ojeda wrote:
> 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 <ojeda@kernel.org>
> ---
> 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(-)
>
> 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.
If you send a v2, mind you consider reformatting so that this comment
block stays <= 80 chars?
> 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
> --
> 2.46.0
Do we already support rust in external kernel modules? In top-level
Makefile's oot-kmod 'prepare' target we check that the compiler
(version) is the same as when the kernel itself was built. If rust
modules are supported, adding a similar check might be helpful.
Nevertheless,
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 3/6] kbuild: rust: re-run Kconfig if the version text changes
2024-08-17 12:58 ` Nicolas Schier
@ 2024-08-17 13:28 ` Miguel Ojeda
0 siblings, 0 replies; 25+ messages in thread
From: Miguel Ojeda @ 2024-08-17 13:28 UTC (permalink / raw)
To: Nicolas Schier
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, rust-for-linux, Nathan Chancellor,
linux-kbuild, linux-kernel, patches
On Sat, Aug 17, 2024 at 2:58 PM Nicolas Schier <nicolas@fjasle.eu> wrote:
>
> If you send a v2, mind you consider reformatting so that this comment
> block stays <= 80 chars?
Sure.
> Do we already support rust in external kernel modules? In top-level
If you mean out-of-tree modules, then yeah, they should generally work
(at least I test the build with a trivial one regularly, but perhaps
it is missing something), although they are not the highest priority.
> Makefile's oot-kmod 'prepare' target we check that the compiler
> (version) is the same as when the kernel itself was built. If rust
> modules are supported, adding a similar check might be helpful.
That is a good point, I will take a look.
> Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH 4/6] kbuild: rust: rebuild if the version text changes
2024-08-08 22:11 [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support Miguel Ojeda
` (2 preceding siblings ...)
2024-08-08 22:11 ` [PATCH 3/6] kbuild: rust: re-run Kconfig if the version text changes Miguel Ojeda
@ 2024-08-08 22:11 ` Miguel Ojeda
2024-08-17 13:04 ` Nicolas Schier
2024-08-08 22:11 ` [PATCH 5/6] kbuild: rust: replace proc macros dependency on `core.o` with the version text Miguel Ojeda
` (2 subsequent siblings)
6 siblings, 1 reply; 25+ messages in thread
From: Miguel Ojeda @ 2024-08-08 22:11 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, rust-for-linux, Nathan Chancellor,
Nicolas Schier, linux-kbuild, linux-kernel, patches
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 <ojeda@kernel.org>
---
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(-)
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
--
2.46.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH 4/6] kbuild: rust: rebuild if the version text changes
2024-08-08 22:11 ` [PATCH 4/6] kbuild: rust: rebuild " Miguel Ojeda
@ 2024-08-17 13:04 ` Nicolas Schier
2024-08-17 13:36 ` Miguel Ojeda
0 siblings, 1 reply; 25+ messages in thread
From: Nicolas Schier @ 2024-08-17 13:04 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, rust-for-linux, Nathan Chancellor, linux-kbuild,
linux-kernel, patches
On Fri, Aug 09, 2024 at 12:11:36AM +0200, Miguel Ojeda wrote:
> 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 <ojeda@kernel.org>
> ---
> 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(-)
>
> 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
> --
> 2.46.0
Looks good to me, but I'd prefer something like the suggestion from
Masahiro:
https://lore.kernel.org/linux-kbuild/CAK7LNAQBG0nDupXSgAAk-6nOqeqGVkr3H1RjYaqRJ1OxmLm6xA@mail.gmail.com/
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 4/6] kbuild: rust: rebuild if the version text changes
2024-08-17 13:04 ` Nicolas Schier
@ 2024-08-17 13:36 ` Miguel Ojeda
2024-08-17 15:49 ` Nicolas Schier
0 siblings, 1 reply; 25+ messages in thread
From: Miguel Ojeda @ 2024-08-17 13:36 UTC (permalink / raw)
To: Nicolas Schier
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, rust-for-linux, Nathan Chancellor,
linux-kbuild, linux-kernel, patches
On Sat, Aug 17, 2024 at 3:04 PM Nicolas Schier <nicolas@fjasle.eu> wrote:
>
> Looks good to me, but I'd prefer something like the suggestion from
> Masahiro:
> https://lore.kernel.org/linux-kbuild/CAK7LNAQBG0nDupXSgAAk-6nOqeqGVkr3H1RjYaqRJ1OxmLm6xA@mail.gmail.com/
Do you mean for `core` (here), or for `macros` (in the next commit)?
(if you mean for `core`, please see my reply to Masahiro there).
Thanks for taking a look!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 4/6] kbuild: rust: rebuild if the version text changes
2024-08-17 13:36 ` Miguel Ojeda
@ 2024-08-17 15:49 ` Nicolas Schier
2024-09-02 17:40 ` Miguel Ojeda
0 siblings, 1 reply; 25+ messages in thread
From: Nicolas Schier @ 2024-08-17 15:49 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, rust-for-linux, Nathan Chancellor,
linux-kbuild, linux-kernel, patches
On Sat, Aug 17, 2024 at 03:36:30PM +0200, Miguel Ojeda wrote:
> On Sat, Aug 17, 2024 at 3:04 PM Nicolas Schier <nicolas@fjasle.eu> wrote:
> >
> > Looks good to me, but I'd prefer something like the suggestion from
> > Masahiro:
> > https://lore.kernel.org/linux-kbuild/CAK7LNAQBG0nDupXSgAAk-6nOqeqGVkr3H1RjYaqRJ1OxmLm6xA@mail.gmail.com/
>
> Do you mean for `core` (here), or for `macros` (in the next commit)?
> (if you mean for `core`, please see my reply to Masahiro there).
oops, I missed that 'core' is delivered external. Sorry for the noise.
Kind regards,
Nicolas
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 4/6] kbuild: rust: rebuild if the version text changes
2024-08-17 15:49 ` Nicolas Schier
@ 2024-09-02 17:40 ` Miguel Ojeda
0 siblings, 0 replies; 25+ messages in thread
From: Miguel Ojeda @ 2024-09-02 17:40 UTC (permalink / raw)
To: Nicolas Schier
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, rust-for-linux, Nathan Chancellor,
linux-kbuild, linux-kernel, patches
On Sat, Aug 17, 2024 at 5:50 PM Nicolas Schier <nicolas@fjasle.eu> wrote:
>
> oops, I missed that 'core' is delivered external. Sorry for the noise.
No worries at all, thanks for taking a look! I appreciate the reviews.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH 5/6] kbuild: rust: replace proc macros dependency on `core.o` with the version text
2024-08-08 22:11 [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support Miguel Ojeda
` (3 preceding siblings ...)
2024-08-08 22:11 ` [PATCH 4/6] kbuild: rust: rebuild " Miguel Ojeda
@ 2024-08-08 22:11 ` Miguel Ojeda
2024-08-09 17:31 ` Masahiro Yamada
2024-08-08 22:11 ` [PATCH 6/6] docs: rust: include other expressions in conditional compilation section Miguel Ojeda
2024-08-19 7:28 ` [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support Alice Ryhl
6 siblings, 1 reply; 25+ messages in thread
From: Miguel Ojeda @ 2024-08-08 22:11 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, rust-for-linux, Nathan Chancellor,
Nicolas Schier, linux-kbuild, linux-kernel, patches
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 <ojeda@kernel.org>
---
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 $@
--
2.46.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH 5/6] kbuild: rust: replace proc macros dependency on `core.o` with the version text
2024-08-08 22:11 ` [PATCH 5/6] kbuild: rust: replace proc macros dependency on `core.o` with the version text Miguel Ojeda
@ 2024-08-09 17:31 ` Masahiro Yamada
2024-08-10 11:36 ` Miguel Ojeda
0 siblings, 1 reply; 25+ messages in thread
From: Masahiro Yamada @ 2024-08-09 17:31 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
rust-for-linux, Nathan Chancellor, Nicolas Schier, linux-kbuild,
linux-kernel, patches
On Fri, Aug 9, 2024 at 7:12 AM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> 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 <ojeda@kernel.org>
> ---
> 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)
The touched file, include/config/*, is an implementation detail
in Kconfig and fixdep.
Rather, I'd like to put the string "CONFIG_RUST_VERSION_TEXT"
in the comment of the source file.
This is the idea adopted in include/linux/compiler-version.h
diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs
index 5be0cb9db3ee..91be2112ceee 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 add 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;
I do not know how to do it for rust/core.o because there is no in-tree
source file.
But, can we add rust/core.rs, from which
rustlib/src/rust/library/core/src/macros/mod.rs is imported?
>
> quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
> --
> 2.46.0
>
>
--
Best Regards
Masahiro Yamada
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH 5/6] kbuild: rust: replace proc macros dependency on `core.o` with the version text
2024-08-09 17:31 ` Masahiro Yamada
@ 2024-08-10 11:36 ` Miguel Ojeda
0 siblings, 0 replies; 25+ messages in thread
From: Miguel Ojeda @ 2024-08-10 11:36 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, rust-for-linux, Nathan Chancellor, Nicolas Schier,
linux-kbuild, linux-kernel, patches
On Fri, Aug 9, 2024 at 7:31 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> The touched file, include/config/*, is an implementation detail
> in Kconfig and fixdep.
>
> Rather, I'd like to put the string "CONFIG_RUST_VERSION_TEXT"
> in the comment of the source file.
>
> This is the idea adopted in include/linux/compiler-version.h
+1, I did it this way to follow the same pattern to the previous patch
on `core.o`, since that one needed another approach, but I am happy to
change it.
> I do not know how to do it for rust/core.o because there is no in-tree
> source file.
>
> But, can we add rust/core.rs, from which
> rustlib/src/rust/library/core/src/macros/mod.rs is imported?
That is an interesting idea... :)
Hmm... I think `core` is a bit too special for that, since we need
attributes on the crate root and it is the one defining things like
`include!`. Even if we generated the file on the fly to mimic the
original, we would still need to handle the paths for each module or
recreate a directory hierarchy or similar.
We are also in talks with the Rust project to figure out building
`core` in a stable way, so the details around it may change too, e.g.
probably something like passing a flag like `-Cbuild-std=core`. They
may also want to figure out the right input file path themselves, i.e.
rather than having to provide one from our side.
So I think a hack may not be worth it compared to depending on the
implementation detail, and may be a bit brittle until we know the
final details of that.
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH 6/6] docs: rust: include other expressions in conditional compilation section
2024-08-08 22:11 [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support Miguel Ojeda
` (4 preceding siblings ...)
2024-08-08 22:11 ` [PATCH 5/6] kbuild: rust: replace proc macros dependency on `core.o` with the version text Miguel Ojeda
@ 2024-08-08 22:11 ` Miguel Ojeda
2024-08-19 7:28 ` [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support Alice Ryhl
6 siblings, 0 replies; 25+ messages in thread
From: Miguel Ojeda @ 2024-08-08 22:11 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, rust-for-linux, Nathan Chancellor,
Nicolas Schier, linux-kbuild, linux-kernel, patches
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 <ojeda@kernel.org>
---
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
--
2.46.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support
2024-08-08 22:11 [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support Miguel Ojeda
` (5 preceding siblings ...)
2024-08-08 22:11 ` [PATCH 6/6] docs: rust: include other expressions in conditional compilation section Miguel Ojeda
@ 2024-08-19 7:28 ` Alice Ryhl
2024-09-02 17:40 ` Miguel Ojeda
6 siblings, 1 reply; 25+ messages in thread
From: Alice Ryhl @ 2024-08-19 7:28 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
rust-for-linux, Nathan Chancellor, Nicolas Schier, linux-kbuild,
linux-kernel, patches
On Fri, Aug 9, 2024 at 12:12 AM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> Hi all,
>
> This series introduces `RUSTC_VERSION` support, which is needed for
> several patch series getting upstreamed, and it will be increasingly
> useful as we now support several Rust compiler (and `bindgen`) versions.
> Later on, we will likely introduce other macros, such as
> `rustc-min-version`.
>
> In addition, the series introduces automatic reconfiguration and rebuild
> based on `RUSTC_VERSION_TEXT`, to mimic the C side, which is also good
> to have now that we support several versions.
>
> It is based on top of the current `rust-fixes`, since there are a couple
> pending changes to the version text Kconfig symbols that will be sent to
> Linus soon for an -rc.
>
> Cheers,
> Miguel
I tested this together with Rust Binder. I also ran this patchset
through Android's CI setup to verify that it works in builds with
CONFIG_RUST disabled. It passes both with and without a Rust compiler
available to the build system.
Tested-by: Alice Ryhl <aliceryhl@google.com>
I'm happy to rerun these tests for new versions.
Alice
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support
2024-08-19 7:28 ` [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support Alice Ryhl
@ 2024-09-02 17:40 ` Miguel Ojeda
2024-09-05 1:19 ` Masahiro Yamada
0 siblings, 1 reply; 25+ messages in thread
From: Miguel Ojeda @ 2024-09-02 17:40 UTC (permalink / raw)
To: Alice Ryhl
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, rust-for-linux, Nathan Chancellor,
Nicolas Schier, linux-kbuild, linux-kernel, patches
On Mon, Aug 19, 2024 at 9:29 AM Alice Ryhl <aliceryhl@google.com> wrote:
>
> I tested this together with Rust Binder. I also ran this patchset
> through Android's CI setup to verify that it works in builds with
> CONFIG_RUST disabled. It passes both with and without a Rust compiler
> available to the build system.
>
> Tested-by: Alice Ryhl <aliceryhl@google.com>
>
> I'm happy to rerun these tests for new versions.
Thanks a lot Alice, that is very useful.
I sent v2, in case you have time to give it another go.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support
2024-09-02 17:40 ` Miguel Ojeda
@ 2024-09-05 1:19 ` Masahiro Yamada
2024-09-05 20:47 ` Miguel Ojeda
0 siblings, 1 reply; 25+ messages in thread
From: Masahiro Yamada @ 2024-09-05 1:19 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Alice Ryhl, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, rust-for-linux, Nathan Chancellor,
Nicolas Schier, linux-kbuild, linux-kernel, patches
On Tue, Sep 3, 2024 at 2:40 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Mon, Aug 19, 2024 at 9:29 AM Alice Ryhl <aliceryhl@google.com> wrote:
> >
> > I tested this together with Rust Binder. I also ran this patchset
> > through Android's CI setup to verify that it works in builds with
> > CONFIG_RUST disabled. It passes both with and without a Rust compiler
> > available to the build system.
> >
> > Tested-by: Alice Ryhl <aliceryhl@google.com>
> >
> > I'm happy to rerun these tests for new versions.
>
> Thanks a lot Alice, that is very useful.
>
> I sent v2, in case you have time to give it another go.
>
> Cheers,
> Miguel
With the nit in 1/6 fixed (No need to resend if you fix it locally)
Acked-by: Masahiro Yamada <masahiroy@kernel.org>
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support
2024-09-05 1:19 ` Masahiro Yamada
@ 2024-09-05 20:47 ` Miguel Ojeda
2024-09-05 23:59 ` Masahiro Yamada
0 siblings, 1 reply; 25+ messages in thread
From: Miguel Ojeda @ 2024-09-05 20:47 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Alice Ryhl, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, rust-for-linux, Nathan Chancellor,
Nicolas Schier, linux-kbuild, linux-kernel, patches
On Thu, Sep 5, 2024 at 3:19 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> With the nit in 1/6 fixed (No need to resend if you fix it locally)
>
> Acked-by: Masahiro Yamada <masahiroy@kernel.org>
Thanks a lot Masahiro (nit fixed and tag applied). I guess you meant
to reply to v2?
Cheers,
Miguel
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 0/6] kbuild: rust: add `RUSTC_VERSION` and reconfig/rebuild support
2024-09-05 20:47 ` Miguel Ojeda
@ 2024-09-05 23:59 ` Masahiro Yamada
0 siblings, 0 replies; 25+ messages in thread
From: Masahiro Yamada @ 2024-09-05 23:59 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Alice Ryhl, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, rust-for-linux, Nathan Chancellor,
Nicolas Schier, linux-kbuild, linux-kernel, patches
On Fri, Sep 6, 2024 at 5:47 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Thu, Sep 5, 2024 at 3:19 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > With the nit in 1/6 fixed (No need to resend if you fix it locally)
> >
> > Acked-by: Masahiro Yamada <masahiroy@kernel.org>
>
> Thanks a lot Masahiro (nit fixed and tag applied). I guess you meant
> to reply to v2?
Yes, I meant Ack to v2.
Sorry for confusion.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 25+ messages in thread