#!/usr/bin/env bash # WAI Studio's files, as `wai dev` serves them at /_wai/, built into one directory: # # bash wai/quickstart/build-studio.sh # # holds Studio's build (wai/wai-studio: node build.mjs): its interface, its worker and # styles, index.html (the page `wai dev` serves), its core in WebAssembly under pkg/ # (wai-studio/core through wasm-bindgen's web target), and Quantum Studio under quantum/ with # its engine (wai-web with the feature quantum_engine) under quantum/pkg/, and BUILD.json, each # file's SHA-256. The same files on every platform: an archive for any of them carries this # directory as share/wai/studio/, where `wai dev` looks for it beside its own binary. # # Needs the wasm32-unknown-unknown target, the wasm-bindgen CLI at 0.2.127 (the version the # crates pin), Node and npm. Run from anywhere; CARGO_TARGET_DIR is honoured, with a directory # of its own under it for each workspace. Without it the builds go under the repository's # target/studio/, which git ignores, as build-web.sh's go under an ignored target/: a build # leaves the checkout as it found it. set -euo pipefail [ $# -eq 1 ] || { echo "usage: bash wai/quickstart/build-studio.sh " >&2; exit 2; } ROOT=$(cd "$(dirname "$0")/../.." && pwd) OUT=$(mkdir -p "$1" && cd "$1" && pwd) # Written over only when it is empty or holds an earlier build of this script. if [ -n "$(ls -A "$OUT")" ] && [ ! -f "$OUT/BUILD.json" ]; then echo "build-studio.sh: $OUT holds files of its own; name an empty directory" >&2 exit 2 fi STUDIO="$ROOT/wai/wai-studio" TARGET=${CARGO_TARGET_DIR:-$ROOT/target/studio} command -v wasm-bindgen >/dev/null || { echo "wasm-bindgen CLI 0.2.127 is needed (cargo install --locked wasm-bindgen-cli --version 0.2.127)" >&2; exit 2; } wasm-bindgen --version | grep -q ' 0\.2\.127$' || { echo "the wasm-bindgen CLI must be 0.2.127, the version the crates pin" >&2; exit 2; } command -v npm >/dev/null || { echo "Node and npm are needed to build Studio's interface" >&2; exit 2; } WORK=$(mktemp -d) trap 'rm -rf "$WORK"' EXIT # The floor's zstd is C, compiled for wasm32: the archive needs an archiver that indexes # WebAssembly objects (llvm-ar), as wai-studio/e2e/run.sh finds it. if [ -z "${AR_wasm32_unknown_unknown:-}" ]; then for a in llvm-ar /opt/homebrew/opt/llvm/bin/llvm-ar /usr/local/opt/llvm/bin/llvm-ar; do if command -v "$a" >/dev/null 2>&1; then export AR_wasm32_unknown_unknown="$(command -v "$a")"; break; fi done fi if [ -z "${CC_wasm32_unknown_unknown:-}" ] && [ -n "${AR_wasm32_unknown_unknown:-}" ] && [ -x "$(dirname "$AR_wasm32_unknown_unknown")/clang" ]; then export CC_wasm32_unknown_unknown="$(dirname "$AR_wasm32_unknown_unknown")/clang" fi # Studio's core. (cd "$STUDIO/core" && CARGO_TARGET_DIR="$TARGET/core" cargo build --locked --release --target wasm32-unknown-unknown) wasm-bindgen --target web --out-dir "$WORK/core-pkg" --out-name wai_studio_core "$TARGET/core/wasm32-unknown-unknown/release/wai_studio_core.wasm" # The quantum engine, for Quantum Studio. (cd "$ROOT/wai/wai-web" && CARGO_TARGET_DIR="$TARGET/wai-web" cargo build --locked --release --target wasm32-unknown-unknown --features quantum_engine) wasm-bindgen --target web --out-dir "$WORK/quantum-pkg" --out-name wai_quantum_ide "$TARGET/wai-web/wasm32-unknown-unknown/release/wai_web.wasm" # The pages need the modules and the binaries alone, not the type declarations. rm -f "$WORK"/core-pkg/*.d.ts "$WORK"/quantum-pkg/*.d.ts # Quantum Studio, then Studio, their packages from their lock files with no install script run. (cd "$ROOT/wai/quantum-studio" && npm ci --ignore-scripts --no-audit --no-fund && node build.mjs --pkg "$WORK/quantum-pkg") (cd "$STUDIO" && npm ci --ignore-scripts --no-audit --no-fund && node build.mjs --core-pkg "$WORK/core-pkg" --quantum "$ROOT/wai/quantum-studio/dist") find "$OUT" -mindepth 1 -delete cp -R "$STUDIO/dist/." "$OUT/" for f in index.html wai-studio.js pkg/wai_studio_core_bg.wasm quantum/pkg/wai_quantum_ide_bg.wasm BUILD.json; do [ -f "$OUT/$f" ] || { echo "build-studio.sh: the build has no $f" >&2; exit 1; } done ls -l "$OUT" "$OUT/pkg" echo "WAI Studio is in $OUT"