forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kbuild: rust: add
rustc-version
support
Now that we are starting to support several Rust versions, introduce `rustc-version` support, mimicking the C side: - `scripts/rustc-version.sh`, that mimics the other version scripts (with one more digit, e.g. Rust 1.79.0 is 107900). - `rustc-{info,name,version}` Kbuild macros. - `CONFIG_RUSTC_VERSION` Kconfig symbol that calls `rustc-version`. - `rustc-min-version` Kbuild macro that uses `CONFIG_RUSTC_VERSION`. With these, we can easily support flags conditionally depending on `rustc`'s version -- a user comes in the next patch. Another user will be the `-Ctarget-feature=+reserve-x18`/`-Zfixed-x18` arm64 flags [1]. Link: https://lore.kernel.org/rust-for-linux/[email protected]/ [1] Reviewed-by: Finn Behrens <[email protected]> Tested-by: Benno Lossin <[email protected]> Tested-by: Andreas Hindborg <[email protected]> Signed-off-by: Miguel Ojeda <[email protected]> Link: https://lore.kernel.org/r/[email protected]
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |