Skip to content

Commit 6faa8a5

Browse files
committed
Merge branch 'main' into ports-deferred
2 parents 031ff61 + bb29e61 commit 6faa8a5

File tree

101 files changed

+402
-397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+402
-397
lines changed

Diff for: ChangeLog.md

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ See docs/process.md for more on how version tagging works.
2323
- Added experimental support for Wasm ESM integration with
2424
`-sWASM_ESM_INTEGRATION`. This is currently only supported in node behind a
2525
flag and not in any browsers. (#23985)
26+
- Runtime callbacks registered in `Module['preRun']` or `Module['postRun']`, or
27+
using `addOnPreRun()`, `addOnInit()`, `addOnPostCtor()`, `addOnPreMain()`,
28+
`addOnExit()`, or `addOnPostRun()`, are now enqueued and executed following
29+
the order of registration (i.e. `Module['preRun'] = [a, b]`, or equivalently
30+
`addOnPreRun(a); addOnPreRun(b);` will run `a` then `b`; the previous behavior
31+
was to run `b` then `a`). While this might be a breaking change for some users,
32+
the intention is to be more consistent by making those callbacks match the
33+
behavior of `Module['preInit']` and compile time callbacks (rather than the
34+
contrary, as we generally expect an array of functions to be executed left to
35+
right). (#24012)
2636

2737
4.0.6 - 03/26/25
2838
----------------

Diff for: cmake/Modules/FindOpenGL.cmake

+15-11
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ mark_as_advanced(
3131
OPENGL_gl_LIBRARY
3232
)
3333

34-
add_library(OpenGL::GL INTERFACE IMPORTED)
35-
set_target_properties(OpenGL::GL PROPERTIES
36-
IMPORTED_LIBNAME "${OPENGL_gl_LIBRARY}"
37-
INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}"
38-
)
39-
40-
add_library(OpenGL::GLU INTERFACE IMPORTED)
41-
set_target_properties(OpenGL::GLU PROPERTIES
42-
IMPORTED_LIBNAME "${OPENGL_glu_LIBRARY}"
43-
INTERFACE_LINK_LIBRARIES OpenGL::GL
44-
)
34+
if (NOT TARGET OpenGL::GL)
35+
add_library(OpenGL::GL INTERFACE IMPORTED)
36+
set_target_properties(OpenGL::GL PROPERTIES
37+
IMPORTED_LIBNAME "${OPENGL_gl_LIBRARY}"
38+
INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}"
39+
)
40+
endif()
41+
42+
if (NOT TARGET OpenGL::GLU)
43+
add_library(OpenGL::GLU INTERFACE IMPORTED)
44+
set_target_properties(OpenGL::GLU PROPERTIES
45+
IMPORTED_LIBNAME "${OPENGL_glu_LIBRARY}"
46+
INTERFACE_LINK_LIBRARIES OpenGL::GL
47+
)
48+
endif()

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ conf\.py |
8080
emrun\.py |
8181
site/source/_themes/ |
8282
tools/scons/site_scons/site_tools/emscripten/__init__\.py |
83+
tools/maint/create_dom_pk_codes.py |
8384
site/source/get_wiki\.py |
8485
test/parse_benchmark_output\.py
8586
)'''
8687

8788
[[tool.mypy.overrides]]
8889
module = [
89-
"tools.create_dom_pk_codes",
9090
"tools.webidl_binder",
9191
"tools.toolchain_profiler",
9292
"tools.filelock",

Diff for: site/source/docs/getting_started/FAQ.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Why do I get errors building basic code and the tests?
1818

1919
All the tests in the :ref:`Emscripten test suite <emscripten-test-suite>` are
2020
known to build and pass on our test infrastructure, so if you see failures
21-
locally it is likely that there is some problem with your environment. (Rarely,
21+
locally, it is likely that there is some problem with your environment. (Rarely,
2222
there may be temporary breakage, but never on a tagged release version.)
2323

2424
First call ``emcc --check``, which runs basic sanity checks and prints out
@@ -105,13 +105,13 @@ compilation time).
105105
Why is my compiled code big?
106106
============================
107107

108-
Make sure you build with ``-O3`` or ``-Os`` so code is fully optimized and
108+
Make sure you build with ``-O3`` or ``-Os``, so the code is fully optimized and
109109
minified. You should use the closure compiler, gzip compression on your
110110
webserver, etc., see the :ref:`section on code size in Optimizing code
111111
<optimizing-code-size>`.
112112

113113

114-
Why does compiling code that works on another machine gives me errors?
114+
Why does compiling code that works on another machine give me errors?
115115
======================================================================
116116

117117
Make sure you are using the Emscripten bundled system headers. Using :ref:`emcc
@@ -207,11 +207,11 @@ JavaScript that does not complete and return control to the browser.
207207
Graphical C++ apps typically have an infinite main loop in which event handling,
208208
processing and rendering is done, followed by a delay to keep the frame-rate
209209
right (``SDL_DELAY`` in :term:`SDL` apps). As the main loop does not complete
210-
(is infinite) it cannot return control to the browser, and the app will hang.
210+
(is infinite), it cannot return control to the browser, and the app will hang.
211211

212212
Apps that use an infinite main loop should be re-coded to put the actions for a
213213
single iteration of the loop into a single "finite" function. In the native
214-
build this function can be run in an infinite loop as before. In the Emscripten
214+
build, this function can be run in an infinite loop as before. In the Emscripten
215215
build it is set as the :ref:`main loop function <faq-how-run-event-loop>` and
216216
will be called by the browser at a specified frequency.
217217

Diff for: site/source/docs/getting_started/Tutorial.rst

+10-19
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ using ``./emcc`` or ``./em++``.
2828
For the next section you will need to open a command prompt:
2929

3030
- On Linux or macOS, open a *Terminal*.
31-
- On Windows open the :ref:`Emscripten Command Prompt <emcmdprompt>`, a command
31+
- On Windows, open the :ref:`Emscripten Command Prompt <emcmdprompt>`, a command
3232
prompt that has been pre-configured with the correct system paths and settings
3333
to point to the :term:`active <Active Tool/SDK>` Emscripten tools. To access
34-
this prompt, type **Emscripten** in the Windows 8 start screen, and then
34+
this prompt, type **Emscripten** in the Windows start menu, and then
3535
select the **Emscripten Command Prompt** option.
3636

3737
Navigate with the command prompt to the emscripten directory under the SDK. This
3838
is a folder below the :term:`emsdk root directory`, typically
3939
**<emsdk root directory>/upstream/emscripten/**.
4040
The examples below will depend on finding files relative to that location.
4141

42-
.. note:: In older emscripten versions the directory structure was different:
42+
.. note:: In older emscripten versions, the directory structure was different:
4343
the version number appeared, and the backend (fastcomp/upstream) did not, so
4444
you would use something like **<emsdk root directory>/emscripten/1.20.0/**.
4545

@@ -52,7 +52,7 @@ If you haven't run Emscripten before, run it now with: ::
5252
./emcc -v
5353

5454
If the output contains warnings about missing tools, see
55-
:ref:`verifying-the-emscripten-environment` for debugging help. Otherwise
55+
:ref:`verifying-the-emscripten-environment` for debugging help. Otherwise,
5656
continue to the next sections where we'll build some code.
5757

5858

@@ -61,7 +61,7 @@ Running Emscripten
6161

6262
You can now compile your first C/C++ file to JavaScript.
6363

64-
First, lets have a look at the file to be compiled: **hello_world.c**. This is
64+
First, let's have a look at the file to be compiled: **hello_world.c**. This is
6565
the simplest test code in the SDK, and as you can see, all it does is print
6666
"hello, world!" to the console and then exit.
6767

@@ -86,15 +86,6 @@ execute it. You can run them using :term:`node.js`:
8686

8787
This prints "hello, world!" to the console, as expected.
8888

89-
.. note:: Older node.js versions do not have WebAssembly support yet. In that
90-
case you will see an error message suggesting that you build with
91-
``-sWASM=0`` to disable WebAssembly, and then emscripten will emit the compiled
92-
code as JavaScript. In general, WebAssembly is recommended as it has
93-
widespread browser support and is more efficient both to execute and to
94-
download (and therefore emscripten emits it by default), but sometimes you
95-
may need your code to run in an environment where it is not yet present and
96-
so should disable it.
97-
9889
.. tip:: If an error occurs when calling *emcc*, run it with the ``-v`` option
9990
to print out a lot of useful debug information.
10091

@@ -116,11 +107,11 @@ file as the target file: ::
116107

117108
You can now open ``hello.html`` in a web browser.
118109

119-
.. note:: Unfortunately several browsers (including *Chrome*, *Safari*, and
120-
*Internet Explorer*) do not support ``file://`` :term:`XHR` requests, and
121-
can't load extra files needed by the HTML (like a ``.wasm`` file, or packaged
122-
file data as mentioned lower down). For these browsers you'll need to serve
123-
the files using a :ref:`local webserver <faq-local-webserver>` and then open
110+
.. note:: Unfortunately, several browsers (including *Chrome* and *Safari*) do
111+
not support ``file://`` :term:`XHR` requests, and can't load extra files
112+
needed by the HTML (like a ``.wasm`` file, or packaged file data as mentioned
113+
lower down). For these browsers, you'll need to serve the files using a
114+
:ref:`local webserver <faq-local-webserver>` and then open
124115
``http://localhost:8000/hello.html``).
125116

126117
Once you have the HTML loaded in your browser, you'll see a text area for

Diff for: site/source/docs/getting_started/downloads.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ Download and install
88
<installing-from-source>` if you prefer that to downloading binaries using
99
the emsdk.
1010

11-
.. tip:: if you'd like to install emscripten using the **unofficial** packages
11+
.. tip:: If you'd like to install emscripten using the **unofficial** packages
1212
instead of the **officially supported** emsdk, see the bottom of the page.
1313

1414
.. _sdk-installation-instructions:
1515

1616
Installation instructions using the emsdk (recommended)
1717
=======================================================
1818

19-
First check the :ref:`Platform-specific notes
19+
First, check the :ref:`Platform-specific notes
2020
<platform-notes-installation_instructions-SDK>` below and install any
2121
prerequisites.
2222

2323
The core Emscripten SDK (emsdk) driver is a Python script. You can get it for
24-
the first time with
24+
the first time with:
2525

2626
::
2727

@@ -52,7 +52,7 @@ GitHub and set them as :term:`active <Active Tool/SDK>`:
5252
# Activate PATH and other environment variables in the current terminal
5353
source ./emsdk_env.sh
5454

55-
.. tip:: If you want to avoid executing `source ./emsdk_env.sh` every time you open a new terminal you can follow the instructions given by the `emsdk activate` command above to add this command to your startup scripts.
55+
.. tip:: If you want to avoid executing `source ./emsdk_env.sh` every time you open a new terminal, you can follow the instructions given by the `emsdk activate` command above to add this command to your startup scripts.
5656

5757
.. note:: On Windows, run ``emsdk.bat`` instead of ``./emsdk``, and ``emsdk_env.bat`` instead of ``source ./emsdk_env.sh``.
5858

@@ -67,7 +67,7 @@ commands.
6767
Emsdk install targets
6868
---------------------
6969

70-
In the description above we asked the emsdk to install and activate ``latest``,
70+
In the description above, we asked the emsdk to install and activate ``latest``,
7171
which is the latest tagged release. That is often what you want.
7272

7373
You can also install a specific version by specifying it, for example,
@@ -101,7 +101,7 @@ target, and note that you must specify the backend explicitly,
101101
# Get a tip-of-tree
102102
./emsdk install tot
103103

104-
(In the above examples we installed the various targets; remember to also
104+
(In the above examples, we installed the various targets; remember to also
105105
``activate`` them as in the full example from earlier.)
106106

107107
.. _platform-notes-installation_instructions-SDK:
@@ -122,8 +122,8 @@ macOS
122122

123123
.. note:: Emscripten requires macOS 10.14 Mojave or above.
124124

125-
If you use the Emscripten SDK it includes a bundled version of Python 3.
126-
Otherwise you will need to manually install and use Python 3.6 or newer.
125+
If you use the Emscripten SDK, it includes a bundled version of Python 3.
126+
Otherwise, you will need to manually install and use Python 3.6 or newer.
127127

128128
These instructions explain how to install **all** the :ref:`required tools
129129
<toolchain-what-you-need>`. You can :ref:`test whether some of these are already

Diff for: site/source/docs/getting_started/test-suite.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ the first failure.
9999
that are normally run in parallel you can force them to run serially using
100100
``-j1``.
101101

102-
One a test is fixed you continue where you left off using ``--start-at`` option:
102+
Once a test is fixed, you continue where you left off using ``--start-at`` option:
103103

104104
.. code-block:: bash
105105

Diff for: src/jsifier.mjs

-9
Original file line numberDiff line numberDiff line change
@@ -734,15 +734,6 @@ function(${args}) {
734734
}
735735
contentText = `var ${mangled} = ${snippet};`;
736736
}
737-
// asm module exports are done in emscripten.py, after the asm module is ready. Here
738-
// we also export library methods as necessary.
739-
if ((EXPORT_ALL || EXPORTED_FUNCTIONS.has(mangled)) && !isStub) {
740-
if (MODULARIZE === 'instance') {
741-
contentText += `\n__exp_${mangled} = ${mangled};`;
742-
} else {
743-
contentText += `\nModule['${mangled}'] = ${mangled};`;
744-
}
745-
}
746737
// Relocatable code needs signatures to create proper wrappers.
747738
if (sig && RELOCATABLE) {
748739
if (!WASM_BIGINT) {

Diff for: src/lib/libcore.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,7 @@ addToLibrary({
23002300
ATPRERUNS.unshift('callRuntimeCallbacks(onPreRuns);');
23012301
},
23022302
$addOnPreRun__deps: ['$onPreRuns'],
2303-
$addOnPreRun: (cb) => onPreRuns.unshift(cb),
2303+
$addOnPreRun: (cb) => onPreRuns.push(cb),
23042304
// See ATINITS in parseTools.mjs for more information.
23052305
$onInits: [],
23062306
$onInits__internal: true,
@@ -2309,7 +2309,7 @@ addToLibrary({
23092309
ATINITS.unshift('callRuntimeCallbacks(onInits);');
23102310
},
23112311
$addOnInit__deps: ['$onInits'],
2312-
$addOnInit: (cb) => onInits.unshift(cb),
2312+
$addOnInit: (cb) => onInits.push(cb),
23132313
// See ATPOSTCTORS in parseTools.mjs for more information.
23142314
$onPostCtors: [],
23152315
$onPostCtors__internal: true,
@@ -2318,7 +2318,7 @@ addToLibrary({
23182318
ATPOSTCTORS.unshift('callRuntimeCallbacks(onPostCtors);');
23192319
},
23202320
$addOnPostCtor__deps: ['$onPostCtors'],
2321-
$addOnPostCtor: (cb) => onPostCtors.unshift(cb),
2321+
$addOnPostCtor: (cb) => onPostCtors.push(cb),
23222322
// See ATMAINS in parseTools.mjs for more information.
23232323
$onMains: [],
23242324
$onMains__internal: true,
@@ -2327,7 +2327,7 @@ addToLibrary({
23272327
ATMAINS.unshift('callRuntimeCallbacks(onMains);');
23282328
},
23292329
$addOnPreMain__deps: ['$onMains'],
2330-
$addOnPreMain: (cb) => onMains.unshift(cb),
2330+
$addOnPreMain: (cb) => onMains.push(cb),
23312331
// See ATEXITS in parseTools.mjs for more information.
23322332
$onExits: [],
23332333
$onExits__internal: true,
@@ -2336,7 +2336,7 @@ addToLibrary({
23362336
ATEXITS.unshift('callRuntimeCallbacks(onExits);');
23372337
},
23382338
$addOnExit__deps: ['$onExits'],
2339-
$addOnExit: (cb) => onExits.unshift(cb),
2339+
$addOnExit: (cb) => onExits.push(cb),
23402340
// See ATPOSTRUNS in parseTools.mjs for more information.
23412341
$onPostRuns: [],
23422342
$onPostRuns__internal: true,
@@ -2345,7 +2345,7 @@ addToLibrary({
23452345
ATPOSTRUNS.unshift('callRuntimeCallbacks(onPostRuns);');
23462346
},
23472347
$addOnPostRun__deps: ['$onPostRuns'],
2348-
$addOnPostRun: (cb) => onPostRuns.unshift(cb),
2348+
$addOnPostRun: (cb) => onPostRuns.push(cb),
23492349

23502350
// We used to define these globals unconditionally in support code.
23512351
// Instead, we now define them here so folks can pull it in explicitly, on

Diff for: src/lib/libdylink.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -871,13 +871,18 @@ var LibraryDylink = {
871871
}
872872

873873
if (flags.loadAsync) {
874-
if (binary instanceof WebAssembly.Module) {
875-
var instance = new WebAssembly.Instance(binary, info);
876-
return Promise.resolve(postInstantiation(binary, instance));
877-
}
878-
return WebAssembly.instantiate(binary, info).then(
879-
(result) => postInstantiation(result.module, result.instance)
880-
);
874+
return (async () => {
875+
var instance;
876+
if (binary instanceof WebAssembly.Module) {
877+
instance = new WebAssembly.Instance(binary, info);
878+
} else {
879+
// Destructuring assignment without declaration has to be wrapped
880+
// with parens or parser will treat the l-value as an object
881+
// literal instead.
882+
({ module: binary, instance } = await WebAssembly.instantiate(binary, info));
883+
}
884+
return postInstantiation(binary, instance);
885+
})();
881886
}
882887

883888
var module = binary instanceof WebAssembly.Module ? binary : new WebAssembly.Module(binary);

Diff for: src/lib/libegl.js

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const eglDefaultDisplay = 62000;
2222
const eglDefaultConfig = 62002;
2323
// Magic ID for Emscripten EGLContext
2424
const eglDefaultContext = 62004;
25-
null;
2625
}}}
2726

2827
var LibraryEGL = {

Diff for: src/lib/libemval.js

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
{{{
2020
const EMVAL_RESERVED_HANDLES = 5;
2121
const EMVAL_LAST_RESERVED_HANDLE = EMVAL_RESERVED_HANDLES * 2 - 1;
22-
null;
2322
}}}
2423
var LibraryEmVal = {
2524
// Stack of handles available for reuse.

Diff for: src/lib/libglemu.js

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ assert(!FULL_ES3, 'cannot emulate both ES3 and legacy GL');
2121
}
2222
return '';
2323
};
24-
null;
2524
}}}
2625

2726
var LibraryGLEmulation = {

Diff for: src/lib/libhtml5_webgpu.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
{{{
22
// Helper functions for code generation
3-
globalThis.html5_gpu = {
4-
makeImportExport: (snake_case, CamelCase) => {
5-
return `
3+
const html5_gpu = {
4+
makeImportExport: (snake_case, CamelCase) => {
5+
return `
66
LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case}__deps = ['$WebGPU', '$JsValStore'];
77
LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case} = (handle) =>
88
WebGPU.mgr${CamelCase}.create(JsValStore.get(handle));
99
1010
LibraryHTML5WebGPU.emscripten_webgpu_export_${snake_case}__deps = ['$WebGPU', '$JsValStore'];
1111
LibraryHTML5WebGPU.emscripten_webgpu_export_${snake_case} = (handle) =>
1212
JsValStore.add(WebGPU.mgr${CamelCase}.get(handle));`
13-
},
14-
};
15-
null;
13+
},
14+
};
1615
}}}
1716

1817

Diff for: src/lib/libpthread.js

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ const pthreadWorkerOptions = `{
5252
#endif
5353
#endif
5454
}`;
55-
null
5655
}}}
5756

5857
var LibraryPThread = {

0 commit comments

Comments
 (0)