Skip to content

Commit

Permalink
emscripten-3.1.58
Browse files Browse the repository at this point in the history
  • Loading branch information
DerThorsten committed Aug 1, 2024
1 parent df57fe8 commit 24685a4
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
emsdk_ver: ["3.1.45"]
emsdk_ver: ["3.1.58"]

steps:
- uses: actions/checkout@v2
Expand Down
9 changes: 1 addition & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ if (NOT TARGET pybind11::headers)
endif ()


set(EM_FLAGS "${EM_FLAGS} -s WASM=1 --bind --pre-js pyjs_pre.js --post-js pyjs_post.js")

add_library(pyjs STATIC
src/export_js_module.cpp
src/export_js_proxy.cpp
Expand All @@ -121,14 +119,12 @@ target_link_libraries(pyjs PRIVATE ${PYTHON_UTIL_LIBS} pybind11::embed)
target_compile_options(pyjs
PUBLIC --std=c++17
PUBLIC -Wno-deprecated
PUBLIC "SHELL: --bind"
PUBLIC "SHELL: -fexceptions"
)

target_link_options(pyjs
PUBLIC --bind
PUBLIC -lembind
PUBLIC -Wno-unused-command-line-argument
PUBLIC "SHELL: --bind"
PUBLIC "SHELL: -fexceptions"
#PUBLIC "SHELL:-s EXPORT_EXCEPTION_HANDLING_HELPERS"
#PUBLIC "SHELL:-s EXCEPTION_CATCHING_ALLOWED=['we only want to allow exception handling in side modules']"
Expand Down Expand Up @@ -195,7 +191,6 @@ target_link_libraries(pyjs_runtime_browser PRIVATE ${PYTHON_UTIL_LIBS} pybind11:
target_compile_options(pyjs_runtime_browser
PUBLIC --std=c++17
PUBLIC -Wno-deprecated
PUBLIC "SHELL: --bind"
PUBLIC "SHELL: -s ENVIRONMENT=${ENVIRONMENT}"
PUBLIC "SHELL: -fexceptions"
#PUBLIC "SHELL:-s EXPORT_EXCEPTION_HANDLING_HELPERS"
Expand All @@ -206,9 +201,7 @@ target_compile_options(pyjs_runtime_browser
)

target_link_options(pyjs_runtime_browser
PUBLIC --bind
PUBLIC -Wno-unused-command-line-argument
PUBLIC "SHELL: --bind"
PUBLIC "SHELL: -s MODULARIZE=1"
PUBLIC "SHELL: -s EXPORT_NAME=\"createModule\""
PUBLIC "SHELL: -s EXPORT_ES6=0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 0170462a78e86de9ee95017bfa7e4a3dd620a375 Mon Sep 17 00:00:00 2001
From 137dae4dbdf9a192551582cdae827b085510956f Mon Sep 17 00:00:00 2001
From: Hood Chatham <[email protected]>
Date: Fri, 2 Jun 2023 11:59:32 -0700
Subject: [PATCH] Add back fs.findObject and fs.readFile in loadLibData
Subject: [PATCH 1/6] Add back fs.findObject and fs.readFile in loadLibData

See upstream PR:
https://github.com/emscripten-core/emscripten/pull/19513
Expand All @@ -10,10 +10,10 @@ https://github.com/emscripten-core/emscripten/pull/19513
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/library_dylink.js b/src/library_dylink.js
index d7676cdc2..f616d230d 100644
index aa90bea2b..1e67818a1 100644
--- a/src/library_dylink.js
+++ b/src/library_dylink.js
@@ -993,14 +993,23 @@ var LibraryDylink = {
@@ -994,14 +994,23 @@ var LibraryDylink = {
#endif

// for wasm, we can use fetch for async, but for fs mode we can only imitate it
Expand All @@ -40,5 +40,5 @@ index d7676cdc2..f616d230d 100644
var libFile = locateFile(libName);
if (flags.loadAsync) {
--
2.25.1
2.34.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From a8bdb50a29062ee70c8667e4fd94dde47917f8fa Mon Sep 17 00:00:00 2001
From e0cb884277200310eba263dcce5a7b1c4567bae6 Mon Sep 17 00:00:00 2001
From: Hood Chatham <[email protected]>
Date: Fri, 19 May 2023 12:19:00 -0700
Subject: [PATCH] Add useful error when symbol resolution fails
Subject: [PATCH 2/6] Add useful error when symbol resolution fails

Currently if symbol resolution fails, we get:
```js
Expand All @@ -19,19 +19,19 @@ symbol.
1 file changed, 3 insertions(+)

diff --git a/src/library_dylink.js b/src/library_dylink.js
index d96e6b425..7f63b5c5e 100644
index 1e67818a1..cea3ce05d 100644
--- a/src/library_dylink.js
+++ b/src/library_dylink.js
@@ -727,6 +727,9 @@ var LibraryDylink = {
@@ -709,6 +709,9 @@ var LibraryDylink = {
var resolved;
stubs[prop] = function() {
if (!resolved) resolved = resolveSymbol(prop);
stubs[prop] = (...args) => {
resolved ||= resolveSymbol(prop);
+ if (!resolved) {
+ throw new Error(`Dynamic linking error: cannot resolve symbol ${prop}`);
+ }
return resolved.apply(null, arguments);
return resolved(...args);
};
}
--
2.25.1
2.34.1

87 changes: 87 additions & 0 deletions emsdk/patches/0003-Changes-for-JSPI.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
From d4d5d35072b6d28c5f98b77a0d578e01bd25ef7e Mon Sep 17 00:00:00 2001
From: Hood Chatham <[email protected]>
Date: Thu, 22 Jun 2023 18:53:22 -0700
Subject: [PATCH 3/6] Changes for JSPI

---
src/library.js | 2 +-
src/library_dylink.js | 3 ++-
src/parseTools.mjs | 2 +-
src/preamble.js | 7 +++++++
4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/library.js b/src/library.js
index 44531ee1d..f02e85ea2 100644
--- a/src/library.js
+++ b/src/library.js
@@ -1269,7 +1269,7 @@ addToLibrary({
#if EXCEPTION_STACK_TRACES
throw new EmscriptenSjLj;
#else
- throw Infinity;
+ throw Module.wrapException(Infinity);
#endif
},
#elif !SUPPORT_LONGJMP
diff --git a/src/library_dylink.js b/src/library_dylink.js
index cea3ce05d..c3f3c2bbf 100644
--- a/src/library_dylink.js
+++ b/src/library_dylink.js
@@ -73,6 +73,7 @@ var LibraryDylink = {
#if !DISABLE_EXCEPTION_CATCHING || SUPPORT_LONGJMP == 'emscripten'
$createInvokeFunction__internal: true,
$createInvokeFunction__deps: ['$dynCall', 'setThrew', '$stackSave', '$stackRestore'],
+ $createInvokeFunction__postset: "if(!Module.createInvoke) { Module.createInvoke = Module.createInvokeFunction; }",
$createInvokeFunction: (sig) => {
return function() {
var sp = stackSave();
@@ -125,7 +126,7 @@ var LibraryDylink = {
// Asm.js-style exception handling: invoke wrapper generation
else if (symName.startsWith('invoke_')) {
// Create (and cache) new invoke_ functions on demand.
- sym = wasmImports[symName] = createInvokeFunction(symName.split('_')[1]);
+ sym = wasmImports[symName] = Module.createInvoke(symName.split('_')[1]);
}
#endif
#if !DISABLE_EXCEPTION_CATCHING
diff --git a/src/parseTools.mjs b/src/parseTools.mjs
index 7f20321c3..118a32078 100644
--- a/src/parseTools.mjs
+++ b/src/parseTools.mjs
@@ -581,7 +581,7 @@ function makeThrow(excPtr) {
}
return `assert(false, '${assertInfo}');`;
}
- return `throw ${excPtr};`;
+ return `throw Module.wrapException(${excPtr});`;
}

function storeException(varName, excPtr) {
diff --git a/src/preamble.js b/src/preamble.js
index 18cf93959..57a7245ab 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -18,6 +18,10 @@
#include "runtime_pthread.js"
#endif

+if(!Module.wrapException) {
+ Module.wrapException = (e) => e;
+}
+
#if RELOCATABLE
{{{ makeModuleReceiveWithVar('dynamicLibraries', undefined, '[]', true) }}}
#endif
@@ -942,6 +946,9 @@ function getWasmImports() {
// Receives the wasm imports, returns the exports.
function createWasm() {
var info = getWasmImports();
+ if (Module.adjustWasmImports) {
+ Module.adjustWasmImports(info);
+ }
// Load the wasm module and create an instance of using native support in the JS engine.
// handle a generated wasm instance, receiving its exports and
// performing other necessary setup
--
2.34.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From 9352fac9a4618603fbe5ce7ad97a26a3963704bd Mon Sep 17 00:00:00 2001
From: Joe Marshall <[email protected]>
Date: Sat, 13 Apr 2024 21:41:11 +0100
Subject: [PATCH 4/6] Upstream PR:
https://github.com/emscripten-core/emscripten/pull/21759

---
src/library_dylink.js | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/src/library_dylink.js b/src/library_dylink.js
index c3f3c2bbf..e0fa4721c 100644
--- a/src/library_dylink.js
+++ b/src/library_dylink.js
@@ -93,6 +93,10 @@ var LibraryDylink = {
if (e !== e+0) throw e;
#endif
_setThrew(1, 0);
+ // In theory this if could be done on creating the function,
+ // but I just added this to save wasting code space
+ // and it only happens on an exception
+ if (sig[0] == "j") return 0n;
}
}
},
--
2.34.1

31 changes: 31 additions & 0 deletions emsdk/patches/0005-Raise-when-no-argument-is-given.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From 44983793a7f67009c228c5c95899f6fe735fd1c5 Mon Sep 17 00:00:00 2001
From: ryanking13 <[email protected]>
Date: Sat, 20 Jan 2024 19:02:32 +0900
Subject: [PATCH 5/6] Raise when no argument is given

Emscripten 3.1.51 does not raise an error when no argument is given.
Some build tools (e.g. ffmpeg) relies on this behavior, so we should
keep it.

Upstream issue: https://github.com/emscripten-core/emscripten/issues/21116
---
emcc.py | 3 +++
1 file changed, 3 insertions(+)

diff --git a/emcc.py b/emcc.py
index 6be37b217..a77f41c4a 100644
--- a/emcc.py
+++ b/emcc.py
@@ -628,6 +628,9 @@ There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR P
print(libname)
return 0

+ if not input_files and not state.link_flags:
+ exit_with_error('no input files')
+
if options.reproduce:
create_reproduce_file(options.reproduce, args)

--
2.34.1

35 changes: 35 additions & 0 deletions emsdk/patches/0006-Load-dependent-libs-globally.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From 2f3ae3b30cf8ce8cd04d512ebb4c8b2218563085 Mon Sep 17 00:00:00 2001
From: Hood Chatham <[email protected]>
Date: Mon, 17 Jun 2024 18:32:07 -0700
Subject: [PATCH 6/6] Load dependent libs globally

I'm not 100% sure why, but we need all dependent shared libs to be loaded
globally.
---
src/library_dylink.js | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/library_dylink.js b/src/library_dylink.js
index e0fa4721c..502bc7b25 100644
--- a/src/library_dylink.js
+++ b/src/library_dylink.js
@@ -880,11 +880,15 @@ var LibraryDylink = {

// now load needed libraries and the module itself.
if (flags.loadAsync) {
+ const origGlobal = flags.global;
+ flags.global = true;
return metadata.neededDynlibs
.reduce((chain, dynNeeded) => chain.then(() =>
loadDynamicLibrary(dynNeeded, flags)
), Promise.resolve())
- .then(loadModule);
+ .then(() => {
+ flags.global = origGlobal;
+ }).then(loadModule);
}

metadata.neededDynlibs.forEach((needed) => loadDynamicLibrary(needed, flags, localScope));
--
2.34.1

2 changes: 1 addition & 1 deletion src/js_timestamp.cpp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define PYJS_JS_UTC_TIMESTAMP "2024-03-19 09:56:38.004136"
#define PYJS_JS_UTC_TIMESTAMP "2024-08-01 08:54:38.482179"

0 comments on commit 24685a4

Please sign in to comment.