1+ #! /bin/bash
2+
3+ # CuteDSP WebAssembly Build Script
4+ # Builds and prepares the web example with fresh WASM binaries
5+
6+ set -e # Exit on any error
7+
8+ echo " 🎵 CuteDSP WebAssembly Builder"
9+ echo " ================================"
10+
11+ # Colors for output
12+ RED=' \033[0;31m'
13+ GREEN=' \033[0;32m'
14+ YELLOW=' \033[1;33m'
15+ BLUE=' \033[0;34m'
16+ NC=' \033[0m' # No Color
17+
18+ # Function to print colored output
19+ print_status () {
20+ echo -e " ${BLUE} [INFO]${NC} $1 "
21+ }
22+
23+ print_success () {
24+ echo -e " ${GREEN} [SUCCESS]${NC} $1 "
25+ }
26+
27+ print_warning () {
28+ echo -e " ${YELLOW} [WARNING]${NC} $1 "
29+ }
30+
31+ print_error () {
32+ echo -e " ${RED} [ERROR]${NC} $1 "
33+ }
34+
35+ # Check if we're in the right directory
36+ if [ ! -f " Cargo.toml" ]; then
37+ print_error " Cargo.toml not found. Please run this script from the project root."
38+ exit 1
39+ fi
40+
41+ print_status " Checking Rust toolchain..."
42+ if ! command -v rustc & > /dev/null; then
43+ print_error " Rust is not installed. Please install Rust from https://rustup.rs/"
44+ exit 1
45+ fi
46+
47+ print_status " Checking wasm-pack..."
48+ if ! command -v wasm-pack & > /dev/null; then
49+ print_error " wasm-pack is not installed. Install with: cargo install wasm-pack"
50+ exit 1
51+ fi
52+
53+ print_status " Building WebAssembly package..."
54+ cd " $( dirname " $0 " ) " # Go to script directory (project root)
55+
56+ # Clean previous build
57+ if [ -d " web_example/pkg" ]; then
58+ print_status " Cleaning previous build..."
59+ rm -rf web_example/pkg
60+ fi
61+
62+ # Build WASM with optimizations
63+ print_status " Compiling Rust to WebAssembly..."
64+ wasm-pack build --target no-modules --out-dir web_example/pkg --features wasm
65+
66+ if [ $? -ne 0 ]; then
67+ print_error " WASM build failed!"
68+ exit 1
69+ fi
70+
71+ print_success " WebAssembly build completed!"
72+
73+ # Verify the build
74+ if [ ! -f " web_example/pkg/cute_dsp_bg.wasm" ]; then
75+ print_error " WASM file not found after build!"
76+ exit 1
77+ fi
78+
79+ WASM_SIZE=$( stat -c%s " web_example/pkg/cute_dsp_bg.wasm" 2> /dev/null || stat -f%z " web_example/pkg/cute_dsp_bg.wasm" 2> /dev/null || echo " unknown" )
80+ print_success " WASM binary size: ${WASM_SIZE} bytes"
81+
82+ # Copy additional assets if needed
83+ print_status " Preparing web assets..."
84+
85+ # Make sure the serve script is executable
86+ chmod +x web_example/serve.sh
87+
88+ print_success " Build completed successfully!"
89+ echo " "
90+ echo " 🎯 Next steps:"
91+ echo " cd web_example"
92+ echo " ./serve.sh"
93+ echo " Open http://localhost:8080 in your browser"
94+ echo " "
95+ echo " 📁 Build artifacts:"
96+ echo " • web_example/pkg/cute_dsp.js"
97+ echo " • web_example/pkg/cute_dsp_bg.wasm"
98+ echo " • web_example/index.html"
99+ echo " "
100+ print_success " Ready to serve! 🚀"
0 commit comments