#!/usr/bin/env bash
#
# Install all dependencies required to build Warp on Web.

set -e

# Install Rust and other development libraries needed in the compilation
# process. Web and Linux are both built on Linux runners, so we can reuse
# the linux build dependencies script here.
"$PWD"/script/linux/install_build_deps

# Make sure the wasm Rust toolchain target is available.
rustup target add wasm32-unknown-unknown

# Install cargo-managed dependencies required to build for wasm.
# The wasm-bindgen version installed here must be kept in sync with the version
# used in the project.
WASM_BINDGEN_VERSION="$(cargo metadata --format-version 1 | jq -rc '.packages[] | select(.name == "wasm-bindgen") | .version')"
cargo binstall --force -y wasm-bindgen-cli --version "$WASM_BINDGEN_VERSION"
cargo binstall --force -y wasm-opt

# Install wasm-split binary.
mkdir -p "$HOME/.local/bin"
cd "$HOME/.local/bin"
curl -L https://github.com/getsentry/symbolicator/releases/download/26.3.1/wasm-split-Linux-x86_64 -o wasm-split
chmod +x wasm-split
# Export .local/bin into the path so we can find the wasm-split binary.
echo "$HOME/.local/bin" >> $GITHUB_PATH