set -euo pipefail
cd "$(dirname "$")"
TC="$HOME/.rustup/toolchains/stable-aarch64-apple-darwin"
OUT=ingest/static/tracker
# panic=immediate-abort + build-std: panics become bare traps and the whole
# core::fmt/panic machinery is dead-code-eliminated (~12 KB brotli). needs
# the rust-src component (rustup component add rust-src).
RUSTC_BOOTSTRAP=1 RUSTFLAGS="-Zunstable-options -Cpanic=immediate-abort" \
RUSTC="$TC/bin/rustc" ~/.cargo/bin/cargo +stable build \
-p lytics-core --target wasm32-unknown-unknown --release -Z build-std=std
~/.cargo/bin/wasm-bindgen --target web --no-typescript \
--out-dir "$OUT" target/wasm32-unknown-unknown/release/lytics_core.wasm
if command -v wasm-opt >/dev/null 2>&1; then
wasm-opt -Oz --enable-bulk-memory --enable-nontrapping-float-to-int "$OUT/lytics_core_bg.wasm" -o "$OUT/lytics_core_bg.wasm"
fi
echo "tracker built:"
ls -la "$OUT"
printf "wasm gzip: %s bytes\n" "$(gzip -c "$OUT/lytics_core_bg.wasm" | wc -c | tr -d ' ')"