Skip to content

Commit 9b4209b

Browse files
committed
Merge branch 'main' into update_libcxx_libcxxabi_20
2 parents 24e1fa9 + 074e618 commit 9b4209b

19 files changed

+218
-109
lines changed

site/source/docs/compiling/Modularized-Output.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ fix in future releses. Current limitations include:
123123

124124
* `ccall`/`cwrap` are not supported (depends on the ``Module`` global).
125125

126-
* :ref:`abort_on_wasm_exceptions` is not supported (requires wrapping wasm
127-
exports).
126+
* :ref:`dyncalls` is not supported (depends on the ``Module`` global)
127+
128+
* :ref:`asyncify` is not supported (depends on :ref:`dyncalls`)
128129

129130
* :ref:`asyncify_lazy_load_code` is not supported (depends on ``wasmExports``
130131
global)
@@ -166,15 +167,14 @@ This setting implicitly enables :ref:`export_es6` and sets :ref:`MODULARIZE` to
166167

167168
Some additional limitations are:
168169

169-
- ``-pthread`` / :ref:`wasm_workers` are not yet supported.
170+
* ``-pthread`` / :ref:`wasm_workers` are not yet supported.
170171

171-
* :ref:`dyncalls` is not supported (depends on the ``Module`` global)
172-
173-
* :ref:`asyncify` is not supported (depends on :ref:`dyncalls`)
172+
* :ref:`abort_on_wasm_exceptions` is not supported (requires wrapping wasm
173+
exports).
174174

175-
- Setting :ref:`wasm` to ``0`` is not supported.
175+
* Setting :ref:`wasm` to ``0`` is not supported.
176176

177-
- Setting :ref:`wasm_async_compilation` to ``0`` is not supported.
177+
* Setting :ref:`wasm_async_compilation` to ``0`` is not supported.
178178

179179

180180
.. _Source phase imports: https://github.com/tc39/proposal-source-phase-imports

site/source/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.rst

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -362,20 +362,18 @@ Implement a C API in JavaScript
362362
It is possible to implement a C API in JavaScript! This is the approach
363363
used in many of Emscripten's libraries, like SDL1 and OpenGL.
364364

365-
You can use it to write your own APIs to call from C/C++. To do this
366-
you define the interface, decorating with ``extern`` to mark the methods
367-
in the API as external symbols. You then implement the symbols in
368-
JavaScript by simply adding their definition to `library.js`_ (by
369-
default). When compiling the C code, the compiler looks in the JavaScript
370-
libraries for relevant external symbols.
371-
372-
By default, the implementation is added to **library.js** (and this is
373-
where you'll find parts of Emscripten's *libc*). You can put
374-
the JavaScript implementation in your own library file and add it using
375-
the :ref:`emcc option <emcc-js-library>` ``--js-library``. See
376-
`test_jslib`_ in **test/test_other.py** for a complete working
377-
example, including the syntax you should use inside the JavaScript library
378-
file.
365+
You can use it to write your own APIs to call from C/C++. To do this you define
366+
the interface, decorating with ``extern`` to mark the methods in the API as
367+
external symbols. You can then implement the symbols in JavaScript by simply
368+
adding their definition to one of the `core JS library`_ files. Undefined
369+
native symbols will be resolved by looking for them in JavaScript library files.
370+
371+
The `core JS library`_ files are where you will find Emscripten internals. For
372+
example, parts of Emscripten's *libc* are implemented there. You can also put
373+
the JavaScript implementation in your own library file and add it using the
374+
:ref:`emcc option <emcc-js-library>` ``--js-library``. See `test_jslib`_ in
375+
**test/test_other.py** for a complete working example, including the syntax you
376+
should use inside the JavaScript library file.
379377

380378
As a simple example, consider the case where you have some C code like this:
381379

@@ -843,8 +841,8 @@ on Emscripten. If you would like to port existing Node-API addon to WebAssembly
843841
or compile the same binding code to both Node.js native addon and WebAssembly,
844842
you can give it a try. See `Emnapi documentation`_ for more details.
845843

