@@ -19,34 +19,34 @@ cd ./CppInterOp-wasm
1919```
2020
2121To create a wasm build of CppInterOp we make use of the emsdk toolchain. This can be installed by executing (we only currently
22- support version 3.1.73 )
22+ support version 4.0.9 )
2323``` bash
2424git clone https://github.com/emscripten-core/emsdk.git
25- ./emsdk/emsdk install 3.1.73
25+ ./emsdk/emsdk install 4.0.9
2626```
2727
2828and to activate the emsdk environment on Linux and osx execute (we are defining SYSROOT_PATH for use later)
2929
3030``` bash
31- ./emsdk/emsdk activate 3.1.73
31+ ./emsdk/emsdk activate 4.0.9
3232source ./emsdk/emsdk_env.sh
3333export SYSROOT_PATH=$PWD /emsdk/upstream/emscripten/cache/sysroot
3434```
3535
3636and on Windows execute in Powershell
3737
3838``` powershell
39- .\emsdk\emsdk activate 3.1.73
39+ .\emsdk\emsdk activate 4.0.9
4040.\emsdk\emsdk_env.ps1
4141$env:PWD_DIR= $PWD.Path
4242$env:SYSROOT_PATH="$env:EMSDK/upstream/emscripten/cache/sysroot"
4343```
4444
45- Now clone the 20 .x release of the LLVM project repository and CppInterOp (the building of the emscripten version of llvm can be
45+ Now clone the 21 .x release of the LLVM project repository and CppInterOp (the building of the emscripten version of llvm can be
4646avoided by executing micromamba install llvm -c < https://repo.mamba.pm/emscripten-forge > and setting the LLVM_BUILD_DIR/$env: LLVM_BUILD_DIR appropriately)
4747
4848``` bash
49- git clone --depth=1 --branch release/20 .x https://github.com/llvm/llvm-project.git
49+ git clone --depth=1 --branch release/21 .x https://github.com/llvm/llvm-project.git
5050git clone --depth=1 https://github.com/compiler-research/CppInterOp.git
5151```
5252
@@ -55,16 +55,17 @@ executing
5555
5656``` bash
5757cd ./llvm-project/
58- git apply -v ../CppInterOp/patches/llvm/emscripten-clang20 -* .patch
58+ git apply -v ../CppInterOp/patches/llvm/emscripten-clang21 -* .patch
5959```
6060
6161On Windows execute the following
6262
6363``` powershell
6464cd .\llvm-project\
65- cp -r ..\patches\llvm\emscripten-clang20*
66- git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
67- git apply -v emscripten-clang20-3-enable_exception_handling.patch
65+ cp -r ..\patches\llvm\emscripten-clang21*
66+ git apply -v emscripten-clang21-1-shift-temporary-files-to-tmp-dir.patch
67+ git apply -v emscripten-clang21-2-enable_exception_handling.patch
68+ git apply -v emscripten-clang21-3-webassembly_target_machine_reordering.patch
6869```
6970
7071We are now in a position to build an emscripten build of llvm by executing the following on Linux
@@ -101,9 +102,7 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release \
101102 -DCMAKE_CXX_FLAGS_RELEASE=" -Oz -g0 -DNDEBUG" \
102103 -DLLVM_ENABLE_LTO=Full \
103104 ../llvm
104- emmake make libclang -j $( nproc --all)
105- emmake make clangInterpreter clangStaticAnalyzerCore -j $( nproc --all)
106- emmake make lldWasm -j $( nproc --all)
105+ EMCC_CFLAGS=" -sSUPPORT_LONGJMP=wasm -fwasm-exceptions" emmake make libclang clangInterpreter clangStaticAnalyzerCore -j $( nproc --all)
107106```
108107
109108or executing
@@ -142,7 +141,9 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release `
142141 -DCMAKE_CXX_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" `
143142 -DLLVM_ENABLE_LTO=Full `
144143 ..\llvm
145- emmake ninja libclang clangInterpreter clangStaticAnalyzerCore lldWasm
144+ $env:EMCC_CFLAGS="-sSUPPORT_LONGJMP=wasm -fwasm-exceptions"
145+ emmake ninja libclang clangInterpreter clangStaticAnalyzerCore
146+ $env:EMCC_CFLAGS=""
146147```
147148
148149on Windows. Once this finishes building we need to take note of where we built our llvm build. This can be done by executing the following on Linux and osx
@@ -163,7 +164,7 @@ by executing (assumes you have micromamba installed and that your shell is initi
163164
164165``` bash
165166cd ../../CppInterOp/
166- micromamba create -f environment-wasm.yml --platform=emscripten-wasm32
167+ micromamba create -f environment-wasm.yml --platform=emscripten-wasm32 -c https://prefix.dev/emscripten-forge-4x -c https://prefix.dev/conda-forge
167168micromamba activate CppInterOp-wasm
168169```
169170
@@ -178,7 +179,7 @@ export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
178179and
179180
180181``` powershell
181- $env:PREFIX="%CONDA_PREFIX% /envs/CppInterOp-wasm"
182+ $env:PREFIX="$env:MAMBA_ROOT_PREFIX /envs/CppInterOp-wasm"
182183$env:CMAKE_PREFIX_PATH=$env:PREFIX
183184$env:CMAKE_SYSTEM_PREFIX_PATH=$env:PREFIX
184185```
@@ -337,13 +338,13 @@ emmake make -j $(nproc --all) install
337338## Xeus-cpp-lite Wasm Build Instructions
338339
339340A project which makes use of the wasm build of CppInterOp is xeus-cpp. xeus-cpp is a C++ Jupyter kernel. Assuming you are in
340- the CppInterOp build folder, you can build the wasm version of xeus-cpp by executing (replace LLVM_VERSION with the version
341+ the CppInterOp build folder, you can build the wasm version of xeus-cpp on Linux/MacOS by executing (replace LLVM_VERSION with the version
341342of llvm you are building against)
342343
343344``` bash
344345cd ../..
345346git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
346- export LLVM_VERSION=20
347+ export LLVM_VERSION=21
347348cd ./xeus-cpp
348349mkdir build
349350cd build
@@ -356,20 +357,58 @@ emcmake cmake \
356357 -DXEUS_CPP_RESOURCE_DIR=" $LLVM_BUILD_DIR /lib/clang/$LLVM_VERSION " \
357358 -DSYSROOT_PATH=$SYSROOT_PATH \
358359 ..
359- emmake make -j $( nproc --all) install
360+ EMCC_CFLAGS= " -sSUPPORT_LONGJMP=wasm -fwasm-exceptions " emmake make -j $( nproc --all) install
360361```
361362
362- To build and test Jupyter Lite with this kernel locally you can execute the following
363+ and on Windows by executing
364+
365+ ``` powershell
366+ cd ..\..
367+ git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
368+ $env:LLVM_VERSION=21
369+ cd .\xeus-cpp
370+ mkdir build
371+ cd build
372+ emcmake cmake `
373+ -DCMAKE_BUILD_TYPE=Release `
374+ -DCMAKE_PREFIX_PATH="$env:PREFIX" `
375+ -DCMAKE_INSTALL_PREFIX="$env:PREFIX" `
376+ -DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON `
377+ -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON `
378+ -DXEUS_CPP_RESOURCE_DIR="$env:LLVM_BUILD_DIR/lib/clang/$env:LLVM_VERSION" `
379+ -DSYSROOT_PATH="$env:SYSROOT_PATH" `
380+ ..
381+ $env:EMCC_CFLAGS="-sSUPPORT_LONGJMP=wasm -fwasm-exceptions"
382+ emmake make -j $(nproc --all) install
383+ $env:EMCC_CFLAGS=""
384+ ```
385+
386+ To build and test Jupyter Lite with this kernel locally on Linux/MacOS you can execute the following
363387
364388``` bash
365389cd ../..
366- micromamba create -n xeus-lite-host jupyterlite-core=0.6 jupyterlite-xeus jupyter_server jupyterlab notebook python-libarchive-c -c conda-forge
390+ micromamba create -n xeus-lite-host jupyterlite-core jupyterlite-xeus jupyter_server jupyterlab notebook python-libarchive-c -c conda-forge
367391micromamba activate xeus-lite-host
368392jupyter lite serve --XeusAddon.prefix=$PREFIX \
369393 --contents xeus-cpp/notebooks/xeus-cpp-lite-demo.ipynb \
370- --contents xeus-cpp/notebooks/smallpt .ipynb \
394+ --contents xeus-cpp/notebooks/tinyraytracer .ipynb \
371395 --contents xeus-cpp/notebooks/images/marie.png \
372396 --contents xeus-cpp/notebooks/audio/audio.wav \
373397 --XeusAddon.mounts=" $PREFIX /share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles" \
374398 --XeusAddon.mounts=" $PREFIX /etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d"
375399```
400+
401+ and on Windows execute
402+
403+ ``` powershell
404+ cd ..\..
405+ micromamba create -n xeus-lite-host jupyterlite-core jupyterlite-xeus jupyter_server jupyterlab notebook python-libarchive-c -c conda-forge
406+ micromamba activate xeus-lite-host
407+ jupyter lite serve --XeusAddon.prefix="$env:PREFIX" `
408+ --contents xeus-cpp/notebooks/xeus-cpp-lite-demo.ipynb `
409+ --contents xeus-cpp/notebooks/tinyraytracer.ipynb `
410+ --contents xeus-cpp/notebooks/images/marie.png `
411+ --contents xeus-cpp/notebooks/audio/audio.wav `
412+ --XeusAddon.mounts="$env:PREFIX/share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles" `
413+ --XeusAddon.mounts="$env:PREFIX/etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d"
414+ ```
0 commit comments