Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 62376f9

Browse files
nbdd0121metti
authored andcommitted
FROMGIT: kbuild: rust: add CONFIG_RUSTC_LLVM_VERSION
Each version of Rust supports a range of LLVM versions. There are cases where we want to gate a config on the LLVM version instead of the Rust version. Normalized cfi integer tags are one example [1]. The invocation of rustc-version is being moved from init/Kconfig to scripts/Kconfig.include for consistency with cc-version. Link: https://lore.kernel.org/all/[email protected]/ [1] Signed-off-by: Gary Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Added missing `-llvm` to the Usage documentation. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]> Bug: 359429865 (cherry picked from commit af0121c https://github.com/Rust-for-Linux/linux.git rust-fixes) Change-Id: I4a54c0c0963504e99583c32b507c8e257301094d Signed-off-by: Alice Ryhl <[email protected]>
1 parent 3b03660 commit 62376f9

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

init/Kconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ config LLD_VERSION
6262

6363
config RUSTC_VERSION
6464
int
65-
default $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC))
65+
default $(rustc-version)
6666
help
6767
It does not depend on `RUST` since that one may need to use the version
6868
in a `depends on`.
@@ -78,6 +78,10 @@ config RUST_IS_AVAILABLE
7878
In particular, the Makefile target 'rustavailable' is useful to check
7979
why the Rust toolchain is not being detected.
8080

81+
config RUSTC_LLVM_VERSION
82+
int
83+
default $(rustc-llvm-version)
84+
8185
config CC_CAN_LINK
8286
bool
8387
default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag)) if 64BIT

scripts/Kconfig.include

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$
6565
m32-flag := $(cc-option-bit,-m32)
6666
m64-flag := $(cc-option-bit,-m64)
6767

68+
rustc-version := $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC))
69+
rustc-llvm-version := $(shell,$(srctree)/scripts/rustc-llvm-version.sh $(RUSTC))
70+
6871
# $(rustc-option,<flag>)
6972
# Return y if the Rust compiler supports <flag>, n otherwise
7073
# Calls to this should be guarded so that they are not evaluated if

scripts/rustc-llvm-version.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# Usage: $ ./rustc-llvm-version.sh rustc
5+
#
6+
# Print the LLVM version that the Rust compiler uses in a 6 digit form.
7+
8+
# Convert the version string x.y.z to a canonical up-to-6-digits form.
9+
get_canonical_version()
10+
{
11+
IFS=.
12+
set -- $1
13+
echo $((10000 * $1 + 100 * $2 + $3))
14+
}
15+
16+
if output=$("$@" --version --verbose 2>/dev/null | grep LLVM); then
17+
set -- $output
18+
get_canonical_version $3
19+
else
20+
echo 0
21+
exit 1
22+
fi

0 commit comments

Comments
 (0)