Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/nornir

crates/nornir-viz-web/build-wasm.sh

#!/usr/bin/env bash
# Build the nornir-viz-web wasm bundle into `dist/` (a self-contained static site:
# index.html + the wasm-bindgen JS glue + the `_bg.wasm`), mirroring facett's
# `cargo xtask demo-wasm`. Needs: the `wasm32-unknown-unknown` rustup target and a
# `wasm-bindgen` CLI matching the `wasm-bindgen` crate version in Cargo.lock.
#
# Usage (from anywhere):
#   CARGO_TARGET_DIR=/mnt/work4t/cargo-target/nornir ./crates/nornir-viz-web/build-wasm.sh
# then serve it:
#   cargo run -p nornir-viz-web --features serve -- serve --dir crates/nornir-viz-web/dist
set -euo pipefail

CRATE="nornir-viz-web"
TARGET="wasm32-unknown-unknown"
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(cd "$HERE/../.." && pwd)"              # the nornir repo root
DIST="$HERE/dist"

# Honour CARGO_TARGET_DIR (a fast scratch disk) exactly like the cargo build will.
if [[ -n "${CARGO_TARGET_DIR:-}" ]]; then
  TARGET_DIR="$CARGO_TARGET_DIR"
else
  TARGET_DIR="$ROOT/target"
fi

echo "nornir-viz-web: building $CRATE -> $TARGET (release)…"
( cd "$ROOT" && cargo build --release -p "$CRATE" --target "$TARGET" )

WASM_IN="$TARGET_DIR/$TARGET/release/${CRATE}.wasm"
[[ -f "$WASM_IN" ]] || { echo "expected wasm artifact missing: $WASM_IN" >&2; exit 1; }

echo "nornir-viz-web: wasm-bindgen -> $DIST"
rm -rf "$DIST"; mkdir -p "$DIST"
wasm-bindgen "$WASM_IN" --out-dir "$DIST" --target web --no-typescript

# Optional size shrink (best-effort; never fails the build).
if command -v wasm-opt >/dev/null 2>&1; then
  echo "nornir-viz-web: wasm-opt -Oz"
  wasm-opt -Oz -o "$DIST/${CRATE}_bg.wasm" "$DIST/${CRATE}_bg.wasm" || true
fi

cp "$HERE/index.html" "$DIST/index.html"
echo "✔ nornir-viz-web bundle ready in $DIST"
echo "  serve: cargo run -p nornir-viz-web --features serve -- serve --dir $DIST --addr 127.0.0.1:8080"