846-
.. _library.js: https://github.com/emscripten-core/emscripten/blob/main/src/library.js
847-
.. _test_jslib: https://github.com/emscripten-core/emscripten/blob/1.29.12/tests/test_core.py#L5043
844+
.. _core JS library: https://github.com/emscripten-core/emscripten/blob/main/src/lib/
845+
.. _test_jslib: https://github.com/emscripten-core/emscripten/blob/4.0.9/test/test_core.py#L6261
848846
.. _tools/system_libs.py: https://github.com/emscripten-core/emscripten/blob/main/tools/system_libs.py
849847
.. _library_\*.js: https://github.com/emscripten-core/emscripten/tree/main/src
850848
.. _test_add_function in test/test_core.py: https://github.com/emscripten-core/emscripten/blob/1.29.12/tests/test_core.py#L6237

src/lib/libcore.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,13 +1729,25 @@ addToLibrary({
17291729
},
17301730

17311731
#if DYNCALLS || !WASM_BIGINT
1732-
$dynCalls__internal: true,
1733-
$dynCalls: {},
1734-
$dynCallLegacy__deps: ['$dynCalls'],
1732+
#if MINIMAL_RUNTIME
1733+
$dynCalls: '{}',
1734+
#endif
1735+
$dynCallLegacy__deps: [
1736+
#if MINIMAL_RUNTIME
1737+
'$dynCalls',
1738+
#endif
1739+
#if MODULARIZE == 'instance'
1740+
() => error('dynCallLegacy is not yet compatible with MODULARIZE=instance'),
1741+
#endif
1742+
],
17351743
$dynCallLegacy: (sig, ptr, args) => {
17361744
sig = sig.replace(/p/g, {{{ MEMORY64 ? "'j'" : "'i'" }}})
17371745
#if ASSERTIONS
1746+
#if MINIMAL_RUNTIME
17381747
assert(sig in dynCalls, `bad function pointer type - sig is not in dynCalls: '${sig}'`);
1748+
#else
1749+
assert(('dynCall_' + sig) in Module, `bad function pointer type - dynCall function not found for sig '${sig}'`);
1750+
#endif
17391751
if (args?.length) {
17401752
#if WASM_BIGINT
17411753
// j (64-bit integer) is fine, and is implemented as a BigInt. Without
@@ -1750,7 +1762,11 @@ addToLibrary({
17501762
assert(sig.length == 1);
17511763
}
17521764
#endif
1765+
#if MINIMAL_RUNTIME
17531766
var f = dynCalls[sig];
1767+
#else
1768+
var f = Module['dynCall_' + sig];
1769+
#endif
17541770
return f(ptr, ...args);
17551771
},
17561772
#if DYNCALLS
@@ -2274,6 +2290,18 @@ addToLibrary({
22742290
$wasmTable: undefined,
22752291
#endif
22762292

2293+
$getUniqueRunDependency: (id) => {
2294+
#if ASSERTIONS
2295+
var orig = id;
2296+
while (1) {
2297+
if (!runDependencyTracking[id]) return id;
2298+
id = orig + Math.random();
2299+
}
2300+
#else
2301+
return id;
2302+
#endif
2303+
},
2304+
22772305
$noExitRuntime__postset: () => addAtModule(makeModuleReceive('noExitRuntime')),
22782306
$noExitRuntime: {{{ !EXIT_RUNTIME }}},
22792307

src/lib/libfs_shared.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ addToLibrary({
4747
'$asyncLoad',
4848
'$PATH_FS',
4949
'$FS_createDataFile',
50+
'$getUniqueRunDependency',
5051
#if !MINIMAL_RUNTIME
5152
'$FS_handledByPreloadPlugin',
5253
#endif

src/lib/liblz4.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#if LZ4
88
addToLibrary({
9-
$LZ4__deps: ['$FS', '$preloadPlugins'],
9+
$LZ4__deps: ['$FS', '$preloadPlugins', '$getUniqueRunDependency'],
1010
$LZ4: {
1111
DIR_MODE: {{{ cDefs.S_IFDIR | 0o777 }}},
1212
FILE_MODE: {{{ cDefs.S_IFREG | 0o777 }}},

src/preamble.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,6 @@ var runDependencyTracking = {};
295295
var runDependencyWatcher = null;
296296
#endif
297297

298-
function getUniqueRunDependency(id) {
299-
#if ASSERTIONS
300-
var orig = id;
301-
while (1) {
302-
if (!runDependencyTracking[id]) return id;
303-
id = orig + Math.random();
304-
}
305-
#else
306-
return id;
307-
#endif
308-
}
309-
310298
function addRunDependency(id) {
311299
runDependencies++;
312300

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8287
1+
8294
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22193
1+
22216
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6591
1+
6598
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
17562
1+
17585
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
53787
1+
53661
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
27050
1+
26996
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
51837
1+
51711

test/test_core.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ def metafunc(self, jspi, *args, **kwargs):
212212
self.require_jspi()
213213
else:
214214
self.set_setting('ASYNCIFY')
215+
if self.get_setting('MODULARIZE') == 'instance':
216+
self.skipTest('MODULARIZE=instance is not compatible with ASYNCIFY=1')
215217
f(self, *args, **kwargs)
216218

217219
parameterize(metafunc, {'': (False,),
@@ -231,6 +233,8 @@ def metafunc(self, asyncify, *args, **kwargs):
231233
self.require_jspi()
232234
elif asyncify == 1:
233235
self.set_setting('ASYNCIFY')
236+
if self.get_setting('MODULARIZE') == 'instance':
237+
self.skipTest('MODULARIZE=instance is not compatible with ASYNCIFY=1')
234238
else:
235239
assert asyncify == 0
236240
f(self, *args, **kwargs)
@@ -1881,7 +1885,7 @@ def test_emscripten_get_compiler_setting(self):
18811885
self.set_setting('RETAIN_COMPILER_SETTINGS')
18821886
self.do_runf(src, read_file(output).replace('waka', utils.EMSCRIPTEN_VERSION))
18831887

1884-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
1888+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
18851889
def test_emscripten_has_asyncify(self):
18861890
src = r'''
18871891
#include <stdio.h>
@@ -6950,7 +6954,7 @@ def test_autodebug_wasm(self):
69506954
### Integration tests
69516955

69526956
@crossplatform
6953-
@no_modularize_instance('ccall is not compatible with WASM_ESM_INTEGRATION')
6957+
@no_modularize_instance('ccall is not compatible with MODULARIZE=instance')
69546958
def test_ccall(self):
69556959
self.emcc_args.append('-Wno-return-stack-address')
69566960
self.set_setting('EXPORTED_RUNTIME_METHODS', ['ccall', 'cwrap', 'STACK_SIZE'])
@@ -6995,7 +6999,7 @@ def test_ccall(self):
69956999
if self.maybe_closure():
69967000
self.do_core_test('test_ccall.cpp')
69977001

6998-
@no_modularize_instance('ccall is not compatible with WASM_ESM_INTEGRATION')
7002+
@no_modularize_instance('ccall is not compatible with MODULARIZE=instance')
69997003
def test_ccall_cwrap_fast_path(self):
70007004
self.emcc_args.append('-Wno-return-stack-address')
70017005
self.set_setting('EXPORTED_RUNTIME_METHODS', ['ccall', 'cwrap'])
@@ -7020,7 +7024,7 @@ def test_EXPORTED_RUNTIME_METHODS(self):
70207024
self.do_core_test('EXPORTED_RUNTIME_METHODS.c')
70217025

70227026
@also_with_minimal_runtime
7023-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with DYNCALLS')
7027+
@no_modularize_instance('uses dynCallLegacy')
70247028
def test_dyncall_specific(self):
70257029
if self.get_setting('WASM_BIGINT') != 0 and not self.is_wasm2js():
70267030
# define DYNCALLS because this test does test calling them directly, and
@@ -7047,8 +7051,8 @@ def test_dyncall_specific(self):
70477051
'legacy': (['-sDYNCALLS'],),
70487052
})
70497053
def test_dyncall_pointers(self, args):
7050-
if args and self.get_setting('WASM_ESM_INTEGRATION'):
7051-
self.skipTest('WASM_ESM_INTEGRATION is not compatible with DYNCALLS')
7054+
if args and self.get_setting('MODULARIZE') == 'instance' or self.get_setting('WASM_ESM_INTEGRATION'):
7055+
self.skipTest('dynCallLegacy is not yet compatible with MODULARIZE=instance')
70527056
self.do_core_test('test_dyncall_pointers.c', emcc_args=args)
70537057

70547058
@also_with_wasm_bigint
@@ -8064,7 +8068,7 @@ def test_vswprintf_utf8(self):
80648068

80658069
# Test async sleeps in the presence of invoke_* calls, which can happen with
80668070
# longjmp or exceptions.
8067-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8071+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
80688072
def test_asyncify_longjmp(self):
80698073
self.set_setting('ASYNCIFY')
80708074
self.set_setting('STRICT')
@@ -8124,11 +8128,11 @@ def test_async_loop(self):
81248128
self.do_runf('main.c', 'hello 0\nhello 1\nhello 2\nhello 3\nhello 4\n')
81258129

81268130
@requires_v8
8127-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8131+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
81288132
def test_async_hello_v8(self):
81298133
self.test_async_hello()
81308134

8131-
@no_modularize_instance('ccall is not compatible with WASM_ESM_INTEGRATION')
8135+
@no_modularize_instance('ccall is not compatible with MODULARIZE=instance')
81328136
def test_async_ccall_bad(self):
81338137
# check bad ccall use
81348138
# needs to flush stdio streams
@@ -8160,7 +8164,7 @@ def test_async_ccall_bad(self):
81608164
self.do_runf('main.c', 'The call to main is running asynchronously.')
81618165

81628166
@with_asyncify_and_jspi
8163-
@no_modularize_instance('ccall is not compatible with WASM_ESM_INTEGRATION')
8167+
@no_modularize_instance('ccall is not compatible with MODULARIZE=instance')
81648168
def test_async_ccall_good(self):
81658169
# check reasonable ccall use
81668170
self.set_setting('ASYNCIFY')
@@ -8189,7 +8193,7 @@ def test_async_ccall_good(self):
81898193
'exit_runtime': (True,),
81908194
})
81918195
@with_asyncify_and_jspi
8192-
@no_modularize_instance('ccall is not compatible with WASM_ESM_INTEGRATION')
8196+
@no_modularize_instance('ccall is not compatible with MODULARIZE=instance')
81938197
def test_async_ccall_promise(self, exit_runtime):
81948198
if self.get_setting('ASYNCIFY') == 2:
81958199
self.set_setting('JSPI_EXPORTS', ['stringf', 'floatf'])
@@ -8229,7 +8233,7 @@ def test_async_ccall_promise(self, exit_runtime):
82298233
self.emcc_args += ['--pre-js', 'pre.js']
82308234
self.do_runf('main.c', 'stringf: first\nsecond\n6.4')
82318235

8232-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8236+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
82338237
def test_fibers_asyncify(self):
82348238
self.set_setting('ASYNCIFY')
82358239
self.maybe_closure()
@@ -8240,7 +8244,7 @@ def test_asyncify_unused(self):
82408244
# test a program not using asyncify, but the pref is set
82418245
self.do_core_test('test_hello_world.c')
82428246

8243-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8247+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
82448248
@parameterized({
82458249
'normal': ([], True),
82468250
'removelist_a': (['-sASYNCIFY_REMOVE=["foo(int, double)"]'], False),
@@ -8288,7 +8292,7 @@ def test_asyncify_lists(self, args, should_pass, response=None):
82888292
# virt() manually, rather than have them inferred automatically.
82898293
'add_no_prop': (['-sASYNCIFY_IGNORE_INDIRECT', '-sASYNCIFY_ADD=["__original_main","main","virt()"]', '-sASYNCIFY_PROPAGATE_ADD=0'], True),
82908294
})
8291-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8295+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
82928296
def test_asyncify_indirect_lists(self, args, should_pass):
82938297
self.set_setting('ASYNCIFY')
82948298
self.emcc_args += args
@@ -8306,7 +8310,7 @@ def test_asyncify_indirect_lists(self, args, should_pass):
83068310
raise
83078311

83088312
@with_dylink_reversed
8309-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8313+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
83108314
def test_asyncify_side_module(self):
83118315
self.set_setting('ASYNCIFY')
83128316
self.set_setting('ASYNCIFY_IMPORTS', ['my_sleep'])
@@ -8336,12 +8340,12 @@ def test_asyncify_side_module(self):
83368340
''', 'before sleep\n42\n42\nafter sleep\n', header='void my_sleep(int);', force_c=True)
83378341

83388342
@no_asan('asyncify stack operations confuse asan')
8339-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8343+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
83408344
def test_emscripten_scan_registers(self):
83418345
self.set_setting('ASYNCIFY')
83428346
self.do_core_test('test_emscripten_scan_registers.cpp')
83438347

8344-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8348+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
83458349
def test_asyncify_assertions(self):
83468350
self.set_setting('ASYNCIFY')
83478351
self.set_setting('ASYNCIFY_IMPORTS', ['suspend'])
@@ -8350,7 +8354,7 @@ def test_asyncify_assertions(self):
83508354

83518355
@no_lsan('leaks asyncify stack during exit')
83528356
@no_asan('leaks asyncify stack during exit')
8353-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8357+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
83548358
def test_asyncify_during_exit(self):
83558359
self.set_setting('ASYNCIFY')
83568360
self.set_setting('ASSERTIONS')
@@ -9540,7 +9544,7 @@ def test_emscripten_stack(self):
95409544
self.do_core_test('test_stack_get_free.c')
95419545

95429546
# Tests settings.ABORT_ON_WASM_EXCEPTIONS
9543-
@no_modularize_instance('ABORT_ON_WASM_EXCEPTIONS')
9547+
@no_modularize_instance('ccall is not compatible with MODULARIZE=instance')
95449548
def test_abort_on_exceptions(self):
95459549
self.set_setting('ABORT_ON_WASM_EXCEPTIONS')
95469550
self.set_setting('ALLOW_TABLE_GROWTH')
@@ -9549,7 +9553,7 @@ def test_abort_on_exceptions(self):
95499553
self.emcc_args += ['-lembind', '--post-js', test_file('core/test_abort_on_exceptions_post.js')]
95509554
self.do_core_test('test_abort_on_exceptions.cpp', interleaved_output=False)
95519555

9552-
@no_modularize_instance('ABORT_ON_WASM_EXCEPTIONS')
9556+
@no_esm_integration('ABORT_ON_WASM_EXCEPTIONS is not compatible with WASM_ESM_INTEGRATION')
95539557
def test_abort_on_exceptions_main(self):
95549558
# The unhandled exception wrappers should not kick in for exceptions thrown during main
95559559
self.set_setting('ABORT_ON_WASM_EXCEPTIONS')
@@ -9563,7 +9567,7 @@ def test_abort_on_exceptions_main(self):
95639567

95649568
@node_pthreads
95659569
@flaky('https://github.com/emscripten-core/emscripten/issues/20067')
9566-
@no_modularize_instance('ABORT_ON_WASM_EXCEPTIONS')
9570+
@no_esm_integration('ABORT_ON_WASM_EXCEPTIONS is not compatible with WASM_ESM_INTEGRATION')
95679571
def test_abort_on_exceptions_pthreads(self):
95689572
self.set_setting('ABORT_ON_WASM_EXCEPTIONS')
95699573
self.set_setting('PROXY_TO_PTHREAD')

0 commit comments

Comments
 (0)