From 163e6ec14b9ddba9232d2c1a3159e0d8870c6ebc Mon Sep 17 00:00:00 2001 From: Thorsten Beier Date: Tue, 19 Sep 2023 10:01:52 +0200 Subject: [PATCH] using -fexception instead of fwasm-exception (#48) --- CMakeLists.txt | 12 ++++++--- include/pyjs/post_js/fixes.js | 7 +++-- include/pyjs/pre_js/load_pkg.js | 45 ++++++++++++++++++++++----------- src/js_timestamp.cpp | 2 +- 4 files changed, 44 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae5caf5..4b84e1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,14 +140,16 @@ target_link_libraries(pyjs PRIVATE ${PYTHON_UTIL_LIBS} pybind11::embed) PUBLIC --std=c++17 PUBLIC -Wno-deprecated PUBLIC "SHELL: --bind" - PUBLIC "SHELL: -fwasm-exceptions" + PUBLIC "SHELL: -fexceptions" ) target_link_options(pyjs PUBLIC --bind PUBLIC -Wno-unused-command-line-argument PUBLIC "SHELL: --bind" - PUBLIC "SHELL: -fwasm-exceptions" + 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']" ) @@ -213,7 +215,8 @@ target_compile_options(pyjs_runtime_browser PUBLIC -Wno-deprecated PUBLIC "SHELL: --bind" PUBLIC "SHELL: -s ENVIRONMENT=${ENVIRONMENT}" - PUBLIC "SHELL: -fwasm-exceptions" + PUBLIC "SHELL: -fexceptions" + #PUBLIC "SHELL:-s EXPORT_EXCEPTION_HANDLING_HELPERS" PUBLIC "SHELL: -s FORCE_FILESYSTEM" PUBLIC "SHELL: -s LZ4=1" PUBLIC "SHELL: -flto" @@ -234,7 +237,8 @@ target_link_options(pyjs_runtime_browser PUBLIC "SHELL: -s EXIT_RUNTIME=1" PUBLIC "SHELL: -s WASM=1" PUBLIC "SHELL: -s USE_PTHREADS=0" - PUBLIC "SHELL: -fwasm-exceptions" + PUBLIC "SHELL: -s ENVIRONMENT=${ENVIRONMENT}" + PUBLIC "SHELL: -fexceptions" PUBLIC "SHELL: -s MAIN_MODULE=1" PUBLIC "SHELL: -s ENVIRONMENT=${ENVIRONMENT}" PUBLIC "SHELL: -s TOTAL_STACK=16mb" diff --git a/include/pyjs/post_js/fixes.js b/include/pyjs/post_js/fixes.js index f17dbf6..3260295 100644 --- a/include/pyjs/post_js/fixes.js +++ b/include/pyjs/post_js/fixes.js @@ -2,5 +2,8 @@ if (!('wasmTable' in Module)) { Module['wasmTable'] = wasmTable } - -Module['FS'] = FS \ No newline at end of file +Module['FS'] = FS +Module['PATH'] = PATH +Module['LDSO'] = LDSO +Module['getDylinkMetadata'] = getDylinkMetadata +Module['loadDynamicLibrary'] = loadDynamicLibrary diff --git a/include/pyjs/pre_js/load_pkg.js b/include/pyjs/pre_js/load_pkg.js index 584126a..504bac0 100644 --- a/include/pyjs/pre_js/load_pkg.js +++ b/include/pyjs/pre_js/load_pkg.js @@ -28,6 +28,13 @@ import shutil import os import sys + +def check_wasm_magic_number(file_path: Path) -> bool: + WASM_BINARY_MAGIC = b"\\0asm" + with file_path.open(mode="rb") as file: + return file.read(4) == WASM_BINARY_MAGIC + + target_dir = "${target_dir}" if target_dir == "": target_dir = sys.prefix @@ -44,6 +51,11 @@ try: shared_libs.append(f"{target_dir}/{file.name}") tar.extractall(target_dir) + for file in shared_libs: + if not check_wasm_magic_number(Path(file)): + print(f" {file} is not a wasm file") + else: + print(f" {file} is a wasm file") s = json.dumps(shared_libs) except Exception as e: print("ERROR",e) @@ -84,7 +96,8 @@ Module["bootstrap_from_empack_packed_environment"] = async function ( packages_json_url, package_tarballs_root_url, - verbose = false + verbose = false, + skip_loading_shared_libs = true ) { @@ -153,22 +166,24 @@ Module["bootstrap_from_empack_packed_environment"] = async function // create array with size let shared_libs = await Promise.all(packages.map(package => fetchAndUntar(package_tarballs_root_url, python_is_ready_promise, package))) - // instantiate all packages - for (let i = 0; i < packages.length; i++) { - - // if we have any shared libraries, load them - if (shared_libs[i].length > 0) { + if(!skip_loading_shared_libs){ + // instantiate all packages + for (let i = 0; i < packages.length; i++) { - for (let j = 0; j < shared_libs[i].length; j++) { - let sl = shared_libs[i][j]; + // if we have any shared libraries, load them + if (shared_libs[i].length > 0) { + + for (let j = 0; j < shared_libs[i].length; j++) { + let sl = shared_libs[i][j]; + } + await Module._loadDynlibsFromPackage( + prefix, + python_version, + packages[i].name, + false, + shared_libs[i] + ) } - await Module._loadDynlibsFromPackage( - prefix, - python_version, - packages[i].name, - false, - shared_libs[i] - ) } } } \ No newline at end of file diff --git a/src/js_timestamp.cpp b/src/js_timestamp.cpp index 19a11ee..a17eeda 100644 --- a/src/js_timestamp.cpp +++ b/src/js_timestamp.cpp @@ -1 +1 @@ -#define PYJS_JS_UTC_TIMESTAMP "2023-09-05 07:59:30.761501" \ No newline at end of file +#define PYJS_JS_UTC_TIMESTAMP "2023-09-12 06:47:21.229070" \ No newline at end of file