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# rustup target add x86_64-unknown-linux-musl
22set -euo pipefail
23
24TARGET="x86_64-unknown-linux-musl"
25PROFILE=release
26CARGO_FLAGS=(--release)
27# Binary name → where the Dockerfile that COPYs it expects to find it.
28BINS=(anvild)
29
30for arg in "$@"; do
31 case "$arg" in
32 --debug) PROFILE=debug; CARGO_FLAGS=() ;;
33 --worker) BINS+=(anvil-worker) ;;
34 *) echo "usage: $0 [--debug] [--worker]" >&2; exit 64 ;;
35 esac
36done
37
38cd "$(dirname "$0")/.."
39
40# macOS terminals default to a 256 open-file soft limit; zig's linker opens
41# every rlib at once and dies with ProcessFdQuotaExceeded. Raise it for this
42# process (children inherit it).
43ulimit -n 4096 2>/dev/null || true
44
45# Static musl even for --debug: the runtime image is Ubuntu, and a binary
46# linked against Fedora's glibc would not run there.
47for bin in "${BINS[@]}"; do
48 echo "==> cross-compiling $bin for $TARGET ($PROFILE, native, via zig)"
49 cargo zigbuild --target "$TARGET" --bin "$bin" "${CARGO_FLAGS[@]}"
50
51 echo "==> staging binary at deploy/$bin"
52 cp "target/$TARGET/$PROFILE/$bin" "deploy/$bin"
53done
54
55# Deliberately left in place: `docker compose build` runs after this and needs
56# it in the context. It is gitignored, and the next build overwrites it.
57echo "==> staged ($PROFILE). Build the image with: docker compose build"