Skip to content

Commit 4851d85

Browse files
authored
Deprecate unsed MEM_INIT_METHOD setting (#18868)
We were already aborting if the user ever specified this on the command line. Because it was already effectively banned I'm not sure we need to mention this in the changelog.
1 parent ad1dfd7 commit 4851d85

6 files changed

+17
-29
lines changed

emcc.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ def minify_whitespace():
389389
return settings.OPT_LEVEL >= 2 and settings.DEBUG_LEVEL == 0
390390

391391

392-
def embed_memfile():
392+
def embed_memfile(options):
393393
return (settings.SINGLE_FILE or
394-
(settings.WASM2JS and settings.MEM_INIT_METHOD == 0 and
394+
(settings.WASM2JS and not options.memory_init_file and
395395
(not settings.MAIN_MODULE and
396396
not settings.SIDE_MODULE and
397397
not settings.GENERATE_SOURCE_MAP)))
@@ -2569,14 +2569,9 @@ def check_memory_setting(setting):
25692569
if options.use_closure_compiler == 2 and not settings.WASM2JS:
25702570
exit_with_error('closure compiler mode 2 assumes the code is asm.js, so not meaningful for wasm')
25712571

2572-
if 'MEM_INIT_METHOD' in user_settings:
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.')
2574-
25752572
if settings.WASM2JS:
25762573
if options.memory_init_file is None:
25772574
options.memory_init_file = settings.OPT_LEVEL >= 2
2578-
if options.memory_init_file:
2579-
settings.MEM_INIT_METHOD = 1
25802575
settings.MAYBE_WASM2JS = 1
25812576
# when using wasm2js, if the memory segments are in the wasm then they
25822577
# end up converted by wasm2js into base64 encoded JS. alternatively, we
@@ -2586,11 +2581,6 @@ def check_memory_setting(setting):
25862581
# shared memory builds we must keep the memory segments in the wasm as
25872582
# they will be passive segments which the .mem format cannot handle.
25882583
settings.MEM_INIT_IN_WASM = not options.memory_init_file or settings.SINGLE_FILE or settings.SHARED_MEMORY
2589-
else:
2590-
# wasm includes the mem init in the wasm binary. The exception is
2591-
# wasm2js, which behaves more like js.
2592-
# TODO(sbc): Error out here in --memory-init-file used.
2593-
settings.MEM_INIT_IN_WASM = True
25942584

25952585
if (
25962586
settings.MAYBE_WASM2JS or
@@ -3115,7 +3105,7 @@ def phase_post_link(options, state, in_wasm, wasm_target, target):
31153105
else:
31163106
memfile = shared.replace_or_append_suffix(target, '.mem')
31173107

3118-
phase_emscript(in_wasm, wasm_target, memfile)
3108+
phase_emscript(options, in_wasm, wasm_target, memfile)
31193109

31203110
if options.js_transform:
31213111
phase_source_transforms(options)
@@ -3133,11 +3123,11 @@ def phase_post_link(options, state, in_wasm, wasm_target, target):
31333123

31343124

31353125
@ToolchainProfiler.profile_block('emscript')
3136-
def phase_emscript(in_wasm, wasm_target, memfile):
3126+
def phase_emscript(options, in_wasm, wasm_target, memfile):
31373127
# Emscripten
31383128
logger.debug('emscript')
31393129

3140-
if embed_memfile():
3130+
if embed_memfile(options):
31413131
settings.SUPPORT_BASE64_EMBEDDING = 1
31423132
# _read in shell.js depends on intArrayToString when SUPPORT_BASE64_EMBEDDING is set
31433133
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.append('$intArrayToString')
@@ -3274,7 +3264,7 @@ def phase_final_emitting(options, state, target, wasm_target, memfile):
32743264
elif settings.PROXY_TO_WORKER:
32753265
generate_worker_js(target, js_target, target_basename)
32763266

3277-
if embed_memfile() and memfile:
3267+
if embed_memfile(options) and memfile:
32783268
delete_file(memfile)
32793269

32803270
if settings.SPLIT_MODULE:
@@ -3527,6 +3517,8 @@ def consume_arg_file():
35273517
ports.show_ports()
35283518
should_exit = True
35293519
elif check_arg('--memory-init-file'):
3520+
# This flag is ignored unless targetting wasm2js.
3521+
# TODO(sbc): Error out if used without wasm2js.
35303522
options.memory_init_file = int(consume_arg())
35313523
elif check_flag('--proxy-to-worker'):
35323524
settings_changes.append('PROXY_TO_WORKER=1')

src/postamble_minimal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then(function(output) {
219219
updateMemoryViews();
220220
#endif
221221

222-
#if MEM_INIT_METHOD == 1 && !MEM_INIT_IN_WASM && !SINGLE_FILE
222+
#if !MEM_INIT_IN_WASM && !SINGLE_FILE
223223
#if ASSERTIONS
224224
if (!Module['mem']) throw 'Must load memory initializer as an ArrayBuffer in to variable Module.mem before adding compiled output .js script to the DOM';
225225
#endif

src/settings.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,6 @@ var INVOKE_RUN = true;
9191
// [link]
9292
var EXIT_RUNTIME = false;
9393

94-
// How to represent the initial memory content.
95-
// 0: embed a base64 string literal representing the initial memory data
96-
// 1: create a *.mem file containing the binary data of the initial memory;
97-
98-
// use the --memory-init-file command line switch to select this method
99-
// [link]
100-
var MEM_INIT_METHOD = 0;
101-
10294
// The total stack size. There is no way to enlarge the stack, so this
10395
// value must be large enough for the program's requirements. If
10496
// assertions are on, we will assert on not exceeding this, otherwise,
@@ -2185,4 +2177,5 @@ var LEGACY_SETTINGS = [
21852177
['EMIT_EMSCRIPTEN_METADATA', [0], 'No longer supported'],
21862178
['SHELL_FILE', [''], 'No longer supported'],
21872179
['LLD_REPORT_UNDEFINED', [1], 'Disabling is no longer supported'],
2180+
['MEM_INIT_METHOD', [0], 'No longer supported'],
21882181
];

src/settings_internal.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ var AUDIO_WORKLET_FILE = '';
143143
// Base URL the source mapfile, if relevant
144144
var SOURCE_MAP_BASE = '';
145145

146-
var MEM_INIT_IN_WASM = false;
146+
// When this is false we use an external memory init file
147+
// See --memory-init-file. When not using wasm2js this flag is ignored, and
148+
// this setting will always be true.
149+
var MEM_INIT_IN_WASM = true;
147150

148151
// If set to 1, src/base64Utils.js will be included in the bundle.
149152
// This is set internally when needed (SINGLE_FILE)

src/shell_minimal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ if (ENVIRONMENT_IS_NODE) {
9494
Module['wasm'] = fs.readFileSync(__dirname + '/{{{ TARGET_BASENAME }}}.wasm');
9595
#endif
9696
#endif
97-
#if MEM_INIT_METHOD == 1 && !MEM_INIT_IN_WASM
97+
#if !MEM_INIT_IN_WASM
9898
Module['mem'] = fs.readFileSync(__dirname + '/{{{ TARGET_BASENAME }}}.mem');
9999
#endif
100100
}
@@ -110,7 +110,7 @@ if (ENVIRONMENT_IS_SHELL) {
110110
Module['wasm'] = read('{{{ TARGET_BASENAME }}}.wasm', 'binary');
111111
#endif
112112
#endif
113-
#if MEM_INIT_METHOD == 1 && !MEM_INIT_IN_WASM
113+
#if !MEM_INIT_IN_WASM
114114
Module['mem'] = read('{{{ TARGET_BASENAME }}}.mem', 'binary');
115115
#endif
116116
}

tools/minimal_runtime_shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def generate_minimal_runtime_load_statement(target_basename):
4646
files_to_load = ["script('%s')" % (target_basename + '.js')] # Main JS file always in first entry
4747

4848
# Download separate memory initializer file .mem
49-
if settings.MEM_INIT_METHOD == 1 and not settings.MEM_INIT_IN_WASM:
49+
if not settings.MEM_INIT_IN_WASM:
5050
if settings.MODULARIZE:
5151
modularize_imports += ['mem: r[%d]' % len(files_to_load)]
5252
else:

0 commit comments

Comments
 (0)