Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Gary Guo and committed by
Miguel Ojeda
af0121c2 e72a076c

+30 -1
+5 -1
init/Kconfig
··· 62 62 63 63 config RUSTC_VERSION 64 64 int 65 - default $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC)) 65 + default $(rustc-version) 66 66 help 67 67 It does not depend on `RUST` since that one may need to use the version 68 68 in a `depends on`. ··· 77 77 78 78 In particular, the Makefile target 'rustavailable' is useful to check 79 79 why the Rust toolchain is not being detected. 80 + 81 + config RUSTC_LLVM_VERSION 82 + int 83 + default $(rustc-llvm-version) 80 84 81 85 config CC_CAN_LINK 82 86 bool
+3
scripts/Kconfig.include
··· 65 65 m32-flag := $(cc-option-bit,-m32) 66 66 m64-flag := $(cc-option-bit,-m64) 67 67 68 + rustc-version := $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC)) 69 + rustc-llvm-version := $(shell,$(srctree)/scripts/rustc-llvm-version.sh $(RUSTC)) 70 + 68 71 # $(rustc-option,<flag>) 69 72 # Return y if the Rust compiler supports <flag>, n otherwise 70 73 # Calls to this should be guarded so that they are not evaluated if
+22
scripts/rustc-llvm-version.sh
··· 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