From 308d50b84de4d92b61e3bfbd990ea88895bb6a8d Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Wed, 15 Jan 2025 12:17:22 +0530 Subject: [PATCH 1/5] 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 From 72ac4b46af27599e2aff88231a5892a9f8b2e078 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Wed, 15 Jan 2025 12:50:13 +0530 Subject: [PATCH 2/5] Specify needed shared libs in wasm kernel spec --- .github/workflows/deploy-github-page.yml | 2 -- .github/workflows/main.yml | 2 -- CMakeLists.txt | 32 ++++++++++++++++--- README.md | 8 ----- .../kernels/xcpp20/wasm_kernel.json.in | 22 +++++++++++++ 5 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 share/jupyter/kernels/xcpp20/wasm_kernel.json.in diff --git a/.github/workflows/deploy-github-page.yml b/.github/workflows/deploy-github-page.yml index ed063653..a2bc89ff 100644 --- a/.github/workflows/deploy-github-page.yml +++ b/.github/workflows/deploy-github-page.yml @@ -75,8 +75,6 @@ jobs: micromamba activate xeus-lite-host python -m pip install jupyterlite-xeus jupyter_server notebook jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }} --contents notebooks/xeus-cpp-lite-demo.ipynb --output-dir dist - cp $PREFIX/bin/xcpp.data dist/extensions/@jupyterlite/xeus/static - cp $PREFIX/lib/libclangCppInterOp.so dist/extensions/@jupyterlite/xeus/static - name: Upload artifact uses: actions/upload-pages-artifact@v3 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6ee31bfb..fd0ebf8c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -276,8 +276,6 @@ jobs: micromamba activate xeus-lite-host python -m pip install jupyterlite-xeus jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }} - cp $PREFIX/bin/xcpp.data _output/extensions/@jupyterlite/xeus/static - cp $PREFIX/lib/libclangCppInterOp.so _output/extensions/@jupyterlite/xeus/static - name: Setup tmate session if: ${{ failure() && runner.debug }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 57066a80..1ad2265d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,7 +116,7 @@ if (NOT DEFINED XEUS_CPP_KERNELSPEC_PATH) set(XEUS_CPP_KERNELSPEC_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/") endif () -function(configure_kernel kernel) +function(configure_native_kernel kernel) set(XEUS_CPP_PATH "$ENV{PATH}") set(XEUS_CPP_LD_LIBRARY_PATH "$ENV{LD_LIBRARY_PATH}") set(XEUS_CPP_RESOURCE_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/clang/${CPPINTEROP_LLVM_VERSION_MAJOR}) @@ -148,6 +148,30 @@ function(configure_kernel kernel) COPYONLY) endfunction() +function(configure_wasm_kernel kernel) + set(XEUS_CPP_PATH "$ENV{PATH}") + set(XEUS_CPP_LD_LIBRARY_PATH "$ENV{LD_LIBRARY_PATH}") + set(XEUS_CPP_RESOURCE_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/clang/${CPPINTEROP_LLVM_VERSION_MAJOR}) + set(XEUS_CPP_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include) + + configure_file ( + "${CMAKE_CURRENT_SOURCE_DIR}${kernel}wasm_kernel.json.in" + "${CMAKE_CURRENT_BINARY_DIR}${kernel}kernel.json") + + configure_file ( + "${CMAKE_CURRENT_SOURCE_DIR}${kernel}logo-32x32.png" + "${CMAKE_CURRENT_BINARY_DIR}${kernel}" + COPYONLY) + configure_file ( + "${CMAKE_CURRENT_SOURCE_DIR}${kernel}logo-64x64.png" + "${CMAKE_CURRENT_BINARY_DIR}${kernel}" + COPYONLY) + configure_file ( + "${CMAKE_CURRENT_SOURCE_DIR}${kernel}logo-svg.svg" + "${CMAKE_CURRENT_BINARY_DIR}${kernel}" + COPYONLY) +endfunction() + message("Configure kernels: ...") if(EMSCRIPTEN) # TODO: Currently jupyterlite-xeus and xeus-lite do not provide @@ -160,10 +184,10 @@ if(EMSCRIPTEN) # to be able to deal with arguments present in kernel.json # 3) Finally we should fetch the C++ version from the kernel.json file and # be able to pass it to our wasm interpreter rather than forcing a version. - configure_kernel("/share/jupyter/kernels/xcpp20/") + configure_wasm_kernel("/share/jupyter/kernels/xcpp20/") else() - configure_kernel("/share/jupyter/kernels/xcpp17/") - configure_kernel("/share/jupyter/kernels/xcpp20/") + configure_native_kernel("/share/jupyter/kernels/xcpp17/") + configure_native_kernel("/share/jupyter/kernels/xcpp20/") endif() # Source files diff --git a/README.md b/README.md index bb143784..c987a379 100644 --- a/README.md +++ b/README.md @@ -105,14 +105,6 @@ python -m pip install jupyterlite-xeus jupyter lite build --XeusAddon.prefix=$PREFIX ``` -We now need to shift necessary files like `xcpp.data` which contains the binary representation of the file(s) -we want to include in our application. As of now this would contain all important files like Standard Headers, -Libraries etc coming out of emscripten's sysroot. Assuming we are still inside build we should do the following -```bash -cp $PREFIX/bin/xcpp.data _output/extensions/@jupyterlite/xeus/static -cp $PREFIX/lib/libclangCppInterOp.so _output/extensions/@jupyterlite/xeus/static -``` - Once the Jupyter Lite site has built you can test the website locally by executing ```bash jupyter lite serve --XeusAddon.prefix=$PREFIX diff --git a/share/jupyter/kernels/xcpp20/wasm_kernel.json.in b/share/jupyter/kernels/xcpp20/wasm_kernel.json.in new file mode 100644 index 00000000..c3ed8847 --- /dev/null +++ b/share/jupyter/kernels/xcpp20/wasm_kernel.json.in @@ -0,0 +1,22 @@ +{ + "display_name": "C++20", + "env": { + "PATH":"@XEUS_CPP_PATH@", + "LD_LIBRARY_PATH":"@XEUS_CPP_LD_LIBRARY_PATH@" + }, + "argv": [ + "@XEUS_CPP_KERNELSPEC_PATH@xcpp", + "-f", + "{connection_file}", + "-resource-dir", "@XEUS_CPP_RESOURCE_DIR@", + "-I", "@XEUS_CPP_INCLUDE_DIR@", + "-std=c++20" + ], + "language": "cpp", + "metadata": { + "debugger": false, + "shared": { + "libclangCppInterOp.so": "lib/libclangCppInterOp.so" + } + } +} From ab3de9de3b75dbbf0a2fc0cd191e561aeb7734fe Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Wed, 15 Jan 2025 14:15:47 +0530 Subject: [PATCH 3/5] Remove unnecessary stuff from wasm kernel --- CMakeLists.txt | 4 ---- share/jupyter/kernels/xcpp20/wasm_kernel.json.in | 6 ------ 2 files changed, 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ad2265d..0a9248a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,10 +149,6 @@ function(configure_native_kernel kernel) endfunction() function(configure_wasm_kernel kernel) - set(XEUS_CPP_PATH "$ENV{PATH}") - set(XEUS_CPP_LD_LIBRARY_PATH "$ENV{LD_LIBRARY_PATH}") - set(XEUS_CPP_RESOURCE_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/clang/${CPPINTEROP_LLVM_VERSION_MAJOR}) - set(XEUS_CPP_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include) configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}${kernel}wasm_kernel.json.in" diff --git a/share/jupyter/kernels/xcpp20/wasm_kernel.json.in b/share/jupyter/kernels/xcpp20/wasm_kernel.json.in index c3ed8847..697e46a9 100644 --- a/share/jupyter/kernels/xcpp20/wasm_kernel.json.in +++ b/share/jupyter/kernels/xcpp20/wasm_kernel.json.in @@ -1,15 +1,9 @@ { "display_name": "C++20", - "env": { - "PATH":"@XEUS_CPP_PATH@", - "LD_LIBRARY_PATH":"@XEUS_CPP_LD_LIBRARY_PATH@" - }, "argv": [ "@XEUS_CPP_KERNELSPEC_PATH@xcpp", "-f", "{connection_file}", - "-resource-dir", "@XEUS_CPP_RESOURCE_DIR@", - "-I", "@XEUS_CPP_INCLUDE_DIR@", "-std=c++20" ], "language": "cpp", From cfd76cad12557351fb8aafa5c03aca93d6077c01 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 16 Jan 2025 10:19:18 +0530 Subject: [PATCH 4/5] update deploy pages --- .github/workflows/deploy-github-page.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-github-page.yml b/.github/workflows/deploy-github-page.yml index a2bc89ff..6819acfc 100644 --- a/.github/workflows/deploy-github-page.yml +++ b/.github/workflows/deploy-github-page.yml @@ -71,10 +71,14 @@ jobs: - name: Jupyter Lite integration shell: bash -l {0} run: | - micromamba create -n xeus-lite-host jupyterlite-core + micromamba create -n xeus-lite-host jupyterlite-core jupyter_server notebook micromamba activate xeus-lite-host - python -m pip install jupyterlite-xeus jupyter_server notebook - jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }} --contents notebooks/xeus-cpp-lite-demo.ipynb --output-dir dist + python -m pip install jupyterlite-xeus + jupyter lite build \ + --XeusAddon.prefix=${{ env.PREFIX }} \ + --contents README.md \ + --contents notebooks/xeus-cpp-lite-demo.ipynb \ + --output-dir dist - name: Upload artifact uses: actions/upload-pages-artifact@v3 From b9db408071ebcf19e2904c527195b103e1b4f225 Mon Sep 17 00:00:00 2001 From: Anutosh Bhat Date: Thu, 16 Jan 2025 14:28:47 +0530 Subject: [PATCH 5/5] Update deploy-github-page.yml --- .github/workflows/deploy-github-page.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-github-page.yml b/.github/workflows/deploy-github-page.yml index 6819acfc..1bfca783 100644 --- a/.github/workflows/deploy-github-page.yml +++ b/.github/workflows/deploy-github-page.yml @@ -71,7 +71,7 @@ jobs: - name: Jupyter Lite integration shell: bash -l {0} run: | - micromamba create -n xeus-lite-host jupyterlite-core jupyter_server notebook + micromamba create -n xeus-lite-host jupyterlite-core jupyter_server micromamba activate xeus-lite-host python -m pip install jupyterlite-xeus jupyter lite build \