From 1d49b63295ce3c04df4ed75876b8827bd4584e45 Mon Sep 17 00:00:00 2001 From: lingdar77 Date: Sun, 7 Jun 2026 23:14:44 +0800 Subject: [PATCH] fix build steps --- scripts/build-web.bat | 27 ++++++--------- scripts/build-web.sh | 71 --------------------------------------- scripts/build-windows.bat | 10 ++++-- scripts/build-windows.sh | 35 ------------------- scripts/clean.sh | 18 ---------- 5 files changed, 17 insertions(+), 144 deletions(-) delete mode 100644 scripts/build-web.sh delete mode 100644 scripts/build-windows.sh delete mode 100644 scripts/clean.sh diff --git a/scripts/build-web.bat b/scripts/build-web.bat index 8d53315..5947c1d 100644 --- a/scripts/build-web.bat +++ b/scripts/build-web.bat @@ -13,28 +13,21 @@ if %errorlevel% == 0 ( powershell -Command "(Get-Content thirdparty/leanclr/src/runtime/build_config.h) -replace 'LEANCLR_FATAL_ON_RAISE_NOT_IMPLEMENTED_ERROR 1', 'LEANCLR_FATAL_ON_RAISE_NOT_IMPLEMENTED_ERROR 0' | Set-Content thirdparty/leanclr/src/runtime/build_config.h" ) -REM Find the Emscripten toolchain. Override via EMSDK_TOOLCHAIN if needed. -if "%EMSDK_TOOLCHAIN%"=="" ( - for /f "delims=" %%i in ('where emcc 2^>nul') do set "EMCC_PATH=%%i" - if not "%EMCC_PATH%"=="" ( - REM \upstream\emscripten\emcc -> \upstream\emscripten\cmake\Modules\Platform\Emscripten.cmake - for %%i in ("%EMCC_PATH%") do set "EMCC_DIR=%%~dpi" - set "EMSDK_TOOLCHAIN=%EMCC_DIR%cmake\Modules\Platform\Emscripten.cmake" - ) -) -if "%EMSDK_TOOLCHAIN%"=="" ( - echo [build-web] Emscripten toolchain not found. Set EMSDK_TOOLCHAIN to: 1>&2 - echo [build-web] ^\upstream\emscripten\cmake\Modules\Platform\Emscripten.cmake 1>&2 +REM Assume Emscripten is on PATH (emsdk_env.bat / emsdk activated). +where emcc >nul 2>&1 +if errorlevel 1 ( + echo [build-web] emcc not found on PATH. Activate Emscripten via emsdk_env.bat first. 1>&2 exit /b 1 ) -echo [build-web] Using toolchain: %EMSDK_TOOLCHAIN% +echo [build-web] Using emcc from PATH. -cmake -S . -B build-web -G Ninja -DCMAKE_TOOLCHAIN_FILE="%EMSDK_TOOLCHAIN%" -DCMAKE_BUILD_TYPE=Release || exit /b 1 -python tools\binding_generator\generate_bindings.py --api build-web\_deps\godot-cpp-src\gdextension\extension_api.json +emcmake cmake -S . -B build-web -G Ninja -DCMAKE_BUILD_TYPE=Release if errorlevel 1 ( - py tools\binding_generator\generate_bindings.py --api build-web\_deps\godot-cpp-src\gdextension\extension_api.json + echo [build-web] Initial cmake configure failed, running binding generator and retrying... + python3 tools\binding_generator\generate_bindings.py --api build-web\_deps\godot-cpp-src\gdextension\extension_api.json + if errorlevel 1 exit /b 1 + emcmake cmake -S . -B build-web -G Ninja -DCMAKE_BUILD_TYPE=Release || exit /b 1 ) -cmake -S . -B build-web -G Ninja -DCMAKE_TOOLCHAIN_FILE="%EMSDK_TOOLCHAIN%" -DCMAKE_BUILD_TYPE=Release || exit /b 1 cmake --build build-web --target leanclr_godot || exit /b 1 dotnet msbuild managed\GodotSharpCompat\GodotSharpCompat.csproj -p:Configuration=Debug || exit /b 1 diff --git a/scripts/build-web.sh b/scripts/build-web.sh deleted file mode 100644 index 9548f7e..0000000 --- a/scripts/build-web.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env bash -# Build the Web (WASM) target. -# Requires Emscripten 3.1+ and Ninja on PATH. -# Run from the repo root. -set -euo pipefail - -REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -cd "$REPO_ROOT" - -if [ ! -f "thirdparty/leanclr/CMakeLists.txt" ]; then - git submodule update --init --recursive -fi - -# Re-apply the LeanCLR NotImplemented patch if needed. -if grep -q "LEANCLR_FATAL_ON_RAISE_NOT_IMPLEMENTED_ERROR 1" \ - thirdparty/leanclr/src/runtime/build_config.h 2>/dev/null; then - echo "[build-web] Re-applying leanclr NotImplemented patch..." - sed -i 's/LEANCLR_FATAL_ON_RAISE_NOT_IMPLEMENTED_ERROR 1/LEANCLR_FATAL_ON_RAISE_NOT_IMPLEMENTED_ERROR 0/' \ - thirdparty/leanclr/src/runtime/build_config.h -fi - -# Find the Emscripten toolchain. Override via $EMSDK_TOOLCHAIN if your install -# is in a non-default location. -if [ -z "${EMSDK_TOOLCHAIN:-}" ]; then - if command -v emcc >/dev/null 2>&1; then - # `which emcc` may resolve to either /upstream/emscripten/emcc - # (POSIX) or /upstream/bin/emcc.bat (Windows launcher). Walk up - # until we find a directory that contains cmake/Modules/Platform/. - EMCC_PATH="$(command -v emcc)" - d="$(dirname "$EMCC_PATH")" - for _ in 1 2 3 4 5 6 7 8; do - candidate="$d/cmake/Modules/Platform/Emscripten.cmake" - if [ -f "$candidate" ]; then - EMSDK_TOOLCHAIN="$candidate" - break - fi - d="$(dirname "$d")" - done - fi -fi -if [ -z "${EMSDK_TOOLCHAIN:-}" ] || [ ! -f "$EMSDK_TOOLCHAIN" ]; then - echo "[build-web] Emscripten toolchain not found. Set EMSDK_TOOLCHAIN to the" >&2 - echo "[build-web] full path of Emscripten.cmake, e.g.:" >&2 - echo "[build-web] /upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" >&2 - exit 1 -fi -echo "[build-web] Using toolchain: $EMSDK_TOOLCHAIN" - -# Configure (first pass — fetches godot-cpp). Single-threaded is forced by -# the CMakeLists's own if(EMSCRIPTEN) block (GODOTCPP_THREADS=OFF, -O1). -cmake -S . -B build-web -G Ninja \ - -DCMAKE_TOOLCHAIN_FILE="$EMSDK_TOOLCHAIN" \ - -DCMAKE_BUILD_TYPE=Release - -# Generate bindings (uses the same extension_api.json path, just inside build-web/). -python3 tools/binding_generator/generate_bindings.py \ - --api build-web/_deps/godot-cpp-src/gdextension/extension_api.json - -# Re-configure so the generated cpp is part of the target, then build. -cmake -S . -B build-web -G Ninja \ - -DCMAKE_TOOLCHAIN_FILE="$EMSDK_TOOLCHAIN" \ - -DCMAKE_BUILD_TYPE=Release -cmake --build build-web --target leanclr_godot - -# Managed C# (same output dir as the desktop build). -dotnet msbuild managed/GodotSharpCompat/GodotSharpCompat.csproj -p:Configuration=Debug -dotnet msbuild project/Game.csproj -p:Configuration=Debug - -echo "[build-web] Done. Output:" -echo "[build-web] project/bin/Release/libleanclr_godot.wasm" -echo "[build-web] Export the project for Web in the Godot editor to run." diff --git a/scripts/build-windows.bat b/scripts/build-windows.bat index e83f86d..2e10143 100644 --- a/scripts/build-windows.bat +++ b/scripts/build-windows.bat @@ -15,9 +15,13 @@ if %errorlevel% == 0 ( powershell -Command "(Get-Content thirdparty/leanclr/src/runtime/build_config.h) -replace 'LEANCLR_FATAL_ON_RAISE_NOT_IMPLEMENTED_ERROR 1', 'LEANCLR_FATAL_ON_RAISE_NOT_IMPLEMENTED_ERROR 0' | Set-Content thirdparty/leanclr/src/runtime/build_config.h" ) -python3 tools\binding_generator\generate_bindings.py --api build-master\_deps\godot-cpp-src\gdextension\extension_api.json -cmake -S . -B build-master -DCMAKE_BUILD_TYPE=Debug || exit /b 1 -cmake -S . -B build-master -DCMAKE_BUILD_TYPE=Debug || exit /b 1 +cmake -S . -B build-master -DCMAKE_BUILD_TYPE=Debug +if errorlevel 1 ( + echo [build-windows] Initial cmake configure failed, running binding generator and retrying... + python3 tools\binding_generator\generate_bindings.py --api build-master\_deps\godot-cpp-src\gdextension\extension_api.json + if errorlevel 1 exit /b 1 + cmake -S . -B build-master -DCMAKE_BUILD_TYPE=Debug || exit /b 1 +) cmake --build build-master --config Debug --target leanclr_godot || exit /b 1 dotnet msbuild managed\GodotSharpCompat\GodotSharpCompat.csproj -p:Configuration=Debug || exit /b 1 diff --git a/scripts/build-windows.sh b/scripts/build-windows.sh deleted file mode 100644 index ecb505c..0000000 --- a/scripts/build-windows.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# Build the Windows (Desktop) target: native GDExtension + managed C# DLLs. -# Run from the repo root. -set -euo pipefail - -REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -cd "$REPO_ROOT" - -# Pull submodules if missing. -if [ ! -f "thirdparty/leanclr/CMakeLists.txt" ]; then - git submodule update --init --recursive -fi - -# Re-apply the LeanCLR NotImplemented patch if a fresh submodule overwrote it. -if grep -q "LEANCLR_FATAL_ON_RAISE_NOT_IMPLEMENTED_ERROR 1" \ - thirdparty/leanclr/src/runtime/build_config.h 2>/dev/null; then - echo "[build-windows] Re-applying leanclr NotImplemented patch..." - sed -i 's/LEANCLR_FATAL_ON_RAISE_NOT_IMPLEMENTED_ERROR 1/LEANCLR_FATAL_ON_RAISE_NOT_IMPLEMENTED_ERROR 0/' \ - thirdparty/leanclr/src/runtime/build_config.h -fi - -# Generate bindings (needs the just-fetched extension_api.json). -python3 tools/binding_generator/generate_bindings.py \ - --api build-master/_deps/godot-cpp-src/gdextension/extension_api.json -# Configure CMake (first pass — fetches godot-cpp via FetchContent). -cmake -S . -B build-master -DCMAKE_BUILD_TYPE=Debug -# Re-configure so add_library sees the generated cpp, then build. -cmake -S . -B build-master -DCMAKE_BUILD_TYPE=Debug -cmake --build build-master --config Debug --target leanclr_godot - -# Managed C#. -dotnet msbuild managed/GodotSharpCompat/GodotSharpCompat.csproj -p:Configuration=Debug -dotnet msbuild project/Game.csproj -p:Configuration=Debug - -echo "[build-windows] Done. Run with: \"/path/to/Godot\" --path project" diff --git a/scripts/clean.sh b/scripts/clean.sh deleted file mode 100644 index ab9e878..0000000 --- a/scripts/clean.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# Remove all build outputs. Leaves sources, scripts, and the leanclr -# submodule intact. -# Run from the repo root. -set -euo pipefail - -REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -cd "$REPO_ROOT" - -rm -rf build build-master build-web -rm -rf src/generated -rm -rf managed/GodotSharpCompat/Generated -rm -rf project/bin -rm -rf project/leanclr -rm -rf project/obj -rm -f tools/binding_generator/__pycache__ - -echo "[clean] Removed build directories, generated bindings, C# outputs."