#!/usr/bin/env bash # Build the core crate for wazero. No wasm-bindgen, no wasm-pack: the Go host # provides no JS glue, so the module must be plain wasm32 with a C ABI. set -euo pipefail cd "$(dirname "$0")/.." # Lint before building: disallowed-methods (clippy.toml) enforces the # Doc-construction rule documented in core/src/lib.rs — Doc::new() and # Doc::with_client_id() both draw entropy this build has no safe source # for. A doc comment alone has been wrong, or gotten around, more than # once; this is the actual enforcement. cargo clippy --manifest-path core/Cargo.toml --all-targets -- -D warnings -D clippy::disallowed_methods # --lib only: the wasm module shipped to wazero is the library crate. Any # native tooling this crate ever grows under src/bin would not be part of # that artifact and would not define the __getrandom_v03_custom symbol # itself, so building it for wasm32 would fail to link -- it isn't meant to # run there. # # --remap-path-prefix (x2): rustc embeds the absolute source path of every # panic site (Location::caller()) into the binary. Left alone, that means # the registry path of every dependency (which contains $HOME, so it # leaks a username) and this worktree's own absolute path end up baked # into slides_core.wasm -- so the artifact only reproduces byte-for-byte on # the machine, and under the $HOME, that built it. The gate's `cmp` # against the committed copy then fails everywhere else and misreports # a stale artifact instead of a non-reproducible build. Remapping both # roots to fixed placeholders makes the build's output independent of # where it ran. # # Setting RUSTFLAGS here does not merge with .cargo/config.toml's # target.wasm32-unknown-unknown.rustflags -- an env RUSTFLAGS replaces a # config-file rustflags for the same target outright, it does not append # to it. That config entry (--cfg getrandom_backend="custom") is what # routes getrandom to our no-JS-import backend on wasm32; dropping it # breaks the build (getrandom falls back to a backend wasm32-unknown- # unknown doesn't support) rather than just losing the cfg silently. So # it has to be repeated here alongside the remap flags. registry_root="${CARGO_HOME:-$HOME/.cargo}/registry/src" workspace_root="$(pwd)" export RUSTFLAGS="--cfg getrandom_backend=\"custom\" --remap-path-prefix=${registry_root}=/cargo-registry-src --remap-path-prefix=${workspace_root}=/slides-core" cargo build --release --manifest-path core/Cargo.toml --target wasm32-unknown-unknown --locked --lib out="core/target/wasm32-unknown-unknown/release/slides_core.wasm" [ -f "$out" ] || { echo "build-wasm: no artifact at $out" >&2; exit 1; } echo "$out ($(wc -c < "$out") bytes)"