Skip to content

Commit b805400

Browse files
authored
Make addRunDependency/removeRunDependency optional (#24974)
This saves on code size is configurations where its not needed. i.e. in `MODULARIZE` mode where we use `await` to wait for instantiation, or if sync instantiation is used.
1 parent b9b9aba commit b805400

27 files changed

+93
-75
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works.
2020

2121
4.0.14 (in development)
2222
-----------------------
23+
- The `addRunDependency` and `removeRunDependency` API are now optional and need
24+
to be included and/or exported using, for example,
25+
`DEFAULT_LIBRARY_FUNCS_TO_INCLUDE` or `EXPORTED_RUNTIME_METHODS`. (#24974)
2326
- The `LOAD_SOURCE_MAP` setting was made an internal setting. This was always
2427
an internal detail of the sanitizers, which is enabled automatically when
2528
needed, so setting it explicitly should never be needed. (#24967)

src/lib/libcore.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2274,6 +2274,7 @@ addToLibrary({
22742274
$noExitRuntime__postset: () => addAtModule(makeModuleReceive('noExitRuntime')),
22752275
$noExitRuntime: {{{ !EXIT_RUNTIME }}},
22762276

2277+
#if !MINIMAL_RUNTIME
22772278
// A counter of dependencies for calling run(). If we need to
22782279
// do asynchronous work before running, increment this and
22792280
// decrement it. Incrementing must happen in a place like
@@ -2293,7 +2294,7 @@ addToLibrary({
22932294
$runDependencyWatcher: null,
22942295
#endif
22952296

2296-
$addRunDependency__deps: ['$runDependencies',
2297+
$addRunDependency__deps: ['$runDependencies', '$removeRunDependency',
22972298
#if ASSERTIONS
22982299
'$runDependencyTracking',
22992300
'$runDependencyWatcher',
@@ -2377,6 +2378,7 @@ addToLibrary({
23772378
}
23782379
}
23792380
},
2381+
#endif
23802382

23812383
// The following addOn<X> functions are for adding runtime callbacks at
23822384
// various executions points. Each addOn<X> function has a corresponding

src/lib/libfs_shared.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ addToLibrary({
5555
'$PATH_FS',
5656
'$FS_createDataFile',
5757
'$getUniqueRunDependency',
58+
'$addRunDependency',
59+
'$removeRunDependency',
5860
'$FS_handledByPreloadPlugin',
5961
],
6062
$FS_preloadFile: async (parent, name, url, canRead, canWrite, dontCreateFile, canOwn, preFinish) => {

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', '$getUniqueRunDependency'],
9+
$LZ4__deps: ['$FS', '$preloadPlugins', '$getUniqueRunDependency', '$addRunDependency', '$removeRunDependency'],
1010
$LZ4: {
1111
DIR_MODE: {{{ cDefs.S_IFDIR | 0o777 }}},
1212
FILE_MODE: {{{ cDefs.S_IFREG | 0o777 }}},

src/lib/libpthread.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ var LibraryPThread = {
6969
'$addOnPreRun',
7070
#if MAIN_MODULE
7171
'$markAsFinished',
72+
#endif
73+
#if !MINIMAL_RUNTIME && PTHREAD_POOL_SIZE && !PTHREAD_POOL_DELAY_LOAD
74+
'$addRunDependency',
75+
'$removeRunDependency',
7276
#endif
7377
'$spawnThread',
7478
'_emscripten_thread_free_data',

src/postamble.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ var mainArgs = undefined;
3636
{{{ asyncIf(ASYNCIFY == 2) }}}function callMain() {
3737
#endif
3838
#if ASSERTIONS
39+
#if '$runDependencies' in addedLibraryItems
3940
assert(runDependencies == 0, 'cannot call main when async dependencies remain! (listen on Module["onRuntimeInitialized"])');
41+
#endif
4042
assert(typeof onPreRuns === 'undefined' || onPreRuns.length == 0, 'cannot call main when preRun functions remain to be called');
4143
#endif
4244

@@ -133,7 +135,7 @@ function run(args = arguments_) {
133135
function run() {
134136
#endif
135137

136-
#if !BOOTSTRAPPING_STRUCT_INFO
138+
#if '$runDependencies' in addedLibraryItems
137139
if (runDependencies > 0) {
138140
#if RUNTIME_DEBUG
139141
dbg('run() called, but dependencies remain, so not running');
@@ -159,7 +161,7 @@ function run() {
159161

160162
preRun();
161163

162-
#if !BOOTSTRAPPING_STRUCT_INFO
164+
#if '$runDependencies' in addedLibraryItems
163165
// a preRun added a dependency, run will be called later
164166
if (runDependencies > 0) {
165167
#if RUNTIME_DEBUG

src/preamble.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,12 +754,12 @@ function getWasmImports() {
754754
#if DECLARE_ASM_MODULE_EXPORTS
755755
assignWasmExports(wasmExports);
756756
#endif
757-
#if WASM_ASYNC_COMPILATION
757+
#if WASM_ASYNC_COMPILATION && !MODULARIZE
758758
removeRunDependency('wasm-instantiate');
759759
#endif
760760
return wasmExports;
761761
}
762-
#if WASM_ASYNC_COMPILATION
762+
#if WASM_ASYNC_COMPILATION && !MODULARIZE
763763
addRunDependency('wasm-instantiate');
764764
#endif
765765

test/code_size/test_codesize_cxx_ctors2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 19731,
3-
"a.out.js.gz": 8149,
3+
"a.out.js.gz": 8148,
44
"a.out.nodebug.wasm": 128935,
55
"a.out.nodebug.wasm.gz": 48881,
66
"total": 148666,
7-
"total_gz": 57030,
7+
"total_gz": 57029,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/code_size/test_codesize_cxx_wasmfs.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 7143,
3-
"a.out.js.gz": 3340,
3+
"a.out.js.gz": 3337,
44
"a.out.nodebug.wasm": 169796,
55
"a.out.nodebug.wasm.gz": 63083,
66
"total": 176939,
7-
"total_gz": 66423,
7+
"total_gz": 66420,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

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": 22497,
3-
"a.out.js.gz": 8330,
3+
"a.out.js.gz": 8329,
44
"a.out.nodebug.wasm": 15143,
55
"a.out.nodebug.wasm.gz": 7452,
66
"total": 37640,
7-
"total_gz": 15782,
7+
"total_gz": 15781,
88
"sent": [
99
"fd_write"
1010
],

0 commit comments

Comments
 (0)