#!/bin/sh
# Build quarry on a Linux host, with the zit it is meant to run against.
#
# Why a script and not a cross-compile: the DuckDB bindings ship a static
# C++ library per platform that links against the GNU C++ runtime, and a
# cross-link from macOS with zig's libc++ fails on missing std::string
# symbols (tried 2026-09-04). Building ON Linux is the honest path, and
# the golang image proves it works in a container before a VPS exists:
#
# docker run --rm -v "$PWD":/src -w /src golang:1.26 scripts/build-linux.sh
#
# zit is pinned to a RELEASE, not whatever is on PATH: 0001 ยง2 makes the
# zit CLI the entire store interface, so quarry's behaviour is zit's,
# and the two must not drift. The release tarballs are qualified per
# target (see zit's release-manifest.json) and checksummed.
#
# Inputs (environment):
# ZIT_VERSION zit release to install (default below)
# VERSION stamp for `quarry version` (default: 0.1.0-beta+<checkout hash or "local">)
# PREFIX where binaries land (default: ./bin)
set -eu
ZIT_VERSION="${ZIT_VERSION:-0.3.4}"
PREFIX="${PREFIX:-$PWD/bin}"
mkdir -p "$PREFIX"
arch="$(uname -m)"
case "$arch" in
x86_64|amd64) zit_arch=x86_64 ;;
aarch64|arm64) zit_arch=aarch64 ;;
*) echo "build-linux: unsupported architecture $arch" >&2; exit 1 ;;
esac
[ "$(uname -s)" = Linux ] || { echo "build-linux: this builds on Linux (see the header for why)" >&2; exit 1; }
# ---- zit, from its release ---------------------------------------------
base="https://github.com/danmestas/zit/releases/download/version-${ZIT_VERSION}"
tarball="zit-${ZIT_VERSION}-linux-${zit_arch}.tar.gz"
work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT
echo "build-linux: fetching zit ${ZIT_VERSION} for linux-${zit_arch}"
curl -fsSL "$base/$tarball" -o "$work/$tarball"
curl -fsSL "$base/SHA256SUMS" -o "$work/SHA256SUMS"
( cd "$work" && grep " $tarball\$" SHA256SUMS | sha256sum -c - >/dev/null ) || {
echo "build-linux: checksum mismatch for $tarball" >&2; exit 1; }
tar -xzf "$work/$tarball" -C "$work"
install -m 0755 "$work/zit-${ZIT_VERSION}/zit" "$PREFIX/zit"
echo "build-linux: $("$PREFIX/zit" version)"
# ---- quarry, from this tree -------------------------------------------
if [ -z "${VERSION:-}" ]; then
tip="$("$PREFIX/zit" status 2>/dev/null | awk '/^checkout:/ {print substr($2,1,12)}')"
VERSION="0.1.0-beta+${tip:-local}"
fi
echo "build-linux: building quarry $VERSION with $(go version)"
CGO_ENABLED=1 go build -trimpath -ldflags "-X main.version=$VERSION" -o "$PREFIX/quarry" ./cmd/quarry
echo "build-linux: quarry built: $("$PREFIX/quarry" version 2>/dev/null || echo "$VERSION")"
echo "build-linux: binaries in $PREFIX"