Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

ci: run the C++ harnesses under ASan + UBSan

yhh93ac7fd7f3e4
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index a75b33c3c..27c792ca8 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -19,23 +19,23 @@ concurrency:
permissions:
contents: read
+# Single source of truth for the C++ doctest harnesses: every job's build-target
+# list and run loop derives from it, so a new harness can no longer be compiled-
+# but-never-run (the hand-kept lists had drifted).
+env:
+ CPP_TESTS: >-
+ test_ecs test_events test_particle test_tilemap test_sparse_set
+ test_resource_pool test_shader_variant test_log_format test_registry_safety
+ test_registry_ondestroy
+ test_shader_device test_draw_params test_texture_fb test_buffer_device
+ test_compressed_format test_batch_builder test_boundary_span test_webgpu_device
+
jobs:
build-emscripten:
name: Web (Emscripten) + C++ tests
runs-on: ubuntu-latest
timeout-minutes: 40
- # Single source of truth for the C++ doctest harnesses: the build-target
- # list and the run loop both derive from CPP_TESTS, so a new harness can no
- # longer be compiled-but-never-run (the two hand-kept lists had drifted).
- env:
- CPP_TESTS: >-
- test_ecs test_events test_particle test_tilemap test_sparse_set
- test_resource_pool test_shader_variant test_log_format test_registry_safety
- test_registry_ondestroy
- test_shader_device test_draw_params test_texture_fb test_buffer_device
- test_compressed_format test_batch_builder test_boundary_span test_webgpu_device
-
steps:
- uses: actions/checkout@v7
with:
@@ -95,6 +95,46 @@ jobs:
path: build/wasm/web/
retention-days: 3
+ # The same harnesses, instrumented. An out-of-bounds read that lands in
+ # allocation slack (or in the next allocation) is silent in the plain build and
+ # is exactly what these gates cannot otherwise see. Findings are fatal —
+ # ES_SANITIZE passes -fno-sanitize-recover, or UBSan would print and continue.
+ sanitizers:
+ name: C++ tests (ASan + UBSan)
+ runs-on: ubuntu-latest
+ timeout-minutes: 40
+
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ submodules: recursive
+
+ - name: Setup Emscripten
+ uses: mymindstorm/setup-emsdk@v16
+ with:
+ version: 5.0.0
+
+ - name: Setup ccache
+ uses: hendrikmuhs/[email protected]
+ with:
+ key: emscripten-asan
+
+ - name: Configure (ASan + UBSan)
+ run: |
+ emcmake cmake -S . -B build/wasm/asan -DCMAKE_BUILD_TYPE=Debug \
+ -DES_BUILD_WEB=ON -DES_BUILD_TESTS=ON -DES_SANITIZE=ON
+
+ - name: Build C++ test harnesses
+ run: cmake --build build/wasm/asan -j "$(nproc)" --target $CPP_TESTS
+
+ - name: Run C++ test harnesses
+ run: |
+ for t in $CPP_TESTS; do
+ cp "build/wasm/asan/bin/$t.js" "build/wasm/asan/bin/$t.cjs"
+ echo "=== $t"
+ node "build/wasm/asan/bin/$t.cjs"
+ done
+
test:
name: Tests (SDK + Desktop)
runs-on: ubuntu-latest
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6789017a9..99ce8a31e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,6 +32,23 @@ option(ES_BUILD_SIDE_MODULE "Build side modules for dynamic linking" OFF)
# "physics", so exactly one may exist per configure — pick the ESM flavour here.
option(ES_PHYSICS_ESM "Emit the physics module as an ES6 module (web) instead of require()-style (WeChat)" OFF)
+# ASan + UBSan for the test harnesses (the sanitizers job in build.yml). Findings
+# are fatal: without -fno-sanitize-recover UBSan prints and continues, which a CI
+# gate reads as green. clang/gcc/emcc flags — MSVC has no UBSan.
+option(ES_SANITIZE "Build with AddressSanitizer + UndefinedBehaviorSanitizer" OFF)
+if(ES_SANITIZE)
+ if(MSVC)
+ message(FATAL_ERROR "ES_SANITIZE requires clang or gcc (MSVC has no UBSan).")
+ endif()
+ add_compile_options(-fsanitize=address,undefined -fno-sanitize-recover=all
+ -fno-omit-frame-pointer -g)
+ add_link_options(-fsanitize=address,undefined)
+ if(EMSCRIPTEN)
+ # ASan's shadow memory does not fit in the harnesses' fixed default heap.
+ add_link_options(-sALLOW_MEMORY_GROWTH=1)
+ endif()
+endif()
+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(ESEngineConfig)
include(CompilerCache)