Skip to content

Commit 893fb9f

Browse files
committed
Build wasm bundle on release
1 parent a51654c commit 893fb9f

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ textwrap = "0.11"
112112
typify = "0.3.0"
113113
unicode-width = "0.2.0"
114114
urlencoding = "2.1"
115-
wasm-bindgen = "0.2.95"
115+
wasm-bindgen = "0.2.100"
116116
wasm-bindgen-test = "0.3"
117117
web-sys = { version = "0.3", features = ["console"] }
118118
zip = { version = "4.3", default-features = false, features = ["deflate"] }

bin/build-wasm-bundle.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
echo "Building WASM bundle for release..."
5+
6+
# Add wasm32-unknown-unknown target
7+
rustup target add wasm32-unknown-unknown
8+
9+
# Get wasm-bindgen version from the project to ensure CLI matches
10+
WASM_BINDGEN_VERSION=$(cargo tree -p pcb-zen-wasm -i wasm-bindgen | grep '^wasm-bindgen' | head -1 | awk '{print $2}' | sed 's/v//')
11+
echo "Detected wasm-bindgen version: $WASM_BINDGEN_VERSION"
12+
13+
if [ -z "$WASM_BINDGEN_VERSION" ]; then
14+
echo "❌ Failed to detect wasm-bindgen version"
15+
exit 1
16+
fi
17+
18+
# Install matching wasm-bindgen-cli
19+
cargo install wasm-bindgen-cli --version "$WASM_BINDGEN_VERSION"
20+
21+
# Build pcb-zen-wasm with production optimizations (matching Bazel wasm-prod config)
22+
echo "Building pcb-zen-wasm with production optimizations..."
23+
RUSTFLAGS="-C opt-level=3 -C lto=fat -C embed-bitcode=yes -C codegen-units=1 -C target-feature=+tail-call" \
24+
cargo build --release --target wasm32-unknown-unknown -p pcb-zen-wasm
25+
26+
# Create output directory in target
27+
mkdir -p target/wasm-bundle
28+
29+
# Run wasm-bindgen to generate JS bindings
30+
echo "Running wasm-bindgen..."
31+
wasm-bindgen target/wasm32-unknown-unknown/release/pcb_zen_wasm.wasm \
32+
--out-dir target/wasm-bundle \
33+
--target web \
34+
--out-name pcb_zen_wasm_bindgen
35+
36+
# Create tarball in target directory
37+
echo "Creating wasm-bundle.tar.gz..."
38+
tar -czf target/wasm-bundle.tar.gz -C target/wasm-bundle .
39+
40+
# Show what we created
41+
echo "✅ WASM bundle created:"
42+
ls -lh target/wasm-bundle.tar.gz
43+
echo ""
44+
echo "Bundle contains:"
45+
tar -tzf target/wasm-bundle.tar.gz
46+
47+
echo "Done!"
48+

dist-workspace.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ x86_64-apple-darwin = "macos-15-large"
2323
aarch64-apple-darwin = "macos-15-xlarge"
2424
x86_64-pc-windows-msvc = "windows-large"
2525
x86_64-unknown-linux-gnu = "ubicloud-standard-30-ubuntu-2204"
26+
27+
# Build WASM bundle as extra artifact
28+
[[dist.extra-artifacts]]
29+
artifacts = ["target/wasm-bundle.tar.gz"]
30+
build = ["./bin/build-wasm-bundle.sh"]

0 commit comments

Comments
 (0)