#!/bin/sh # Build ghosttyconf 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 literal in # version.go is only ever what a bare `go build` picks up. # # ./bin ends up with ghosttyconf--, one file per platform, which # `mgsh release ` attaches to the release as they are. # # Override the platform list to build just one: # PLATFORMS="linux/amd64" ./build.sh # # Set the version instead of bumping it: # VERSION=1.1.0 ./build.sh # The automatic bump only ever touches the last number, so a minor or major # step is a decision, and this is how it is made. # # Windows is not in the list: Ghostty does not run there. # # -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"} if [ -n "$VERSION" ]; then # Checked rather than trusted: this number goes into the binary, into # version.txt and onto the release tag. if ! printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then echo "VERSION=$VERSION is not MAJOR.MINOR.PATCH" >&2 exit 1 fi NV="$VERSION" else V=$(cat version.txt 2>/dev/null || echo 1.0.0) # split MAJOR.MINOR.PATCH and increment PATCH (no carry: 1.0.9 -> 1.0.10) MAJOR=${V%%.*} REST=${V#*.} MINOR=${REST%%.*} PATCH=${REST#*.} PATCH=$((PATCH + 1)) NV="$MAJOR.$MINOR.$PATCH" fi mkdir -p bin HOST="$(go env GOOS)/$(go env GOARCH)" for p in $PLATFORMS; do os=${p%/*} arch=${p#*/} out="bin/ghosttyconf-$os-$arch" # CGO_ENABLED=0 throughout: it makes the cross builds work without a # toolchain per target and the binaries static. ghosttyconf only runs # ghostty and osascript and reads files, 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 "ghosttyconf-$os-$arch" bin/ghosttyconf # the one for this machine echo " $out -> bin/ghosttyconf" else echo " $out" fi done echo "$NV" > version.txt echo "built ghosttyconf v$NV"