Skip to content

Commit e5e84e6

Browse files
authored
Fix for webpack + SINGLE_FILE + WASM=0 (#25195)
Without this fix the output code contains a references to the non-existent wasm file URL. Fixes: #25012
1 parent 5f85d61 commit e5e84e6

File tree

6 files changed

+36
-25
lines changed

6 files changed

+36
-25
lines changed

src/preamble.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,17 @@ function instrumentWasmTableWithAbort() {
413413
#if !SOURCE_PHASE_IMPORTS && !WASM_ESM_INTEGRATION
414414
var wasmBinaryFile;
415415

416+
#if WASM2JS && WASM != 2
417+
418+
// When building with wasm2js these 3 functions all no-ops.
419+
function findWasmBinary(file) {}
420+
function getBinarySync(file) {}
421+
function getWasmBinary(file) {}
422+
423+
#else
424+
416425
function findWasmBinary() {
417-
#if SINGLE_FILE && WASM == 1 && !WASM2JS
426+
#if SINGLE_FILE
418427
return base64Decode('<<< WASM_BINARY_DATA >>>');
419428
#else
420429
#if EXPORT_ES6 && !AUDIO_WORKLET
@@ -435,7 +444,7 @@ function findWasmBinary() {
435444
}
436445

437446
function getBinarySync(file) {
438-
#if SINGLE_FILE && WASM == 1 && !WASM2JS
447+
#if SINGLE_FILE
439448
if (ArrayBuffer.isView(file)) {
440449
return file;
441450
}
@@ -474,6 +483,7 @@ async function getWasmBinary(binaryFile) {
474483
// Otherwise, getBinarySync should be able to get it synchronously
475484
return getBinarySync(binaryFile);
476485
}
486+
#endif
477487

478488
#if SPLIT_MODULE
479489
{{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync') }}}
@@ -572,8 +582,8 @@ async function instantiateArrayBuffer(binaryFile, imports) {
572582

573583
#if ASSERTIONS
574584
// Warn on some common problems.
575-
if (isFileURI(wasmBinaryFile)) {
576-
err(`warning: Loading from a file URI (${wasmBinaryFile}) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing`);
585+
if (isFileURI(binaryFile)) {
586+
err(`warning: Loading from a file URI (${binaryFile}) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing`);
577587
}
578588
#endif
579589
abort(reason);

test/code_size/test_codesize_hello_O0.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 22485,
3-
"a.out.js.gz": 8317,
3+
"a.out.js.gz": 8312,
44
"a.out.nodebug.wasm": 15127,
55
"a.out.nodebug.wasm.gz": 7450,
66
"total": 37612,
7-
"total_gz": 15767,
7+
"total_gz": 15762,
88
"sent": [
99
"fd_write"
1010
],

test/code_size/test_codesize_minimal_O0.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 17746,
3-
"a.out.js.gz": 6620,
3+
"a.out.js.gz": 6616,
44
"a.out.nodebug.wasm": 1136,
55
"a.out.nodebug.wasm.gz": 659,
66
"total": 18882,
7-
"total_gz": 7279,
7+
"total_gz": 7275,
88
"sent": [],
99
"imports": [],
1010
"exports": [
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"hello_world.js": 54027,
3-
"hello_world.js.gz": 17075,
2+
"hello_world.js": 54019,
3+
"hello_world.js.gz": 17072,
44
"hello_world.wasm": 15127,
55
"hello_world.wasm.gz": 7450,
66
"no_asserts.js": 26497,
77
"no_asserts.js.gz": 8849,
88
"no_asserts.wasm": 12227,
99
"no_asserts.wasm.gz": 6010,
10-
"strict.js": 52065,
11-
"strict.js.gz": 16409,
10+
"strict.js": 52057,
11+
"strict.js.gz": 16407,
1212
"strict.wasm": 15127,
1313
"strict.wasm.gz": 7447,
14-
"total": 175070,
15-
"total_gz": 63240
14+
"total": 175054,
15+
"total_gz": 63235
1616
}

test/other/codesize/test_codesize_minimal_O0.expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ async function instantiateArrayBuffer(binaryFile, imports) {
598598
err(`failed to asynchronously prepare wasm: ${reason}`);
599599

600600
// Warn on some common problems.
601-
if (isFileURI(wasmBinaryFile)) {
602-
err(`warning: Loading from a file URI (${wasmBinaryFile}) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing`);
601+
if (isFileURI(binaryFile)) {
602+
err(`warning: Loading from a file URI (${binaryFile}) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing`);
603603
}
604604
abort(reason);
605605
}

test/test_browser.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5495,23 +5495,24 @@ def test_error_reporting(self):
54955495
self.btest('hello_world.c', cflags=['--post-js=post.js'], expected='exception:foo')
54965496

54975497
@also_with_threads
5498+
@also_with_wasm2js
54985499
@parameterized({
5499-
'': (False,),
5500-
'es6': (True,),
5500+
'': ([],),
5501+
'es6': (['-sEXPORT_ES6', '-pthread', '-sPTHREAD_POOL_SIZE=1'],),
55015502
})
5502-
def test_webpack(self, es6):
5503-
if es6:
5503+
def test_webpack(self, args):
5504+
if '-sEXPORT_ES6' in args:
55045505
copytree(test_file('webpack_es6'), '.')
5505-
self.cflags += ['-sEXPORT_ES6', '-pthread', '-sPTHREAD_POOL_SIZE=1']
55065506
outfile = 'src/hello.mjs'
55075507
else:
55085508
copytree(test_file('webpack'), '.')
55095509
outfile = 'src/hello.js'
5510-
self.compile_btest('hello_world.c', ['-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web', '-o', outfile])
5510+
self.compile_btest('hello_world.c', ['-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web', '-o', outfile] + args)
55115511
self.run_process(shared.get_npm_cmd('webpack') + ['--mode=development', '--no-devtool'])
5512-
# Webpack doesn't bundle the wasm file by default so we need to copy it
5513-
# TODO(sbc): Look into plugins that do bundling.
5514-
shutil.copy('src/hello.wasm', 'dist/')
5512+
if not self.is_wasm2js():
5513+
# Webpack doesn't bundle the wasm file by default so we need to copy it
5514+
# TODO(sbc): Look into plugins that do bundling.
5515+
shutil.copy('src/hello.wasm', 'dist/')
55155516
self.run_browser('dist/index.html', '/report_result?exit:0')
55165517

55175518
@also_with_threads

0 commit comments

Comments
 (0)