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

Commit af0121c

Browse files
nbdd0121ojeda
authored andcommitted
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/20240925-cfi-norm-kasan-fix-v1-1-0328985cdf33@google.com/ [1] Signed-off-by: Gary Guo <gary@garyguo.net> Link: https://lore.kernel.org/r/20241011114040.3900487-1-gary@garyguo.net [ Added missing `-llvm` to the Usage documentation. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent e72a076 commit af0121c

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

init/Kconfig

+5-1
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

+3
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

+22
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)