Skip to content

Commit 9677b7d

Browse files
authored
dylink: Make preload plugin dependency conditional on FILESYTEM (#19362)
The preload plugin system is part of the core filesystem code in `library_fs_shared.py`. Fixes: #19361
1 parent 8d978a5 commit 9677b7d

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/library_browser.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ var LibraryBrowser = {
1212
'$safeSetTimeout',
1313
'$warnOnce',
1414
'emscripten_set_main_loop_timing',
15+
#if FILESYSTEM || WASMFS
1516
'$preloadPlugins',
1617
#if MAIN_MODULE
1718
'$preloadedWasm',
19+
#endif
1820
#endif
1921
],
2022
$Browser__postset: `
@@ -105,6 +107,7 @@ var LibraryBrowser = {
105107
if (Browser.initted) return;
106108
Browser.initted = true;
107109

110+
#if FILESYSTEM || WASMFS
108111
// Support for plugins that can process preloaded files. You can add more of these to
109112
// your app by creating and appending to preloadPlugins.
110113
//
@@ -209,6 +212,7 @@ var LibraryBrowser = {
209212
}, 10000);
210213
};
211214
preloadPlugins.push(audioPlugin);
215+
#endif
212216

213217
// Canvas event setup
214218

src/library_dylink.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var dlopenMissingError = "'To use dlopen, you need enable dynamic linking, see h
1010

1111
var LibraryDylink = {
1212
#if RELOCATABLE
13+
#if FILESYSTEM || WASMFS
1314
$registerWasmPlugin__deps: ['$preloadPlugins'],
1415
$registerWasmPlugin: function() {
1516
// Use string keys here to avoid minification since the plugin consumer
@@ -43,6 +44,7 @@ var LibraryDylink = {
4344
registerWasmPlugin();
4445
`,
4546
$preloadedWasm: {},
47+
#endif // FILESYSTEM
4648

4749
$isSymbolDefined: function(symName) {
4850
// Ignore 'stub' symbols that are auto-generated as part of the original
@@ -910,7 +912,11 @@ var LibraryDylink = {
910912
// Once a library becomes "global" or "nodelete", it cannot be removed or unloaded.
911913
$loadDynamicLibrary__deps: ['$LDSO', '$loadWebAssemblyModule',
912914
'$isInternalSym', '$mergeLibSymbols', '$newDSO',
913-
'$asyncLoad', '$preloadedWasm'],
915+
'$asyncLoad',
916+
#if FILESYSTEM || WASMFS
917+
'$preloadedWasm',
918+
#endif
919+
],
914920
$loadDynamicLibrary__docs: `
915921
/**
916922
* @param {number=} handle
@@ -981,6 +987,7 @@ var LibraryDylink = {
981987

982988
// libName -> exports
983989
function getExports() {
990+
#if FILESYSTEM || WASMFS
984991
// lookup preloaded cache first
985992
if (preloadedWasm[libName]) {
986993
#if DYLINK_DEBUG
@@ -989,6 +996,7 @@ var LibraryDylink = {
989996
var libModule = preloadedWasm[libName];
990997
return flags.loadAsync ? Promise.resolve(libModule) : libModule;
991998
}
999+
#endif
9921000

9931001
// module not preloaded - load lib data and create new module from it
9941002
if (flags.loadAsync) {

test/test_other.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4994,7 +4994,7 @@ def test_libc_files_without_syscalls(self):
49944994
}''')
49954995
self.run_process([EMXX, 'src.cpp'])
49964996

4997-
def test_syscall_without_filesystem(self):
4997+
def test_syscall_no_filesystem(self):
49984998
# a program which includes a non-trivial syscall, but disables the filesystem.
49994999
create_file('src.c', r'''
50005000
#include <sys/time.h>
@@ -5004,6 +5004,9 @@ def test_syscall_without_filesystem(self):
50045004
}''')
50055005
self.run_process([EMCC, 'src.c', '-sNO_FILESYSTEM'])
50065006

5007+
def test_dylink_no_filesystem(self):
5008+
self.run_process([EMCC, test_file('hello_world.c'), '-sMAIN_MODULE=2', '-sNO_FILESYSTEM'])
5009+
50075010
def test_dashS(self):
50085011
self.run_process([EMCC, test_file('hello_world.c'), '-S'])
50095012
self.assertExists('hello_world.s')

0 commit comments

Comments
 (0)