chore(workspace): Rust workspace R0 — builder image, core crate (JS-compatible JSON, report contracts, facade), wasm facade, core-wasm package with proofs

This commit is contained in:
bchanot committed 2026-10-13 00:01:25 +02:00
1 parent 5fec0654d3
commit 2a38fa37b5
39 files changed
+1913 -1

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
# Faunosteo reference Rust build environment (plan R0, RUST_ARCHITECTURE_REVIEW Annex B).
# Every Rust command of the repository runs through this image (CI and local), so the
# toolchain is identical everywhere and the production VPS never needs Rust.
#
# docker build -f docker/rust-builder.Dockerfile -t faunosteo_rust_builder:1.99.0 docker
# bash docker/rust-run.sh cargo test --workspace --exclude faunosteo-worker
#
# The pinned versions below must match rust-toolchain.toml (channel) and Cargo.lock
# (wasm-bindgen crate): docker/wasm-build.sh refuses to run when they differ.
FROM rust:1.99.0-bookworm
ARG WASM_BINDGEN_VERSION=0.2.129
ARG CARGO_DENY_VERSION=0.20.2
# The wasm target is the browser build of crates/wasm.
RUN rustup target add wasm32-unknown-unknown
# Build tools compiled from crates.io at pinned versions with their own lockfiles.
RUN cargo install wasm-bindgen-cli --version "${WASM_BINDGEN_VERSION}" --locked \
&& cargo install cargo-deny --version "${CARGO_DENY_VERSION}" --locked \
&& rm -rf /usr/local/cargo/registry
# The official image installs rustup's minimal profile: without this line every container
# would download rustfmt and clippy again (rust-toolchain.toml lists them as components).
RUN rustup component add rustfmt clippy
WORKDIR /w
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# The Rust quality gate, identical in CI and locally: `pnpm rust:check`.
# Runs inside the builder image (glibc). The worker's sandbox tests run in its own
# Alpine/musl image (crates/worker/Dockerfile, stage `test`) because the seccomp
# allowlist is derived for the musl static binary that ships.
set -euo pipefail
cd "$(dirname "$0")/.."
cargo fmt --all --check
cargo clippy --workspace --all-targets --locked -- -D warnings
cargo test --workspace --exclude faunosteo-worker --locked
# Exports the TypeScript types of the contracts (ts-rs) into packages/core-wasm/types;
# CI fails on a diff so the committed types never drift from the Rust structs.
cargo test -p faunosteo-core --features ts --locked
cargo deny check licenses bans sources
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Runs a command inside the reference Rust builder image with the repository mounted
# at /w. Cargo's registry and the target directory live in named Docker volumes
# (faunosteo_ prefix, DEPLOY.md "Docker resource naming") so incremental builds stay
# fast across runs while the host needs no Rust toolchain.
#
# bash docker/rust-run.sh cargo test --workspace --exclude faunosteo-worker
# bash docker/rust-run.sh bash docker/wasm-build.sh
set -euo pipefail
IMAGE="${FAUNOSTEO_RUST_BUILDER:-faunosteo_rust_builder:1.99.0}"
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
TTY_FLAG=()
if [ -t 0 ] && [ -t 1 ]; then
TTY_FLAG=(-t)
fi
exec docker run --rm -i "${TTY_FLAG[@]}" \
-v "$ROOT":/w \
-v faunosteo_cargo_registry:/usr/local/cargo/registry \
-v faunosteo_rust_target:/w/target \
-w /w \
"$IMAGE" "$@"
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Builds the browser module of crates/wasm into packages/core-wasm/pkg (git-ignored).
# Runs inside the builder image: `pnpm wasm:build` or `bash docker/rust-run.sh bash docker/wasm-build.sh`.
# The wasm-bindgen CLI must be the exact version of the wasm-bindgen crate in Cargo.lock
# (wasm-bindgen >= 0.2.128 refuses a mismatch at runtime; we refuse it up front).
set -euo pipefail
cd "$(dirname "$0")/.."
lock_version="$(awk '/^name = "wasm-bindgen"$/ { getline; sub(/^version = "/, ""); sub(/"$/, ""); print; exit }' Cargo.lock)"
cli_version="$(wasm-bindgen --version | awk '{ print $2 }')"
if [ "$lock_version" != "$cli_version" ]; then
echo "wasm-bindgen crate ${lock_version} (Cargo.lock) != wasm-bindgen-cli ${cli_version} (builder image)" >&2
exit 1
fi
cargo build -p faunosteo-wasm --release --target wasm32-unknown-unknown --locked
out=packages/core-wasm/pkg
rm -rf "$out"
wasm-bindgen --target web --out-dir "$out" --out-name faunosteo_wasm \
target/wasm32-unknown-unknown/release/faunosteo_wasm.wasm
raw=$(wc -c < "$out/faunosteo_wasm_bg.wasm")
gz=$(gzip -9 -c "$out/faunosteo_wasm_bg.wasm" | wc -c)
echo "faunosteo_wasm_bg.wasm: ${raw} bytes raw, ${gz} bytes gzip -9"