Skip to content

Commit 77ee1d0

Browse files
authored
Merge branch 'main' into Add-llvm-21-support
2 parents 7e1bd6e + 2ec0b9a commit 77ee1d0

18 files changed

+361
-757
lines changed

.github/workflows/emscripten.yml

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,13 @@ jobs:
842842
.\emsdk\emsdk_env.ps1
843843
$env:PWD_DIR= $PWD.Path
844844
$env:SYSROOT_PATH="$env:EMSDK/upstream/emscripten/cache/sysroot"
845-
$env:PREFIX="%CONDA_PREFIX%/envs/CppInterOp-wasm"
845+
echo "SYSROOT_PATH=$env:SYSROOT_PATH"
846+
echo "SYSROOT_PATH=$env:SYSROOT_PATH" >> $env:GITHUB_ENV
847+
848+
$env:PREFIX="$env:MAMBA_ROOT_PREFIX/envs/CppInterOp-wasm"
849+
echo "PREFIX=$env:PREFIX"
850+
echo "PREFIX=$env:PREFIX" >> $env:GITHUB_ENV
851+
846852
$env:CMAKE_PREFIX_PATH=$env:PREFIX
847853
$env:CMAKE_SYSTEM_PREFIX_PATH=$env:PREFIX
848854
@@ -945,6 +951,11 @@ jobs:
945951
Error-OnFailure { emrun.bat --browser="chrome.exe" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html }
946952
cd ..\..
947953
Error-OnFailure { emmake make -j ${{ env.ncpus }} install }
954+
echo "SYSROOT_PATH=$env:SYSROOT_PATH" >> $GITHUB_ENV
955+
echo "CPPINTEROP_DIR=$env:CPPINTEROP_DIR" >> $GITHUB_ENV
956+
echo "LLVM_BUILD_DIR=$env:LLVM_BUILD_DIR" >> $GITHUB_ENV
957+
echo "CPLUS_INCLUDE_PATH=$env:CPLUS_INCLUDE_PATH" >> $GITHUB_ENV
958+
echo "PREFIX=$env:PREFIX" >> $GITHUB_ENV
948959
949960
- name: Build and Test/Install CppInterOp on Windows systems (static library)
950961
if: ${{ runner.os == 'windows' }}
@@ -1047,7 +1058,7 @@ jobs:
10471058
echo "Running DynamicLibraryManagerTests in Chromium"
10481059
Error-OnFailure{ emrun.bat --browser="chrome.exe" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html }
10491060
1050-
- name: Build xeus-cpp
1061+
- name: Build xeus-cpp on Unix Systems
10511062
if: ${{ runner.os != 'windows' }}
10521063
shell: bash -l {0}
10531064
run: |
@@ -1071,7 +1082,31 @@ jobs:
10711082
..
10721083
emmake make -j ${{ env.ncpus }} install
10731084
1074-
- name: Test xeus-cpp C++ Emscripten
1085+
- name: Build xeus-cpp on Windows systems
1086+
if: ${{ runner.os == 'windows' }}
1087+
shell: powershell
1088+
run: |
1089+
.\emsdk\emsdk activate ${{matrix.emsdk_ver}}
1090+
.\emsdk\emsdk_env.ps1
1091+
micromamba activate CppInterOp-wasm
1092+
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
1093+
cd .\xeus-cpp
1094+
mkdir build
1095+
pushd build
1096+
$env:CMAKE_PREFIX_PATH="${{ env.PREFIX }}"
1097+
$env:CMAKE_SYSTEM_PREFIX_PATH="${{ env.PREFIX }}"
1098+
emcmake cmake `
1099+
-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} `
1100+
-DCMAKE_PREFIX_PATH=${{ env.PREFIX }} `
1101+
-DCMAKE_INSTALL_PREFIX=${{ env.PREFIX }} `
1102+
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON `
1103+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON `
1104+
-DXEUS_CPP_RESOURCE_DIR=${{ env.LLVM_BUILD_DIR }}\lib\clang\${{ matrix.clang-runtime }} `
1105+
-DSYSROOT_PATH=${{ env.SYSROOT_PATH }} `
1106+
..
1107+
emmake make -j ${{ env.ncpus }} install
1108+
1109+
- name: Test xeus-cpp C++ Emscripten on Unix Systems
10751110
if: ${{ runner.os != 'windows' }}
10761111
shell: bash -l {0}
10771112
run: |
@@ -1080,6 +1115,30 @@ jobs:
10801115
cd ./xeus-cpp/build/test
10811116
node test_xeus_cpp.js
10821117
1118+
- name: Test xeus-cpp C++ Emscripten on Windows Systems
1119+
if: ${{ runner.os == 'windows' }}
1120+
shell: powershell
1121+
run: |
1122+
function Error-OnFailure {
1123+
param (
1124+
[Parameter(Mandatory)]
1125+
[ScriptBlock]$Command
1126+
)
1127+
1128+
& $Command
1129+
1130+
if ($LASTEXITCODE -ne 0) {
1131+
exit $LASTEXITCODE
1132+
}
1133+
}
1134+
micromamba activate CppInterOp-wasm
1135+
cd .\xeus-cpp\build\test
1136+
node test_xeus_cpp.js
1137+
echo "Running test_xeus_cpp in Firefox"
1138+
Error-OnFailure { emrun.bat --browser="firefox.exe" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html }
1139+
echo "Running test_xeus_cpp in Chromium"
1140+
Error-OnFailure { emrun.bat --browser="chrome.exe" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html }
1141+
10831142
- name: Jupyter Lite integration
10841143
if: ${{ runner.os != 'windows' }}
10851144
shell: bash -l {0}
@@ -1088,3 +1147,12 @@ jobs:
10881147
micromamba create -n xeus-lite-host jupyterlite-core=0.6 jupyterlite-xeus jupyter_server jupyterlab notebook python-libarchive-c -c conda-forge
10891148
micromamba activate xeus-lite-host
10901149
jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }} --contents notebooks/xeus-cpp-lite-demo.ipynb --contents notebooks/smallpt.ipynb --contents notebooks/images/marie.png --contents notebooks/audio/audio.wav --output-dir dist
1150+
1151+
- name: Jupyter Lite integration
1152+
if: ${{ runner.os == 'windows' }}
1153+
shell: powershell
1154+
run: |
1155+
cd .\xeus-cpp\
1156+
micromamba create -n xeus-lite-host jupyterlite-core=0.6 jupyterlite-xeus jupyter_server jupyterlab notebook python-libarchive-c -c conda-forge
1157+
micromamba activate xeus-lite-host
1158+
jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }} --contents notebooks/xeus-cpp-lite-demo.ipynb --contents notebooks/smallpt.ipynb --contents notebooks/images/marie.png --contents notebooks/audio/audio.wav --output-dir dist

