#!/usr/bin/env bash # Shared build paths; XBPS state is project-local, Rustup/Cargo also use user caches. set -euo pipefail export LC_ALL=C FDS_ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd) FDS_VOID="$FDS_ROOT/vendor/void-packages" FDS_XBPS="$FDS_ROOT/.host/xbps/usr/bin" die() { printf 'ERROR: %s\n' "$*" >&2; exit 1; } need() { command -v "$1" >/dev/null || die "Missing host command: $1 (see docs/build-host.md)"; } check_void_pin() { local pin actual pin=$(cat "$FDS_ROOT/VOID_PACKAGES_COMMIT") [[ $pin =~ ^[0-9a-f]{40}$ ]] || die 'Invalid VOID_PACKAGES_COMMIT' [[ -f $FDS_VOID/xbps-src ]] || die 'Void submodule is missing; run make bootstrap' actual=$(git -C "$FDS_VOID" rev-parse HEAD) [[ $actual == "$pin" ]] || die "Void checkout mismatch: expected $pin, found $actual" git -C "$FDS_VOID" diff --quiet HEAD -- || die 'Tracked Void files were changed; keep FDS changes in packages/' export SOURCE_DATE_EPOCH SOURCE_DATE_EPOCH=$(git -C "$FDS_VOID" show -s --format=%ct HEAD) } # Keep the upstream entry point unchanged. Offline builds retain normal # dependency resolution, but use only the restored local repositories. xbps_src() { if [[ ${FDS_OFFLINE:-0} == 1 ]]; then [[ -f $FDS_ROOT/.host/frozen/lock.json ]] || die 'Offline builds require restored frozen inputs' ./xbps-src -N -n "$@" else ./xbps-src "$@" fi } fetch_rust_inputs() { local flags=() if [[ ${FDS_OFFLINE:-0} == 1 ]]; then flags=(--offline) fi cargo fetch --locked "${flags[@]}" --target aarch64-unknown-linux-musl --target x86_64-unknown-linux-gnu } use_xbps() { [[ -x $FDS_XBPS/xbps-install ]] || die 'Static XBPS tools are missing; run make bootstrap' export PATH="$FDS_XBPS:$PATH" # A musl-linked host tool must still build a glibc host container. export XBPS_ARCH=x86_64 }