Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify needed shared libs in wasm kernel spec #221

Merged
merged 6 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .github/workflows/deploy-github-page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is notebook really required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really but I think was added earlier by a contributor as an alternative to lab, hence the change is present there. Keeping it for now and can be removed subsequently if not adding value.

Copy link

@martinRenou martinRenou Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as an alternative to lab

Installing notebook will have no impact on this concerning JupyterLite.

It's the jupyter lite build --apps notebook --apps lab which impacts which kinds of UIs are installed.

JupyterLite already defaults to providing the notebook UI actually, you'll only need to point to a different URL. e.g. for xeus-r you can go on https://jupyter-xeus.github.io/xeus-r/tree instead of https://jupyter-xeus.github.io/xeus-r/lab

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh okay wow, I didn't know we could frame the url like this. Getting rid of it !

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
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
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines -279 to -280

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to see this being removed :D


- name: Setup tmate session
if: ${{ failure() && runner.debug }}
Expand Down
36 changes: 28 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -148,6 +148,26 @@ function(configure_kernel kernel)
COPYONLY)
endfunction()

function(configure_wasm_kernel kernel)

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
Expand All @@ -160,10 +180,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
Expand Down Expand Up @@ -414,10 +434,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
Expand Down
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions share/jupyter/kernels/xcpp20/wasm_kernel.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"display_name": "C++20",
"argv": [
"@XEUS_CPP_KERNELSPEC_PATH@xcpp",
"-f",
"{connection_file}",
"-std=c++20"
],
"language": "cpp",
"metadata": {
"debugger": false,
"shared": {
"libclangCppInterOp.so": "lib/libclangCppInterOp.so"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏽

}
}
}
12 changes: 12 additions & 0 deletions wasm_patches/post.js
Original file line number Diff line number Diff line change
@@ -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;