Emscripten-build-instructions.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
178178
and
179179

180180
```powershell
181-
$env:PREFIX="%CONDA_PREFIX%/envs/CppInterOp-wasm"
181+
$env:PREFIX="$env:MAMBA_ROOT_PREFIX/envs/CppInterOp-wasm"
182182
$env:CMAKE_PREFIX_PATH=$env:PREFIX
183183
$env:CMAKE_SYSTEM_PREFIX_PATH=$env:PREFIX
184184
```
@@ -337,7 +337,7 @@ emmake make -j $(nproc --all) install
337337
## Xeus-cpp-lite Wasm Build Instructions
338338

339339
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
340-
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 on Linux/MacOS by executing (replace LLVM_VERSION with the version
341341
of llvm you are building against)
342342

343343
```bash
@@ -359,7 +359,28 @@ emcmake cmake \
359359
emmake make -j $(nproc --all) install
360360
```
361361

362-
To build and test Jupyter Lite with this kernel locally you can execute the following
362+
and on Windows by executing
363+
364+
```powershell
365+
cd ..\..
366+
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
367+
$env:LLVM_VERSION=20
368+
cd .\xeus-cpp
369+
mkdir build
370+
cd build
371+
emcmake cmake `
372+
-DCMAKE_BUILD_TYPE=Release `
373+
-DCMAKE_PREFIX_PATH="$env:PREFIX" `
374+
-DCMAKE_INSTALL_PREFIX="$env:PREFIX" `
375+
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON `
376+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON `
377+
-DXEUS_CPP_RESOURCE_DIR="$env:LLVM_BUILD_DIR/lib/clang/$env:LLVM_VERSION" `
378+
-DSYSROOT_PATH="$env:SYSROOT_PATH" `
379+
..
380+
emmake make -j $(nproc --all) install
381+
```
382+
383+
To build and test Jupyter Lite with this kernel locally on Linux/MacOS you can execute the following
363384

