anvilsign in

collin/anvil

1#!/usr/bin/env bash
2# Stage the anvild binary that the image COPYs in. NOT run on the VPS — it
3# never compiles anything.
4#
5# Uses cargo-zigbuild to cross-compile a fully static x86_64-musl executable at
6# native speed (no QEMU) and leaves it at deploy/anvild, which is where the
7# Dockerfile expects it. Building and pushing the image is compose's job from
8# there (see compose.yaml); ./deploy/deploy.sh runs both halves.
9#
10# ./deploy/build.sh release — what gets deployed
11# ./deploy/build.sh --debug unoptimized, for the local compose.override.yaml
12# ./deploy/build.sh --worker also stage anvil-worker, for the local runners
13#
14# --worker is a local-development thing only: production runners are native
15# processes on the build host (docs/remote-runners.md), and nothing on hagrid
16# builds or runs the worker image.
17#
18# Prereqs (one-time):
19# zig (dnf install zig, or brew install zig)
20# cargo install cargo-zigbuild
21# The toolchain and the musl target come from rust-toolchain.toml — rustup
22# installs both on the first cargo invocation in the repo.
23set -euo pipefail
24
25TARGET="x86_64-unknown-linux-musl"
26PROFILE=release
27CARGO_FLAGS=(--release)
28# Binary name → where the Dockerfile that COPYs it expects to find it.
29BINS=(anvild)
30
31for arg in "$@"; do
32 case "$arg" in
33 --debug) PROFILE=debug; CARGO_FLAGS=() ;;
34 --worker) BINS+=(anvil-worker) ;;
35 *) echo "usage: $0 [--debug] [--worker]" >&2; exit 64 ;;
36 esac
37done
38
39cd "$(dirname "$0")/.."
40
41# macOS terminals default to a 256 open-file soft limit; zig's linker opens
42# every rlib at once and dies with ProcessFdQuotaExceeded. Raise it for this
43# process (children inherit it).
44ulimit -n 4096 2>/dev/null || true
45
46# Static musl even for --debug: the runtime image is Ubuntu, and a binary
47# linked against Fedora's glibc would not run there.
48for bin in "${BINS[@]}"; do
49 echo "==> cross-compiling $bin for $TARGET ($PROFILE, native, via zig)"
50 cargo zigbuild --target "$TARGET" --bin "$bin" "${CARGO_FLAGS[@]}"
51
52 echo "==> staging binary at deploy/$bin"
53 cp "target/$TARGET/$PROFILE/$bin" "deploy/$bin"
54done
55
56# Deliberately left in place: `docker compose build` runs after this and needs
57# it in the context. It is gitignored, and the next build overwrites it.
58echo "==> staged ($PROFILE). Build the image with: docker compose build"