Skip to content

Commit 2d77f00

Browse files
authored
Merge branch 'main' into Add-c++23-kernel
2 parents e0a7edd + c805027 commit 2d77f00

File tree

9 files changed

+500
-41
lines changed

9 files changed

+500
-41
lines changed

.github/workflows/deploy-github-page.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,14 @@ jobs:
5757
5858
export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-cpp-wasm-host
5959
echo "PREFIX=$PREFIX" >> $GITHUB_ENV
60-
export CMAKE_PREFIX_PATH=$PREFIX
61-
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
60+
export SYSROOT_PATH=$HOME/emsdk/upstream/emscripten/cache/sysroot
6261
6362
emcmake cmake \
6463
-DCMAKE_BUILD_TYPE=Release \
65-
-DCMAKE_PREFIX_PATH=$PREFIX \
6664
-DCMAKE_INSTALL_PREFIX=$PREFIX \
6765
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
68-
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
66+
-DCMAKE_FIND_ROOT_PATH=$PREFIX \
67+
-DSYSROOT_PATH=$SYSROOT_PATH \
6968
..
7069
emmake make -j ${{ env.ncpus }} install
7170
@@ -74,11 +73,10 @@ jobs:
7473
run: |
7574
micromamba create -n xeus-lite-host jupyterlite-core
7675
micromamba activate xeus-lite-host
77-
python -m pip install jupyterlite-xeus
78-
jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }} --output-dir dist
79-
mkdir -p dist/files
80-
mv notebooks dist/files
81-
mv README.md dist/files
76+
python -m pip install jupyterlite-xeus jupyter_server notebook
77+
jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }} --contents notebooks/xeus-cpp-lite-demo.ipynb --output-dir dist
78+
cp $PREFIX/bin/xcpp.data dist/extensions/@jupyterlite/xeus/static
79+
cp $PREFIX/lib/libclangCppInterOp.so dist/extensions/@jupyterlite/xeus/static
8280
8381
- name: Upload artifact
8482
uses: actions/upload-pages-artifact@v3

.github/workflows/main.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,14 @@ jobs:
255255
256256
export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-cpp-wasm-host
257257
echo "PREFIX=$PREFIX" >> $GITHUB_ENV
258-
export CMAKE_PREFIX_PATH=$PREFIX
259-
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
258+
export SYSROOT_PATH=$HOME/emsdk/upstream/emscripten/cache/sysroot
260259
261260
emcmake cmake \
262261
-DCMAKE_BUILD_TYPE=Release \
263-
-DCMAKE_PREFIX_PATH=$PREFIX \
264262
-DCMAKE_INSTALL_PREFIX=$PREFIX \
265263
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
266-
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
264+
-DCMAKE_FIND_ROOT_PATH=$PREFIX \
265+
-DSYSROOT_PATH=$SYSROOT_PATH \
267266
..
268267
emmake make -j ${{ env.ncpus }} install
269268
@@ -274,6 +273,8 @@ jobs:
274273
micromamba activate xeus-lite-host
275274
python -m pip install jupyterlite-xeus
276275
jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }}
276+
cp $PREFIX/bin/xcpp.data _output/extensions/@jupyterlite/xeus/static
277+
cp $PREFIX/lib/libclangCppInterOp.so _output/extensions/@jupyterlite/xeus/static
277278
278279
- name: Setup tmate session
279280
if: ${{ failure() && runner.debug }}

CMakeLists.txt

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ if(EMSCRIPTEN)
8484
set(XEUS_CPP_USE_SHARED_XEUS_CPP OFF)
8585
set(XEUS_CPP_BUILD_TESTS OFF)
8686
# ENV (https://github.com/emscripten-core/emscripten/commit/6d9681ad04f60b41ef6345ab06c29bbc9eeb84e0)
87-
set(EMSCRIPTEN_FEATURES "${EMSCRIPTEN_FEATURES} -s \"EXTRA_EXPORTED_RUNTIME_METHODS=[ENV']\"")
87+
set(EMSCRIPTEN_FEATURES "${EMSCRIPTEN_FEATURES} -s \"EXPORTED_RUNTIME_METHODS=[ENV']\"")
8888
endif()
8989

