nix: build using scripts/build-universal.sh
2 unmodified lines345672 unmodified linestobiinternal/remote/payloads/*.gzinternal/remote/payloads/*.zstinternal/remote/payloads/tobi-*tobi-universal19 unmodified lines20212223242524272526272829303132333435363730313233343536373839404142434445464748493819 unmodified lines pname = "tobi"; version = "0.1.0"; inherit src; vendorHash = "sha256-qbOGgVRsO0/F1dB/vIERm6EsUjgWGzT2z938pnKVbcI="; subPackages = [ "." ]; ldflags = [ "-s" "-w" "-X tobi/internal/remote.Version=${rev}" ]; nativeBuildInputs = [ pkgs.zstd ]; postInstall = '' # one build path shared with manual runs; VERSION replaces the script's # git describe because the sandbox has no .git buildPhase = '' runHook preBuild VERSION=${rev} bash scripts/build-universal.sh ./dist runHook postBuild ''; installPhase = '' runHook preInstall install -Dm755 ./dist/tobi $out/bin/tobi install -Dm644 contrib/tobi.nu $out/share/nushell/vendor/autoload/tobi.nu runHook postInstall ''; # cross-compile every carrier slice into a temp dir outside # internal/remote/payloads, so no slice can recursively embed the # slices of earlier loop iterations (same slices as # scripts/build-universal.sh); the host carrier is built last and # embeds all of them preBuild = '' mkdir -p internal/remote/payloads slices=$(mktemp -d) for target in linux/amd64 linux/arm64 darwin/arm64; do os=''${target%%/*} arch=''${target##*/} echo "building carrier slice for $os/$arch" CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -trimpath \ -ldflags="-s -w -X tobi/internal/remote.Version=${rev}" \ -o $slices/tobi-$os-$arch . zstd -19 -q --rm $slices/tobi-$os-$arch done mv $slices/*.zst internal/remote/payloads/ rm -rf $slices '';}1234567891011121314151617101112181920218 unmodified lines3031323329343536373832333435394041#!/usr/bin/env bashset -euo pipefail
# usage: build-universal.sh [out-dir] (default: .)# env: VERSION - stamped into every slice and the host binary; defaults to# `git describe`, but nix passes it explicitly because the sandbox has# no .git to describeout_dir="${1:-.}"VERSION="${VERSION:-$(git describe --always --dirty 2>/dev/null || echo dev)}"LDFLAGS="-s -w -X tobi/internal/remote.Version=${VERSION}"
targets=( "linux/amd64" "linux/arm64" "darwin/arm64")
VERSION="$(git describe --always --dirty 2>/dev/null || echo dev)"LDFLAGS="-s -w -X tobi/internal/remote.Version=${VERSION}"
tmp_dir="$(mktemp -d /tmp/tobi-slices-XXXXXX)"trap 'rm -rf "${tmp_dir}"' EXIT
mkdir -p internal/remote/payloads8 unmodified lines CGO_ENABLED=0 GOOS="${os}" GOARCH="${arch}" go build -trimpath -ldflags="${LDFLAGS}" -o "${out}" . zstd -19 -q --rm "${out}"done
echo "copying zstd compressed slices into payloads/..."# slices stay in the temp dir until all of them exist; anything under# internal/remote/payloads would be re-embedded by the slices of later# iterations, so the host build only sees complete slicesmv "${tmp_dir}"/*.zst internal/remote/payloads/
echo "building final carrier binary..."CGO_ENABLED=0 go build -trimpath -ldflags="${LDFLAGS}" -o tobi-universal .
echo "done! tobi-universal contains slices for: ${targets[*]}"echo "building final binary with embedded slices (${targets[*]})..."CGO_ENABLED=0 go build -trimpath -ldflags="${LDFLAGS}" -o "${out_dir}/tobi" .echo "done: ${out_dir}/tobi"