Skip to content

Commit ce0ad5e

Browse files
committed
Fix emscripten build
1 parent 70daba2 commit ce0ad5e

7 files changed

+763
-43
lines changed

.github/workflows/ci.yml

+275-32
Large diffs are not rendered by default.

.github/workflows/deploy-pages.yml

+6-8
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
path: |
8888
llvm-project
8989
${{ matrix.cling=='On' && 'cling' || '' }}
90-
key: ${{ env.CLING_HASH }}-${{ runner.os }}-${{ matrix.os }}-${{ matrix.compiler }}-clang-${{ matrix.clang-runtime }}.x-patch-${{ hashFiles(format('patches/llvm/clang{0}-*.patch', matrix.clang-runtime)) || 'none' }}
90+
key: ${{ env.CLING_HASH }}-${{ runner.os }}-${{ matrix.os }}-${{ matrix.compiler }}-clang-${{ matrix.clang-runtime }}.x-emscripten
9191

9292
- name: Emscripten build of CppInterOp on Unix systems
9393
if: ${{ runner.os != 'windows' }}
@@ -123,28 +123,26 @@ jobs:
123123
-DUSE_REPL=OFF \
124124
-DCMAKE_PREFIX_PATH=$PREFIX \
125125
-DCling_DIR=$LLVM_BUILD_DIR/tools/cling \
126+
-DLLD_DIR=$LLVM_BUILD_DIR \
126127
-DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm \
127128
-DClang_DIR=$LLVM_BUILD_DIR/lib/cmake/clang \
128-
-DBUILD_SHARED_LIBS=OFF \
129+
-DBUILD_SHARED_LIBS=ON \
129130
-DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \
130131
-DCMAKE_INSTALL_PREFIX=$PREFIX \
131132
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
132-
-DZLIB_INCLUDE_DIR=$PREFIX/include \
133-
-DZLIB_LIBRARY=$PREFIX/lib/ \
134133
../
135134
else
136135
emcmake cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \
137136
-DUSE_CLING=OFF \
138137
-DUSE_REPL=ON \
139138
-DCMAKE_PREFIX_PATH=$PREFIX \
140139
-DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm \
140+
-DLLD_DIR=$LLVM_BUILD_DIR \
141141
-DClang_DIR=$LLVM_BUILD_DIR/lib/cmake/clang \
142-
-DBUILD_SHARED_LIBS=OFF \
142+
-DBUILD_SHARED_LIBS=ON \
143143
-DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \
144144
-DCMAKE_INSTALL_PREFIX=$PREFIX \
145145
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
146-
-DZLIB_INCLUDE_DIR=$PREFIX/include \
147-
-DZLIB_LIBRARY=$PREFIX/lib/ \
148146
../
149147
fi
150148
@@ -179,7 +177,7 @@ jobs:
179177
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
180178
-DCppInterOp_DIR="${{ env.CPPINTEROP_BUILD_DIR }}/lib/cmake/CppInterOp" \
181179
..
182-
EMCC_CFLAGS='-sERROR_ON_UNDEFINED_SYMBOLS=0' emmake make -j ${{ env.ncpus }} install
180+
emmake make -j ${{ env.ncpus }} install
183181
184182
- name: Jupyter Lite integration
185183
shell: bash -l {0}

