Skip to content

Commit e90db55

Browse files
committed
kbuild: rust_is_available: check that environment variables are set
Sometimes [1] users may attempt to setup the Rust support by checking what Kbuild does and they end up finding out about `scripts/rust_is_available.sh`. Inevitably, they run the script directly, but unless they setup the required variables, the result of the script is not meaningful. We could add some defaults to the variables, but that could be confusing for those that may override the defaults (compared to their kernel builds), and `$CC` would not be a simple default in any case. Therefore, instead, explicitly check whether the expected variables are set (`$RUSTC`, `$BINDGEN` and `$CC`). If not, print an explanation about the fact that the script is meant to be called from Kbuild, since that is the most likely cause for the variables not being set. Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/ [1] Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 52cae7f commit e90db55

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

scripts/rust_is_available.sh

+29
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,40 @@ print_docs_reference()
2828
echo >&2 "***"
2929
}
3030

31+
# Print an explanation about the fact that the script is meant to be called from Kbuild.
32+
print_kbuild_explanation()
33+
{
34+
echo >&2 "***"
35+
echo >&2 "*** This script is intended to be called from Kbuild."
36+
echo >&2 "*** Please use the 'rustavailable' target to call it instead."
37+
echo >&2 "*** Otherwise, the results may not be meaningful."
38+
exit 1
39+
}
40+
3141
# If the script fails for any reason, or if there was any warning, then
3242
# print a reference to the documentation on exit.
3343
warning=0
3444
trap 'if [ $? -ne 0 ] || [ $warning -ne 0 ]; then print_docs_reference; fi' EXIT
3545

46+
# Check that the expected environment variables are set.
47+
if [ -z "${RUSTC+x}" ]; then
48+
echo >&2 "***"
49+
echo >&2 "*** Environment variable 'RUSTC' is not set."
50+
print_kbuild_explanation
51+
fi
52+
53+
if [ -z "${BINDGEN+x}" ]; then
54+
echo >&2 "***"
55+
echo >&2 "*** Environment variable 'BINDGEN' is not set."
56+
print_kbuild_explanation
57+
fi
58+
59+
if [ -z "${CC+x}" ]; then
60+
echo >&2 "***"
61+
echo >&2 "*** Environment variable 'CC' is not set."
62+
print_kbuild_explanation
63+
fi
64+
3665
# Check that the Rust compiler exists.
3766
if ! command -v "$RUSTC" >/dev/null; then
3867
echo >&2 "***"

0 commit comments

Comments
 (0)