Files
tsrun/build-windows.sh
T
dmgnr e588b9a527
Deploy tsrun / deploy (push) Failing after 15s
feat: add tsrun bootstrap service and deploy
2026-07-22 06:23:21 +00:00

67 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
MANIFEST_PATH="$ROOT_DIR/secrets/tsrun.manifest.json"
EXAMPLE_MANIFEST_PATH="$ROOT_DIR/secrets/tsrun.manifest.json.example"
WINTUN_DLL_PATH="$ROOT_DIR/internal/runtime/full/wintun.dll"
WINTUN_ZIP_PATH="/tmp/opencode/wintun-0.14.1.zip"
WINDOWS_OUTPUT="$ROOT_DIR/tsrun.exe"
WINDOWS_UPX_OUTPUT="$ROOT_DIR/tsrun-upx.exe"
INSIDE_NIX_FLAG="${1:-}"
if [[ "$INSIDE_NIX_FLAG" != "--inside-nix" ]]; then
exec nix develop -c bash "$0" --inside-nix
fi
ensure_manifest() {
if [[ ! -f "$MANIFEST_PATH" ]]; then
cp "$EXAMPLE_MANIFEST_PATH" "$MANIFEST_PATH"
printf 'Created %s from the example manifest.\n' "$MANIFEST_PATH"
printf 'Fill in your OAuth credentials and user passwords, then rerun ./build-windows.sh\n'
exit 1
fi
if grep -q 'tskey-client-xxxxxxxx\|replace-me' "$MANIFEST_PATH"; then
printf 'Edit %s with your real OAuth credentials and user passwords, then rerun ./build-windows.sh\n' "$MANIFEST_PATH"
exit 1
fi
}
ensure_wintun() {
if [[ -f "$WINTUN_DLL_PATH" ]]; then
printf 'Using existing %s\n' "$WINTUN_DLL_PATH"
return
fi
printf 'Downloading wintun.dll...\n'
curl -L "https://www.wintun.net/builds/wintun-0.14.1.zip" -o "$WINTUN_ZIP_PATH"
unzip -p "$WINTUN_ZIP_PATH" wintun/bin/amd64/wintun.dll > "$WINTUN_DLL_PATH"
}
build() {
printf 'Generating embedded credential blob...\n'
go run ./cmd/buildblob -in "$MANIFEST_PATH" -out internal/embedded/blob_gen.go
printf 'Building tsrun.exe...\n'
env GOOS=windows GOARCH=amd64 go build -trimpath -ldflags='-s -w -buildid=' -o "$WINDOWS_OUTPUT" ./cmd/tsrun
if command -v upx >/dev/null 2>&1; then
printf 'Building tsrun-upx.exe...\n'
cp "$WINDOWS_OUTPUT" "$WINDOWS_UPX_OUTPUT"
upx --best --lzma "$WINDOWS_UPX_OUTPUT"
else
printf 'Skipping UPX build because upx is not available.\n'
fi
printf 'Build complete:\n'
printf ' %s\n' "$WINDOWS_OUTPUT"
if [[ -f "$WINDOWS_UPX_OUTPUT" ]]; then
printf ' %s\n' "$WINDOWS_UPX_OUTPUT"
fi
}
ensure_manifest
ensure_wintun
build