#!/usr/bin/env bash
# Cross-build Windows executable only (no NSIS) - for portable zip on Linux.
set -euo pipefail

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
cd "$REPO_ROOT"

if ! command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then
  echo "Install mingw: apt-get install -y mingw-w64"
  exit 1
fi

rustup target add x86_64-pc-windows-gnu 2>/dev/null || true
if [[ -f package-lock.json ]]; then npm ci 2>/dev/null || npm install; else npm install; fi
npm run build
npm run tauri -- build --target x86_64-pc-windows-gnu --no-bundle

EXE="$REPO_ROOT/src-tauri/target/x86_64-pc-windows-gnu/release/vigthoria-workbench.exe"
if [[ ! -f "$EXE" ]]; then
  echo "Expected exe not found: $EXE"
  exit 1
fi
echo "Built: $EXE"
ls -la "$EXE"
