Skip to content

Commit 304f75a

Browse files
committed
[interop] Upgrade cppinterop to latest
1 parent 816001b commit 304f75a

35 files changed

+1186
-3776
lines changed

interpreter/CppInterOp/.codecov.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ codecov:
44
coverage:
55
precision: 2
66
round: down
7-
range: "70...100"
7+
range: "75...100"
88

99
status:
1010
project: yes
@@ -22,4 +22,7 @@ parsers:
2222
comment:
2323
layout: "reach, diff, flags, tree, files"
2424
behavior: default
25-
require_changes: no
25+
require_changes: no
26+
27+
github_checks:
28+
annotations: true # Deprecated but very useful
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"no-duplicate-heading": false
3+
}

interpreter/CppInterOp/.readthedocs.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ build:
99
tools:
1010
python: "3.11"
1111
apt_packages:
12-
- clang-16
12+
- clang-18
1313
- cmake
14-
- libclang-16-dev
15-
- llvm-16-dev
16-
- llvm-16-tools
14+
- libclang-18-dev
15+
- llvm-18-dev
16+
- llvm-18-tools

interpreter/CppInterOp/CMakeLists.txt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,13 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
6767
include(GNUInstallDirs)
6868
## Define supported version of clang and llvm
6969

70-
if (CPPINTEROP_USE_CLING)
7170
set(CLANG_MIN_SUPPORTED 18.0)
72-
else()
73-
set(CLANG_MIN_SUPPORTED 16.0)
74-
endif(CPPINTEROP_USE_CLING)
7571
set(CLANG_MAX_SUPPORTED "20.1.x")
7672
set(CLANG_VERSION_UPPER_BOUND 21.0.0)
77-
if (CPPINTEROP_USE_CLING)
7873
set(LLD_MIN_SUPPORTED 18.0)
79-
else()
80-
set(LLD_MIN_SUPPORTED 16.0)
81-
endif(CPPINTEROP_USE_CLING)
8274
set(LLD_MAX_SUPPORTED "20.1.x")
8375
set(LLD_VERSION_UPPER_BOUND 21.0.0)
84-
if (CPPINTEROP_USE_CLING)
8576
set(LLVM_MIN_SUPPORTED 18.0)
86-
else()
87-
set(LLVM_MIN_SUPPORTED 16.0)
88-
endif(CPPINTEROP_USE_CLING)
8977
set(LLVM_MAX_SUPPORTED "20.1.x")
9078
set(LLVM_VERSION_UPPER_BOUND 21.0.0)
9179

@@ -242,7 +230,7 @@ endif()
242230
message(STATUS "Found supported version: Clang ${CLANG_PACKAGE_VERSION}")
243231
message(STATUS "Using ClangConfig.cmake in: ${Clang_DIR}")
244232

245-
## Clang 16 require c++17 or later.
233+
## Clang 18 require c++17 or later.
246234
if (NOT CMAKE_CXX_STANDARD)
247235
set (CMAKE_CXX_STANDARD 17)
248236
endif()
@@ -286,10 +274,10 @@ endif()
286274
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
287275

288276
set( CPPINTEROP_BUILT_STANDALONE 1 )
289-
endif()
290277

291-
include(AddLLVM)
292-
include(HandleLLVMOptions)
278+
include(AddLLVM)
279+
include(HandleLLVMOptions)
280+
endif()
293281

294282
set(CMAKE_INCLUDE_CURRENT_DIR ON)
295283

interpreter/CppInterOp/Emscripten-build-instructions.md

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ On Windows execute the following
6363
```powershell
6464
cd .\llvm-project\
6565
cp -r ..\patches\llvm\emscripten-clang20*
66-
cp -r ..\patches\llvm\Windows-emscripten-clang20*
67-
git apply -v Windows-emscripten-clang20-1-CrossCompile.patch
6866
git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
67+
git apply -v emscripten-clang20-3-enable_exception_handling.patch
6968
```
7069

