|
| 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 |
0 commit comments