gcc -O0 keeps unused cst_test_util.h helpers that need os_*; clang GC'd them so only the gcc CMake step failed. Prefer ghfast/ghproxy.net for the llvm-mingw tarball (gitclone 500 / github unreachable on the runner).
68 lines
2.3 KiB
Bash
Executable File
68 lines
2.3 KiB
Bash
Executable File
#!/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 <stdio.h>\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"
|