Files
2026-09-24 13:54:28 +08:00

58 lines
2.5 KiB
Bash

#!/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_SOURCE="$FDS_ROOT/vendor/void-packages"
FDS_VOID="$FDS_ROOT/.host/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 fds-os.wiki/Developer-Build-Host.md)"; }
check_void_source() {
local pin actual
pin=$(cat "$FDS_ROOT/VOID_PACKAGES_COMMIT")
[[ $pin =~ ^[0-9a-f]{40}$ ]] || die 'Invalid VOID_PACKAGES_COMMIT'
[[ -f $FDS_VOID_SOURCE/xbps-src ]] || die 'Void submodule is missing; run make bootstrap'
actual=$(git -C "$FDS_VOID_SOURCE" rev-parse HEAD)
[[ $actual == "$pin" ]] || die "Void checkout mismatch: expected $pin, found $actual"
git -C "$FDS_VOID_SOURCE" 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_SOURCE" show -s --format=%ct HEAD)
}
check_void_pin() {
check_void_source
[[ -z $(git -C "$FDS_VOID_SOURCE" status --porcelain --untracked-files=all) ]] || die 'Upstream Void submodule is dirty; run make bootstrap to migrate known build copies'
[[ -f $FDS_VOID/xbps-src ]] || die 'Void build checkout is missing; run make bootstrap'
[[ $(git -C "$FDS_VOID" rev-parse HEAD) == "$(cat "$FDS_ROOT/VOID_PACKAGES_COMMIT")" ]] || die 'Void build checkout pin changed; run make bootstrap'
git -C "$FDS_VOID" diff --quiet HEAD -- || die 'Tracked build-checkout files changed; keep FDS sources in packages/'
}
# 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
}