9090
# Dependencies
9191
# ============
9292

9393
set(xeus_REQUIRED_VERSION 5.0.0)
9494
set(xeus_zmq_REQUIRED_VERSION 3.0.0)
95-
set(CppInterOp_REQUIRED_VERSION 1.4.0)
95+
set(CppInterOp_REQUIRED_VERSION 1.5.0)
9696

9797
if (NOT TARGET xeus AND NOT TARGET xeus-static)
9898
find_package(xeus ${xeus_REQUIRED_VERSION} REQUIRED)
@@ -103,10 +103,7 @@ endif ()
103103

104104
find_package(CppInterOp ${CppInterOp_REQUIRED_VERSION} REQUIRED)
105105
if(CppInterOp_FOUND)
106-
message(STATUS "Found CppInterOp: compatible with Clang ${CPPINTEROP_LLVM_VERSION_MAJOR}.x")
107-
# TODO : Fix after variables are set correctly
108-
# Check https://github.com/compiler-research/CppInterOp/pull/336
109-
# message(STATUS "Found CppInterOp: config=${CPPINTEROP_CONFIG} dir=${CPPINTEROP_DIR} (found version=${CPPINTEROP_VERSION} compatible with Clang ${CPPINTEROP_LLVM_VERSION_MAJOR}.x)")
106+
message(STATUS "Found CppInterOp: config=${CPPINTEROP_CMAKE_DIR} dir=${CPPINTEROP_INSTALL_PREFIX} (found version=${CPPINTEROP_VERSION} compatible with Clang ${CPPINTEROP_LLVM_VERSION_MAJOR}.x)")
110107
endif()
111108

112109
find_package(argparse REQUIRED)
@@ -152,9 +149,23 @@ function(configure_kernel kernel)
152149
endfunction()
153150

154151
message("Configure kernels: ...")
155-
configure_kernel("/share/jupyter/kernels/xcpp17/")
156-
configure_kernel("/share/jupyter/kernels/xcpp20/")
157-
configure_kernel("/share/jupyter/kernels/xcpp23/")
152+
if(EMSCRIPTEN)
153+
# TODO: Currently jupyterlite-xeus and xeus-lite do not provide
154+
# methods to fetch information from the arguments present in the
155+
# generated emscripten kernel.
156+
# The following needs to be done here :
157+
# 1) We need to configure the kernel properly
158+
# Check issue https://github.com/compiler-research/xeus-cpp/issues/185.
159+
# 2) Once the above is done we need to add support in jupyterlite-xeus & xeus-lite
160+
# to be able to deal with arguments present in kernel.json
161+
# 3) Finally we should fetch the C++ version from the kernel.json file and
162+
# be able to pass it to our wasm interpreter rather than forcing a version.
163+
configure_kernel("/share/jupyter/kernels/xcpp20/")
164+
else()
165+
configure_kernel("/share/jupyter/kernels/xcpp17/")
166+
configure_kernel("/share/jupyter/kernels/xcpp20/")
167+
configure_kernel("/share/jupyter/kernels/xcpp23/")
168+
endif()
158169

159170
# Source files
160171
# ============
@@ -402,8 +413,24 @@ if(EMSCRIPTEN)
402413
xeus_cpp_set_kernel_options(xcpp)
403414
xeus_wasm_compile_options(xcpp)
404415
xeus_wasm_link_options(xcpp "web,worker")
416+
# TODO: Remove the exported runtime methods
417+
# after the next xeus release.
418+
target_link_options(xcpp PUBLIC
419+
-sEXPORTED_RUNTIME_METHODS=FS,PATH,ERRNO_CODES
420+
# add sysroot location here
421+
--preload-file ${SYSROOT_PATH}/include@/include
422+
)
423+
# TODO: Emscripten supports preloading files just once before it generates
424+
# the xcpp.data file (containing the binary representation of the file(s) we
425+
# want to include in our application).
426+
# Hence although we are adding support for Standard Headers, Libraries etc
427+
# through emscripten's sysroot for now, we need to do the following:
428+
# 1) Enable CppInterOp to provide us with a resource dir.
429+
# 2) If the above cannot be done, we can use the resource dir provided
430+
# by llvm on emscripten-forge but would involve adding a dependency.
431+
# 3) Shift the resource dir and the sysroot to a common location.
432+
# 4) Preload everything required together.
405433
endif()
406-
407434
# Tests
408435
# =====
409436

