64 lines
2.2 KiB
Bash
Executable File
64 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# Build upd 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.
|
|
#
|
|
# The asset names ./bin ends up with are exactly what selfupdate.go looks for
|
|
# in a release: upd-<goos>-<goarch>. Upload the directory as it is.
|
|
#
|
|
# Override the platform list to build just one, or to add a platform:
|
|
# PLATFORMS="linux/amd64" ./build.sh
|
|
# PLATFORMS="linux/386 linux/arm64" ./build.sh
|
|
#
|
|
# Windows is not in the list: the run is wrapped in a SIGHUP handler and the
|
|
# install path rules assume a Unix $PATH, 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.0.0)
|
|
|
|
# split MAJOR.MINOR.PATCH and increment PATCH (no carry: 2.0.9 -> 2.0.10)
|
|
MAJOR=${V%%.*}
|
|
REST=${V#*.}
|
|
MINOR=${REST%%.*}
|
|
PATCH=${REST#*.}
|
|
PATCH=$((PATCH + 1))
|
|
NV="$MAJOR.$MINOR.$PATCH"
|
|
|
|
mkdir -p bin
|
|
HOST="$(go env GOOS)/$(go env GOARCH)"
|
|
|
|
for p in $PLATFORMS; do
|
|
os=${p%/*}
|
|
arch=${p#*/}
|
|
out="bin/upd-$os-$arch"
|
|
|
|
# CGO_ENABLED=0 throughout: it makes the cross builds work without a
|
|
# toolchain per target and the binaries static - which is the point on the
|
|
# old machines upd exists for. It also settles the one thing cgo would
|
|
# change here: name resolution goes through Go's own resolver, not the
|
|
# system one, and TLS never touched the C library to begin with.
|
|
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 "upd-$os-$arch" bin/upd # the one for this machine
|
|
echo " $out -> bin/upd"
|
|
else
|
|
echo " $out"
|
|
fi
|
|
done
|
|
|
|
echo "$NV" > version.txt
|
|
echo "built upd v$NV"
|