#!/bin/sh # Build one native Koh release into build/releases/koh-. # koh build supplies KOH_TARGET; otherwise use this host. # The pinned V disables GC when cross-compiling, so each target needs # its own OS and CPU. macOS binaries require ad-hoc signing. set -eu die() { echo "build.sh: $*" >&2 exit 1 } cd "$(dirname "$0")" # The pin is the only compiler Koh is verified against; see AGENTS.md. command -v v >/dev/null 2>&1 || die 'V is not on PATH; install V 0.5.2 b9a2d87 (see AGENTS.md)' [ "$(v version)" = 'V 0.5.2 b9a2d87' ] || die "Koh requires V 0.5.2 b9a2d87, found: $(v version)" host_target() { case "$(uname -s)" in Darwin) os=macos ;; Linux) os=linux ;; *) die "unsupported host OS: $(uname -s)" ;; esac case "$(uname -m)" in arm64|aarch64) cpu=aarch64 ;; x86_64|amd64) cpu=x86_64 ;; *) die "unsupported host CPU: $(uname -m)" ;; esac echo "$os-$cpu" } native=$(host_target) target=${KOH_TARGET:-$native} case "$target" in macos-aarch64|linux-aarch64|linux-x86_64) ;; *) die "unsupported release target: $target (want macos-aarch64, linux-x86_64 or linux-aarch64)" ;; esac [ "$target" = "$native" ] || die "$target requires a native $target host or VM to retain garbage collection (this host is $native)" out="build/releases/koh-$target" mkdir -p build/releases case "$target" in macos-aarch64) v -prod -gc boehm -d use_bundled_libgc -arch arm64 \ -cflags '-arch arm64 -mmacosx-version-min=11.0' -o "$out" src/koh.v # Apple Silicon refuses to run an unsigned binary. codesign -f -s - "$out" ;; linux-aarch64|linux-x86_64) command -v cc >/dev/null 2>&1 || die 'Linux builds need a C compiler on PATH (cc)' v -prod -gc boehm -d use_bundled_libgc -cc cc \ -ldflags '-static -s' -o "$out" src/koh.v ;; esac echo "built $out"