From 308d50b84de4d92b61e3bfbd990ea88895bb6a8d Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Wed, 15 Jan 2025 12:17:22 +0530 Subject: [PATCH] Add post.js to include missing Emscripten APIs --- CMakeLists.txt | 8 ++++---- wasm_patches/post.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 wasm_patches/post.js diff --git a/CMakeLists.txt b/CMakeLists.txt index fd777a74..57066a80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -414,10 +414,10 @@ if(EMSCRIPTEN) xeus_wasm_link_options(xcpp "web,worker") # TODO: Remove the exported runtime methods # after the next xeus release. - target_link_options(xcpp PUBLIC - -sEXPORTED_RUNTIME_METHODS=FS,PATH,ERRNO_CODES - # add sysroot location here - --preload-file ${SYSROOT_PATH}/include@/include + target_link_options(xcpp + PUBLIC "SHELL: -s EXPORTED_RUNTIME_METHODS='[\"FS\",\"PATH\",\"LDSO\",\"loadDynamicLibrary\",\"ERRNO_CODES\"]'" + PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include" + PUBLIC "SHELL: --post-js ${CMAKE_CURRENT_SOURCE_DIR}/wasm_patches/post.js" ) # TODO: Emscripten supports preloading files just once before it generates # the xcpp.data file (containing the binary representation of the file(s) we diff --git a/wasm_patches/post.js b/wasm_patches/post.js new file mode 100644 index 00000000..8c0acd1b --- /dev/null +++ b/wasm_patches/post.js @@ -0,0 +1,12 @@ +if (!('wasmTable' in Module)) { + Module.wasmTable = wasmTable +} + +Module.FS = FS +Module.PATH = PATH +Module.LDSO = LDSO +Module.getDylinkMetadata = getDylinkMetadata +Module.loadDynamicLibrary = loadDynamicLibrary + +Module.UTF8ToString = UTF8ToString; +Module.ERRNO_CODES = ERRNO_CODES; \ No newline at end of file