Emscripten-build-instructions.md

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Wasm Build Instructions
2+
3+
## CppInterOp Wasm Build Instructions
4+
5+
This document first starts with the instructions on how to build a wasm
6+
build of CppInterOp. Before we start it should be noted that
7+
unlike the non wasm version of CppInterOp we currently only
8+
support the Clang-REPL backend using llvm>19 for osx and Linux.
9+
We will first make folder to build our wasm build of CppInterOp.
10+
This can be done by executing the following command
11+
12+
```bash
13+
mkdir CppInterOp-wasm
14+
```
15+
16+
Now move into this directory using the following command
17+
18+
```bash
19+
cd ./CppInterOp-wasm
20+
```
21+
22+
To create a wasm build of CppInterOp we make use of the emsdk
23+
toolchain. This can be installed by executing (we only currently
24+
support version 3.1.45)
25+
```bash
26+
git clone https://github.com/emscripten-core/emsdk.git
27+
cd emsdk
28+
./emsdk install 3.1.45
29+
```
30+
31+
Go back upto the top level build directory using
32+
33+
```bash
34+
cd ../..
35+
```
36+
37+
and activate the emsdk environment
38+
```bash
39+
./emsdk/emsdk activate 3.1.45
40+
source ./emsdk/emsdk_env.sh
41+
```bash
42+
43+
Now clone the 19.x release of the LLVM project repository
44+
and CppInterOp
45+
46+
```bash
47+
git clone --depth=1 --branch release/19.x https://github.com/llvm/llvm-project.git
48+
git clone --depth=1 https://github.com/compiler-research/CppInterOp.git
49+
```
50+
51+
Now move into the cloned llvm-project folder and apply
52+
a required patch
53+
54+
```bash
55+
cd ./llvm-project/
56+
git apply -v ../CppInterOp/patches/llvm/emscripten-clang${{ matrix.clang-runtime }}-*.patch
57+
```
58+
59+
We are now in a position to build an emscripten build of llvm by executing the following
60+
```bash
61+
mkdir build
62+
cd build
63+
emcmake cmake -DCMAKE_BUILD_TYPE=Release \
64+
-DLLVM_HOST_TRIPLE=wasm32-unknown-emscripten \
65+
-DLLVM_ENABLE_ASSERTIONS=ON \
66+
-DLLVM_TARGETS_TO_BUILD="WebAssembly" \
67+
-DLLVM_ENABLE_LIBEDIT=OFF \
68+
-DLLVM_ENABLE_PROJECTS="clang;lld" \
69+
-DLLVM_ENABLE_ZSTD=OFF \
70+
-DLLVM_ENABLE_LIBXML2=OFF \
71+
-DCLANG_ENABLE_STATIC_ANALYZER=OFF \
72+
-DCLANG_ENABLE_ARCMT=OFF \
73+
-DCLANG_ENABLE_BOOTSTRAP=OFF \
74+
-DCMAKE_CXX_FLAGS="-Dwait4=__syscall_wait4" \
75+
../llvm
76+
emmake make clang -j $(nproc --all)
77+
emmake make clang-repl -j $(nproc --all)
78+
emmake make lld -j $(nproc --all)
79+
```
80+
81+
Once this finishes building we need to take note of where we built our
82+
llvm build. This can be done by executing the following
83+
84+
```bash
85+
export LLVM_BUILD_DIR=$PWD
86+
```
87+
88+
We can move onto building the wasm
89+
version of CppInterOp. To do this execute the following
90+
91+
```bash
92+
cd ../../CppInterOp/
93+
mkdir build
94+
cd ./build/
95+
emcmake cmake -DCMAKE_BUILD_TYPE=Release \
96+
-DUSE_CLING=OFF \
97+
-DUSE_REPL=ON \
98+
-DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm \
99+
-DLLD_DIR=$LLVM_BUILD_DIR \
100+
-DClang_DIR=$LLVM_BUILD_DIR/lib/cmake/clang \
101+
-DBUILD_SHARED_LIBS=ON \
102+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
103+
../
104+
emmake make -j $(nproc --all)
105+
```bash
106+
107+
Once this finishes building we need to take note of where we built our
108+
llvm build. This can be done by executing the following
109+
110+
```bash
111+
export CPPINTEROP_BUILD_DIR=$PWD
112+
```
113+
114+
## Xeus-cpp-lite Wasm Build Instructions
115+
116+
A project which makes use of the wasm build of CppInterOp. To build this
117+
execute the following
118+
119+
```bash
120+
cd ../..
121+
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
122+
cd ./xeus-cpp
123+
mkdir build
124+
cd build
125+
export CMAKE_PREFIX_PATH=${{ env.PREFIX }}
126+
export CMAKE_SYSTEM_PREFIX_PATH=${{ env.PREFIX }}
127+
emcmake cmake \
128+
-DCMAKE_BUILD_TYPE=Release \
129+
-DCMAKE_PREFIX_PATH=${{ env.PREFIX }} \
130+
-DCMAKE_INSTALL_PREFIX=${{ env.PREFIX }} \
131+
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
132+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
133+
-DCppInterOp_DIR="$CPPINTEROP_BUILD_DIR/lib/cmake/CppInterOp" \
134+
..
135+
emmake make -j $(nproc --all)
136+
```bash

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ command
127127
mkdir build
128128
cd build
129129
cmake -DLLVM_ENABLE_PROJECTS="clang;lld" \
130-
-DLLVM_TARGETS_TO_BUILD="WebAssembly;host;NVPTX" \
130+
-DLLVM_TARGETS_TO_BUILD="host;NVPTX" \
131131
-DCMAKE_BUILD_TYPE=Release \
132132
-DLLVM_ENABLE_ASSERTIONS=ON \
133133
-DCLANG_ENABLE_STATIC_ANALYZER=OFF \
@@ -193,7 +193,7 @@ cd llvm-project/build
193193
cmake -DLLVM_ENABLE_PROJECTS="clang;lld" \
194194
-DLLVM_EXTERNAL_PROJECTS=cling \
195195
-DLLVM_EXTERNAL_CLING_SOURCE_DIR=../../cling \
196-
-DLLVM_TARGETS_TO_BUILD="WebAssembly;host;NVPTX" \
196+
-DLLVM_TARGETS_TO_BUILD="host;NVPTX" \
197197
-DCMAKE_BUILD_TYPE=Release \
198198
-DLLVM_ENABLE_ASSERTIONS=ON \
199199
-DCLANG_ENABLE_STATIC_ANALYZER=OFF \

environment-wasm.yml

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: CppInterOp-wasm
22
channels:
33
- https://repo.mamba.pm/emscripten-forge
44
dependencies:
5-
- zlib
65
- nlohmann_json
76
- xeus-lite
87
- xeus

0 commit comments

Comments
 (0)