Skip to content

Instantly share code, notes, and snippets.

@justanotherdot
Last active March 21, 2023 16:59
Show Gist options
  • Save justanotherdot/ca1f163754e9a90f6c6b9dfb25a0598f to your computer and use it in GitHub Desktop.
Save justanotherdot/ca1f163754e9a90f6c6b9dfb25a0598f to your computer and use it in GitHub Desktop.
Attempt to build all cross-compile targets supported by `rustc` and report the time taken.
#!/bin/sh -eu
FILTER="${FILTER:="."}"
TOOLCHAIN_BK="$(rustup toolchain list | rg default | awk '{print $1}')"
TOOLCHAIN_KIND_BK="$(echo "$TOOLCHAIN_BK" | rg -o '^(stable|nightly)')"
if [ "$TOOLCHAIN_KIND_BK" != "stable" ]; then
rustup install stable
rustup default stable
fi
TARGETS="$(rustc --print target-list | rg "$FILTER")"
echo "=== Installing targets."
for target in $TARGETS; do
echo "+ $target"
rustup target add "$target" 1>/dev/null 2>&1 || true
done
echo "=== Compiling with collected targets."
for target in $TARGETS; do
cargo clean 1>/dev/null 2>&1
export RUSTC_WRAPPER=
export RUSTFLAGS=
cargo build --target="$target" 2>&1 | awk "/Finished/{ rc = 1; print \"+ $target in\", \$8 }; END { exit !rc }" || echo "- $target"
done
if [ "$TOOLCHAIN_KIND_BK" != "stable" ]; then
rustup default "$TOOLCHAIN_BK"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment