Skip to content

Commit f0938a8

Browse files
authored
Update Emscripten jobs to add llvm 21 (#776)
1 parent dea9b71 commit f0938a8

15 files changed

Lines changed: 283 additions & 55 deletions

.github/workflows/deploy-pages.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
include:
24-
- name: osx26-arm-clang-repl-20-emscripten_wasm
24+
- name: osx26-arm-clang-repl-21-emscripten_wasm
2525
os: macos-26
26-
clang-runtime: '20'
26+
clang-runtime: '21'
2727
cling: Off
2828
micromamba_shell_init: bash
2929
emsdk_ver: "4.0.9"
@@ -73,7 +73,7 @@ jobs:
7373
set -e
7474
./emsdk/emsdk activate ${{matrix.emsdk_ver}}
7575
source ./emsdk/emsdk_env.sh
76-
micromamba create -f environment-wasm.yml --platform=emscripten-wasm32
76+
micromamba create -f environment-wasm.yml --platform=emscripten-wasm32 -c https://prefix.dev/emscripten-forge-4x -c https://prefix.dev/conda-forge
7777
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
7878
export PREFIX=$MAMBA_ROOT_PREFIX/envs/CppInterOp-wasm
7979
export CMAKE_PREFIX_PATH=$PREFIX
@@ -210,7 +210,7 @@ jobs:
210210
-DXEUS_CPP_RESOURCE_DIR=${{ env.LLVM_BUILD_DIR }}/lib/clang/${{ matrix.clang-runtime }} \
211211
-DSYSROOT_PATH=${{ env.SYSROOT_PATH }} \
212212
..
213-
emmake make -j ${{ env.ncpus }} install
213+
EMCC_CFLAGS="-sSUPPORT_LONGJMP=wasm -fwasm-exceptions" emmake make -j ${{ env.ncpus }} install
214214
215215
- name: Test xeus-cpp C++ Emscripten
216216
shell: bash -l {0}

.github/workflows/emscripten.yml

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,34 @@ jobs:
4949
llvm_enable_projects: "clang;lld"
5050
llvm_targets_to_build: "WebAssembly"
5151
emsdk_ver: "4.0.9"
52+
- name: ubu24-arm-clang-repl-21-emscripten
53+
os: ubuntu-24.04-arm
54+
clang-runtime: '21'
55+
cling: Off
56+
llvm_enable_projects: "clang;lld"
57+
llvm_targets_to_build: "WebAssembly"
58+
emsdk_ver: "4.0.9"
59+
- name: osx26-arm-clang-repl-21-emscripten
60+
os: macos-26
61+
clang-runtime: '21'
62+
cling: Off
63+
llvm_enable_projects: "clang;lld"
64+
llvm_targets_to_build: "WebAssembly"
65+
emsdk_ver: "4.0.9"
66+
- name: ubu24-x86-clang-repl-21-emscripten
67+
os: ubuntu-24.04
68+
clang-runtime: '21'
69+
cling: Off
70+
llvm_enable_projects: "clang;lld"
71+
llvm_targets_to_build: "WebAssembly"
72+
emsdk_ver: "4.0.9"
73+
- name: win2025-x86-clang-repl-21-emscripten
74+
os: windows-2025
75+
clang-runtime: '21'
76+
cling: Off
77+
llvm_enable_projects: "clang;lld"
78+
llvm_targets_to_build: "WebAssembly"
79+
emsdk_ver: "4.0.9"
5280

5381
steps:
5482
- uses: actions/checkout@v6
@@ -167,11 +195,11 @@ jobs:
167195
-DCMAKE_CXX_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" \
168196
-DLLVM_ENABLE_LTO=Full \
169197
../llvm
170-
emmake ninja clang cling lld gtest_main
198+
EMCC_CFLAGS="-sSUPPORT_LONGJMP=wasm -fwasm-exceptions" emmake ninja clang cling lld gtest_main
171199
else
172200
# Apply patches
173201
llvm_vers=$(echo "${{ matrix.clang-runtime }}" | tr '[:lower:]' '[:upper:]')
174-
if [[ "${llvm_vers}" == "19" || "${llvm_vers}" == "20" ]]; then
202+
if [[ "${llvm_vers}" == "19" || "${llvm_vers}" == "20" || "${llvm_vers}" == "21" ]]; then
175203
git apply -v ../patches/llvm/emscripten-clang${{ matrix.clang-runtime }}-*.patch
176204
echo "Apply emscripten-clang${{ matrix.clang-runtime }}-*.patch patches:"
177205
fi
@@ -200,7 +228,7 @@ jobs:
200228
-DCMAKE_CXX_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" \
201229
-DLLVM_ENABLE_LTO=Full \
202230
../llvm
203-
emmake ninja libclang clangInterpreter clangStaticAnalyzerCore lldWasm
231+
EMCC_CFLAGS="-sSUPPORT_LONGJMP=wasm -fwasm-exceptions" emmake ninja libclang clangInterpreter clangStaticAnalyzerCore
204232
fi
205233
cd ../
206234
rm -rf $(find . -maxdepth 1 ! -name "build" ! -name "llvm" ! -name "clang" ! -name ".")
@@ -280,7 +308,9 @@ jobs:
280308
-DLLVM_ENABLE_LTO=Full `
281309
-DLLVM_NATIVE_TOOL_DIR="$env:NATIVE_DIR" `
282310
..\llvm
311+
$env:EMCC_CFLAGS="-sSUPPORT_LONGJMP=wasm -fwasm-exceptions"
283312
emmake make clang cling lld gtest_main
313+
$env:EMCC_CFLAGS=""
284314
}
285315
else
286316
{
@@ -297,6 +327,12 @@ jobs:
297327
git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
298328
git apply -v emscripten-clang20-3-enable_exception_handling.patch
299329
}
330+
elseif ( "${{ matrix.clang-runtime }}" -imatch "21" )
331+
{
332+
git apply -v emscripten-clang21-1-shift-temporary-files-to-tmp-dir.patch
333+
git apply -v emscripten-clang21-2-enable_exception_handling.patch
334+
git apply -v emscripten-clang21-3-webassembly_target_machine_reordering.patch
335+
}
300336
cd build
301337
echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:"
302338
emcmake cmake -DCMAKE_BUILD_TYPE=Release `
@@ -323,7 +359,9 @@ jobs:
323359
-G Ninja `
324360
-DLLVM_NATIVE_TOOL_DIR="$env:NATIVE_DIR" `
325361
..\llvm
326-
emmake ninja libclang clangInterpreter clangStaticAnalyzerCore lldWasm
362+
$env:EMCC_CFLAGS="-sSUPPORT_LONGJMP=wasm -fwasm-exceptions"
363+
emmake ninja libclang clangInterpreter clangStaticAnalyzerCore
364+
$env:EMCC_CFLAGS=""
327365
}
328366
cd ..\
329367
rm -r -force $(find.exe . -maxdepth 1 ! -name "build" ! -name "llvm" ! -name "clang" ! -name ".")
@@ -385,6 +423,30 @@ jobs:
385423
cling: Off
386424
micromamba_shell_init: powershell
387425
emsdk_ver: "4.0.9"
426+
- name: ubu24-x86-clang-repl-21-emscripten_wasm
427+
os: ubuntu-24.04
428+
clang-runtime: '21'
429+
cling: Off
430+
micromamba_shell_init: bash
431+
emsdk_ver: "4.0.9"
432+
- name: osx26-arm-clang-repl-21-emscripten_wasm
433+
os: macos-26
434+
clang-runtime: '21'
435+
cling: Off
436+
micromamba_shell_init: bash
437+
emsdk_ver: "4.0.9"
438+
- name: ubu24-arm-clang-repl-21-emscripten_wasm
439+
os: ubuntu-24.04-arm
440+
clang-runtime: '21'
441+
cling: Off
442+
micromamba_shell_init: bash
443+
emsdk_ver: "4.0.9"
444+
- name: win2025-x86-clang-repl-21-emscripten
445+
os: windows-2025
446+
clang-runtime: '21'
447+
cling: Off
448+
micromamba_shell_init: powershell
449+
emsdk_ver: "4.0.9"
388450

389451
steps:
390452
- uses: actions/checkout@v6
@@ -429,7 +491,7 @@ jobs:
429491
set -e
430492
./emsdk/emsdk activate ${{matrix.emsdk_ver}}
431493
source ./emsdk/emsdk_env.sh
432-
micromamba create -f environment-wasm.yml --platform=emscripten-wasm32
494+
micromamba create -f environment-wasm.yml --platform=emscripten-wasm32 -c https://prefix.dev/emscripten-forge-4x -c https://prefix.dev/conda-forge
433495
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
434496
export PREFIX=$MAMBA_ROOT_PREFIX/envs/CppInterOp-wasm
435497
export CMAKE_PREFIX_PATH=$PREFIX
@@ -483,11 +545,11 @@ jobs:
483545
os="${{ matrix.os }}"
484546
if [[ "${os}" != macos* ]] ; then
485547
actual_size=$(stat -c%s "./lib/libclangCppInterOp.so")
486-
max_size=$((40 * 1024 * 1024))
487-
if [[ "$actual_size" -gt "$max_size" ]]; then
488-
echo "Error: libclangCppInterOp.so is larger than 40 MB."
548+
max_size=$((50 * 1024 * 1024))
549+
if [[ "$actual_size" -gt "$max_size" ]]; then
550+
echo "Error: libclangCppInterOp.so is larger than 50 MB."
489551
exit 1
490-
fi
552+
fi
491553
fi
492554
cd ./unittests/CppInterOp/
493555
# Fresh install browsers, and run Emscripten tests in them
@@ -727,7 +789,7 @@ jobs:
727789
if: ${{ runner.os == 'windows' }}
728790
shell: powershell
729791
run: |
730-
micromamba create -f environment-wasm.yml --platform=emscripten-wasm32
792+
micromamba create -f environment-wasm.yml --platform=emscripten-wasm32 -c https://prefix.dev/emscripten-forge-4x -c https://prefix.dev/conda-forge
731793
.\emsdk\emsdk activate ${{matrix.emsdk_ver}}
732794
.\emsdk\emsdk_env.ps1
733795
$env:PWD_DIR= $PWD.Path
@@ -970,7 +1032,7 @@ jobs:
9701032
-DXEUS_CPP_RESOURCE_DIR=${{ env.LLVM_BUILD_DIR }}/lib/clang/${{ matrix.clang-runtime }} \
9711033
-DSYSROOT_PATH=${{ env.SYSROOT_PATH }} \
9721034
..
973-
emmake make -j ${{ env.ncpus }} install
1035+
EMCC_CFLAGS="-sSUPPORT_LONGJMP=wasm -fwasm-exceptions" emmake make -j ${{ env.ncpus }} install
9741036
9751037
- name: Build xeus-cpp on Windows systems
9761038
if: ${{ runner.os == 'windows' }}
@@ -994,7 +1056,9 @@ jobs:
9941056
-DXEUS_CPP_RESOURCE_DIR=${{ env.LLVM_BUILD_DIR }}\lib\clang\${{ matrix.clang-runtime }} `
9951057
-DSYSROOT_PATH=${{ env.SYSROOT_PATH }} `
9961058
..
1059+
$env:EMCC_CFLAGS="-sSUPPORT_LONGJMP=wasm -fwasm-exceptions"
9971060
emmake make -j ${{ env.ncpus }} install
1061+
$env:EMCC_CFLAGS=""
9981062
9991063
- name: Test xeus-cpp C++ Emscripten on Unix Systems
10001064
if: ${{ runner.os != 'windows' }}

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ set(CMAKE_CXX_EXTENSIONS NO)
1212
option(CPPINTEROP_USE_CLING "Use Cling as backend" OFF)
1313
option(CPPINTEROP_USE_REPL "Use clang-repl as backend" ON)
1414
option(CPPINTEROP_ENABLE_TESTING "Enable the CppInterOp testing infrastructure." ON)
15+
if(EMSCRIPTEN)
16+
set(CPPINTEROP_EXTRA_WASM_FLAGS "-sSUPPORT_LONGJMP=wasm -fwasm-exceptions" CACHE STRING "Extra flags for wasm")
17+
endif()
1518

1619
if (CPPINTEROP_USE_CLING AND CPPINTEROP_USE_REPL)
1720
message(FATAL_ERROR "We can only use Cling (${CPPINTEROP_USE_CLING}=On) or Repl (CPPINTEROP_USE_REPL=On), but not both of them.")
@@ -359,6 +362,9 @@ endif()
359362
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
360363
if (APPLE OR EMSCRIPTEN)
361364
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
365+
if (EMSCRIPTEN)
366+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPPINTEROP_EXTRA_WASM_FLAGS}")
367+
endif ()
362368
else()
363369
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
364370
endif ()

Emscripten-build-instructions.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ $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
4646
avoided 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
5050
git clone --depth=1 https://github.com/compiler-research/CppInterOp.git
5151
```
5252

@@ -55,16 +55,17 @@ executing
5555

5656
```bash
5757
cd ./llvm-project/
58-
git apply -v ../CppInterOp/patches/llvm/emscripten-clang20-*.patch
58+
git apply -v ../CppInterOp/patches/llvm/emscripten-clang21-*.patch
5959
```
6060

6161
On Windows execute the following
6262

6363
```powershell
6464
cd .\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

7071
We 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

109108
or 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

148149
on 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
165166
cd ../../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
167168
micromamba activate CppInterOp-wasm
168169
```
169170

@@ -343,7 +344,7 @@ of llvm you are building against)
343344
```bash
344345
cd ../..
345346
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
346-
export LLVM_VERSION=20
347+
export LLVM_VERSION=21
347348
cd ./xeus-cpp
348349
mkdir build
349350
cd build
@@ -356,15 +357,15 @@ 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

362363
and on Windows by executing
363364

364365
```powershell
365366
cd ..\..
366367
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
367-
$env:LLVM_VERSION=20
368+
$env:LLVM_VERSION=21
368369
cd .\xeus-cpp
369370
mkdir build
370371
cd build
@@ -377,7 +378,9 @@ emcmake cmake `
377378
-DXEUS_CPP_RESOURCE_DIR="$env:LLVM_BUILD_DIR/lib/clang/$env:LLVM_VERSION" `
378379
-DSYSROOT_PATH="$env:SYSROOT_PATH" `
379380
..
380-
emmake make -j $(nproc --all) install
381+
$env:EMCC_CFLAGS="-sSUPPORT_LONGJMP=wasm -fwasm-exceptions"
382+
emmake make -j $(nproc --all) install
383+
$env:EMCC_CFLAGS=""
381384
```
382385

383386
To build and test Jupyter Lite with this kernel locally on Linux/MacOS you can execute the following

cmake/modules/GoogleTest.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ endif()
2020

2121
include(ExternalProject)
2222
if (EMSCRIPTEN)
23+
# FIXME: -sSUPPORT_LONGJMP=wasm in the default option causes a warning in the Emscripten build of Googletest
24+
# and as we treat warnings as errors in the ci, it causes the ci to fail.
25+
string(REPLACE "-sSUPPORT_LONGJMP=wasm" "" GOOGLETEST_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
2326
set(config_cmd emcmake${EMCC_SUFFIX} cmake)
2427
if(CMAKE_GENERATOR STREQUAL "Ninja")
2528
set(build_cmd emmake${EMCC_SUFFIX} ninja)
@@ -49,7 +52,7 @@ ExternalProject_Add(
4952
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
5053
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
5154
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
52-
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
55+
-DCMAKE_CXX_FLAGS=${GOOGLETEST_CMAKE_CXX_FLAGS}
5356
-DCMAKE_AR=${CMAKE_AR}
5457
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
5558
${EXTRA_GTEST_OPTS}

0 commit comments

Comments
 (0)