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

Commit

Permalink
FROMGIT: kbuild: rust: add CONFIG_RUSTC_LLVM_VERSION
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
nbdd0121 authored and metti committed Oct 16, 2024
1 parent 3b03660 commit 62376f9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ config LLD_VERSION

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

config RUSTC_LLVM_VERSION
int
default $(rustc-llvm-version)

config CC_CAN_LINK
bool
default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag)) if 64BIT
Expand Down
3 changes: 3 additions & 0 deletions scripts/Kconfig.include
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$
m32-flag := $(cc-option-bit,-m32)
m64-flag := $(cc-option-bit,-m64)

rustc-version := $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC))
rustc-llvm-version := $(shell,$(srctree)/scripts/rustc-llvm-version.sh $(RUSTC))

# $(rustc-option,<flag>)
# Return y if the Rust compiler supports <flag>, n otherwise
# Calls to this should be guarded so that they are not evaluated if
Expand Down
22 changes: 22 additions & 0 deletions scripts/rustc-llvm-version.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 62376f9

Please sign in to comment.