diff --git a/ChangeLog.md b/ChangeLog.md index b0b22bd35b8c3..b6f25db07afce 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -21,6 +21,9 @@ See docs/process.md for more on how version tagging works. 3.1.55 (in development) ----------------------- - Update sdl2-mixer port from 2.6.0 to 2.8.0 +- Emscripten no longer supported extracting static data and serving it as a + separate `.mem` data file. The feature was already only available under + wasm2js (`-sWASM=0`) so this change will only effect users of this setting. 3.1.54 - 02/15/24 ----------------- @@ -58,7 +61,6 @@ See docs/process.md for more on how version tagging works. - Allow comments in response files. Any line starting with `#` is now ignored. This is useful when listing exported symbols. (#21330) - 3.1.53 - 01/29/24 ----------------- - The llvm version that emscripten uses was updated to 19.0.0 trunk. (#21165) diff --git a/emcc.py b/emcc.py index 6cd88c9793b71..58bc352d41418 100644 --- a/emcc.py +++ b/emcc.py @@ -145,7 +145,6 @@ def __init__(self): self.emrun = False self.cpu_profiler = False self.memory_profiler = False - self.memory_init_file = None self.use_preload_cache = False self.use_preload_plugins = False self.valid_abspaths = [] @@ -1316,7 +1315,7 @@ def consume_arg_file(): ports.show_ports() should_exit = True elif check_arg('--memory-init-file'): - options.memory_init_file = int(consume_arg()) + exit_with_error('--memory-init-file is no longer supported') elif check_flag('--proxy-to-worker'): settings_changes.append('PROXY_TO_WORKER=1') elif check_arg('--valid-abspath'): diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index 5638a986cce94..a17fa34832351 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -221,13 +221,6 @@ WebAssembly.instantiate(Module['wasm'], imports).then((output) => { updateMemoryViews(); #endif -#if !MEM_INIT_IN_WASM && !SINGLE_FILE -#if ASSERTIONS - 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'; -#endif - HEAPU8.set(new Uint8Array(Module['mem']), {{{ GLOBAL_BASE }}}); -#endif - initRuntime(wasmExports); #if PTHREADS // Export Wasm module for pthread creation to access. diff --git a/src/preamble.js b/src/preamble.js index 7526ae4d587f5..5edcca8e5d9c6 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -990,9 +990,6 @@ function createWasm() { #endif updateMemoryViews(); #endif -#if !MEM_INIT_IN_WASM - runMemoryInitializer(); -#endif #if '$wasmTable' in addedLibraryItems && !RELOCATABLE wasmTable = wasmExports['__indirect_function_table']; @@ -1140,88 +1137,6 @@ function getCompilerSetting(name) { } #endif // RETAIN_COMPILER_SETTINGS -#if !MEM_INIT_IN_WASM -var memoryInitializer = <<< MEM_INITIALIZER >>>; - -function runMemoryInitializer() { -#if PTHREADS - if (ENVIRONMENT_IS_PTHREAD) return; -#endif - if (!isDataURI(memoryInitializer)) { - memoryInitializer = locateFile(memoryInitializer); - } - if (ENVIRONMENT_IS_NODE || ENVIRONMENT_IS_SHELL) { - var data = readBinary(memoryInitializer); - HEAPU8.set(data, {{{ GLOBAL_BASE }}}); - } else { - addRunDependency('memory initializer'); - var applyMemoryInitializer = (data) => { - if (data.byteLength) data = new Uint8Array(data); -#if ASSERTIONS - for (var i = 0; i < data.length; i++) { - assert(HEAPU8[{{{ GLOBAL_BASE }}} + i] === 0, "area for memory initializer should not have been touched before it's loaded"); - } -#endif - HEAPU8.set(data, {{{ GLOBAL_BASE }}}); - // Delete the typed array that contains the large blob of the memory initializer request response so that - // we won't keep unnecessary memory lying around. However, keep the XHR object itself alive so that e.g. - // its .status field can still be accessed later. - if (Module['memoryInitializerRequest']) delete Module['memoryInitializerRequest'].response; - removeRunDependency('memory initializer'); - }; - var doBrowserLoad = () => { - readAsync(memoryInitializer, applyMemoryInitializer, () => { - var e = new Error('could not load memory initializer ' + memoryInitializer); -#if MODULARIZE - readyPromiseReject(e); -#else - throw e; -#endif - }); - }; -#if SUPPORT_BASE64_EMBEDDING - var memoryInitializerBytes = tryParseAsDataURI(memoryInitializer); - if (memoryInitializerBytes) { - applyMemoryInitializer(memoryInitializerBytes.buffer); - } else -#endif - if (Module['memoryInitializerRequest']) { - // a network request has already been created, just use that - var useRequest = () => { - var request = Module['memoryInitializerRequest']; - var response = request.response; - if (request.status !== 200 && request.status !== 0) { -#if SUPPORT_BASE64_EMBEDDING - var data = tryParseAsDataURI(Module['memoryInitializerRequestURL']); - if (data) { - response = data.buffer; - } else { -#endif - // If you see this warning, the issue may be that you are using locateFile and defining it in JS. That - // means that the HTML file doesn't know about it, and when it tries to create the mem init request early, does it to the wrong place. - // Look in your browser's devtools network console to see what's going on. - console.warn('a problem seems to have happened with Module.memoryInitializerRequest, status: ' + request.status + ', retrying ' + memoryInitializer); - doBrowserLoad(); - return; -#if SUPPORT_BASE64_EMBEDDING - } -#endif - } - applyMemoryInitializer(response); - }; - if (Module['memoryInitializerRequest'].response) { - setTimeout(useRequest, 0); // it's already here; but, apply it asynchronously - } else { - Module['memoryInitializerRequest'].addEventListener('load', useRequest); // wait for it - } - } else { - // fetch it from the network ourselves - doBrowserLoad(); - } - } -} -#endif // MEM_INIT_IN_WASM == 0 - #if MAIN_MODULE && ASYNCIFY // With MAIN_MODULE + ASYNCIFY the normal method of placing stub functions in // wasmImports for as-yet-undefined symbols doesn't work since ASYNCIFY then diff --git a/src/settings_internal.js b/src/settings_internal.js index 60a77da6b4f9c..c27582b27014c 100644 --- a/src/settings_internal.js +++ b/src/settings_internal.js @@ -143,11 +143,6 @@ var AUDIO_WORKLET_FILE = ''; // Base URL the source mapfile, if relevant var SOURCE_MAP_BASE = ''; -// When this is false we use an external memory init file -// See --memory-init-file. When not using wasm2js this flag is ignored, and -// this setting will always be true. -var MEM_INIT_IN_WASM = true; - // If set to 1, src/base64Utils.js will be included in the bundle. // This is set internally when needed (SINGLE_FILE) var SUPPORT_BASE64_EMBEDDING = false; diff --git a/src/shell_minimal.js b/src/shell_minimal.js index 5dcfd039a1f9b..4a7eae59134ee 100644 --- a/src/shell_minimal.js +++ b/src/shell_minimal.js @@ -82,7 +82,7 @@ if (ENVIRONMENT_IS_NODE && ENVIRONMENT_IS_SHELL) { #endif #if !SINGLE_FILE -#if ENVIRONMENT_MAY_BE_NODE && ((WASM == 1 && (!WASM2JS || !MEM_INIT_IN_WASM)) || WASM == 2) +#if ENVIRONMENT_MAY_BE_NODE && ((WASM == 1 && !WASM2JS) || WASM == 2) // Wasm or Wasm2JS loading: if (ENVIRONMENT_IS_NODE) { @@ -95,13 +95,10 @@ if (ENVIRONMENT_IS_NODE) { Module['wasm'] = fs.readFileSync(__dirname + '/{{{ TARGET_BASENAME }}}.wasm'); #endif #endif -#if !MEM_INIT_IN_WASM - Module['mem'] = fs.readFileSync(__dirname + '/{{{ TARGET_BASENAME }}}.mem'); -#endif } #endif -#if ENVIRONMENT_MAY_BE_SHELL && ((WASM == 1 && (!WASM2JS || !MEM_INIT_IN_WASM)) || WASM == 2) +#if ENVIRONMENT_MAY_BE_SHELL && ((WASM == 1 && !WASM2JS) || WASM == 2) if (ENVIRONMENT_IS_SHELL) { #if WASM == 2 if (typeof WebAssembly != 'undefined') Module['wasm'] = read('{{{ TARGET_BASENAME }}}.wasm', 'binary'); @@ -111,9 +108,6 @@ if (ENVIRONMENT_IS_SHELL) { Module['wasm'] = read('{{{ TARGET_BASENAME }}}.wasm', 'binary'); #endif #endif -#if !MEM_INIT_IN_WASM - Module['mem'] = read('{{{ TARGET_BASENAME }}}.mem', 'binary'); -#endif } #endif diff --git a/test/code_size/embind_val_wasm.json b/test/code_size/embind_val_wasm.json index 8f7f51e0dd8ed..43f4200146319 100644 --- a/test/code_size/embind_val_wasm.json +++ b/test/code_size/embind_val_wasm.json @@ -3,8 +3,8 @@ "a.html.gz": 431, "a.js": 7080, "a.js.gz": 2999, - "a.wasm": 11431, - "a.wasm.gz": 5727, - "total": 19184, - "total_gz": 9157 + "a.wasm": 11428, + "a.wasm.gz": 5724, + "total": 19181, + "total_gz": 9154 } diff --git a/test/code_size/hello_webgl2_wasm2js.json b/test/code_size/hello_webgl2_wasm2js.json index 26f088bfbae7f..d3bb6d57bf6bc 100644 --- a/test/code_size/hello_webgl2_wasm2js.json +++ b/test/code_size/hello_webgl2_wasm2js.json @@ -1,10 +1,8 @@ { - "a.html": 567, - "a.html.gz": 379, - "a.js": 17800, - "a.js.gz": 7981, - "a.mem": 3123, - "a.mem.gz": 2693, - "total": 21490, - "total_gz": 11053 + "a.html": 354, + "a.html.gz": 266, + "a.js": 22323, + "a.js.gz": 11632, + "total": 22677, + "total_gz": 11898 } diff --git a/test/code_size/hello_webgl_wasm2js.json b/test/code_size/hello_webgl_wasm2js.json index 438d4423d35c3..16ce634d5034d 100644 --- a/test/code_size/hello_webgl_wasm2js.json +++ b/test/code_size/hello_webgl_wasm2js.json @@ -1,10 +1,8 @@ { - "a.html": 567, - "a.html.gz": 379, - "a.js": 17272, - "a.js.gz": 7814, - "a.mem": 3123, - "a.mem.gz": 2693, - "total": 20962, - "total_gz": 10886 + "a.html": 354, + "a.html.gz": 266, + "a.js": 21794, + "a.js.gz": 11450, + "total": 22148, + "total_gz": 11716 } diff --git a/test/code_size/hello_world_wasm2js.js b/test/code_size/hello_world_wasm2js.js index 90abfb3c8c621..d81d12e761bf1 100644 --- a/test/code_size/hello_world_wasm2js.js +++ b/test/code_size/hello_world_wasm2js.js @@ -1,19 +1,30 @@ -var c = Module, g, h, k = new TextDecoder("utf8"), l; +var d = Module, g, h, k = new TextDecoder("utf8"), l; -function d(b) { - this.exports = function(f) { - function m(e) { - e.set = function(a, n) { - this[a] = n; +function e(b) { + this.exports = function(r) { + function u(c) { + c.set = function(a, f) { + this[a] = f; }; - e.get = function(a) { + c.get = function(a) { return this[a]; }; - return e; + return c; } - return function(e) { - var a = new ArrayBuffer(16777216), n = e.a.a; - e = m([]); + function x(c, a, f) { + for (var v, p = 0, t = a, w = f.length, y = a + (3 * w >> 2) - ("=" == f[w - 2]) - ("=" == f[w - 1]); p < w; p += 4) a = m[f.charCodeAt(p + 1)], + v = m[f.charCodeAt(p + 2)], c[t++] = m[f.charCodeAt(p)] << 2 | a >> 4, t < y && (c[t++] = a << 4 | v >> 2), + t < y && (c[t++] = v << 6 | m[f.charCodeAt(p + 3)]); + } + for (var q, m = new Uint8Array(123), n = 25; 0 <= n; --n) m[48 + n] = 52 + n, m[65 + n] = n, + m[97 + n] = 26 + n; + m[43] = 62; + m[47] = 63; + return function(c) { + var a = new ArrayBuffer(16777216), f = new Uint8Array(a), v = c.a.a; + q = f; + x(q, 1024, "aGVsbG8h"); + c = u([]); return { b: Object.create(Object.prototype, { grow: {}, @@ -24,33 +35,33 @@ function d(b) { } }), c: function() {}, - d: function(p, q) { - n(1024); + d: function(p, t) { + v(1024); return 0; }, - e: e + e: c }; - }(f); + }(r); }(b); } -(function(b, f) { +(function(b, r) { return { - then: function(m) { - m({ - instance: new d(f) + then: function(u) { + u({ + instance: new e(r) }); } }; -})(c.wasm, { +})(d.wasm, { a: { a: b => { - var f = console, m = f.log; + var r = console, u = r.log; if (b) { - for (var e = b + void 0, a = b; !(a >= e) && g[a]; ) ++a; - b = k.decode(g.subarray(b, a)); + for (var x = b + void 0, q = b; !(q >= x) && g[q]; ) ++q; + b = k.decode(g.subarray(b, q)); } else b = ""; - m.call(f, b); + u.call(r, b); } } }).then((b => { @@ -58,7 +69,6 @@ function d(b) { l = b.d; h = b.b; g = new Uint8Array(h.buffer); - g.set(new Uint8Array(c.mem), 1024); b.c(); l(); })); \ No newline at end of file diff --git a/test/code_size/hello_world_wasm2js.json b/test/code_size/hello_world_wasm2js.json index 6c26b7a43f595..80d9448e1fab5 100644 --- a/test/code_size/hello_world_wasm2js.json +++ b/test/code_size/hello_world_wasm2js.json @@ -1,10 +1,8 @@ { - "a.html": 671, - "a.html.gz": 430, - "a.js": 708, - "a.js.gz": 444, - "a.mem": 6, - "a.mem.gz": 32, - "total": 1385, - "total_gz": 906 + "a.html": 323, + "a.html.gz": 253, + "a.js": 1060, + "a.js.gz": 636, + "total": 1383, + "total_gz": 889 } diff --git a/test/common.py b/test/common.py index bb258b3238fa4..fc74c360ef741 100644 --- a/test/common.py +++ b/test/common.py @@ -847,17 +847,6 @@ def setup_node_pthreads(self): self.js_engines = [nodejs] self.node_args += shared.node_pthread_flags(nodejs) - def uses_memory_init_file(self): - if self.get_setting('SIDE_MODULE') or self.is_wasm(): - return False - - if '--memory-init-file' in self.emcc_args: - return int(self.emcc_args[self.emcc_args.index('--memory-init-file') + 1]) - - # side modules handle memory differently; binaryen puts the memory in the wasm module - opt_supports = any(opt in self.emcc_args for opt in ('-O2', '-O3', '-Os', '-Oz')) - return opt_supports - def set_temp_dir(self, temp_dir): self.temp_dir = temp_dir self.canonical_temp_dir = get_canonical_temp_dir(self.temp_dir) @@ -1104,11 +1093,6 @@ def build(self, filename, libraries=None, includes=None, force_c=False, js_outfi self.run_process(cmd, stderr=self.stderr_redirect if not DEBUG else None) self.assertExists(output) - if js_outfile and self.uses_memory_init_file(): - src = read_file(output) - # side memory init file, or an empty one in the js - assert ('/* memory initializer */' not in src) or ('/* memory initializer */ allocate([]' in src) - return output def get_func(self, src, name): diff --git a/test/test_browser.py b/test/test_browser.py index b1a015d048f34..4adcb365c41b3 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -2383,13 +2383,8 @@ def test_runtimelink(self): self.run_process([EMCC, 'supp.c', '-o', 'supp.wasm', '-sSIDE_MODULE', '-O2'] + self.get_emcc_args()) self.btest_exit('main.c', args=['-sMAIN_MODULE=2', '-O2', 'supp.wasm']) - @parameterized({ - '': ([],), - 'memfile': (['-sWASM=0', '--memory-init-file=1'],) - }) - def test_pre_run_deps(self, args): - if args: - self.require_wasm2js() + @also_with_wasm2js + def test_pre_run_deps(self): # Adding a dependency in preRun will delay run create_file('pre.js', ''' Module.preRun = () => { @@ -2402,7 +2397,7 @@ def test_pre_run_deps(self, args): }; ''') - self.btest('pre_run_deps.cpp', expected='10', args=args + ['--pre-js', 'pre.js']) + self.btest('pre_run_deps.cpp', expected='10', args=['--pre-js', 'pre.js']) @requires_wasm2js def test_mem_init(self): @@ -2993,10 +2988,6 @@ def test_glfw3_hi_dpi_aware(self): @requires_graphics_hardware @no_wasm64('SDL2 + wasm64') - @parameterized({ - '': ([],), - 'memfile': (['-sWASM=0', '--memory-init-file=1'],) - }) def test_sdl2_image(self, args): if args: self.require_wasm2js() @@ -4481,27 +4472,6 @@ def test_vanilla_html_when_proxying(self): create_file('test.html', '') self.run_browser('test.html', '/report_result?0') - @requires_wasm2js - @parameterized({ - 'O0': [('-O0',), '0'], - 'O1': [('-O1',), '0'], - 'O2': [('-O2',), '1'], - }) - def test_in_flight_memfile_request(self, args, expected): - # test the XHR for an asm.js mem init file being in flight already - self.emcc_args += args - self.set_setting('WASM', 0) - - print('plain html') - self.compile_btest('in_flight_memfile_request.c', ['-o', 'test.js']) - create_file('test.html', '') - # never when we provide our own HTML like this. - self.run_browser('test.html', '/report_result?0') - - print('default html') - # should happen when there is a mem init file (-O2+) - self.btest('in_flight_memfile_request.c', expected=expected) - @parameterized({ '': ([], 1), 'O1': (['-O1'], 1), diff --git a/test/test_other.py b/test/test_other.py index 87609b0cd80fa..e2c0372dd8591 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -9101,26 +9101,19 @@ def test_standalone_system_headers(self): }) def test_single_file(self, wasm2js): for (single_file_enabled, - meminit1_enabled, debug_enabled, - closure_enabled) in itertools.product([True, False], repeat=4): + closure_enabled) in itertools.product([True, False], repeat=3): # skip unhelpful option combinations - if meminit1_enabled and not wasm2js: - continue if closure_enabled and debug_enabled: continue expect_wasm = not wasm2js - expect_meminit = meminit1_enabled and wasm2js cmd = [EMCC, test_file('hello_world.c')] if single_file_enabled: - expect_meminit = False expect_wasm = False cmd += ['-sSINGLE_FILE'] - if meminit1_enabled: - cmd += ['--memory-init-file', '1'] if debug_enabled: cmd += ['-g'] if closure_enabled: @@ -9134,7 +9127,6 @@ def do_test(cmd): print(' '.join(cmd)) self.run_process(cmd) print(os.listdir('.')) - assert expect_meminit == (os.path.exists('a.out.mem') or os.path.exists('a.out.js.mem')) assert expect_wasm == os.path.exists('a.out.wasm') assert not os.path.exists('a.out.wat') self.assertContained('hello, world!', self.run_js('a.out.js')) @@ -10674,7 +10666,7 @@ def test_minimal_runtime_code_size(self, test_name, js, compare_js_output=False) '-DNDEBUG', '-ffast-math'] - wasm2js = ['-sWASM=0', '--memory-init-file', '1'] + wasm2js = ['-sWASM=0'] math_sources = [test_file('code_size/math.c')] hello_world_sources = [test_file('small_hello_world.c'), @@ -10715,7 +10707,6 @@ def print_percent(actual, expected): args = smallest_code_size_args[:] if js: - outputs += ['a.mem'] args += wasm2js test_name += '_wasm2js' else: @@ -14107,8 +14098,8 @@ def run(args, expect_bulk_mem): run(['-pthread'], expect_bulk_mem=True) def test_memory_init_file_unsupported(self): - err = self.expect_fail([EMCC, test_file('hello_world.c'), '-Werror', '--memory-init-file=1']) - self.assertContained('error: --memory-init-file is only supported with -sWASM=0 [-Wunsupported] [-Werror]', err) + err = self.expect_fail([EMCC, test_file('hello_world.c'), '--memory-init-file=1']) + self.assertContained('error: --memory-init-file is no longer supported', err) @node_pthreads def test_node_pthreads_err_out(self): diff --git a/tools/link.py b/tools/link.py index 57f32d09280e0..fa1c520370058 100644 --- a/tools/link.py +++ b/tools/link.py @@ -193,9 +193,9 @@ def setup_environment_settings(): exit_with_error('when building with multithreading enabled and a "-sENVIRONMENT=" directive is specified, it must include "worker" as a target! (Try e.g. -sENVIRONMENT=web,worker)') -def embed_memfile(options): +def embed_memfile(): return (settings.SINGLE_FILE or - (settings.WASM2JS and not options.memory_init_file and + (settings.WASM2JS and (not settings.MAIN_MODULE and not settings.SIDE_MODULE and not settings.GENERATE_SOURCE_MAP))) @@ -325,13 +325,7 @@ def should_run_binaryen_optimizer(): return settings.OPT_LEVEL >= 2 -def remove_trailing_zeros(memfile): - mem_data = utils.read_binary(memfile) - mem_data = mem_data.rstrip(b'\0') - utils.write_binary(memfile, mem_data) - - -def get_binaryen_passes(memfile): +def get_binaryen_passes(): passes = [] optimizing = should_run_binaryen_optimizer() # wasm-emscripten-finalize will strip the features section for us @@ -417,12 +411,6 @@ def check_human_readable_list(items): if settings.MEMORY64 == 2: passes += ['--memory64-lowering'] - if memfile: - passes += [ - f'--separate-data-segments={memfile}', - f'--pass-arg=separate-data-segments-global-base@{settings.GLOBAL_BASE}' - ] - if settings.BINARYEN_IGNORE_IMPLICIT_TRAPS: passes += ['--ignore-implicit-traps'] # normally we can assume the memory, if imported, has not been modified @@ -1465,19 +1453,7 @@ def check_memory_setting(setting): exit_with_error('closure compiler mode 2 assumes the code is asm.js, so not meaningful for wasm') if settings.WASM2JS: - if options.memory_init_file is None: - options.memory_init_file = settings.OPT_LEVEL >= 2 settings.MAYBE_WASM2JS = 1 - # when using wasm2js, if the memory segments are in the wasm then they - # end up converted by wasm2js into base64 encoded JS. alternatively, we - # can use a .mem file like asm.js used to. - # generally we follow what the options tell us to do (which is to use - # a .mem file in most cases, since it is binary & compact). however, for - # shared memory builds we must keep the memory segments in the wasm as - # they will be passive segments which the .mem format cannot handle. - settings.MEM_INIT_IN_WASM = not options.memory_init_file or settings.SINGLE_FILE or settings.SHARED_MEMORY - elif options.memory_init_file: - diagnostics.warning('unsupported', '--memory-init-file is only supported with -sWASM=0') if settings.AUTODEBUG: settings.REQUIRED_EXPORTS += ['setTempRet0'] @@ -1842,7 +1818,7 @@ def phase_post_link(options, state, in_wasm, wasm_target, target, js_syms): settings.TARGET_JS_NAME = os.path.basename(state.js_target) - metadata = phase_emscript(options, in_wasm, wasm_target, js_syms) + metadata = phase_emscript(in_wasm, wasm_target, js_syms) if settings.EMBIND_AOT: phase_embind_aot(wasm_target, js_syms) @@ -1853,24 +1829,19 @@ def phase_post_link(options, state, in_wasm, wasm_target, target, js_syms): if options.js_transform: phase_source_transforms(options) - if settings.MEM_INIT_IN_WASM: - memfile = None - else: - memfile = shared.replace_or_append_suffix(target, '.mem') - - phase_binaryen(target, options, wasm_target, memfile) + phase_binaryen(target, options, wasm_target) # If we are not emitting any JS then we are all done now if options.oformat != OFormat.WASM: - phase_final_emitting(options, state, target, wasm_target, memfile) + phase_final_emitting(options, state, target, wasm_target) @ToolchainProfiler.profile_block('emscript') -def phase_emscript(options, in_wasm, wasm_target, js_syms): +def phase_emscript(in_wasm, wasm_target, js_syms): # Emscripten logger.debug('emscript') - settings.SUPPORT_BASE64_EMBEDDING = embed_memfile(options) + settings.SUPPORT_BASE64_EMBEDDING = embed_memfile() if shared.SKIP_SUBPROCS: return @@ -1972,18 +1943,6 @@ def phase_source_transforms(options): save_intermediate('transformed') -@ToolchainProfiler.profile_block('memory initializer') -def phase_memory_initializer(memfile): - # For the wasm backend, we don't have any memory info in JS. All we need to do - # is set the memory initializer url. - global final_js - - src = read_file(final_js) - src = do_replace(src, '<<< MEM_INITIALIZER >>>', '"%s"' % os.path.basename(memfile)) - write_file(final_js + '.mem.js', src) - final_js += '.mem.js' - - # Unmangle previously mangled `import.meta` and `await import` references in # both main code and libraries. # See also: `preprocess` in parseTools.js. @@ -2013,7 +1972,7 @@ def create_worker_file(input_file, target_dir, output_file): @ToolchainProfiler.profile_block('final emitting') -def phase_final_emitting(options, state, target, wasm_target, memfile): +def phase_final_emitting(options, state, target, wasm_target): global final_js if shared.SKIP_SUBPROCS: @@ -2076,13 +2035,10 @@ def phase_final_emitting(options, state, target, wasm_target, memfile): # If we were asked to also generate HTML, do that if options.oformat == OFormat.HTML: generate_html(target, options, js_target, target_basename, - wasm_target, memfile) + wasm_target) elif settings.PROXY_TO_WORKER: generate_worker_js(target, js_target, target_basename) - if embed_memfile(options) and memfile: - delete_file(memfile) - if settings.SPLIT_MODULE: diagnostics.warning('experimental', 'the SPLIT_MODULE setting is experimental and subject to change') do_split_module(wasm_target, options) @@ -2095,7 +2051,7 @@ def phase_final_emitting(options, state, target, wasm_target, memfile): @ToolchainProfiler.profile_block('binaryen') -def phase_binaryen(target, options, wasm_target, memfile): +def phase_binaryen(target, options, wasm_target): global final_js logger.debug('using binaryen') # whether we need to emit -g (function name debug info) in the final wasm @@ -2118,7 +2074,7 @@ def phase_binaryen(target, options, wasm_target, memfile): # run wasm-opt if we have work for it: either passes, or if we are using # source maps (which requires some extra processing to keep the source map # but remove DWARF) - passes = get_binaryen_passes(memfile) + passes = get_binaryen_passes() if passes: # if asyncify is used, we will use it in the next stage, and so if it is # the only reason we need intermediate debug info, we can stop keeping it @@ -2135,18 +2091,6 @@ def phase_binaryen(target, options, wasm_target, memfile): debug=intermediate_debug_info) building.save_intermediate(wasm_target, 'byn.wasm') - if memfile: - # we have a separate .mem file. binaryen did not strip any trailing zeros, - # because it's an ABI question as to whether it is valid to do so or not. - # we can do so here, since we make sure to zero out that memory (even in - # the dynamic linking case, our loader zeros it out) - remove_trailing_zeros(memfile) - - # MINIMAL_RUNTIME doesn't use `var memoryInitializer` but instead expects Module['mem'] to - # be loaded before the module. See src/postamble_minimal.js. - if not settings.MINIMAL_RUNTIME: - phase_memory_initializer(memfile) - if settings.EVAL_CTORS: with ToolchainProfiler.profile_block('eval_ctors'): building.eval_ctors(final_js, wasm_target, debug_info=intermediate_debug_info) @@ -2412,7 +2356,7 @@ def module_export_name_substitution(): def generate_traditional_runtime_html(target, options, js_target, target_basename, - wasm_target, memfile): + wasm_target): script = ScriptSource() if settings.EXPORT_NAME != 'Module' and options.shell_path == DEFAULT_SHELL_HTML: @@ -2456,19 +2400,6 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam script.src = base_js_target if not settings.SINGLE_FILE: - if memfile and not settings.MINIMAL_RUNTIME: - # start to load the memory init file in the HTML, in parallel with the JS - script.un_src() - script.inline = (''' - var memoryInitializer = '%s'; - memoryInitializer = Module['locateFile'] ? Module['locateFile'](memoryInitializer, '') : memoryInitializer; - Module['memoryInitializerRequestURL'] = memoryInitializer; - var meminitXHR = Module['memoryInitializerRequest'] = new XMLHttpRequest(); - meminitXHR.open('GET', memoryInitializer, true); - meminitXHR.responseType = 'arraybuffer'; - meminitXHR.send(null); -''' % get_subresource_location(memfile)) + script.inline - if not settings.WASM_ASYNC_COMPILATION: # We need to load the wasm file before anything else, since it # has be synchronously ready. @@ -2565,15 +2496,13 @@ def minify_html(filename): logger.debug(f'HTML minification took {elapsed_time:.2f} seconds, and shrunk size of {filename} from {size_before} to {size_after} bytes, delta={delta} ({delta * 100.0 / size_before:+.2f}%)') -def generate_html(target, options, js_target, target_basename, - wasm_target, memfile): +def generate_html(target, options, js_target, target_basename, wasm_target): logger.debug('generating HTML') if settings.MINIMAL_RUNTIME: generate_minimal_runtime_html(target, options, js_target, target_basename) else: - generate_traditional_runtime_html(target, options, js_target, target_basename, - wasm_target, memfile) + generate_traditional_runtime_html(target, options, js_target, target_basename, wasm_target) if settings.MINIFY_HTML and (settings.OPT_LEVEL >= 1 or settings.SHRINK_LEVEL >= 1): minify_html(target) diff --git a/tools/minimal_runtime_shell.py b/tools/minimal_runtime_shell.py index 7fd0716e5fa37..8afddc5c531be 100644 --- a/tools/minimal_runtime_shell.py +++ b/tools/minimal_runtime_shell.py @@ -45,14 +45,6 @@ def generate_minimal_runtime_load_statement(target_basename): files_to_load = ["script('%s')" % (target_basename + '.js')] # Main JS file always in first entry - # Download separate memory initializer file .mem - if not settings.MEM_INIT_IN_WASM: - if settings.MODULARIZE: - modularize_imports += ['mem: r[%d]' % len(files_to_load)] - else: - then_statements += ["%s.mem = r[%d];" % (settings.EXPORT_NAME, len(files_to_load))] - files_to_load += ["binary('%s')" % (target_basename + '.mem')] - # Download .wasm file if (settings.WASM == 1 and settings.WASM2JS == 0) or not download_wasm: if settings.MODULARIZE: