port(2A): port/common Win32 layer, port_logic target and header gate

- Win32Types.h: fixed-width Win32 scalars, pointer-sized handles, static_asserts
- Win32Crt.{h,cpp}: MSVC _snprintf truncation contract, stricmp, timeGetTime wrap
- port_logic static lib linked into libmtgodot; standalone MTGODOT_BUILD_PORT build
- port_header_gate: every port/**.h compiles alone (twice) with its lib's
  40250 Distribute|Win32 defines (NDEBUG, USE_LOD, _DISTRIBUTE)
- script/port_gate.sh: macOS/Android/iOS/Windows(mingw) PASS, Linux BLOCKED

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-22 19:57:58 +09:00
co-authored by Claude Opus 5
parent 4521845a69
commit 2bae8d7644
11 changed files with 498 additions and 1 deletions
+87
View File
@@ -0,0 +1,87 @@
#!/usr/bin/env bash
# Batch 2A gate (docs/PORT-PLAN.md): build port_logic + the header self-containment gate per
# platform. A platform whose toolchain is missing prints BLOCKED and never counts as a pass.
#
# script/port_gate.sh [macos|android|ios|windows|linux ...] (default: all)
#
# Build trees go to $MT_PORT_GATE_DIR (default build-port-gate/). Toolchains:
# android ANDROID_NDK_HOME / ANDROID_NDK_ROOT (NDK 27.2)
# ios Xcode with the iphoneos SDK
# windows MT_WIN_CXX (default x86_64-w64-mingw32-g++); MSVC is covered on a Windows host
# linux MT_LINUX_TOOLCHAIN (a CMake toolchain file), or a Linux host
set -uo pipefail
cd "$(dirname "$0")/.."
OUT="${MT_PORT_GATE_DIR:-build-port-gate}"
PLATFORMS=("$@")
[ ${#PLATFORMS[@]} -eq 0 ] && PLATFORMS=(macos android ios windows linux)
PORT_ONLY=(-DMTGODOT_BUILD_EXTENSION=OFF -DMTGODOT_BUILD_PORT=ON)
declare -a RESULTS=()
run() { # name, build dir, configure args...
local name="$1" dir="$2"; shift 2
if cmake -S . -B "$dir" "$@" >"$dir.log" 2>&1 \
&& cmake --build "$dir" --target port_logic ${BUILD_EXTRA[@]+"${BUILD_EXTRA[@]}"} >>"$dir.log" 2>&1; then
RESULTS+=("$name PASS")
else
RESULTS+=("$name FAIL (see $dir.log)")
fi
}
mkdir -p "$OUT"
for p in "${PLATFORMS[@]}"; do
BUILD_EXTRA=()
case "$p" in
macos)
BUILD_EXTRA=(--target port_common_test)
run macos "$OUT/macos" "${PORT_ONLY[@]}" -DBUILD_TESTING=ON
last=$((${#RESULTS[@]} - 1))
if [[ "${RESULTS[$last]}" == *PASS ]] && ! ctest --test-dir "$OUT/macos" -R '^port\.' --output-on-failure >>"$OUT/macos.log" 2>&1; then
RESULTS[$last]="macos FAIL (port tests, see $OUT/macos.log)"
fi
;;
android)
NDK="${ANDROID_NDK_ROOT:-${ANDROID_NDK_HOME:-}}"
SDK="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$HOME/Library/Android/sdk}}"
if [ -z "$NDK" ] && [ -d "$SDK/ndk" ]; then
NDK="$SDK/ndk/$(ls -1 "$SDK/ndk" | sort -V | tail -1)"
fi
if [ -z "$NDK" ] || [ ! -f "$NDK/build/cmake/android.toolchain.cmake" ]; then
RESULTS+=("android BLOCKED (no NDK)"); continue
fi
run android "$OUT/android" "${PORT_ONLY[@]}" -DBUILD_TESTING=OFF \
-DCMAKE_TOOLCHAIN_FILE="$NDK/build/cmake/android.toolchain.cmake" \
-DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-24
;;
ios)
if ! xcrun --sdk iphoneos --show-sdk-path >/dev/null 2>&1; then
RESULTS+=("ios BLOCKED (no iphoneos SDK)"); continue
fi
BUILD_EXTRA=(-- -sdk iphoneos CODE_SIGNING_ALLOWED=NO)
run ios "$OUT/ios" "${PORT_ONLY[@]}" -DBUILD_TESTING=OFF -G Xcode -DCMAKE_SYSTEM_NAME=iOS \
-DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_OSX_DEPLOYMENT_TARGET=14.0
;;
windows)
CXX_W="${MT_WIN_CXX:-x86_64-w64-mingw32-g++}"
if [[ "$(uname -s)" != MINGW* ]] && ! command -v "$CXX_W" >/dev/null; then
RESULTS+=("windows BLOCKED (no $CXX_W)"); continue
fi
run windows "$OUT/windows" "${PORT_ONLY[@]}" -DBUILD_TESTING=OFF -DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_C_COMPILER="${CXX_W%g++}gcc" -DCMAKE_CXX_COMPILER="$CXX_W"
;;
linux)
if [ "$(uname -s)" = Linux ]; then
BUILD_EXTRA=(--target port_common_test)
run linux "$OUT/linux" "${PORT_ONLY[@]}" -DBUILD_TESTING=ON
elif [ -n "${MT_LINUX_TOOLCHAIN:-}" ]; then
run linux "$OUT/linux" "${PORT_ONLY[@]}" -DBUILD_TESTING=OFF -DCMAKE_TOOLCHAIN_FILE="$MT_LINUX_TOOLCHAIN"
else
RESULTS+=("linux BLOCKED (not a Linux host and no MT_LINUX_TOOLCHAIN)")
fi
;;
*) RESULTS+=("$p UNKNOWN") ;;
esac
done
printf '%s\n' "${RESULTS[@]}"
! printf '%s\n' "${RESULTS[@]}" | grep -q FAIL