Skip to content

Commit 60de077

Browse files
Merge branch 'emscripten-core:main' into mas-entry-point-fix
2 parents dfd0682 + 27d725b commit 60de077

20 files changed

+149
-70
lines changed

.circleci/config.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ commands:
142142
cd ~/emsdk
143143
./emsdk install tot
144144
./emsdk activate tot
145+
# Write the version of clang into a file for use in the ccache key
146+
./upstream/bin/clang --version > clang_version.txt
147+
echo "clang version:"
148+
cat ~/emsdk/clang_version.txt
145149
# Remove the emsdk version of emscripten to save space in the
146150
# persistent workspace and to avoid any confusion with the version
147151
# we are trying to test.
@@ -171,7 +175,7 @@ commands:
171175
command: |
172176
./emcc --clear-cache
173177
- pip-install
174-
- run: apt-get install -q -y ninja-build
178+
- run: apt-get install -q -y ninja-build ccache
175179
- run:
176180
name: embuilder build ALL
177181
command: |
@@ -196,6 +200,12 @@ commands:
196200
command: |
197201
./embuilder build MINIMAL --pic --lto
198202
./test/runner test_hello_world
203+
- run:
204+
name: "Ccache stats"
205+
command: |
206+
ccache --print-stats
207+
ccache --zero-stats
208+
199209
persist:
200210
description: "Persist the emsdk, libraries, and engines"
201211
steps:
@@ -209,6 +219,19 @@ commands:
209219
- vms/
210220
- wasi-sdk/
211221
- .jsvu/
222+
- when:
223+
# Only the main branch will store its cache results, and only the non-main branches
224+
# will use cached results. This prevents untrusted PRs from polluting caches used
225+
# by other branches.
226+
condition:
227+
equal: [ "main", << pipeline.git.branch >> ]
228+
steps:
229+
- save_cache:
230+
name: "Save Ccache cache"
231+
paths:
232+
- ~/.ccache
233+
key: clang-{{ checksum "~/emsdk/clang_version.txt" }}
234+
212235
prepare-for-tests:
213236
description: "Setup emscripten tests"
214237
steps:
@@ -543,6 +566,7 @@ jobs:
543566
environment:
544567
EMCC_CORES: 16
545568
EMCC_USE_NINJA: 1
569+
EM_COMPILER_WRAPPER: "ccache"
546570
steps:
547571
- checkout
548572
- run:
@@ -570,6 +594,14 @@ jobs:
570594
tar xvf wasi-sysroot-11.0.tar.gz -C ~/wasi-sdk/
571595
- install-v8
572596
- install-emsdk
597+
- when:
598+
condition:
599+
not:
600+
equal: [ "main", << pipeline.git.branch >> ]
601+
steps:
602+
- restore_cache:
603+
name: "Restore Ccache cache"
604+
key: clang-{{ checksum "~/emsdk/clang_version.txt" }}
573605
- build-libs
574606
- run:
575607
name: Clean build directory
@@ -714,6 +746,8 @@ jobs:
714746
wasmfs.test_fs_llseek_rawfs
715747
wasmfs.test_freetype
716748
minimal0.test_utf
749+
minimal0.test_static_variable
750+
minimal0.test_stack_overflow
717751
omitexports0.test_asyncify_longjmp
718752
omitexports0.test_emscripten_api
719753
strict.test_no_declare_asm_module_exports