7170
We are now in a position to build an emscripten build of llvm by executing the following on Linux
@@ -81,7 +80,6 @@ mkdir build
8180
cd build
8281
emcmake cmake -DCMAKE_BUILD_TYPE=Release \
8382
-DLLVM_HOST_TRIPLE=wasm32-unknown-emscripten \
84-
-DLLVM_ENABLE_ASSERTIONS=ON \
8583
-DLLVM_TARGETS_TO_BUILD="WebAssembly" \
8684
-DLLVM_ENABLE_LIBEDIT=OFF \
8785
-DLLVM_ENABLE_PROJECTS="clang;lld" \
@@ -99,6 +97,9 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release \
9997
-DLLVM_ENABLE_LIBPFM=OFF \
10098
-DCLANG_BUILD_TOOLS=OFF \
10199
-DLLVM_NATIVE_TOOL_DIR=$NATIVE_DIR \
100+
-DCMAKE_C_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" \
101+
-DCMAKE_CXX_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" \
102+
-DLLVM_ENABLE_LTO=Full \
102103
../llvm
103104
emmake make libclang -j $(nproc --all)
104105
emmake make clangInterpreter clangStaticAnalyzerCore -j $(nproc --all)
@@ -108,11 +109,17 @@ emmake make lldWasm -j $(nproc --all)
108109
or executing
109110

110111
```powershell
112+
mkdir native_build
113+
cd native_build
114+
cmake -DLLVM_ENABLE_PROJECTS=clang -DLLVM_TARGETS_TO_BUILD=host -DCMAKE_BUILD_TYPE=Release -G Ninja ../llvm/
115+
cmake --build . --target llvm-tblgen clang-tblgen --parallel $(nproc --all)
116+
$env:PWD_DIR= $PWD.Path
117+
$env:NATIVE_DIR="$env:PWD_DIR/bin/"
118+
cd ..
111119
mkdir build
112120
cd build
113121
emcmake cmake -DCMAKE_BUILD_TYPE=Release `
114122
-DLLVM_HOST_TRIPLE=wasm32-unknown-emscripten `
115-
-DLLVM_ENABLE_ASSERTIONS=ON `
116123
-DLLVM_TARGETS_TO_BUILD="WebAssembly" `
117124
-DLLVM_ENABLE_LIBEDIT=OFF `
118125
-DLLVM_ENABLE_PROJECTS="clang;lld" `
@@ -129,7 +136,11 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release `
129136
-DLLVM_BUILD_TOOLS=OFF `
130137
-DLLVM_ENABLE_LIBPFM=OFF `
131138
-DCLANG_BUILD_TOOLS=OFF `
139+
-DLLVM_NATIVE_TOOL_DIR="$env:NATIVE_DIR" `
132140
-G Ninja `
141+
-DCMAKE_C_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" `
142+
-DCMAKE_CXX_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" `
143+
-DLLVM_ENABLE_LTO=Full `
133144
..\llvm
134145
emmake ninja libclang clangInterpreter clangStaticAnalyzerCore lldWasm
135146
```
@@ -208,14 +219,14 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release `
208219
emmake make -j $(nproc --all) check-cppinterop
209220
```
210221

211-
It is possible to run the Emscripten tests in a headless browser on Linux and osx (in future we plan to include instructions on how to run the tests in a browser on Windows too). To do this we will first move to the tests directory
222+
It is possible to run the Emscripten tests in a headless browser. To do this we will first move to the tests directory
212223

213224

214225
```bash
215226
cd ./unittests/CppInterOp/
216227
```
217228

218-
We will run our tests in a fresh installed browser. Installing the browsers, and running the tests within the installed browsers will be platform dependent. To do this on MacOS execute the following
229+
We will run our tests in a fresh installed browser. Installing the browsers, and running the tests within the installed browsers will be platform dependent. To do this for Chrome and Firefox on MacOS execute the following
219230

220231
```bash
221232
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
@@ -242,6 +253,19 @@ echo "Running DynamicLibraryManagerTests in Google Chrome"
242253
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
243254
```
244255

