@@ -102,6 +102,9 @@ def library_emitter(target, source, env):
102102def 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