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+ )
4852rust_compiler_min_version=$( $min_tool_version rustc)
4953rust_compiler_cversion=$( get_canonical_version $rust_compiler_version )
5054rust_compiler_min_cversion=$( get_canonical_version $rust_compiler_min_version )
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+ )
7381rust_bindings_generator_min_version=$( $min_tool_version bindgen)
7482rust_bindings_generator_cversion=$( get_canonical_version $rust_bindings_generator_version )
7583rust_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
92100fi
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' ' )
104108bindgen_libclang_min_version=$( $min_tool_version llvm)
105109bindgen_libclang_cversion=$( get_canonical_version $bindgen_libclang_version )
106110bindgen_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
116120fi
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.
120127if [ " $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
@@ -146,8 +157,3 @@ if [ ! -e "$rustc_src_core" ]; then
146157 fi
147158 exit 1
148159fi
149-
150- # Success!
151- if [ " $1 " = -v ]; then
152- echo >&2 " Rust is available!"
153- fi
0 commit comments