364385
```bash
365386
cd ../..
@@ -373,3 +394,18 @@ jupyter lite serve --XeusAddon.prefix=$PREFIX \
373394
--XeusAddon.mounts="$PREFIX/share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles" \
374395
--XeusAddon.mounts="$PREFIX/etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d"
375396
```
397+
398+
and on Windows execute
399+
400+
```powershell
401+
cd ..\..
402+
micromamba create -n xeus-lite-host jupyterlite-core=0.6 jupyterlite-xeus jupyter_server jupyterlab notebook python-libarchive-c -c conda-forge
403+
micromamba activate xeus-lite-host
404+
jupyter lite serve --XeusAddon.prefix="$env:PREFIX" `
405+
--contents xeus-cpp/notebooks/xeus-cpp-lite-demo.ipynb `
406+
--contents xeus-cpp/notebooks/smallpt.ipynb `
407+
--contents xeus-cpp/notebooks/images/marie.png `
408+
--contents xeus-cpp/notebooks/audio/audio.wav `
409+
--XeusAddon.mounts="$env:PREFIX/share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles" `
410+
--XeusAddon.mounts="$env:PREFIX/etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d"
411+
```

docs/DevelopersDocumentation.rst

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -423,54 +423,12 @@ library files and run pytest:
423423
python -m pip install pytest
424424
python -m pytest -sv
425425
426-
###################################
426+
***********************************
427427
CppInterOp Internal Documentation
428-
###################################
428+
***********************************
429429

430430
CppInterOp maintains an internal Doxygen documentation of its components.
431431
Internal documentation aims to capture intrinsic details and overall usage of
432432
code components. The goal of internal documentation is to make the codebase
433433
easier to understand for the new developers. Internal documentation can be
434434
visited : `here <build/html/index.html>`_
435-
436-
**************************************
437-
Multiple Interpreter & Thread-Safety
438-
**************************************
439-
440-
CppInterOp allows the user to create multiple interpreters at a time and
441-
use those interpreters. The interpreters that are created are stored in a
442-
stack and a map. The stack is used to enable the model where the user
443-
wants to create a temporary interpreter and destroy it after performing a
444-
few operations. In such a use case, the top of the stack is the only
445-
interpreter in use at any given point in time.
446-
447-
The map is used to store the mapping from :code:`clang::ASTContext` to
448-
:code:`Cpp::InterpreterInfo`. This is required to figure out which
449-
interpreter an object belongs to. Say the library user performs the
450-
following operations:
451-
452-
1. Create an Interpreter
453-
2. Compile some code with variable :code:`a`
454-
3. Create another Interpreter
455-
4. Performs :code:`Cpp::GetVariableOffset(a)`
456-
457-
In step 4, the top of the stack is an interpreter without the definition of
458-
:code:`a`. And we cannot use it to figure out the address of :code:`a`.
459-
The :code:`clang::Decl` passed to :code:`Cpp::GetVariableOffset` is used to
460-
retrieve the :code:`clang::ASTContext`, using
461-
:code:`clang::Decl::getASTContext`. We then use the map to figure out the
462-
exact Interpreter Instance this :code:`clang::Decl` belongs to and perform
463-
the operation.
464-
465-
A shortcoming of this is that if the CppInterOp accepts a
466-
:code:`clang::QualType` instead of :code:`clang::Decl`, then it is not
467-
possible to get the :code:`clang::ASTContext` from the :code:`clang::QualType`.
468-
In such cases, we iterate over the Allocator of all the Interpreters in our
469-
stack and figure out which :code:`clang::ASTContext` allocated this
470-
:code:`clang::QualType`. This is a very expensive operation. But there is no
471-
alternative to this.
472-
473-
For **thread-safety**, we introduce a lock for each of the interpreters we
474-
create. And lock only that one specific interpreter when required. We also
475-
have 2 global locks, one for LLVM, and another is used to lock operations
476-
performed on the interpreter stack and the map itself.

