summaryrefslogtreecommitdiffstats
path: root/scripts/rustc-llvm-version.sh
diff options
context:
space:
mode:
authorGary Guo <gary@garyguo.net>2024-10-11 12:40:33 +0100
committerMiguel Ojeda <ojeda@kernel.org>2024-10-13 22:22:28 +0200
commitaf0121c2d303111d363c62e40413ffb39d5dc0f1 (patch)
tree9f99fbc0e5e054de6a2670e6ca188397181382d7 /scripts/rustc-llvm-version.sh
parente72a076c620f692b405dd6c39e8a7c98c8a59ecc (diff)
downloadlinux-stable-af0121c2d303111d363c62e40413ffb39d5dc0f1.tar.gz
linux-stable-af0121c2d303111d363c62e40413ffb39d5dc0f1.tar.bz2
linux-stable-af0121c2d303111d363c62e40413ffb39d5dc0f1.zip
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>
Diffstat (limited to 'scripts/rustc-llvm-version.sh')
-rwxr-xr-xscripts/rustc-llvm-version.sh22
1 files changed, 22 insertions, 0 deletions
diff --git a/scripts/rustc-llvm-version.sh b/scripts/rustc-llvm-version.sh
new file mode 100755
index 000000000000..b6063cbe5bdc
--- /dev/null
+++ b/scripts/rustc-llvm-version.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Usage: $ ./rustc-llvm-version.sh rustc
+#
+# Print the LLVM version that the Rust compiler uses in a 6 digit form.
+
+# Convert the version string x.y.z to a canonical up-to-6-digits form.
+get_canonical_version()
+{
+ IFS=.
+ set -- $1
+ echo $((10000 * $1 + 100 * $2 + $3))
+}
+
+if output=$("$@" --version --verbose 2>/dev/null | grep LLVM); then
+ set -- $output
+ get_canonical_version $3
+else
+ echo 0
+ exit 1
+fi