@@ -1920,6 +1920,12 @@ config RUST
If unsure, say N.
+config RUSTC_VERSION
+ int
+ depends on RUST
+ default $(rustc-version)
+ default 0
+
config RUSTC_VERSION_TEXT
string
depends on RUST
@@ -45,6 +45,12 @@ $(error-if,$(success,test -z "$(cc-info)"),Sorry$(comma) this C compiler is not
cc-name := $(shell,set -- $(cc-info) && echo $1)
cc-version := $(shell,set -- $(cc-info) && echo $2)
+# Get the Rust compiler name, version, and error out if it is not supported.
+rustc-info := $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC))
+$(error-if,$(success,test -z "$(rustc-info)"),Sorry$(comma) this Rust compiler is not supported.)
+rustc-name := $(shell,set -- $(rustc-info) && echo $1)
+rustc-version := $(shell,set -- $(rustc-info) && echo $2)
+
# Get the assembler name, version, and error out if it is not supported.
as-info := $(shell,$(srctree)/scripts/as-version.sh $(CC) $(CLANG_FLAGS))
$(error-if,$(success,test -z "$(as-info)"),Sorry$(comma) this assembler is not supported.)
@@ -69,6 +69,10 @@ gcc-min-version = $(call test-ge, $(CONFIG_GCC_VERSION), $1)
# Usage: cflags-$(call clang-min-version, 110000) += -foo
clang-min-version = $(call test-ge, $(CONFIG_CLANG_VERSION), $1)
+# rustc-min-version
+# Usage: rustflags-$(call rustc-min-version, 107900) += -foo
+rustc-min-version = $(call test-ge, $(CONFIG_RUSTC_VERSION), $1)
+
# ld-option
# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
new file mode 100755
@@ -0,0 +1,52 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Print the Rust compiler name and its version in a 6 or 7-digit form.
+# Also, perform the minimum version check.
+
+set -e
+
+# 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))
+}
+
+orig_args="$@"
+
+set -- $("$@" --version)
+
+name=$1
+
+min_tool_version=$(dirname $0)/min-tool-version.sh
+
+case "$name" in
+rustc)
+ version=$2
+ min_version=$($min_tool_version rustc)
+ ;;
+*)
+ echo "$orig_args: unknown Rust compiler" >&2
+ exit 1
+ ;;
+esac
+
+rustcversion=$(get_canonical_version $version)
+min_rustcversion=$(get_canonical_version $min_version)
+
+if [ "$rustcversion" -lt "$min_rustcversion" ]; then
+ echo >&2 "***"
+ echo >&2 "*** Rust compiler is too old."
+ echo >&2 "*** Your $name version: $version"
+ echo >&2 "*** Minimum $name version: $min_version"
+ echo >&2 "***"
+ exit 1
+fi
+
+echo $name $rustcversion