Skip to content

Commit 5439b0d

Browse files
committed
Merge pull request godotengine#105692 from adamscott/prepare-for-new-emscripten
[Web] Add required exported functions and runtime methods for emscripten
2 parents fa2533b + 64b0d5c commit 5439b0d

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

platform/web/SCsub

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ for ext in sys_env["JS_EXTERNS"]:
7676
sys_env["ENV"]["EMCC_CLOSURE_ARGS"] += " --externs " + ext.abspath
7777
sys_env["ENV"]["EMCC_CLOSURE_ARGS"] = sys_env["ENV"]["EMCC_CLOSURE_ARGS"].strip()
7878

79+
if len(env["EXPORTED_FUNCTIONS"]):
80+
sys_env.Append(LINKFLAGS=["-sEXPORTED_FUNCTIONS=" + repr(sorted(list(set(env["EXPORTED_FUNCTIONS"]))))])
81+
if len(env["EXPORTED_RUNTIME_METHODS"]):
82+
sys_env.Append(LINKFLAGS=["-sEXPORTED_RUNTIME_METHODS=" + repr(sorted(list(set(env["EXPORTED_RUNTIME_METHODS"]))))])
83+
7984
build = []
8085
build_targets = ["#bin/godot${PROGSUFFIX}.js", "#bin/godot${PROGSUFFIX}.wasm"]
8186
if env["dlink_enabled"]:

platform/web/detect.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def library_emitter(target, source, env):
102102
def configure(env: "SConsEnvironment"):
103103
env.Append(LIBEMITTER=[library_emitter])
104104

105+
env["EXPORTED_FUNCTIONS"] = ["_main"]
106+
env["EXPORTED_RUNTIME_METHODS"] = []
107+
105108
# Validate arch.
106109
supported_arches = ["wasm32"]
107110
validate_arch(env["arch"], get_name(), supported_arches)
@@ -249,7 +252,7 @@ def configure(env: "SConsEnvironment"):
249252
if not env["dlink_enabled"]:
250253
# Workaround https://github.com/emscripten-core/emscripten/issues/21844#issuecomment-2116936414.
251254
# Not needed (and potentially dangerous) when dlink_enabled=yes, since we set EXPORT_ALL=1 in that case.
252-
env.Append(LINKFLAGS=["-sEXPORTED_FUNCTIONS=['__emscripten_thread_crashed','_main']"])
255+
env["EXPORTED_FUNCTIONS"] += ["__emscripten_thread_crashed"]
253256

254257
elif env["proxy_to_pthread"]:
255258
print_warning('"threads=no" support requires "proxy_to_pthread=no", disabling proxy to pthread.')
@@ -276,7 +279,7 @@ def configure(env: "SConsEnvironment"):
276279
if env["proxy_to_pthread"]:
277280
env.Append(LINKFLAGS=["-sPROXY_TO_PTHREAD=1"])
278281
env.Append(CPPDEFINES=["PROXY_TO_PTHREAD_ENABLED"])
279-
env.Append(LINKFLAGS=["-sEXPORTED_RUNTIME_METHODS=['_emscripten_proxy_main']"])
282+
env["EXPORTED_RUNTIME_METHODS"] += ["_emscripten_proxy_main"]
280283
# https://github.com/emscripten-core/emscripten/issues/18034#issuecomment-1277561925
281284
env.Append(LINKFLAGS=["-sTEXTDECODER=0"])
282285

@@ -303,7 +306,13 @@ def configure(env: "SConsEnvironment"):
303306
env.Append(LINKFLAGS=["-sINVOKE_RUN=0"])
304307

305308
# callMain for manual start, cwrap for the mono version.
306-
env.Append(LINKFLAGS=["-sEXPORTED_RUNTIME_METHODS=['callMain','cwrap']"])
309+
# Make sure also to have those memory-related functions available.
310+
heap_arrays = [f"HEAP{heap_type}{heap_size}" for heap_size in [8, 16, 32, 64] for heap_type in ["", "U"]] + [
311+
"HEAPF32",
312+
"HEAPF64",
313+
]
314+
env["EXPORTED_RUNTIME_METHODS"] += ["callMain", "cwrap"] + heap_arrays
315+
env["EXPORTED_FUNCTIONS"] += ["_malloc", "_free"]
307316

308317
# Add code that allow exiting runtime.
309318
env.Append(LINKFLAGS=["-sEXIT_RUNTIME=1"])

0 commit comments

Comments
 (0)