synapse-wasm / run.sh
Robbo
Initial: WASM sensor stack β€” core types, MCU module (32KB), WIT contract
7932636 unverified
#!/usr/bin/env bash
export PATH="/run/current-system/sw/bin:/root/.nix-profile/bin:/nix/var/nix/profiles/default/bin:$PATH"
set -euo pipefail
cd /opt/synapse-wasm
echo "=== ENV ==="
rustc --version
cargo --version
echo ""
echo "=== STEP 1: NATIVE TESTS ==="
cargo test --workspace 2>&1
echo ""
echo "=== STEP 2: WASM TARGET CHECK ==="
if rustc --print target-list | grep -q wasm32-unknown-unknown; then
echo "wasm32 target available β€” building..."
cargo build --package synapse-sensor --target wasm32-unknown-unknown --release 2>&1
WASM="target/wasm32-unknown-unknown/release/synapse_sensor.wasm"
RAW=$(wc -c < "$WASM")
echo "Raw WASM: $RAW bytes ($((RAW/1024))KB)"
# Try wasm-opt if available
if command -v wasm-opt &>/dev/null; then
mkdir -p target/wasm-opt
wasm-opt -Oz --strip-debug --strip-producers -o target/wasm-opt/synapse_sensor.wasm "$WASM"
OPT=$(wc -c < target/wasm-opt/synapse_sensor.wasm)
echo "Optimized: $OPT bytes ($((OPT/1024))KB) β€” $(( (RAW - OPT) * 100 / RAW ))% reduction"
fi
if command -v twiggy &>/dev/null; then
echo ""
echo "=== TWIGGY TOP 10 ==="
twiggy top target/wasm-opt/synapse_sensor.wasm -n 10 2>&1 || true
fi
if command -v wasm-tools &>/dev/null; then
echo ""
echo "=== VALIDATE ==="
wasm-tools validate target/wasm-opt/synapse_sensor.wasm 2>&1 && echo "VALID" || echo "INVALID"
fi
if command -v wasm2wat &>/dev/null; then
echo ""
echo "=== EXPORTS ==="
wasm2wat "$WASM" 2>/dev/null | grep 'export' || echo "(none)"
echo ""
echo "=== IMPORTS ==="
wasm2wat "$WASM" 2>/dev/null | grep 'import' || echo "(none)"
fi
else
echo "wasm32 target NOT in system rustc β€” need NixOS config update"
fi
echo ""
echo "=== COMPLETE ==="