@@ -493,6 +520,7 @@ if(EMSCRIPTEN)
493520
install(FILES
494521
"$<TARGET_FILE_DIR:xcpp>/xcpp.js"
495522
"$<TARGET_FILE_DIR:xcpp>/xcpp.wasm"
523+
"$<TARGET_FILE_DIR:xcpp>/xcpp.data"
496524
DESTINATION ${CMAKE_INSTALL_BINDIR})
497525
endif ()
498526

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,14 @@ micromamba create -f environment-wasm-host.yml --platform=emscripten-wasm32
8585
mkdir build
8686
pushd build
8787
export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-cpp-wasm-host
88-
export CMAKE_PREFIX_PATH=$PREFIX
89-
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
88+
export SYSROOT_PATH=$HOME/emsdk/upstream/emscripten/cache/sysroot
9089

9190
emcmake cmake \
9291
-DCMAKE_BUILD_TYPE=Release \
93-
-DCMAKE_PREFIX_PATH=$PREFIX \
9492
-DCMAKE_INSTALL_PREFIX=$PREFIX \
9593
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
96-
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
94+
-DCMAKE_FIND_ROOT_PATH=$PREFIX \
95+
-DSYSROOT_PATH=$SYSROOT_PATH \
9796
..
9897
emmake make install
9998
```
@@ -105,12 +104,20 @@ micromamba activate xeus-lite-host
105104
python -m pip install jupyterlite-xeus
106105
jupyter lite build --XeusAddon.prefix=$PREFIX
107106
```
107+
108+
We now need to shift necessary files like `xcpp.data` which contains the binary representation of the file(s)
109+
we want to include in our application. As of now this would contain all important files like Standard Headers,
110+
Libraries etc coming out of emscripten's sysroot. Assuming we are still inside build we should do the following
111+
```bash
112+
cp $PREFIX/bin/xcpp.data _output/extensions/@jupyterlite/xeus/static
113+
cp $PREFIX/lib/libclangCppInterOp.so _output/extensions/@jupyterlite/xeus/static
114+
```
115+
108116
Once the Jupyter Lite site has built you can test the website locally by executing
109117
```bash
110118
jupyter lite serve --XeusAddon.prefix=$PREFIX
111119
```
112120

113-
114121
## Trying it online
115122

116123
To try out xeus-cpp interactively in your web browser, just click on the binder link:
@@ -135,7 +142,7 @@ http://xeus-cpp.readthedocs.io
135142

136143
| `xeus-cpp` | `xeus-zmq` | `CppInterOp` | `pugixml` | `cpp-argparse`| `nlohmann_json` |
137144
|------------|-----------------|--------------|-----------|---------------|-----------------|
138-
| main | >=3.0.0,<4.0.0 | >=1.4.0 | ~1.8.1 | <3.1 | >=3.11.3,<4.0 |
145+
| main | >=3.0.0,<4.0.0 | >=1.5.0 | ~1.8.1 | <3.1 | >=3.11.3,<4.0 |
139146
| 0.5.0 | >=3.0.0,<4.0.0 | >=1.3.0 | ~1.8.1 | <3.1 | >=3.11.3,<4.0 |
140147

