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#
13# Prereqs (one-time):
14# zig (dnf install zig, or brew install zig)
15# cargo install cargo-zigbuild
16# rustup target add x86_64-unknown-linux-musl
17set -euo pipefail
18
19TARGET="x86_64-unknown-linux-musl"
20PROFILE=release
21CARGO_FLAGS=(--release)
22
23case "${1:-}" in
24 --debug) PROFILE=debug; CARGO_FLAGS=() ;;
25 "") ;;
26 *) echo "usage: $0 [--debug]" >&2; exit 64 ;;
27esac
28
29cd "$(dirname "$0")/.."
30
31# macOS terminals default to a 256 open-file soft limit; zig's linker opens
32# every rlib at once and dies with ProcessFdQuotaExceeded. Raise it for this
33# process (children inherit it).
34ulimit -n 4096 2>/dev/null || true
35
36# Static musl even for --debug: the runtime image is Ubuntu, and a binary
37# linked against Fedora's glibc would not run there.
38echo "==> cross-compiling anvild for $TARGET ($PROFILE, native, via zig)"
39cargo zigbuild --target "$TARGET" --bin anvild "${CARGO_FLAGS[@]}"
40
41echo "==> staging binary at deploy/anvild"
42cp "target/$TARGET/$PROFILE/anvild" deploy/anvild
43
44# Deliberately left in place: `docker compose build` runs after this and needs
45# it in the context. It is gitignored, and the next build overwrites it.
46echo "==> staged ($PROFILE). Build the image with: docker compose build"