forked from WHC/Hermit
53 lines
2.0 KiB
Bash
Executable File
53 lines
2.0 KiB
Bash
Executable File
#!/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 $MINGW_HOST-gcc
|
|
# (default x86_64-w64-mingw32; UCRT flavour, with winpthreads), cmake, ninja,
|
|
# git and perl must be installed. CST_WIN_CFLAGS adds C flags (CI: -Werror).
|
|
# 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"
|
|
|
|
H="${MINGW_HOST:-x86_64-w64-mingw32}"
|
|
if ! command -v "$H-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; }; }
|
|
export MINGW_HOST="$H"
|
|
need git; need cmake; need ninja; need perl; need "$H-gcc"
|
|
if ! printf '#include <stdio.h>\n' | "$H-gcc" -dM -E - | grep -qw _UCRT; then
|
|
echo "$H-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 \
|
|
-DCMAKE_C_FLAGS="${CST_WIN_CFLAGS:-}"
|
|
# Package only needs the agent binary; skip host-unrunnable Win32 tests.
|
|
cmake --build build-win-tui --target cst-agent
|
|
|
|
echo "==> package"
|
|
scripts/package_windows.sh
|