build.sh

1.8 KB · raw

1#!/bin/sh2# Build one native Koh release into build/releases/koh-<target>.3# koh build supplies KOH_TARGET; otherwise use this host.4# The pinned V disables GC when cross-compiling, so each target needs5# its own OS and CPU. macOS binaries require ad-hoc signing.6set -eu78die() {9  echo "build.sh: $*" >&210  exit 111}1213cd "$(dirname "$0")"1415# The pin is the only compiler Koh is verified against; see AGENTS.md.16command -v v >/dev/null 2>&1 || die 'V is not on PATH; install V 0.5.2 b9a2d87 (see AGENTS.md)'17[ "$(v version)" = 'V 0.5.2 b9a2d87' ] || die "Koh requires V 0.5.2 b9a2d87, found: $(v version)"1819host_target() {20  case "$(uname -s)" in21    Darwin) os=macos ;;22    Linux) os=linux ;;23    *) die "unsupported host OS: $(uname -s)" ;;24  esac25  case "$(uname -m)" in26    arm64|aarch64) cpu=aarch64 ;;27    x86_64|amd64) cpu=x86_64 ;;28    *) die "unsupported host CPU: $(uname -m)" ;;29  esac30  echo "$os-$cpu"31}3233native=$(host_target)34target=${KOH_TARGET:-$native}35case "$target" in36  macos-aarch64|linux-aarch64|linux-x86_64) ;;37  *) die "unsupported release target: $target (want macos-aarch64, linux-x86_64 or linux-aarch64)" ;;38esac39[ "$target" = "$native" ] || die "$target requires a native $target host or VM to retain garbage collection (this host is $native)"40out="build/releases/koh-$target"41mkdir -p build/releases4243case "$target" in44  macos-aarch64)45    v -prod -gc boehm -d use_bundled_libgc -arch arm64 \46      -cflags '-arch arm64 -mmacosx-version-min=11.0' -o "$out" src/koh.v47    # Apple Silicon refuses to run an unsigned binary.48    codesign -f -s - "$out"49    ;;50  linux-aarch64|linux-x86_64)51    command -v cc >/dev/null 2>&1 || die 'Linux builds need a C compiler on PATH (cc)'52    v -prod -gc boehm -d use_bundled_libgc -cc cc \53      -ldflags '-static -s' -o "$out" src/koh.v54    ;;55esac5657echo "built $out"