Skip to content

Commit 2dbcd52

Browse files
committed
fix(web): make the Emscripten build produce a module the browser will accept
Two independent blockers, both found running the web build against a current emsdk (5.0.7) after the Game-lifetime crash in 16c3b67 was fixed: - sol2 v3.3.0 does not compile. optional<T&>::emplace calls this->construct(), which that specialization does not have; because optional<T&> is a full specialization the lookup is not deferred, so a newer clang diagnoses it even though nothing instantiates it, and LuaScriptRunner.cpp fails. v3.3.1 still has it; v3.5.0 replaced the body with a placement-new that returns properly, so the pin moves there. - The linked module was rejected by the browser at instantiation: "module uses a mix of legacy and new exception handling instructions". CNA selects the standardized try_table exception ABI (-sWASM_LEGACY_EXCEPTIONS=0) in its own root CMakeLists, while this project passed only -fwasm-exceptions -- so everything under CNA_dep used one ABI and MeshCraft's own objects, lua54, imgui, manifold and tinygltf used the other. Matching CNA's flag puts every object in the link on the same ABI. Verified end to end in headless Chrome: the editor now loads and renders -- menu bar, toolbar, hierarchy panel, viewport grid, Properties panel, "0 objects" status -- with "[MeshCraft] New scene" in the output and not a single exception in the console, where the same page previously died immediately after that line.
1 parent 16c3b67 commit 2dbcd52

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,14 @@ meshcraft_select_graphics_backend(
106106
MESH_CRAFT_GRAPHICS_BACKEND_UPPER)
107107

108108
if(EMSCRIPTEN)
109-
add_compile_options(-fwasm-exceptions)
110-
add_link_options(-fwasm-exceptions)
109+
# -sWASM_LEGACY_EXCEPTIONS=0 must match CNA, which sets it in its own root CMakeLists: it
110+
# selects the standardized try_table exception ABI over Emscripten's still-default legacy
111+
# `try`. Without it, MeshCraft's own objects and its third-party subtrees (lua54, imgui,
112+
# manifold, tinygltf) are built on the legacy ABI while everything under CNA_dep uses the
113+
# standardized one, and the browser refuses the linked module outright:
114+
# "module uses a mix of legacy and new exception handling instructions".
115+
add_compile_options(-fwasm-exceptions -sWASM_LEGACY_EXCEPTIONS=0)
116+
add_link_options(-fwasm-exceptions -sWASM_LEGACY_EXCEPTIONS=0)
111117
endif()
112118

113119
if(NOT MESH_CRAFT_GRAPHICS_BACKEND_UPPER MATCHES "^(SDL_RENDERER|EASYGL|BGFX|VULKAN|WEBGPU)$")
@@ -415,9 +421,14 @@ else()
415421
target_compile_options(lua54 PRIVATE /w)
416422
endif()
417423

424+
# v3.3.0 and v3.3.1 do not compile with a current clang: optional<T&>::emplace calls a
425+
# this->construct() that specialization does not have, and since optional<T&> is a full
426+
# specialization the lookup is not deferred, so newer clang reports it even though nothing
427+
# instantiates it. v3.5.0 replaced that body with a placement-new that returns properly.
428+
# Found when the Emscripten build (emsdk 5.0.7) stopped on LuaScriptRunner.cpp.
418429
FetchContent_Declare(sol2
419430
GIT_REPOSITORY https://github.com/ThePhD/sol2.git
420-
GIT_TAG v3.3.0
431+
GIT_TAG v3.5.0
421432
GIT_SHALLOW TRUE
422433
)
423434
FetchContent_MakeAvailable(sol2)

0 commit comments

Comments
 (0)