12345678910111213set -eu1415die() {16 echo "build.sh: $*" >&217 exit 118}192021cd "$(dirname "$0")"222324command -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)"2627host_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}4041target=${KOH_TARGET:-$(host_target)}42out="build/releases/koh-$target"43mkdir -p build/releases4445case "$target" in46 macos-aarch64|macos-x86_64)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 55 codesign -f -s - "$out"56 ;;57 linux-aarch64|linux-x86_64)58 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 64 65 66 67 compiler="$PWD/build/cc-$target"68 printf '#!/bin/sh\nexec zig cc -target %s "$@"\n' "$triple" > "$compiler"69 chmod 755 "$compiler"70 v -prod -gc none -os linux -arch "$arch" -musl -cc "$compiler" \71 -ldflags "-s" -o "$out" src/koh.v72 ;;73 *) die "unsupported release target: $target (want macos-aarch64, macos-x86_64, linux-x86_64 or linux-aarch64)" ;;74esac7576echo "built $out"