From ba3401f81fb90baf69eebf854fe8c74da3fa530d Mon Sep 17 00:00:00 2001 From: NoctemCat Date: Tue, 3 Mar 2026 21:27:59 +0900 Subject: [PATCH] Fix assertions wrongly affecting release template, make it configurable --- platform/web/detect.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/platform/web/detect.py b/platform/web/detect.py index 68608e17ef..e4dec6ecef 100644 --- a/platform/web/detect.py +++ b/platform/web/detect.py @@ -36,14 +36,16 @@ def get_tools(env: "SConsEnvironment"): def get_opts(): - from SCons.Variables import BoolVariable + from SCons.Variables import BoolVariable, EnumVariable return [ ("initial_memory", "Initial WASM memory (in MiB)", 32), # Matches default values from before Emscripten 3.1.27. New defaults are too low for Godot. ("stack_size", "WASM stack size (in KiB)", 5120), ("default_pthread_stack_size", "WASM pthread default stack size (in KiB)", 2048), - BoolVariable("use_assertions", "Use Emscripten runtime assertions", False), + EnumVariable( + "use_assertions", "Use Emscripten runtime assertions", "auto", ["auto", "no", "yes", "extra"], ignorecase=2 + ), BoolVariable("use_ubsan", "Use Emscripten undefined behavior sanitizer (UBSAN)", False), BoolVariable("use_asan", "Use Emscripten address sanitizer (ASAN)", False), BoolVariable("use_lsan", "Use Emscripten leak sanitizer (LSAN)", False), @@ -139,16 +141,19 @@ def configure(env: "SConsEnvironment"): emscripten_include_path = emcc_path.parent.joinpath("cache", "sysroot", "include") env.Append(CPPPATH=[emscripten_include_path]) - ## Build type + ## Configure assertions. + if env["use_assertions"] == "auto": + env["use_assertions"] = "yes" if env.debug_features else "no" + if env["use_assertions"] == "yes": + print_info("Building with runtime assertions.") + env.Append(LINKFLAGS=["-sASSERTIONS=1"]) + elif env["use_assertions"] == "extra": + print_info("Building with runtime assertions with extra tests.") + env.Append(LINKFLAGS=["-sASSERTIONS=2"]) - if env.debug_features: + if env["debug_symbols"]: # Retain function names for backtraces at the cost of file size. env.Append(LINKFLAGS=["--profiling-funcs"]) - else: - env["use_assertions"] = True - - if env["use_assertions"]: - env.Append(LINKFLAGS=["-sASSERTIONS=1"]) if env.editor_build and env["initial_memory"] < 64: print_info("Forcing `initial_memory=64` as it is required for the web editor.")