Skip to content

Commit b9c4822

Browse files
authored
Add Jupyter-Lite xeus-cpp demo to CppInterOp (#380)
1 parent f1391cd commit b9c4822

File tree

2 files changed

+214
-0
lines changed

2 files changed

+214
-0
lines changed

.github/workflows/deploy-pages.yml

+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
name: Build and Deploy
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
jobs:
15+
build:
16+
runs-on: ${{ matrix.os }}
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
- name: ubu22-x86-gcc12-clang-repl-19-emscripten_wasm
23+
os: ubuntu-22.04
24+
compiler: gcc-12
25+
clang-runtime: '19'
26+
cling: Off
27+
micromamba_shell_init: bash
28+
emsdk_ver: "3.1.45"
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Set up Python
36+
uses: actions/setup-python@v5
37+
with:
38+
python-version: '3.11'
39+
40+
- name: Save PR Info on Unix systems
41+
if: ${{ runner.os != 'windows' }}
42+
run: |
43+
mkdir -p ./pr
44+
echo ${{ github.event.number }} > ./pr/NR
45+
echo ${{ github.repository }} > ./pr/REPO
46+
47+
cling_on=$(echo "${{ matrix.cling }}" | tr '[:lower:]' '[:upper:]')
48+
if [[ "$cling_on" == "ON" ]]; then
49+
export CLING_HASH=$(git ls-remote https://github.com/root-project/cling.git refs/tags/v${{ matrix.cling-version }} | tr '\t' '-')
50+
export LLVM_HASH=$(git ls-remote https://github.com/root-project/llvm-project.git cling-llvm${{ matrix.clang-runtime}} | tr '\t' '-')
51+
else
52+
export CLING_HASH="Repl"
53+
# May need to revert back to both having same llvm_hash, as below cause llvm to be rebuilt everytime commit is made to llvm/llvm-project for release a.x
54+
# which could be quite often for new releases
55+
export LLVM_HASH=$(git ls-remote https://github.com/llvm/llvm-project.git refs/heads/release/${{ matrix.clang-runtime}}.x | tr '\t' '-')
56+
fi
57+
58+
echo "CLING_HASH=$CLING_HASH" >> $GITHUB_ENV
59+
echo "LLVM_HASH=$LLVM_HASH" >> $GITHUB_ENV
60+
61+
- name: Setup default Build Type on *nux
62+
if: runner.os != 'windows'
63+
run: |
64+
echo "BUILD_TYPE=Release" >> $GITHUB_ENV
65+
echo "CODE_COVERAGE=0" >> $GITHUB_ENV
66+
echo "ncpus=$(nproc --all)" >> $GITHUB_ENV
67+
68+
- name: install mamba
69+
uses: mamba-org/setup-micromamba@main
70+
with:
71+
environment-file: environment-wasm-build.yml
72+
init-shell: >-
73+
${{ matrix.micromamba_shell_init }}
74+
environment-name: CppInterOp-wasm-build
75+
76+
- name: Setup emsdk
77+
shell: bash -l {0}
78+
run: |
79+
git clone https://github.com/emscripten-core/emsdk.git
80+
cd emsdk
81+
./emsdk install ${{ matrix.emsdk_ver }}
82+
83+
- name: Restore Cache LLVM/Clang runtime build directory
84+
uses: actions/cache/restore@v4
85+
id: cache
86+
with:
87+
path: |
88+
llvm-project
89+
${{ matrix.cling=='On' && 'cling' || '' }}
90+
key: ${{ env.CLING_HASH }}-${{ runner.os }}-${{ matrix.os }}-${{ matrix.compiler }}-clang-${{ matrix.clang-runtime }}.x-patch-${{ hashFiles(format('patches/llvm/clang{0}-*.patch', matrix.clang-runtime)) || 'none' }}
91+
92+
- name: Emscripten build of CppInterOp on Unix systems
93+
if: ${{ runner.os != 'windows' }}
94+
shell: bash -l {0}
95+
run: |
96+
./emsdk/emsdk activate ${{matrix.emsdk_ver}}
97+
source ./emsdk/emsdk_env.sh
98+
micromamba create -f environment-wasm.yml --platform=emscripten-wasm32
99+
100+
export PREFIX=$MAMBA_ROOT_PREFIX/envs/CppInterOp-wasm
101+
export CMAKE_PREFIX_PATH=$PREFIX
102+
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
103+
104+
LLVM_DIR="$(pwd)/llvm-project"
105+
LLVM_BUILD_DIR="$(pwd)/llvm-project/build"
106+
cling_on=$(echo "${{ matrix.cling }}" | tr '[:lower:]' '[:upper:]')
107+
if [[ "${cling_on}" == "ON" ]]; then
108+
CLING_DIR="$(pwd)/cling"
109+
CLING_BUILD_DIR="$(pwd)/cling/build"
110+
CPLUS_INCLUDE_PATH="${CLING_DIR}/tools/cling/include:${CLING_BUILD_DIR}/include:${LLVM_DIR}/llvm/include:${LLVM_DIR}/clang/include:${LLVM_BUILD_DIR}/include:${LLVM_BUILD_DIR}/tools/clang/include:$PWD/include"
111+
else
112+
CPLUS_INCLUDE_PATH="${LLVM_DIR}/llvm/include:${LLVM_DIR}/clang/include:${LLVM_BUILD_DIR}/include:${LLVM_BUILD_DIR}/tools/clang/include:$PWD/include"
113+
fi
114+
115+
# Build CppInterOp next to cling and llvm-project.
116+
mkdir build
117+
cd build
118+
export CPPINTEROP_BUILD_DIR=$PWD
119+
120+
if [[ "${cling_on}" == "ON" ]]; then
121+
emcmake cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \
122+
-DUSE_CLING=ON \
123+
-DUSE_REPL=OFF \
124+
-DCMAKE_PREFIX_PATH=$PREFIX \
125+
-DCling_DIR=$LLVM_BUILD_DIR/tools/cling \
126+
-DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm \
127+
-DClang_DIR=$LLVM_BUILD_DIR/lib/cmake/clang \
128+
-DBUILD_SHARED_LIBS=OFF \
129+
-DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \
130+
-DCMAKE_INSTALL_PREFIX=$PREFIX \
131+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
132+
-DZLIB_INCLUDE_DIR=$PREFIX/include \
133+
-DZLIB_LIBRARY=$PREFIX/lib/ \
134+
../
135+
else
136+
emcmake cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \
137+
-DUSE_CLING=OFF \
138+
-DUSE_REPL=ON \
139+
-DCMAKE_PREFIX_PATH=$PREFIX \
140+
-DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm \
141+
-DClang_DIR=$LLVM_BUILD_DIR/lib/cmake/clang \
142+
-DBUILD_SHARED_LIBS=OFF \
143+
-DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \
144+
-DCMAKE_INSTALL_PREFIX=$PREFIX \
145+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
146+
-DZLIB_INCLUDE_DIR=$PREFIX/include \
147+
-DZLIB_LIBRARY=$PREFIX/lib/ \
148+
../
149+
fi
150+
151+
emmake make -j ${{ env.ncpus }}
152+
153+
cd ..
154+
155+
echo "CB_PYTHON_DIR=$CB_PYTHON_DIR" >> $GITHUB_ENV
156+
echo "CPPINTEROP_BUILD_DIR=$CPPINTEROP_BUILD_DIR" >> $GITHUB_ENV
157+
echo "CPPINTEROP_DIR=$CPPINTEROP_DIR" >> $GITHUB_ENV
158+
echo "LLVM_BUILD_DIR=$LLVM_BUILD_DIR" >> $GITHUB_ENV
159+
echo "CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH" >> $GITHUB_ENV
160+
echo "PREFIX=$PREFIX" >> $GITHUB_ENV
161+
162+
- name: Build xeus-cpp
163+
shell: bash -l {0}
164+
run: |
165+
./emsdk/emsdk activate ${{matrix.emsdk_ver}}
166+
source ./emsdk/emsdk_env.sh
167+
micromamba activate CppInterOp-wasm
168+
git clone https://github.com/compiler-research/xeus-cpp.git
169+
cd ./xeus-cpp
170+
mkdir build
171+
pushd build
172+
export CMAKE_PREFIX_PATH=${{ env.PREFIX }}
173+
export CMAKE_SYSTEM_PREFIX_PATH=${{ env.PREFIX }}
174+
emcmake cmake \
175+
-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \
176+
-DCMAKE_PREFIX_PATH=${{ env.PREFIX }} \
177+
-DCMAKE_INSTALL_PREFIX=${{ env.PREFIX }} \
178+
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
179+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
180+
-DCppInterOp_DIR="${{ env.CPPINTEROP_BUILD_DIR }}/lib/cmake/CppInterOp" \
181+
..
182+
EMCC_CFLAGS='-sERROR_ON_UNDEFINED_SYMBOLS=0' emmake make -j ${{ env.ncpus }}
183+
184+
- name: Jupyter Lite integration
185+
shell: bash -l {0}
186+
run: |
187+
cd ./xeus-cpp/
188+
micromamba create -n xeus-lite-host jupyterlite-core
189+
micromamba activate xeus-lite-host
190+
python -m pip install jupyterlite-xeus
191+
jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }} --output-dir dist
192+
193+
- name: Upload artifact
194+
uses: actions/upload-pages-artifact@v3
195+
with:
196+
path: ./xeus-cpp/dist/
197+
198+
deploy:
199+
needs: build
200+
permissions:
201+
pages: write
202+
id-token: write
203+
environment:
204+
name: github-pages
205+
url: ${{ steps.deployment.outputs.page_url }}
206+
runs-on: ubuntu-22.04
207+
steps:
208+
- name: Deploy to GitHub Pages
209+
id: deployment
210+
uses: actions/deploy-pages@v4

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ In such scenarios CppInterOp can be used to provide the necessary introspection
2020

2121
[CppInterOp API Documentation](https://cppinterop.readthedocs.io/en/latest/build/html/index.html)
2222

23+
Try Jupyter Lite CppInterOp demo by clicking below
24+
25+
[![lite-badge](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://compiler-research.github.io/CppInterOp/lab/index.html)
26+
2327
## CppInterOp Introduction
2428

2529
The CppInterOp library provides a minimalist approach for other languages to

0 commit comments

Comments
 (0)