Skip to contentSkip to conversation

Fix libclang version check for rustavailable

PATCH New Ethan D. Twardy 1 participant 2 messages May 31, 2023 Rust

lore
Share & tools
lore
#0 lore raw

v3 cover Fix libclang version check for rustavailable

This series contains just one two-line patch, to fix a small issue in scripts/rust_is_available.sh. This issue is currently affecting kernel builds with Rust on Gentoo Linux (and potentially other distributions/workflows where the kernel source path contains a version string).

Changes from v2:
* Add tags from review and testing

Changes from v1:
* Patch formatting. I believe there were some serious issues with the formatting that caused it to be lost/ignored by the mailing list. I sincerely hope that the formatting of this patch is acceptable, this is my first contribution to the kernel so I haven't mastered the patch workflow yet.

Ethan D. Twardy (1):
scripts/rust_is_available: Fix clang version check

 scripts/rust_is_available.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

base-commit: ac9a78681b921877518763ba0e89202254349d1b

Signature · 1 line
2.40.1
#1 lore raw

PATCH v3 1/1 scripts/rust_is_available: Fix clang version check

During out-of-tree builds where the path to the kernel source tree contains a version string, scripts/rust_is_available.sh incorrectly identified the version string of libclang to be the version string in the kernel sources path, resulting in CONFIG_RUST_IS_AVAILABLE erroneously set to 'n'.

This issue was previously affecting builds on distributions, such as Gentoo Linux, where the kernel source tree is under version control, and placed under a path containing the current kernel version string in /usr/src.

The fix is to take special care to match only the version string following the string 'clang version' in the output.

To reproduce:

  $ cd ~/build && make -C ~/linux-6.2.0 O=$PWD LLVM=1 rustavailable
  [...]
  *** libclang (used by the Rust bindings generator 'bindgen') is too old.
  ***   Your version:    6.2.0
  ***   Minimum version: 11.0.0
  [...]
Fixes 78521f3399ab ("scripts: add `rust_is_available.sh`")
scripts/rust_is_available.sh +2 -2
index aebbf1913970..e8a1439be9f8 100755
@@ -102,8 +102,8 @@ fi
 # Check that the `libclang` used by the Rust bindings generator is suitable.
 bindgen_libclang_version=$( \
 	LC_ALL=C "$BINDGEN" $(dirname $0)/rust_is_available_bindgen_libclang.h 2>&1 >/dev/null \
-		| grep -F 'clang version ' \
-		| grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \
+		| grep -oE 'clang version [0-9]+\.[0-9]+\.[0-9]+' \
+		| cut -d' ' -f3 \
 		| head -n 1 \
 )
 bindgen_libclang_min_version=$($min_tool_version llvm)
Signature · 1 line
2.40.1