oficina / slides Public

Build the wasm natively in the arm64 rust image on arm64 hosts

On an arm64 host the docker fallback ran the amd64 image under qemu,
which segfaults inside rustup. Use the arm64 variant of the same
rust:1.98.0 image there, at the same fixed paths, with its own volumes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 0d9662e14ad5a923b3c76deaa03480c3b3c5e325 parent ddf880b
2 files changed, +38 −14
  • scripts/build-pdf-wasm.sh +19 −7
  • scripts/build-wasm.sh +19 −7

CI failed — run details

diff --git a/scripts/build-pdf-wasm.sh b/scripts/build-pdf-wasm.sh
index 2ed0659..4c962cb 100755
--- a/scripts/build-pdf-wasm.sh
+++ b/scripts/build-pdf-wasm.sh
@@ -8,9 +8,11 @@ if [[ "${1:-}" != "--build-only" && "${1:-}" != "--canonical-build" ]]; then
cargo clippy --manifest-path core/pdf/Cargo.toml --all-targets -- -D warnings
fi
# Rust/Cargo crate identities affect code ordering even after path remapping.
-# Build on Linux amd64 at fixed source/toolchain paths on every host.
+# Build on Linux at fixed source/toolchain paths on every host: amd64, or
+# arm64 on an arm64 host. The wasm32 output does not depend on the host
+# architecture, and the gate's cmp against the committed bytes checks that.
if [[ "${1:-}" == "--canonical-build" ]]; then
- [[ "$(uname -s)/$(uname -m)" == "Linux/x86_64" && "$(pwd)" == /work \
+ [[ "$(uname -s)/$(uname -m)" =~ ^Linux/(x86_64|aarch64)$ && "$(pwd)" == /work \
&& "$CARGO_HOME" == /usr/local/cargo && "$RUSTUP_HOME" == /usr/local/rustup ]] \
|| { echo "build-pdf-wasm: invalid canonical build environment" >&2; exit 1; }
export CARGO_TARGET_DIR=/work/core/pdf/target RUSTUP_TOOLCHAIN=1.98.0
@@ -36,13 +38,23 @@ else
else
command -v docker >/dev/null || { echo "build-pdf-wasm: install Docker, or bubblewrap on Linux amd64" >&2; exit 1; }
target_key=$(printf %s "$(pwd)" | shasum -a 256 | cut -c1-16)
- docker run --rm --platform linux/amd64 \
+ # Emulating amd64 on an arm64 host crashes (qemu segfaults inside rustup),
+ # so there the arm64 variant of the same rust:1.98.0 image builds
+ # natively, with its own volumes so the two architectures' toolchains
+ # never share one.
+ platform=linux/amd64 arch_suffix=
+ image=rust@sha256:8aea3a845c48caac4091a8d0e6494d213061f8f014dc2f5a5f1a88a1a8c9f301
+ if [[ "$(uname -s)/$(uname -m)" == Linux/aarch64 ]]; then
+ platform=linux/arm64 arch_suffix=-arm64
+ image=rust@sha256:47a38c2b79ea33ae2ce886508310fb9d07998ebc5f8df966b2c442cda04c90df
+ fi
+ docker run --rm --platform "$platform" \
--mount "type=bind,source=$(pwd),target=/work,readonly" \
- --mount "type=volume,source=oficina-slides-pdf-wasm-target-${target_key},target=/work/core/pdf/target" \
- --mount type=volume,source=oficina-slides-pdf-wasm-cargo,target=/usr/local/cargo \
- --mount type=volume,source=oficina-slides-pdf-wasm-rustup,target=/usr/local/rustup \
+ --mount "type=volume,source=oficina-slides-pdf-wasm-target-${target_key}${arch_suffix},target=/work/core/pdf/target" \
+ --mount type=volume,source=oficina-slides-pdf-wasm-cargo${arch_suffix},target=/usr/local/cargo \
+ --mount type=volume,source=oficina-slides-pdf-wasm-rustup${arch_suffix},target=/usr/local/rustup \
--workdir /work \
- rust@sha256:8aea3a845c48caac4091a8d0e6494d213061f8f014dc2f5a5f1a88a1a8c9f301 \
+ "$image" \
bash -ec 'rustup target add wasm32-unknown-unknown >&2; ./scripts/build-pdf-wasm.sh --canonical-build >&2; cat core/pdf/target/wasm32-unknown-unknown/release/slides_pdf.wasm' > "$temporary"
fi
mv "$temporary" "$out"
diff --git a/scripts/build-wasm.sh b/scripts/build-wasm.sh
index dbd11b1..b2e4200 100755
--- a/scripts/build-wasm.sh
+++ b/scripts/build-wasm.sh
@@ -12,9 +12,11 @@ if [[ "${1:-}" != "--build-only" && "${1:-}" != "--canonical-build" ]]; then
cargo clippy --manifest-path core/Cargo.toml --all-targets -- -D warnings -D clippy::disallowed_methods
fi
# Rust/Cargo crate identities affect code ordering even after path remapping.
-# Build on Linux amd64 at fixed source/toolchain paths on every host.
+# Build on Linux at fixed source/toolchain paths on every host: amd64, or
+# arm64 on an arm64 host. The wasm32 output does not depend on the host
+# architecture, and the gate's cmp against the committed bytes checks that.
if [[ "${1:-}" == "--canonical-build" ]]; then
- [[ "$(uname -s)/$(uname -m)" == "Linux/x86_64" && "$(pwd)" == /work \
+ [[ "$(uname -s)/$(uname -m)" =~ ^Linux/(x86_64|aarch64)$ && "$(pwd)" == /work \
&& "$CARGO_HOME" == /usr/local/cargo && "$RUSTUP_HOME" == /usr/local/rustup ]] \
|| { echo "build-wasm: invalid canonical build environment" >&2; exit 1; }
export CARGO_TARGET_DIR=/work/core/target RUSTUP_TOOLCHAIN=1.98.0
@@ -40,13 +42,23 @@ else
else
command -v docker >/dev/null || { echo "build-wasm: install Docker, or bubblewrap on Linux amd64" >&2; exit 1; }
target_key=$(printf %s "$(pwd)" | shasum -a 256 | cut -c1-16)
- docker run --rm --platform linux/amd64 \
+ # Emulating amd64 on an arm64 host crashes (qemu segfaults inside rustup),
+ # so there the arm64 variant of the same rust:1.98.0 image builds
+ # natively, with its own volumes so the two architectures' toolchains
+ # never share one.
+ platform=linux/amd64 arch_suffix=
+ image=rust@sha256:8aea3a845c48caac4091a8d0e6494d213061f8f014dc2f5a5f1a88a1a8c9f301
+ if [[ "$(uname -s)/$(uname -m)" == Linux/aarch64 ]]; then
+ platform=linux/arm64 arch_suffix=-arm64
+ image=rust@sha256:47a38c2b79ea33ae2ce886508310fb9d07998ebc5f8df966b2c442cda04c90df
+ fi
+ docker run --rm --platform "$platform" \
--mount "type=bind,source=$(pwd),target=/work,readonly" \
- --mount "type=volume,source=oficina-slides-core-wasm-target-${target_key},target=/work/core/target" \
- --mount type=volume,source=oficina-slides-core-wasm-cargo,target=/usr/local/cargo \
- --mount type=volume,source=oficina-slides-core-wasm-rustup,target=/usr/local/rustup \
+ --mount "type=volume,source=oficina-slides-core-wasm-target-${target_key}${arch_suffix},target=/work/core/target" \
+ --mount type=volume,source=oficina-slides-core-wasm-cargo${arch_suffix},target=/usr/local/cargo \
+ --mount type=volume,source=oficina-slides-core-wasm-rustup${arch_suffix},target=/usr/local/rustup \
--workdir /work \
- rust@sha256:8aea3a845c48caac4091a8d0e6494d213061f8f014dc2f5a5f1a88a1a8c9f301 \
+ "$image" \
bash -ec 'rustup target add wasm32-unknown-unknown >&2; ./scripts/build-wasm.sh --canonical-build >&2; cat core/target/wasm32-unknown-unknown/release/slides_core.wasm' > "$temporary"
fi
mv "$temporary" "$out"