Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions interpreter/CppInterOp/.codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ codecov:
coverage:
precision: 2
round: down
range: "70...100"
range: "75...100"

status:
project: yes
Expand All @@ -22,4 +22,7 @@ parsers:
comment:
layout: "reach, diff, flags, tree, files"
behavior: default
require_changes: no
require_changes: no

github_checks:
annotations: true # Deprecated but very useful
3 changes: 3 additions & 0 deletions interpreter/CppInterOp/.markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"no-duplicate-heading": false
}
8 changes: 4 additions & 4 deletions interpreter/CppInterOp/.readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ build:
tools:
python: "3.11"
apt_packages:
- clang-16
- clang-18
- cmake
- libclang-16-dev
- llvm-16-dev
- llvm-16-tools
- libclang-18-dev
- llvm-18-dev
- llvm-18-tools
20 changes: 4 additions & 16 deletions interpreter/CppInterOp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,13 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
include(GNUInstallDirs)
## Define supported version of clang and llvm

if (CPPINTEROP_USE_CLING)
set(CLANG_MIN_SUPPORTED 18.0)
else()
set(CLANG_MIN_SUPPORTED 16.0)
endif(CPPINTEROP_USE_CLING)
set(CLANG_MAX_SUPPORTED "20.1.x")
set(CLANG_VERSION_UPPER_BOUND 21.0.0)
if (CPPINTEROP_USE_CLING)
set(LLD_MIN_SUPPORTED 18.0)
else()
set(LLD_MIN_SUPPORTED 16.0)
endif(CPPINTEROP_USE_CLING)
set(LLD_MAX_SUPPORTED "20.1.x")
set(LLD_VERSION_UPPER_BOUND 21.0.0)
if (CPPINTEROP_USE_CLING)
set(LLVM_MIN_SUPPORTED 18.0)
else()
set(LLVM_MIN_SUPPORTED 16.0)
endif(CPPINTEROP_USE_CLING)
set(LLVM_MAX_SUPPORTED "20.1.x")
set(LLVM_VERSION_UPPER_BOUND 21.0.0)

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

## Clang 16 require c++17 or later.
## Clang 18 require c++17 or later.
if (NOT CMAKE_CXX_STANDARD)
set (CMAKE_CXX_STANDARD 17)
endif()
Expand Down Expand Up @@ -286,10 +274,10 @@ endif()
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})

set( CPPINTEROP_BUILT_STANDALONE 1 )
endif()

include(AddLLVM)
include(HandleLLVMOptions)
include(AddLLVM)
include(HandleLLVMOptions)
endif()

set(CMAKE_INCLUDE_CURRENT_DIR ON)

Expand Down
71 changes: 55 additions & 16 deletions interpreter/CppInterOp/Emscripten-build-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ On Windows execute the following
```powershell
cd .\llvm-project\
cp -r ..\patches\llvm\emscripten-clang20*
cp -r ..\patches\llvm\Windows-emscripten-clang20*
git apply -v Windows-emscripten-clang20-1-CrossCompile.patch
git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
git apply -v emscripten-clang20-3-enable_exception_handling.patch
```

We are now in a position to build an emscripten build of llvm by executing the following on Linux
Expand All @@ -81,7 +80,6 @@ mkdir build
cd build
emcmake cmake -DCMAKE_BUILD_TYPE=Release \
-DLLVM_HOST_TRIPLE=wasm32-unknown-emscripten \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_TARGETS_TO_BUILD="WebAssembly" \
-DLLVM_ENABLE_LIBEDIT=OFF \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
Expand All @@ -99,6 +97,9 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_LIBPFM=OFF \
-DCLANG_BUILD_TOOLS=OFF \
-DLLVM_NATIVE_TOOL_DIR=$NATIVE_DIR \
-DCMAKE_C_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" \
-DCMAKE_CXX_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" \
-DLLVM_ENABLE_LTO=Full \
../llvm
emmake make libclang -j $(nproc --all)
emmake make clangInterpreter clangStaticAnalyzerCore -j $(nproc --all)
Expand All @@ -108,11 +109,17 @@ emmake make lldWasm -j $(nproc --all)
or executing

