53 lines
1.5 KiB
Bash
53 lines
1.5 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
rust_bin_dir="${CARGO_HOME:-$HOME/.cargo}/bin"
|
|
case ":$PATH:" in
|
|
*":$rust_bin_dir:"*) ;;
|
|
*) PATH="$rust_bin_dir:$PATH"; export PATH ;;
|
|
esac
|
|
|
|
wasm_target_ready() {
|
|
command -v rustc >/dev/null 2>&1 || return 1
|
|
target_libdir=$(rustc --print target-libdir --target wasm32-unknown-unknown 2>/dev/null) || return 1
|
|
test -d "$target_libdir"
|
|
}
|
|
|
|
rust_ready() {
|
|
command -v cargo >/dev/null 2>&1 || return 1
|
|
[ "${NODEFLARE_NATIVE_RUST_ONLY:-0}" = "1" ] || wasm_target_ready
|
|
}
|
|
|
|
if ! rust_ready; then
|
|
if ! command -v rustup >/dev/null 2>&1; then
|
|
rustup_install_url="https://sh.rustup.rs"
|
|
rustup_installer=$(mktemp)
|
|
trap 'rm -f "$rustup_installer"' 0 HUP INT TERM
|
|
echo "Rust toolchain not found; installing stable Rust..."
|
|
if command -v curl >/dev/null 2>&1; then
|
|
curl --proto '=https' --tlsv1.2 -sSf "$rustup_install_url" -o "$rustup_installer"
|
|
elif command -v wget >/dev/null 2>&1; then
|
|
wget -qO "$rustup_installer" "$rustup_install_url"
|
|
else
|
|
echo "Rust is missing and curl/wget is unavailable" >&2
|
|
exit 1
|
|
fi
|
|
sh "$rustup_installer" -y --profile minimal --default-toolchain stable
|
|
rm -f "$rustup_installer"
|
|
trap - 0 HUP INT TERM
|
|
fi
|
|
|
|
if ! command -v cargo >/dev/null 2>&1; then
|
|
rustup toolchain install stable --profile minimal
|
|
rustup default stable
|
|
fi
|
|
if [ "${NODEFLARE_NATIVE_RUST_ONLY:-0}" != "1" ]; then
|
|
rustup target add wasm32-unknown-unknown
|
|
fi
|
|
fi
|
|
|
|
if ! rust_ready; then
|
|
echo "Required Rust toolchain is unavailable" >&2
|
|
exit 1
|
|
fi
|