oficina / slides Public

Clone
git clone https://amadan.net/oficina/slides

Plain git — no account needed to clone.

Download

Download this file

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