1c1f11a965de

make build.sh run on macOS and Linux: default to the host target, run from any directory, pin -gc none for Linux releases (3.7.1)

time
2026-10-05 21:42 UTC · 1 week ago
machine
Junes-MacBook-Pro.local
agent
claude-opus-5-5
session
portable build script
parent
3b70c9b38348
3 files VERSION+1 −1build.sh+64 −11v.mod+1 −1
VERSION+1 −1
@@ -1 +1 @@1-3.7.01+3.7.1

view file

build.sh+64 −11
@@ -1,23 +1,76 @@11 #!/bin/sh2-# Koh's four release targets use the pinned V compiler; Linux binaries are static musl builds.2+# Builds one Koh release binary into build/releases/koh-<target>.3+#4+#   KOH_TARGET=linux-x86_64 sh build.sh5+#6+# `koh build` sets KOH_TARGET for each platform in koh.build; run by hand, the7+# target defaults to the machine running the script. Runs on macOS and Linux.8+#9+# macOS targets need macOS: they link against the Apple SDK and are ad-hoc10+# signed with codesign. Linux targets are static musl binaries cross-compiled11+# with `zig cc`, so they build the same from either host, and NixOS's gcc12+# wrapper and missing tcc never come into it.313 set -eu4-[ "$(v version)" = 'V 0.5.2 b9a2d87' ] || { echo 'Koh requires V 0.5.2 b9a2d87' >&2; exit 1; }5-target=${KOH_TARGET:-macos-aarch64}14+15+die() {16+  echo "build.sh: $*" >&217+  exit 118+}19+20+# Paths below are relative to the repository, wherever the script is run from.21+cd "$(dirname "$0")"22+23+# The pin is the only compiler Koh is verified against; see AGENTS.md.24+command -v v >/dev/null 2>&1 || die 'V is not on PATH; install V 0.5.2 b9a2d87 (see AGENTS.md)'25+[ "$(v version)" = 'V 0.5.2 b9a2d87' ] || die "Koh requires V 0.5.2 b9a2d87, found: $(v version)"26+27+host_target() {28+  case "$(uname -s)" in29+    Darwin) os=macos ;;30+    Linux) os=linux ;;31+    *) die "unsupported host OS: $(uname -s)" ;;32+  esac33+  case "$(uname -m)" in34+    arm64|aarch64) cpu=aarch64 ;;35+    x86_64|amd64) cpu=x86_64 ;;36+    *) die "unsupported host CPU: $(uname -m)" ;;37+  esac38+  echo "$os-$cpu"39+}40+41+target=${KOH_TARGET:-$(host_target)}42+out="build/releases/koh-$target"643 mkdir -p build/releases44+745 case "$target" in846   macos-aarch64|macos-x86_64)9-    [ "$(uname -s)" = Darwin ] || { echo 'macOS releases require the Apple SDK on macOS' >&2; exit 1; }10-    case "$target" in macos-aarch64) arch=arm64; cpu=arm64 ;; *) arch=x64; cpu=x86_64 ;; esac11-    v -prod -d use_bundled_libgc -arch "$arch" -cflags "-arch $cpu -mmacosx-version-min=11.0" -o "build/releases/koh-$target" src/koh.v12-    codesign -f -s - "build/releases/koh-$target"47+    [ "$(uname -s)" = Darwin ] || die "$target needs the Apple SDK; build it on macOS"48+    case "$target" in49+      macos-aarch64) arch=arm64; cpu=arm64 ;;50+      *) arch=x64; cpu=x86_64 ;;51+    esac52+    v -prod -d use_bundled_libgc -arch "$arch" \53+      -cflags "-arch $cpu -mmacosx-version-min=11.0" -o "$out" src/koh.v54+    # Apple Silicon refuses to run an unsigned binary.55+    codesign -f -s - "$out"1356     ;;1457   linux-aarch64|linux-x86_64)15-    command -v zig >/dev/null 2>&1 || { echo 'Linux cross builds require Zig on PATH' >&2; exit 1; }16-    case "$target" in linux-aarch64) arch=arm64; triple=aarch64-linux-musl ;; *) arch=x64; triple=x86_64-linux-musl ;; esac58+    command -v zig >/dev/null 2>&1 || die 'Linux builds need Zig on PATH (zig cc provides the musl toolchain)'59+    case "$target" in60+      linux-aarch64) arch=arm64; triple=aarch64-linux-musl ;;61+      *) arch=x64; triple=x86_64-linux-musl ;;62+    esac63+    # V's -cc takes a single program, not `zig cc -target …`, so wrap it.64+    # V drops the GC for any cross target, which is how every Linux release65+    # has shipped; -gc none pins that on a Linux host too, where V would66+    # otherwise link libgc against musl and fail on glibc's getcontext.1767     compiler="$PWD/build/cc-$target"1868     printf '#!/bin/sh\nexec zig cc -target %s "$@"\n' "$triple" > "$compiler"1969     chmod 755 "$compiler"20-    v -prod -d use_bundled_libgc -os linux -arch "$arch" -musl -cc "$compiler" -ldflags "-s" -o "build/releases/koh-$target" src/koh.v70+    v -prod -gc none -os linux -arch "$arch" -musl -cc "$compiler" \71+      -ldflags "-s" -o "$out" src/koh.v2172     ;;22-  *) echo "unsupported release target: $target" >&2; exit 1 ;;73+  *) die "unsupported release target: $target (want macos-aarch64, macos-x86_64, linux-x86_64 or linux-aarch64)" ;;2374 esac75+76+echo "built $out"

view file

v.mod+1 −1
@@ -1,6 +1,6 @@11 Module {22 	name: 'koh3'3-	version: '3.7.0'3+	version: '3.7.1'44 	description: 'One SQLite file per repo, one line of history.'55 	license: 'MIT'66 }

view file