141148
Versions prior to `0.5.0` have an additional dependency on [xtl](https://github.com/xtensor-stack/xtl), [clang](https://github.com/llvm/llvm-project/) & [cppzmq](https://github.com/zeromq/cppzmq)

docs/source/InstallationAndUsage.rst

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Installation And Usage
22
--------------------
33

4-
Installation from source
4+
Installation from source (non wasm build instructions)
55
========================
66

77
To ensure that the installation works, it is preferable to install `xeus-cpp` in a
@@ -42,6 +42,65 @@ with a custom installation prefix if need be)
4242
-D CMAKE_INSTALL_LIBDIR=lib
4343
make && make install
4444
45+
Installation within a mamba environment (wasm build instructions)
46+
========================
47+
48+
These instructions will assume you have cmake installed on your system. First clone the repository, and move into that directory
49+
.. code-block:: bash
50+
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
51+
cd ./xeus-cpp
52+
53+
54+
You'll now want to make sure you're using emsdk version "3.1.45" and activate it. You can get this by executing the following
55+
56+
.. code-block:: bash
57+
cd $HOME
58+
git clone https://github.com/emscripten-core/emsdk.git
59+
cd emsdk
60+
./emsdk install 3.1.45
61+
./emsdk activate 3.1.45
62+
source $HOME/emsdk/emsdk_env.sh
63+
64+
65+
You are now in a position to build the xeus-cpp kernel. You build it by executing the following
66+
67+
.. code-block:: bash
68+
micromamba create -f environment-wasm-host.yml --platform=emscripten-wasm32
69+
mkdir build
70+
pushd build
71+
export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-cpp-wasm-host
72+
export SYSROOT_PATH=$HOME/emsdk/upstream/emscripten/cache/sysroot
73+
emcmake cmake \
74+
-DCMAKE_BUILD_TYPE=Release \
75+
-DCMAKE_INSTALL_PREFIX=$PREFIX \
76+
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
77+
-DCMAKE_FIND_ROOT_PATH=$PREFIX \
78+
-DSYSROOT_PATH=$SYSROOT_PATH \
79+
..
80+
emmake make install
81+
82+
83+
To build Jupyter Lite with this kernel without creating a website you can execute the following
84+
85+
.. code-block:: bash
86+
micromamba create -n xeus-lite-host jupyterlite-core
87+
micromamba activate xeus-lite-host
88+
python -m pip install jupyterlite-xeus
89+
jupyter lite build --XeusAddon.prefix=$PREFIX
90+
91+
We now need to shift necessary files like `xcpp.data` which contains the binary representation of the file(s)
92+
we want to include in our application. As of now this would contain all important files like Standard Headers,
93+
Libraries etc coming out of emscripten's sysroot. Assuming we are still inside build we should do the following
94+
95+
.. code-block:: bash
96+
cp $PREFIX/bin/xcpp.data _output/extensions/@jupyterlite/xeus/static
97+
cp $PREFIX/lib/libclangCppInterOp.so _output/extensions/@jupyterlite/xeus/static
98+
99+
Once the Jupyter Lite site has built you can test the website locally by executing
100+
101+
.. code-block:: bash
102+
jupyter lite serve --XeusAddon.prefix=$PREFIX
103+
45104
Installing from conda-forge
46105
===========================
47106

@@ -51,4 +110,4 @@ If you have conda installed then you can install xeus-cpp using the follwing com
51110
52111
conda install conda-forge::xeus-cpp
53112
54-
Xeus-cpp is available for Linux, MacOS and Windows.
113+
Xeus-cpp is available for Linux, MacOS and Windows.

environment-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies:
1010
- xeus>=5.0.0
1111
- xeus-zmq>=3.0,<4.0
1212
- nlohmann_json=3.11.3
13-
- CppInterOp>=1.4.0
13+
- CppInterOp>=1.5.0
1414
- pugixml
1515
- cpp-argparse <3.1
1616
- zlib

environment-wasm-host.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ dependencies:
66
- nlohmann_json
77
- xeus-lite
88
- xeus
9-
- CppInterOp>=1.4.0
9+
- CppInterOp>=1.5.0
1010
- cpp-argparse
1111
- pugixml

0 commit comments

Comments
 (0)