Files
dx/build.sh
2026-08-10 16:35:51 +02:00

61 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
# Build dx for the usual platforms into ./bin, auto-incrementing the patch
# version by 0.0.1 on every build.
#
# version.txt holds the currently built version. Each run increments the patch
# component, then builds every platform with that one version injected via
# -ldflags, and writes it back. So version.txt always reflects the version of
# the binaries just built, and all of them carry the same one.
#
# Override the platform list to build just one:
# PLATFORMS="linux/amd64" ./build.sh
#
# Windows is not in the list: dx compiles there, but the output leans on a
# terminal that speaks 24-bit colour and draws U+2588 block characters, so
# shipping it would promise more than has been tested. PLATFORMS can add it.
#
# -s -w drops the symbol table and DWARF info, -trimpath keeps build paths out
# of the binary; together they roughly halve it. Neither affects a panic trace.
set -e
cd "$(dirname "$0")"
PLATFORMS=${PLATFORMS:-"darwin/arm64 darwin/amd64 linux/amd64 linux/arm64"}
V=$(cat version.txt 2>/dev/null || echo 2.1.0)
# split MAJOR.MINOR.PATCH and increment PATCH (no carry: 2.1.9 -> 2.1.10)
MAJOR=${V%%.*}
REST=${V#*.}
MINOR=${REST%%.*}
PATCH=${REST#*.}
PATCH=$((PATCH + 1))
NV="$MAJOR.$MINOR.$PATCH"
# NOTE: ./dx in the repo root is the Perl original from 2016, not a build
# artefact. Nothing here writes to or removes it — the build only touches ./bin.
mkdir -p bin
HOST="$(go env GOOS)/$(go env GOARCH)"
for p in $PLATFORMS; do
os=${p%/*}
arch=${p#*/}
out="bin/dx-$os-$arch"
# CGO_ENABLED=0 throughout: it makes the cross builds work without a
# toolchain per target and the binaries static. dx only needs the
# filesystem, so nothing is lost by dropping cgo.
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" \
go build -trimpath -ldflags "-s -w -X main.version=$NV" -o "$out" .
if [ "$p" = "$HOST" ]; then
ln -sf "dx-$os-$arch" bin/dx # the one for this machine
echo " $out -> bin/dx"
else
echo " $out"
fi
done
echo "$NV" > version.txt
echo "built dx v$NV"