Skip to content

Commit c515ebe

Browse files
authored
Handle library funcs added during jsifier process. (emscripten-core#20299)
Fixes: emscripten-core#20297
1 parent 3134b14 commit c515ebe

9 files changed

+29
-8
lines changed

emcc.py

+2
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,8 @@ def add_js_deps(sym):
13271327

13281328
for sym in settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE:
13291329
add_js_deps(sym)
1330+
for sym in js_info['extraLibraryFuncs']:
1331+
add_js_deps(sym)
13301332
for sym in settings.EXPORTED_RUNTIME_METHODS:
13311333
add_js_deps(shared.demangle_c_symbol_name(sym))
13321334
if settings.ASYNCIFY:

src/embind/embind_ts.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,6 @@ var LibraryEmbind = {
591591
$runDestructors: () => assert(false, 'stub function should not be called'),
592592
};
593593

594-
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('$embindEmitTypes');
594+
extraLibraryFuncs.push('$embindEmitTypes');
595595

596596
addToLibrary(LibraryEmbind);

src/jsifier.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
global.addedLibraryItems = {};
1313

14+
global.extraLibraryFuncs = [];
15+
1416
// Some JS-implemented library functions are proxied to be called on the main
1517
// browser thread, if the Emscripten runtime is executing in a Web Worker.
1618
// Each such proxied function is identified via an ordinal number (this is not
@@ -104,6 +106,7 @@ function runJSify() {
104106
LibraryManager.load();
105107

106108
const symbolsNeeded = DEFAULT_LIBRARY_FUNCS_TO_INCLUDE;
109+
symbolsNeeded.push(...extraLibraryFuncs);
107110
for (const sym of EXPORTED_RUNTIME_METHODS) {
108111
if ('$' + sym in LibraryManager.library) {
109112
symbolsNeeded.push('$' + sym);
@@ -651,7 +654,8 @@ var proxiedFunctionTable = [
651654
if (symbolsOnly) {
652655
print(JSON.stringify({
653656
deps: symbolDeps,
654-
asyncFuncs
657+
asyncFuncs,
658+
extraLibraryFuncs,
655659
}));
656660
} else {
657661
finalCombiner();

src/library.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3644,7 +3644,7 @@ function autoAddDeps(object, name) {
36443644
#if LEGACY_RUNTIME
36453645
// Library functions that were previously included as runtime functions are
36463646
// automatically included when `LEGACY_RUNTIME` is set.
3647-
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push(
3647+
extraLibraryFuncs.push(
36483648
'$addFunction',
36493649
'$removeFunction',
36503650
'$allocate',

src/library_async.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -660,5 +660,5 @@ addToLibrary({
660660
});
661661

662662
if (ASYNCIFY) {
663-
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('$Asyncify');
663+
extraLibraryFuncs.push('$Asyncify');
664664
}

src/library_autodebug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ addToLibrary({
109109
},
110110
});
111111

112-
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push(
112+
extraLibraryFuncs.push(
113113
'$log_execution',
114114
'$get_i32',
115115
'$get_i64',

src/library_fs_shared.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,5 @@ addToLibrary({
176176
// FORCE_FILESYSTEM makes us always include the FS object, which lets the user
177177
// call APIs on it from JS freely.
178178
if (FORCE_FILESYSTEM) {
179-
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('$FS');
179+
extraLibraryFuncs.push('$FS');
180180
}

src/library_glemu.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3905,7 +3905,7 @@ var LibraryGLEmulation = {
39053905

39063906
// Legacy GL emulation
39073907
if (LEGACY_GL_EMULATION) {
3908-
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('$GLEmulation');
3908+
extraLibraryFuncs.push('$GLEmulation');
39093909
}
39103910

39113911
recordGLProcAddressGet(LibraryGLEmulation);

test/test_other.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -7122,7 +7122,8 @@ def test_umask_0(self):
71227122
self.run_process([EMCC, 'src.c'])
71237123
self.assertContained('hello, world!', self.run_js('a.out.js'))
71247124

7125-
def test_no_missing_symbols(self): # simple hello world should not show any missing symbols
7125+
def test_no_missing_symbols(self):
7126+
# simple hello world should not show any missing symbols
71267127
self.run_process([EMCC, test_file('hello_world.c')])
71277128

71287129
# main() is implemented in C, and even if requested from JS, we should not warn
@@ -7188,6 +7189,20 @@ def test_js_lib_native_deps(self):
71887189

71897190
self.do_runf('test.c', 'dddddddddd\n', emcc_args=['--js-library', 'lib.js'])
71907191

7192+
def test_js_lib_native_deps_extra(self):
7193+
# Similar to above but the JS symbol is not used by the native code.
7194+
# Instead is it explictly injected using `extraLibraryFuncs`.
7195+
create_file('lib.js', r'''
7196+
addToLibrary({
7197+
jsfunc__deps: ['raise'],
7198+
jsfunc: (ptr) => {
7199+
_raise(1);
7200+
},
7201+
});
7202+
extraLibraryFuncs.push('jsfunc');
7203+
''')
7204+
self.do_runf(test_file('hello_world.c'), emcc_args=['--js-library', 'lib.js'])
7205+
71917206
@crossplatform
71927207
def test_realpath(self):
71937208
create_file('src.c', r'''

0 commit comments

Comments
 (0)