256+
To run tests in Safari you can make use of safaridriver. How to enable this will depend on
257+
your MacOS operating system, and is best to consult [safaridriver](https://developer.apple.com/documentation/webkit/testing-with-webdriver-in-safari). You will also need to install the Selenium
258+
python package. This only needs to be enable once, and then you can execute the following to run the tests in Safari
259+
260+
```bash
261+
echo "Running CppInterOpTests in Safari"
262+
emrun --no_browser --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html &
263+
python ../../../scripts/browser_tests_safari.py CppInterOpTests.html
264+
echo "Running DynamicLibraryManagerTests in Safari"
265+
emrun --no_browser --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html &
266+
python ../../../scripts/browser_tests_safari.py DynamicLibraryManagerTests.html
267+
```
268+
245269
To do this on Ubuntu x86 execute the following
246270

247271
```bash
@@ -283,6 +307,26 @@ echo "Running DynamicLibraryManagerTests in Firefox"
283307
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
284308
```
285309

310+
To do this on Windows x86 execute the following
311+
312+
```powershell
313+
Invoke-WebRequest -Uri "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Win/1411573/chrome-win.zip" -OutFile "$PWD\chrome-win.zip" -Verbose
314+
Expand-Archive -Path "$PWD\chrome-win.zip" -DestinationPath "$PWD" -Force -Verbose
315+
Invoke-WebRequest -Uri "https://download.mozilla.org/?product=firefox-latest-ssl&os=win64&lang=en-US" -OutFile "firefox-setup.exe" -Verbose
316+
& "C:\Program Files\7-Zip\7z.exe" x "firefox-setup.exe"
317+
$env:PATH="$PWD\core;$PWD\chrome-win;$env:PATH"
318+
echo "PATH=$env:PATH"
319+
echo "PATH=$env:PATH" >> $env:GITHUB_ENV
320+
echo "Running CppInterOpTests in Firefox"
321+
emrun.bat --browser="firefox.exe" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
322+
echo "Running DynamicLibraryManagerTests in Firefox"
323+
emrun.bat --browser="firefox.exe" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
324+
echo "Running CppInterOpTests in Chromium"
325+
emrun.bat --browser="chrome.exe" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
326+
echo "Running DynamicLibraryManagerTests in Chromium"
327+
emrun.bat --browser="chrome.exe" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
328+
```
329+
286330
Assuming it passes all test you can install by executing the following
287331

288332
```bash
@@ -293,12 +337,13 @@ emmake make -j $(nproc --all) install
293337
## Xeus-cpp-lite Wasm Build Instructions
294338

295339
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
296-
the CppInterOp build folder, you can build the wasm version of xeus-cpp by executing (replace $LLVM_VERSION with the version
340+
the CppInterOp build folder, you can build the wasm version of xeus-cpp by executing (replace LLVM_VERSION with the version
297341
of llvm you are building against)
298342

299343
```bash
300344
cd ../..
301345
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
346+
export LLVM_VERSION=20
302347
cd ./xeus-cpp
303348
mkdir build
304349
cd build
@@ -308,29 +353,23 @@ emcmake cmake \
308353
-DCMAKE_INSTALL_PREFIX=$PREFIX \
309354
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
310355
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
311-
-DXEUS_CPP_RESOURCE_DIR=$LLVM_BUILD_DIR/lib/clang/$LLVM_VERSION \
356+
-DXEUS_CPP_RESOURCE_DIR="$LLVM_BUILD_DIR/lib/clang/$LLVM_VERSION" \
312357
-DSYSROOT_PATH=$SYSROOT_PATH \
313358
..
314359
emmake make -j $(nproc --all) install
315360
```
316361

317-
To build Jupyter Lite website with this kernel locally that you can use for testing execute the following
362+
To build and test Jupyter Lite with this kernel locally you can execute the following
318363

319364
```bash
320365
cd ../..
321366
micromamba create -n xeus-lite-host jupyterlite-core=0.6 jupyterlite-xeus jupyter_server jupyterlab notebook python-libarchive-c -c conda-forge
322367
micromamba activate xeus-lite-host
323-
jupyter lite build --XeusAddon.prefix=$PREFIX \
368+
jupyter lite serve --XeusAddon.prefix=$PREFIX \
324369
--contents xeus-cpp/notebooks/xeus-cpp-lite-demo.ipynb \
325370
--contents xeus-cpp/notebooks/smallpt.ipynb \
326371
--contents xeus-cpp/notebooks/images/marie.png \
327372
--contents xeus-cpp/notebooks/audio/audio.wav \
328373
--XeusAddon.mounts="$PREFIX/share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles" \
329374
--XeusAddon.mounts="$PREFIX/etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d"
330375
```
331-
332-
Once the Jupyter Lite site has built you can test the website locally by executing
333-
334-
```bash
335-
jupyter lite serve --XeusAddon.prefix=$PREFIX
336-
```

0 commit comments

Comments
 (0)