docs/Emscripten-build-instructions.rst

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ and
203203

204204
.. code:: powershell
205205
206-
$env:PREFIX="%CONDA_PREFIX%/envs/CppInterOp-wasm"
206+
$env:PREFIX="$env:MAMBA_ROOT_PREFIX/envs/CppInterOp-wasm"
207207
$env:CMAKE_PREFIX_PATH=$env:PREFIX
208208
$env:CMAKE_SYSTEM_PREFIX_PATH=$env:PREFIX
209209
@@ -358,8 +358,8 @@ Assuming it passes all test you can install by executing the following.
358358

359359
A project which makes use of the wasm build of CppInterOp is xeus-cpp.
360360
xeus-cpp is a C++ Jupyter kernel. Assuming you are in the CppInterOp
361-
build folder, you can build the wasm version of xeus-cpp by executing
362-
(replace LLVM_VERSION with the version of llvm you are building against)
361+
build folder, you can build the wasm version of xeus-cpp on Linux/MacOS
362+
by executing (replace LLVM_VERSION with the version of llvm you are building against)
363363

364364
.. code:: bash
365365
@@ -380,7 +380,28 @@ build folder, you can build the wasm version of xeus-cpp by executing
380380
..
381381
emmake make -j $(nproc --all) install
382382
383-
To build and test Jupyter Lite with this kernel locally you can execute the following
383+
and on Windows by executing
384+
385+
.. code:: powershell
386+
387+
cd ..\..
388+
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
389+
$env:LLVM_VERSION=20
390+
cd .\xeus-cpp
391+
mkdir build
392+
cd build
393+
emcmake cmake `
394+
-DCMAKE_BUILD_TYPE=Release `
395+
-DCMAKE_PREFIX_PATH="$env:PREFIX" `
396+
-DCMAKE_INSTALL_PREFIX="$env:PREFIX" `
397+
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON `
398+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON `
399+
-DXEUS_CPP_RESOURCE_DIR="$env:LLVM_BUILD_DIR/lib/clang/$env:LLVM_VERSION" `
400+
-DSYSROOT_PATH="$env:SYSROOT_PATH" `
401+
..
402+
emmake make -j $(nproc --all) install
403+
404+
To build and test Jupyter Lite with this kernel locally on Linux/MacOS you can execute the following
384405

385406
.. code:: bash
386407
@@ -394,3 +415,18 @@ To build and test Jupyter Lite with this kernel locally you can execute the foll
394415
--contents xeus-cpp/notebooks/audio/audio.wav \
395416
--XeusAddon.mounts="$PREFIX/share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles" \
396417
--XeusAddon.mounts="$PREFIX/etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d"
418+
419+
and on Windows execute
420+
421+
.. code:: powershell
422+
423+
cd ..\..
424+
micromamba create -n xeus-lite-host jupyterlite-core=0.6 jupyterlite-xeus jupyter_server jupyterlab notebook python-libarchive-c -c conda-forge
425+
micromamba activate xeus-lite-host
426+
jupyter lite serve --XeusAddon.prefix="$env:PREFIX" `
427+
--contents xeus-cpp/notebooks/xeus-cpp-lite-demo.ipynb `
428+
--contents xeus-cpp/notebooks/smallpt.ipynb `
429+
--contents xeus-cpp/notebooks/images/marie.png `
430+
--contents xeus-cpp/notebooks/audio/audio.wav `
431+
--XeusAddon.mounts="$env:PREFIX/share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles" `
432+
--XeusAddon.mounts="$env:PREFIX/etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d"

environment-wasm.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
name: CppInterOp-wasm
22
channels:
3-
- https://repo.prefix.dev/emscripten-forge-dev
3+
- https://prefix.dev/emscripten-forge-dev
4+
- https://prefix.dev/conda-forge
45
dependencies:
56
- emscripten-abi==3.1.73
6-
- nlohmann_json=3.12.0
7+
- nlohmann_json
8+
- nlohmann_json-abi
79
- xeus-lite
810
- xeus
911
- cpp-argparse

0 commit comments

Comments
 (0)