#!/usr/bin/env bash # Native Windows build from an MSYS2 UCRT64 shell (https://www.msys2.org/). # scripts/bootstrap_msys2.sh [repo-dir] # Installs the UCRT64 toolchain with pacman, builds the same pinned static # deps as the Linux cross build (curl with Schannel, ncurses with the Windows # console patches, busybox-w32 Unicode), then a static cst-agent.exe with the # UTF-8 manifest, runs the tests and packages dist/windows-x86_64/. # CST_SKIP_TESTS=1 skips ctest. set -euo pipefail if [[ "${MSYSTEM:-}" != UCRT64 ]]; then echo "run this from the MSYS2 UCRT64 shell: the UTF-8 manifest needs the" \ "UCRT runtime (MINGW64 links msvcrt)" >&2 exit 1 fi 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 pacman -S --needed --noconfirm \ mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-cmake \ mingw-w64-ucrt-x86_64-ninja make git patch tar perl zip diffutils if [[ ! -f "$DIR/CMakeLists.txt" ]]; then echo "==> git clone $REPO_URL -> $DIR" git clone "$REPO_URL" "$DIR" fi cd "$DIR" # third-party script: unprefixed native tools export MINGW_HOST= BUILD_CC=gcc [[ -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 if [[ ! -f third_party/busybox/busybox.exe ]]; then scripts/build_third_party_mingw.sh busybox-w32 || scripts/fetch_busybox_w32.sh fi echo "==> cmake (MSYS2 UCRT64, static, TUI)" cmake -S . -B build-msys2 -G Ninja -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_PREFIX_PATH="$PWD/third_party/prefix-mingw" \ -DCST_WIN_STATIC=ON -DCST_BUILD_TUI=ON cmake --build build-msys2 if [[ -z "${CST_SKIP_TESTS:-}" ]]; then echo "==> ctest" cp -f third_party/busybox/busybox.exe build-msys2/ ctest --test-dir build-msys2 --output-on-failure fi echo "==> package" CST_WIN_BUILD=build-msys2 scripts/package_windows.sh