Skip to content

Commit 46c6b54

Browse files
authored
Fix emscripten build instructions
1 parent c446c3e commit 46c6b54

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

Emscripten-build-instructions.md

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Wasm Build Instructions
22

3-
It should be noted that the wasm build of CppInterOp is still experimental and subject to change to change.
3+
It should be noted that the wasm build of CppInterOp is still experimental and subject to change.
44

55
## CppInterOp Wasm Build Instructions
66

@@ -22,14 +22,7 @@ To create a wasm build of CppInterOp we make use of the emsdk toolchain. This ca
2222
support version 3.1.45)
2323
```bash
2424
git clone https://github.com/emscripten-core/emsdk.git
25-
cd emsdk
26-
./emsdk install 3.1.45
27-
```
28-
29-
Go back upto the top level build directory using
30-
31-
```bash
32-
cd ../..
25+
./emsdk/emsdk install 3.1.45
3326
```
3427

3528
and activate the emsdk environment
@@ -48,11 +41,11 @@ git clone --depth=1 --branch release/19.x https://github.com/llvm/llvm-project.g
4841
git clone --depth=1 https://github.com/compiler-research/CppInterOp.git
4942
```
5043

51-
Now move into the cloned llvm-project folder and apply a required patch
44+
Now move into the cloned llvm-project folder and apply the required patches
5245

5346
```bash
5447
cd ./llvm-project/
55-
git apply -v ../CppInterOp/patches/llvm/emscripten-clang${{ matrix.clang-runtime }}-*.patch
48+
git apply -v ../CppInterOp/patches/llvm/emscripten-clang19-*.patch
5649
```
5750

5851
We are now in a position to build an emscripten build of llvm by executing the following
@@ -71,8 +64,11 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release \
7164
-DCLANG_ENABLE_ARCMT=OFF \
7265
-DCLANG_ENABLE_BOOTSTRAP=OFF \
7366
-DCMAKE_CXX_FLAGS="-Dwait4=__syscall_wait4" \
67+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
68+
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true \
7469
../llvm
7570
emmake make clang -j $(nproc --all)
71+
emmake make clang-repl -j $(nproc --all)
7672
emmake make lld -j $(nproc --all)
7773
```
7874

@@ -82,10 +78,27 @@ Once this finishes building we need to take note of where we built our llvm buil
8278
export LLVM_BUILD_DIR=$PWD
8379
```
8480

85-
We can move onto building the wasm version of CppInterOp. To do this execute the following
81+
We can move onto building the wasm version of CppInterOp. We will do this within a Conda environment. We can achieve this
82+
by execut (assumes you have micromamba installed and that your shell is initialised for the micromamba install)
8683

8784
```bash
8885
cd ../../CppInterOp/
86+
micromamba create -f environment-wasm.yml --platform=emscripten-wasm32
87+
micromamba activate CppInterOp-wasm
88+
```
89+
90+
You will also want to set a few environment variables
91+
92+
```bash
93+
export PREFIX=$CONDA_PREFIX/envs/CppInterOp-wasm
94+
export CMAKE_PREFIX_PATH=$PREFIX
95+
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
96+
export LDFLAGS="-s MODULARIZE=1 -s LINKABLE=1 -s EXPORT_ALL=1 -s WASM=1 -std=c++14 -s SIDE_MODULE=1 -sWASM_BIGINT"
97+
```
98+
99+
Now to build CppInterOp execute the following
100+
101+
```bash
89102
mkdir build
90103
cd ./build/
91104
emcmake cmake -DCMAKE_BUILD_TYPE=Release \
@@ -96,7 +109,7 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release \
96109
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
97110
-DCMAKE_INSTALL_PREFIX=$PREFIX \
98111
../
99-
emmake make -j $(nproc --all)
112+
emmake make -j $(nproc --all) install
100113
```
101114

102115
Once this finishes building we need to take note of where we built CppInterOp. This can be done by executing the following
@@ -107,27 +120,17 @@ export CPPINTEROP_BUILD_DIR=$PWD
107120

108121
## Xeus-cpp-lite Wasm Build Instructions
109122

110-
A project which makes use of the wasm build of CppInterOp is xeus-cpp. xeus-cpp is a C++ Jupyter kernel. To build xeus-cpp we first need to
111-
install several other dependencies. To create an Conda environment with this dependencies installed execute the following from the
112-
CppInterOp build folder (these instructions will assume you have already installed micromamba)
113-
114-
```bash
115-
cd ..
116-
micromamba create -f environment-wasm.yml --platform=emscripten-wasm32
117-
micromamba activate CppInterOp-wasm
118-
export PREFIX=$MAMBA_ROOT_PREFIX/envs/CppInterOp-wasm
119-
```
120-
Now we can build an wasm build of xeus-cpp by executing the following
123+
A project which makes use of the wasm build of CppInterOp is xeus-cpp. xeus-cpp is a C++ Jupyter kernel. Assuming you are in
124+
the CppInterOp build folder, you can build the wasm version of xeus-cpp by executing
121125

122126
```bash
123-
cd ..
127+
cd ../..
128+
export LDFLAGS="-s MODULARIZE=1 -s LINKABLE=1 -s EXPORT_ALL=1 -s WASM=1 -std=c++14 -sWASM_BIGINT"
129+
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
124130
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
125131
cd ./xeus-cpp
126132
mkdir build
127133
cd build
128-
export CMAKE_PREFIX_PATH=$PREFIX
129-
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
130-
export SYSROOT_PATH=$HOME/emsdk/upstream/emscripten/cache/sysroot
131134
emcmake cmake \
132135
-DCMAKE_BUILD_TYPE=Release \
133136
-DCMAKE_PREFIX_PATH=$PREFIX \
@@ -140,11 +143,11 @@ emcmake cmake \
140143
emmake make -j $(nproc --all) install
141144
```
142145

143-
To build Jupyter Lite with this kernel without creating a website you can execute the following
146+
To build Jupyter Lite website with this kernel locally that you can use for testing execute the following
144147

145148
```bash
146149
cd ../..
147-
micromamba create -n xeus-lite-host jupyterlite-core
150+
micromamba create -n xeus-lite-host jupyterlite-core -c conda-forge
148151
micromamba activate xeus-lite-host
149152
python -m pip install jupyterlite-xeus
150153
jupyter lite build --XeusAddon.prefix=$PREFIX
@@ -159,7 +162,7 @@ cp $PREFIX/bin/xcpp.data _output/extensions/@jupyterlite/xeus/static
159162
cp $PREFIX/lib/libclangCppInterOp.so _output/extensions/@jupyterlite/xeus/static
160163
```
161164

162-
Once the Jupyter Lite site has built you can test the website locally by executing
165+
Once the Jupyter Lite site has built you can test the website locally by executing
163166

164167
```bash
165168
jupyter lite serve --XeusAddon.prefix=$PREFIX

0 commit comments

Comments
 (0)