#!/usr/bin/env bash # Linux host: cross-build the Windows x86_64 release (mingw-w64, UCRT, static). # scripts/bootstrap_windows.sh [repo-dir] # With Nix the toolchain comes from shell-win.nix; otherwise x86_64-w64-mingw32-gcc # (UCRT flavour, with winpthreads), cmake, ninja, git and perl must be installed. # Output: dist/windows-x86_64/ and dist/cst-agent-VERSION-windows-x86_64.zip set -euo pipefail REPO_URL="${CST_AGENT_REPO:-https://git.whcself.xyz/WHC/CST-agent.git}" DIR="${1:-}" if [[ -z "$DIR" ]]; then if [[ -f CMakeLists.txt && -d src ]]; then DIR="$(pwd)" else DIR="CST-agent" fi fi if [[ ! -f "$DIR/CMakeLists.txt" ]]; then echo "==> git clone $REPO_URL -> $DIR" git clone "$REPO_URL" "$DIR" fi cd "$DIR" if ! command -v x86_64-w64-mingw32-gcc >/dev/null && [[ -z "${IN_NIX_SHELL:-}" ]] && command -v nix-shell >/dev/null; then exec nix-shell shell-win.nix --run "$(printf '%q ' "$0" "$PWD")" fi need() { command -v "$1" >/dev/null || { echo "missing $1 (mingw-w64 UCRT gcc, cmake, ninja, git, perl)" >&2; exit 1; }; } need git; need cmake; need ninja; need perl; need x86_64-w64-mingw32-gcc if ! printf '#include \n' | x86_64-w64-mingw32-gcc -dM -E - | grep -qw _UCRT; then echo "x86_64-w64-mingw32-gcc targets msvcrt; the UTF-8 manifest needs a UCRT toolchain" >&2 exit 1 fi [[ -f third_party/prefix-mingw/lib/libcurl.a ]] || scripts/build_third_party_mingw.sh curl [[ -f third_party/prefix-mingw/lib/libncursesw.a ]] || scripts/build_third_party_mingw.sh ncurses [[ -f third_party/busybox/busybox.exe ]] || scripts/build_third_party_mingw.sh busybox-w32 echo "==> cmake (Windows, TUI)" cmake -S . -B build-win-tui -G Ninja \ -DCMAKE_TOOLCHAIN_FILE=cmake/mingw-w64-x86_64.cmake \ -DCMAKE_BUILD_TYPE=Release -DCST_BUILD_TUI=ON cmake --build build-win-tui echo "==> package" scripts/package_windows.sh