Skip to content

Commit 1f218ec

Browse files
committed
scripts: rust-is-available: do not check the full version of libclang
It turns out that `__clang_version__` is not exactly the full version (e.g. it may not include the `-` suffix), thus we cannot compare the full versions -- we will have to wait until `bindgen` adds proper support for printing the full version. Also, made all version extraction a bit more robust and use the same pattern everywhere. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent c126016 commit 1f218ec

1 file changed

Lines changed: 28 additions & 17 deletions

File tree

scripts/rust-is-available.sh

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ fi
4444
# Check that the Rust compiler version is suitable.
4545
#
4646
# Non-stable and distributions' versions may have a version suffix, e.g. `-dev`.
47-
rust_compiler_version=$("$RUSTC" --version | cut -f2 -d' ' | cut -f1 -d'-')
47+
rust_compiler_version=$( \
48+
LC_ALL=C "$RUSTC" --version 2>/dev/null \
49+
| head -n 1 \
50+
| grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \
51+
)
4852
rust_compiler_min_version=$($min_tool_version rustc)
4953
rust_compiler_cversion=$(get_canonical_version $rust_compiler_version)
5054
rust_compiler_min_cversion=$(get_canonical_version $rust_compiler_min_version)
@@ -69,7 +73,11 @@ fi
6973
# Check that the Rust bindings generator is suitable.
7074
#
7175
# Non-stable and distributions' versions may have a version suffix, e.g. `-dev`.
72-
rust_bindings_generator_version=$("$BINDGEN" --version | cut -f2 -d' ' | cut -f1 -d'-')
76+
rust_bindings_generator_version=$( \
77+
LC_ALL=C "$BINDGEN" --version 2>/dev/null \
78+
| head -n 1 \
79+
| grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \
80+
)
7381
rust_bindings_generator_min_version=$($min_tool_version bindgen)
7482
rust_bindings_generator_cversion=$(get_canonical_version $rust_bindings_generator_version)
7583
rust_bindings_generator_min_cversion=$(get_canonical_version $rust_bindings_generator_min_version)
@@ -92,15 +100,11 @@ if [ "$1" = -v ] && [ "$rust_bindings_generator_cversion" -gt "$rust_bindings_ge
92100
fi
93101

94102
# Check that the `libclang` used by the Rust bindings generator is suitable.
95-
#
96-
# There may be a better way to do this in the future,
97-
# see https://github.com/rust-lang/rust-bindgen/issues/2138
98-
bindgen_libclang_full_version=$(\
99-
"$BINDGEN" $(dirname $0)/rust-is-available-bindgen-libclang.h 2>&1 >/dev/null \
100-
| grep -F 'clang version' \
101-
| sed -E 's:^.*(clang version .*) \[.*$:\1:' \
103+
bindgen_libclang_version=$( \
104+
LC_ALL=C "$BINDGEN" $(dirname $0)/rust-is-available-bindgen-libclang.h 2>&1 >/dev/null \
105+
| grep -F 'clang version ' \
106+
| grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \
102107
)
103-
bindgen_libclang_version=$(echo "$bindgen_libclang_full_version" | cut -f3 -d' ')
104108
bindgen_libclang_min_version=$($min_tool_version llvm)
105109
bindgen_libclang_cversion=$(get_canonical_version $bindgen_libclang_version)
106110
bindgen_libclang_min_cversion=$(get_canonical_version $bindgen_libclang_min_version)
@@ -115,17 +119,24 @@ if [ "$bindgen_libclang_cversion" -lt "$bindgen_libclang_min_cversion" ]; then
115119
exit 1
116120
fi
117121

118-
# If the C compiler is Clang, then we can also check whether its full version
119-
# matches exactly the `libclang` used by the Rust bindings generator.
122+
# If the C compiler is Clang, then we can also check whether its version
123+
# matches the `libclang` version used by the Rust bindings generator.
124+
#
125+
# In the future, we might be able to perform a full version check, see
126+
# https://github.com/rust-lang/rust-bindgen/issues/2138.
120127
if [ "$1" = -v ]; then
121128
cc_name=$($(dirname $0)/cc-version.sh "$CC" | cut -f1 -d' ')
122129
if [ "$cc_name" = Clang ]; then
123-
clang_full_version=$("$CC" --version | grep -F 'clang version')
124-
if [ "$clang_full_version" != "$bindgen_libclang_full_version" ]; then
130+
clang_version=$( \
131+
LC_ALL=C "$CC" --version 2>/dev/null \
132+
| head -n 1 \
133+
| grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \
134+
)
135+
if [ "$clang_version" != "$bindgen_libclang_version" ]; then
125136
echo >&2 "***"
126-
echo >&2 "*** libclang (used by the Rust bindings generator '$BINDGEN') full version does not match Clang's. This may be a problem."
127-
echo >&2 "*** libclang: $bindgen_libclang_full_version"
128-
echo >&2 "*** Clang: $clang_full_version"
137+
echo >&2 "*** libclang (used by the Rust bindings generator '$BINDGEN') version does not match Clang's. This may be a problem."
138+
echo >&2 "*** libclang version: $bindgen_libclang_version"
139+
echo >&2 "*** Clang version: $clang_version"
129140
echo >&2 "***"
130141
fi
131142
fi

0 commit comments

Comments
 (0)