#!/usr/bin/env bash # Builds VibEdit for Windows from any OS (pure Go, no C toolchain needed). # # ./build.sh -> dist/vibedit.exe # ./build.sh --package -> also downloads a Windows ffmpeg build and creates # dist/VibEdit-windows-x64.zip (exe + ffmpeg, ready to run) set -euo pipefail cd "$(dirname "$0")" VERSION=1.0.0 FFMPEG_URL=https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip GO=${GO:-go} if ! command -v "$GO" >/dev/null 2>&1 && [ -x "$HOME/.local/go/bin/go" ]; then GO="$HOME/.local/go/bin/go" fi mkdir -p dist GOOS=windows GOARCH=amd64 CGO_ENABLED=0 "$GO" build -trimpath \ -ldflags "-s -w -X main.version=$VERSION" -o dist/vibedit.exe . echo "Built dist/vibedit.exe" if [ "${1:-}" != "--package" ]; then exit 0 fi mkdir -p dist/cache if [ ! -f dist/cache/ffmpeg-essentials.zip ]; then echo "Downloading ffmpeg for Windows from gyan.dev ..." wget -q --show-progress -O dist/cache/ffmpeg-essentials.zip.tmp "$FFMPEG_URL" mv dist/cache/ffmpeg-essentials.zip.tmp dist/cache/ffmpeg-essentials.zip fi rm -rf dist/VibEdit dist/VibEdit-windows-x64.zip mkdir -p dist/VibEdit cp dist/vibedit.exe dist/VibEdit/ cp package-readme.txt dist/VibEdit/README.txt python3 - <<'EOF' import os, zipfile src = zipfile.ZipFile("dist/cache/ffmpeg-essentials.zip") wanted = {"ffmpeg.exe": "ffmpeg.exe", "ffprobe.exe": "ffprobe.exe", "LICENSE": "ffmpeg-LICENSE.txt"} found = set() for info in src.infolist(): base = os.path.basename(info.filename) if base in wanted and base not in found: with open(os.path.join("dist/VibEdit", wanted[base]), "wb") as f: f.write(src.read(info)) found.add(base) missing = set(wanted) - found if missing: raise SystemExit("ffmpeg zip is missing: " + ", ".join(sorted(missing))) with zipfile.ZipFile("dist/VibEdit-windows-x64.zip", "w", zipfile.ZIP_DEFLATED) as out: for name in sorted(os.listdir("dist/VibEdit")): out.write(os.path.join("dist/VibEdit", name), "VibEdit/" + name) EOF echo "Packaged dist/VibEdit-windows-x64.zip"