src/lib/libcore.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ addToLibrary({
4141
setTempRet0: '$setTempRet0',
4242
getTempRet0: '$getTempRet0',
4343

44+
// Assign a name to a given function. This is mostly useful for debugging
45+
// purposes in cases where new functions are created at runtime.
46+
$createNamedFunction: (name, func) => Object.defineProperty(func, 'name', { value: name }),
47+
4448
$ptrToString: (ptr) => {
4549
#if ASSERTIONS
4650
assert(typeof ptr === 'number', `ptrToString expects a number, got ${typeof ptr}`);

src/lib/libdylink.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ var LibraryDylink = {
116116
// the canonical name of the symbol (in some cases is modify the symbol as
117117
// part of the loop process, so that actual symbol looked up has a different
118118
// name).
119-
$resolveGlobalSymbol__deps: ['$isSymbolDefined',
119+
$resolveGlobalSymbol__deps: ['$isSymbolDefined', '$createNamedFunction',
120120
#if !DISABLE_EXCEPTION_CATCHING || SUPPORT_LONGJMP == 'emscripten'
121121
'$createInvokeFunction',
122122
#endif
@@ -138,7 +138,7 @@ var LibraryDylink = {
138138
// Asm.js-style exception handling: invoke wrapper generation
139139
else if (symName.startsWith('invoke_')) {
140140
// Create (and cache) new invoke_ functions on demand.
141-
sym = wasmImports[symName] = createInvokeFunction(symName.split('_')[1]);
141+
sym = wasmImports[symName] = createNamedFunction(symName, createInvokeFunction(symName.split('_')[1]));
142142
}
143143
#endif
144144
#if !DISABLE_EXCEPTION_CATCHING
@@ -147,13 +147,13 @@ var LibraryDylink = {
147147
// `__cxa_find_matching_catch_` (see jsifier.js) that we know are needed,
148148
// but a side module loaded at runtime might need different/additional
149149
// variants so we create those dynamically.
150-
sym = wasmImports[symName] = (...args) => {
150+
sym = wasmImports[symName] = createNamedFunction(symName, (...args) => {
151151
#if MEMORY64
152152
args = args.map(Number);
153153
#endif
154154
var rtn = findMatchingCatch(args);
155155
return {{{ to64('rtn') }}};
156-
}
156+
});
157157
}
158158
#endif
159159
return {sym, name: symName};

src/lib/libembind.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ var LibraryEmbind = {
122122
}
123123
},
124124

125-
$createNamedFunction: (name, func) => Object.defineProperty(func, 'name', { value: name }),
126-
127125
$embindRepr: (v) => {
128126
if (v === null) {
129127
return 'null';

src/lib/libembind_gen.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,6 @@ var LibraryEmbind = {
870870
// Stub functions used by eval, but not needed for TS generation:
871871
$makeLegalFunctionName: () => { throw new Error('stub function should not be called'); },
872872
$runDestructors: () => { throw new Error('stub function should not be called'); },
873-
$createNamedFunction: () => { throw new Error('stub function should not be called'); },
874873
$flushPendingDeletes: () => { throw new Error('stub function should not be called'); },
875874
$setDelayFunction: () => { throw new Error('stub function should not be called'); },
876875
$PureVirtualError: () => { throw new Error('stub function should not be called'); },

src/lib/libpthread.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ const pthreadWorkerScript = TARGET_JS_NAME;
4242
// See https://github.com/emscripten-core/emscripten/issues/22394
4343
const pthreadWorkerOptions = `{
4444
#if EXPORT_ES6
45+
#if MIN_FIREFOX_VERSION < 114
46+
#error new Worker() supports ECMAScript module only starting from Firefox 114. Pass -sMIN_FIREFOX_VERSION=114 to target -sEXPORT_ES6 with -pthread. See https://caniuse.com/mdn-api_worker_worker_ecmascript_modules
47+
#endif
48+
#if MIN_CHROME_VERSION < 80
49+
#error new Worker() supports ECMAScript module only starting from Chrome 80. Pass -sMIN_CHROME_VERSION=80 to target -sEXPORT_ES6 with -pthread. See https://caniuse.com/mdn-api_worker_worker_ecmascript_modules
50+
#endif
51+
#if MIN_SAFARI_VERSION < 150000
52+
#error new Worker() supports ECMAScript module only starting from Safari 15. Pass -sMIN_SAFARI_VERSION=150000 to target -sEXPORT_ES6 with -pthread. See https://caniuse.com/mdn-api_worker_worker_ecmascript_modules
53+
#endif
4554
'type': 'module',
4655
#endif
4756
#if ENVIRONMENT_MAY_BE_NODE

src/lib/libwasm_worker.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040
`;
4141
const wasmWorkerOptions = `{
4242
#if EXPORT_ES6
43+
#if MIN_FIREFOX_VERSION < 114
44+
#error new Worker() supports ECMAScript module only starting from Firefox 114. Pass -sMIN_FIREFOX_VERSION=114 to target -sEXPORT_ES6 with -sWASM_WORKERS. See https://caniuse.com/mdn-api_worker_worker_ecmascript_modules
45+
#endif
46+
#if MIN_CHROME_VERSION < 80
47+
#error new Worker() supports ECMAScript module only starting from Chrome 80. Pass -sMIN_CHROME_VERSION=80 to target -sEXPORT_ES6 with -sWASM_WORKERS. See https://caniuse.com/mdn-api_worker_worker_ecmascript_modules
48+
#endif
49+
#if MIN_SAFARI_VERSION < 150000
50+
#error new Worker() supports ECMAScript module only starting from Safari 15. Pass -sMIN_SAFARI_VERSION=150000 to target -sEXPORT_ES6 with -sWASM_WORKERS. See https://caniuse.com/mdn-api_worker_worker_ecmascript_modules
51+
#endif
4352
'type': 'module',
4453
#endif
4554
#if ENVIRONMENT_MAY_BE_NODE

src/postamble_minimal.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,26 @@ function run() {
8080
_main({{{ argc_argv() }}}).then(exitRuntime);
8181
#elif EXIT_RUNTIME
8282
// In regular exitRuntime mode, exit with the given return code from main().
83-
exitRuntime(_main({{{ argc_argv() }}}));
83+
try {
84+
exitRuntime(_main({{{ argc_argv() }}}));
85+
} catch(e) {
86+
var exitCode = e.match(/^exit\((\d+)\)$/);
87+
if (exitCode) {
88+
#if RUNTIME_DEBUG
89+
dbg(`main() called ${e}.`); // e.g. "main() called exit(0)."
90+
#endif
91+
#if expectToReceiveOnModule('onExit')
92+
// Report to Module that the program exited.
93+
Module['onExit']?.(exitCode[1]|0);
94+
#endif
95+
} else {
96+
#if RUNTIME_DEBUG
97+
dbg(`main() threw an exception: ${e}.`);
98+
#endif
99+
// Some other exception occurred - re-throw it.
100+
throw e;
101+
}
102+
}
84103
#else
85104
// Run a persistent (never-exiting) application starting at main().
86105
_main({{{ argc_argv() }}});

src/shell_minimal.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,23 @@ if (ENVIRONMENT_IS_NODE) {
5858
}
5959
#endif
6060

61-
#if WASM_WORKERS
61+
#if AUDIO_WORKLET
62+
var ENVIRONMENT_IS_AUDIO_WORKLET = !!globalThis.AudioWorkletGlobalScope;
63+
#endif
64+
65+
#if AUDIO_WORKLET && WASM_WORKERS
66+
var ENVIRONMENT_IS_WASM_WORKER = globalThis.name == 'em-ww' || ENVIRONMENT_IS_AUDIO_WORKLET;
67+
#elif WASM_WORKERS
6268
var ENVIRONMENT_IS_WASM_WORKER = globalThis.name == 'em-ww';
69+
#endif
6370

64-
#if ENVIRONMENT_MAY_BE_NODE
71+
#if WASM_WORKERS && ENVIRONMENT_MAY_BE_NODE
6572
if (ENVIRONMENT_IS_NODE) {
6673
// The way we signal to a worker that it is hosting a pthread is to construct
6774
// it with a specific name.
6875
ENVIRONMENT_IS_WASM_WORKER = worker_threads['workerData'] == 'em-ww'
6976
}
7077
#endif
71-
#endif
72-
73-
#if AUDIO_WORKLET
74-
var ENVIRONMENT_IS_AUDIO_WORKLET = !!globalThis.AudioWorkletGlobalScope;
75-
if (ENVIRONMENT_IS_AUDIO_WORKLET) ENVIRONMENT_IS_WASM_WORKER = true;
76-
#endif
7778

7879
#if ASSERTIONS && ENVIRONMENT_MAY_BE_NODE && ENVIRONMENT_MAY_BE_SHELL
7980
if (ENVIRONMENT_IS_NODE && ENVIRONMENT_IS_SHELL) {

test/codesize/audio_worklet_wasm.expected.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
var m = globalThis.Module || "undefined" != typeof Module ? Module : {}, q = "em-ww" == globalThis.name, r = !!globalThis.AudioWorkletGlobalScope, t, z, J, K, H, E, v, X, F, D, C, Y, A, Z;
2-
3-
r && (q = !0);
1+
var m = globalThis.Module || "undefined" != typeof Module ? Module : {}, q = !!globalThis.AudioWorkletGlobalScope, r = "em-ww" == globalThis.name || q, t, z, J, K, H, E, v, X, F, D, C, Y, A, Z;
42

53
function u(a) {
64
t = a;
@@ -12,12 +10,12 @@ function u(a) {
1210
a.G = a.M = 0;
1311
}
1412

15-
q && !r && (onmessage = a => {
13+
r && !q && (onmessage = a => {
1614
onmessage = null;
1715
u(a.data);
1816
});
1917

20-
if (r) {
18+
if (q) {
2119
function a(e) {
2220
class d extends AudioWorkletProcessor {
2321
constructor(c) {
@@ -98,7 +96,7 @@ function w() {
9896
E = new Float32Array(a);
9997
}
10098

101-
q || (v = m.mem || new WebAssembly.Memory({
99+
r || (v = m.mem || new WebAssembly.Memory({
102100
initial: 256,
103101
maximum: 256,
104102
shared: !0
@@ -236,9 +234,9 @@ function y() {
236234
C = a.n;
237235
Y = a.o;
238236
A = a.k;
239-
q ? (Y(t.J, t.F), r || (removeEventListener("message", N), L = L.forEach(M), addEventListener("message", M))) : a.i();
240-
q || X();
237+
r ? (Y(t.J, t.F), q || (removeEventListener("message", N), L = L.forEach(M), addEventListener("message", M))) : a.i();
238+
r || X();
241239
}));
242240
}
243241

244-
q || y();
242+
r || y();

0 commit comments

Comments
 (0)