#!/bin/bash # Build script for all WASM libraries in the MMX repository set -e # Exit on any error # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color echo -e "${BLUE}🚀 Building all WASM libraries for MMX${NC}" # Set PATH to include cargo export PATH="$HOME/.cargo/bin:$PATH" # Check if wasm-pack is installed if ! command -v wasm-pack &> /dev/null; then echo -e "${RED}❌ wasm-pack not found. Please install it first:${NC}" echo "curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh" exit 1 fi # Change to rust directory cd rust echo -e "${YELLOW}📋 Found WASM crates to build:${NC}" # List all WASM crates (crates with crate-type = ["cdylib"]) wasm_crates=() for dir in */; do if [[ -f "$dir/Cargo.toml" ]]; then if grep -q 'crate-type.*=.*\["cdylib"\]' "$dir/Cargo.toml"; then wasm_crates+=("${dir%/}") echo -e " • ${dir%/}" fi fi done if [[ ${#wasm_crates[@]} -eq 0 ]]; then echo -e "${YELLOW}⚠️ No WASM crates found${NC}" exit 0 fi echo "" # Build each WASM crate for crate in "${wasm_crates[@]}"; do echo -e "${BLUE}🔨 Building $crate...${NC}" cd "$crate" # Determine output directory based on crate name case "$crate" in "rhai-codemirror") output_dir="../../webui/src/wasm/rhai-codemirror" ;; *) output_dir="../../webui/src/wasm/$crate" ;; esac # Build with wasm-pack if wasm-pack build --target web --out-dir "$output_dir"; then echo -e "${GREEN}✅ Successfully built $crate${NC}" else echo -e "${RED}❌ Failed to build $crate${NC}" exit 1 fi cd .. echo "" done echo -e "${GREEN}🎉 All WASM libraries built successfully!${NC}" echo "" echo -e "${YELLOW}📦 Built libraries:${NC}" for crate in "${wasm_crates[@]}"; do case "$crate" in "rhai-codemirror") output_dir="../webui/src/wasm/rhai-codemirror" ;; *) output_dir="../webui/src/wasm/$crate" ;; esac echo -e " • $crate → $output_dir" done