```powershell
mkdir native_build
cd native_build
cmake -DLLVM_ENABLE_PROJECTS=clang -DLLVM_TARGETS_TO_BUILD=host -DCMAKE_BUILD_TYPE=Release -G Ninja ../llvm/
cmake --build . --target llvm-tblgen clang-tblgen --parallel $(nproc --all)
$env:PWD_DIR= $PWD.Path
$env:NATIVE_DIR="$env:PWD_DIR/bin/"
cd ..
mkdir build
cd build
emcmake cmake -DCMAKE_BUILD_TYPE=Release `
-DLLVM_HOST_TRIPLE=wasm32-unknown-emscripten `
-DLLVM_ENABLE_ASSERTIONS=ON `
-DLLVM_TARGETS_TO_BUILD="WebAssembly" `
-DLLVM_ENABLE_LIBEDIT=OFF `
-DLLVM_ENABLE_PROJECTS="clang;lld" `
Expand All @@ -129,7 +136,11 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release `
-DLLVM_BUILD_TOOLS=OFF `
-DLLVM_ENABLE_LIBPFM=OFF `
-DCLANG_BUILD_TOOLS=OFF `
-DLLVM_NATIVE_TOOL_DIR="$env:NATIVE_DIR" `
-G Ninja `
-DCMAKE_C_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" `
-DCMAKE_CXX_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" `
-DLLVM_ENABLE_LTO=Full `
..\llvm
emmake ninja libclang clangInterpreter clangStaticAnalyzerCore lldWasm
```
Expand Down Expand Up @@ -208,14 +219,14 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release `
emmake make -j $(nproc --all) check-cppinterop
```

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
It is possible to run the Emscripten tests in a headless browser. To do this we will first move to the tests directory


```bash
cd ./unittests/CppInterOp/
```

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

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

To run tests in Safari you can make use of safaridriver. How to enable this will depend on
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
python package. This only needs to be enable once, and then you can execute the following to run the tests in Safari

```bash
echo "Running CppInterOpTests in Safari"
emrun --no_browser --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html &
python ../../../scripts/browser_tests_safari.py CppInterOpTests.html
echo "Running DynamicLibraryManagerTests in Safari"
emrun --no_browser --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html &
python ../../../scripts/browser_tests_safari.py DynamicLibraryManagerTests.html
```

To do this on Ubuntu x86 execute the following

```bash
Expand Down Expand Up @@ -283,6 +307,26 @@ echo "Running DynamicLibraryManagerTests in Firefox"
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
```

To do this on Windows x86 execute the following

```powershell
Invoke-WebRequest -Uri "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Win/1411573/chrome-win.zip" -OutFile "$PWD\chrome-win.zip" -Verbose
Expand-Archive -Path "$PWD\chrome-win.zip" -DestinationPath "$PWD" -Force -Verbose
Invoke-WebRequest -Uri "https://download.mozilla.org/?product=firefox-latest-ssl&os=win64&lang=en-US" -OutFile "firefox-setup.exe" -Verbose
& "C:\Program Files\7-Zip\7z.exe" x "firefox-setup.exe"
$env:PATH="$PWD\core;$PWD\chrome-win;$env:PATH"
echo "PATH=$env:PATH"
echo "PATH=$env:PATH" >> $env:GITHUB_ENV
echo "Running CppInterOpTests in Firefox"
emrun.bat --browser="firefox.exe" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
echo "Running DynamicLibraryManagerTests in Firefox"
emrun.bat --browser="firefox.exe" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
echo "Running CppInterOpTests in Chromium"
emrun.bat --browser="chrome.exe" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
echo "Running DynamicLibraryManagerTests in Chromium"
emrun.bat --browser="chrome.exe" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
```

Assuming it passes all test you can install by executing the following

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

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

```bash
cd ../..
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
export LLVM_VERSION=20
cd ./xeus-cpp
mkdir build
cd build
Expand All @@ -308,29 +353,23 @@ emcmake cmake \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DXEUS_CPP_RESOURCE_DIR=$LLVM_BUILD_DIR/lib/clang/$LLVM_VERSION \
-DXEUS_CPP_RESOURCE_DIR="$LLVM_BUILD_DIR/lib/clang/$LLVM_VERSION" \
-DSYSROOT_PATH=$SYSROOT_PATH \
..
emmake make -j $(nproc --all) install
```

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

```bash
cd ../..
micromamba create -n xeus-lite-host jupyterlite-core=0.6 jupyterlite-xeus jupyter_server jupyterlab notebook python-libarchive-c -c conda-forge
micromamba activate xeus-lite-host
jupyter lite build --XeusAddon.prefix=$PREFIX \
jupyter lite serve --XeusAddon.prefix=$PREFIX \
--contents xeus-cpp/notebooks/xeus-cpp-lite-demo.ipynb \
--contents xeus-cpp/notebooks/smallpt.ipynb \
--contents xeus-cpp/notebooks/images/marie.png \
--contents xeus-cpp/notebooks/audio/audio.wav \
--XeusAddon.mounts="$PREFIX/share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles" \
--XeusAddon.mounts="$PREFIX/etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d"
```

Once the Jupyter Lite site has built you can test the website locally by executing

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