#!/usr/bin/env bash # CI helper: MinGW-w64 UCRT toolchain via llvm-mingw (no Nix / no /nix). # Downloads a pinned release, puts it on PATH, then runs bootstrap_windows.sh. set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$ROOT" VER="${CST_LLVM_MINGW_VER:-20241030}" NAME="llvm-mingw-${VER}-ucrt-ubuntu-20.04-x86_64" TGZ="/tmp/${NAME}.tar.xz" # Prefer /opt when writable (root CI); else unpack under $HOME. if [[ -w /opt || "$(id -u)" -eq 0 ]]; then DIR="/opt/${NAME}" PARENT=/opt else DIR="${HOME}/${NAME}" PARENT="$HOME" fi if [[ ! -x "$DIR/bin/x86_64-w64-mingw32-gcc" ]]; then echo "==> download $NAME" # Prefer CN-reachable GitHub proxies; raw github.com is often unreachable. urls=( "https://ghfast.top/https://github.com/mstorsjo/llvm-mingw/releases/download/${VER}/${NAME}.tar.xz" "https://ghproxy.net/https://github.com/mstorsjo/llvm-mingw/releases/download/${VER}/${NAME}.tar.xz" "https://gitclone.com/github.com/mstorsjo/llvm-mingw/releases/download/${VER}/${NAME}.tar.xz" "https://github.com/mstorsjo/llvm-mingw/releases/download/${VER}/${NAME}.tar.xz" ) ok=0 for u in "${urls[@]}"; do echo " try $u" if curl -fL --retry 2 --connect-timeout 15 --max-time 600 \ --retry-delay 2 -o "$TGZ" "$u"; then # Reject tiny error pages that some proxies return with HTTP 200. sz=$(wc -c <"$TGZ") if [[ "$sz" -gt 10000000 ]]; then ok=1 break fi echo " too small ($sz bytes), next mirror" fi done [[ $ok -eq 1 ]] || { echo "failed to download llvm-mingw" >&2; exit 1; } rm -rf "$DIR" mkdir -p "$PARENT" tar -C "$PARENT" -xf "$TGZ" fi export PATH="$DIR/bin:$PATH" export MINGW_HOST=x86_64-w64-mingw32 export BUILD_CC="${BUILD_CC:-cc}" need() { command -v "$1" >/dev/null || { echo "missing $1" >&2; exit 1; }; } need x86_64-w64-mingw32-gcc need x86_64-w64-mingw32-windres need cmake; need ninja; need perl; need zip; need git; need make if ! printf '#include \n' | x86_64-w64-mingw32-gcc -dM -E - | grep -qw _UCRT; then echo "toolchain is not UCRT" >&2 exit 1 fi # Third-party sources live on GitHub; prefer a CN-friendly rewrite. git config --global url."https://gitclone.com/github.com/".insteadOf "https://github.com/" || true echo "==> bootstrap_windows.sh" exec bash scripts/bootstrap_windows.sh "$ROOT"