kbuild: rust_is_available: handle failures calling `$RUSTC`/`$BINDGEN`
[linux-block.git] / scripts / rust_is_available.sh
index b7e0781fdea982e0b5698845cfca34053dc6bc0e..da8296cd9b8d1db3760fa466c6a4ca3f26abae85 100755 (executable)
@@ -81,8 +81,20 @@ fi
 # Check that the Rust compiler version is suitable.
 #
 # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`.
+rust_compiler_output=$( \
+       LC_ALL=C "$RUSTC" --version 2>/dev/null
+) || rust_compiler_code=$?
+if [ -n "$rust_compiler_code" ]; then
+       echo >&2 "***"
+       echo >&2 "*** Running '$RUSTC' to check the Rust compiler version failed with"
+       echo >&2 "*** code $rust_compiler_code. See output and docs below for details:"
+       echo >&2 "***"
+       echo >&2 "$rust_compiler_output"
+       echo >&2 "***"
+       exit 1
+fi
 rust_compiler_version=$( \
-       LC_ALL=C "$RUSTC" --version 2>/dev/null \
+       echo "$rust_compiler_output" \
                | sed -nE '1s:.*rustc ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p'
 )
 rust_compiler_min_version=$($min_tool_version rustc)
@@ -108,8 +120,20 @@ fi
 # Check that the Rust bindings generator is suitable.
 #
 # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`.
+rust_bindings_generator_output=$( \
+       LC_ALL=C "$BINDGEN" --version 2>/dev/null
+) || rust_bindings_generator_code=$?
+if [ -n "$rust_bindings_generator_code" ]; then
+       echo >&2 "***"
+       echo >&2 "*** Running '$BINDGEN' to check the Rust bindings generator version failed with"
+       echo >&2 "*** code $rust_bindings_generator_code. See output and docs below for details:"
+       echo >&2 "***"
+       echo >&2 "$rust_bindings_generator_output"
+       echo >&2 "***"
+       exit 1
+fi
 rust_bindings_generator_version=$( \
-       LC_ALL=C "$BINDGEN" --version 2>/dev/null \
+       echo "$rust_bindings_generator_output" \
                | sed -nE '1s:.*bindgen ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p'
 )
 rust_bindings_generator_min_version=$($min_tool_version bindgen)