@@ -391,7 +391,7 @@ def minify_whitespace():
391
391
392
392
def embed_memfile ():
393
393
return (settings .SINGLE_FILE or
394
- (settings .MEM_INIT_METHOD == 0 and
394
+ (settings .WASM2JS and settings . MEM_INIT_METHOD == 0 and
395
395
(not settings .MAIN_MODULE and
396
396
not settings .SIDE_MODULE and
397
397
not settings .GENERATE_SOURCE_MAP )))
@@ -1808,9 +1808,6 @@ def phase_linker_setup(options, state, newargs):
1808
1808
options .extern_pre_js = read_js_files (options .extern_pre_js )
1809
1809
options .extern_post_js = read_js_files (options .extern_post_js )
1810
1810
1811
- if options .memory_init_file is None :
1812
- options .memory_init_file = settings .OPT_LEVEL >= 2
1813
-
1814
1811
# TODO: support source maps with js_transform
1815
1812
if options .js_transform and settings .GENERATE_SOURCE_MAP :
1816
1813
logger .warning ('disabling source maps because a js transform is being done' )
@@ -2079,10 +2076,6 @@ def phase_linker_setup(options, state, newargs):
2079
2076
if settings .MAIN_MODULE == 1 :
2080
2077
settings .INCLUDE_FULL_LIBRARY = 1
2081
2078
settings .DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$preloadDylibs' ]
2082
- elif settings .SIDE_MODULE :
2083
- assert not settings .MAIN_MODULE
2084
- # memory init file is not supported with side modules, must be executable synchronously (for dlopen)
2085
- options .memory_init_file = False
2086
2079
2087
2080
# If we are including the entire JS library then we know for sure we will, by definition,
2088
2081
# require all the reverse dependencies.
@@ -2580,6 +2573,10 @@ def check_memory_setting(setting):
2580
2573
exit_with_error ('MEM_INIT_METHOD is not supported in wasm. Memory will be embedded in the wasm binary if threads are not used, and included in a separate file if threads are used.' )
2581
2574
2582
2575
if settings .WASM2JS :
2576
+ if options .memory_init_file is None :
2577
+ options .memory_init_file = settings .OPT_LEVEL >= 2
2578
+ if options .memory_init_file :
2579
+ settings .MEM_INIT_METHOD = 1
2583
2580
settings .MAYBE_WASM2JS = 1
2584
2581
# when using wasm2js, if the memory segments are in the wasm then they
2585
2582
# end up converted by wasm2js into base64 encoded JS. alternatively, we
@@ -2592,7 +2589,7 @@ def check_memory_setting(setting):
2592
2589
else :
2593
2590
# wasm includes the mem init in the wasm binary. The exception is
2594
2591
# wasm2js, which behaves more like js.
2595
- options . memory_init_file = True
2592
+ # TODO(sbc): Error out here in --memory-init-file used.
2596
2593
settings .MEM_INIT_IN_WASM = True
2597
2594
2598
2595
if (
@@ -3118,7 +3115,7 @@ def phase_post_link(options, state, in_wasm, wasm_target, target):
3118
3115
else :
3119
3116
memfile = shared .replace_or_append_suffix (target , '.mem' )
3120
3117
3121
- phase_emscript (options , in_wasm , wasm_target , memfile )
3118
+ phase_emscript (in_wasm , wasm_target , memfile )
3122
3119
3123
3120
if options .js_transform :
3124
3121
phase_source_transforms (options )
@@ -3136,13 +3133,9 @@ def phase_post_link(options, state, in_wasm, wasm_target, target):
3136
3133
3137
3134
3138
3135
@ToolchainProfiler .profile_block ('emscript' )
3139
- def phase_emscript (options , in_wasm , wasm_target , memfile ):
3136
+ def phase_emscript (in_wasm , wasm_target , memfile ):
3140
3137
# Emscripten
3141
3138
logger .debug ('emscript' )
3142
- if options .memory_init_file :
3143
- settings .MEM_INIT_METHOD = 1
3144
- else :
3145
- assert settings .MEM_INIT_METHOD != 1
3146
3139
3147
3140
if embed_memfile ():
3148
3141
settings .SUPPORT_BASE64_EMBEDDING = 1
0 commit comments