Skip to content

Commit ce09338

Browse files
committed
Fixes issues which occur when building on Apple Silicon
Link to xeus-zmq Add option to define where cxxopts folder is (Macbook unable to locate folder without) Change header file xeus/xserver_zmq.hpp to xeus-zmq/xserver_zmq.hpp Add #include <iostream> to include/xeus-clang-repl/xmanager.hpp otherwise errors due to use of std::cerr and others Fixes dockerfile so builds on arm based machines Changes CI to include extra dependencies
1 parent aeb22a7 commit ce09338

File tree

8 files changed

+114
-58
lines changed

8 files changed

+114
-58
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,12 @@ jobs:
136136
#
137137
conda update --all
138138
conda install -y -q -c conda-forge \
139-
'xeus>=2.0,<3.0' \
139+
'xeus>=2.0' \
140+
xeus-zmq \
140141
'nlohmann_json>=3.9.1,<3.10' \
141142
'cppzmq>=4.6.0,<5' \
142143
'xtl>=0.7,<0.8' \
144+
'openssl<4' \
143145
pugixml \
144146
'cxxopts>=2.2.1,<2.3' \
145147
libuuid \

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ set(xeus_REQUIRED_VERSION 1.0.0)
8989
set(cppzmq_REQUIRED_VERSION 4.3.0)
9090

9191
find_package(xeus ${xeus_REQUIRED_VERSION} REQUIRED)
92+
find_package(xeus-zmq REQUIRED)
9293
find_package(cppzmq REQUIRED CONFIG)
9394
find_package(pugixml REQUIRED)
9495

@@ -103,6 +104,10 @@ if(POLICY CMP0077)
103104
endif()
104105

105106
find_package(cxxopts REQUIRED)
107+
108+
# Added as system unable to locate cxxopts include folder on MacOS without
109+
include_directories(${cxxopts_DIR}/../include/)
110+
106111
set(Python_FIND_VIRTUALENV ONLY)
107112
find_package(Python COMPONENTS Interpreter Development)
108113

@@ -251,7 +256,7 @@ target_include_directories(xeus-clang-repl SYSTEM
251256
PUBLIC
252257
$<BUILD_INTERFACE:${XEUS_CLANG-REPL_INCLUDE_DIR}>
253258
$<INSTALL_INTERFACE:include>)
254-
target_link_libraries(xeus-clang-repl PUBLIC clangCppInterOp xeus pugixml cxxopts::cxxopts)
259+
target_link_libraries(xeus-clang-repl PUBLIC clangCppInterOp xeus xeus-zmq pugixml)
255260

256261
if(APPLE)
257262
target_link_libraries(xeus-clang-repl PUBLIC -Wl,-w -Wl,-bind_at_load -Wl,-undefined,dynamic_lookup)

Dockerfile

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ RUN \
4545
###libomp-dev \
4646
# Other "our" apt installs (development and testing)
4747
build-essential \
48+
clang-15 \
4849
git \
4950
nano-tiny \
5051
less \
@@ -54,7 +55,9 @@ RUN \
5455
#cuda \
5556
$([ -n "$_CUDA_" ] && echo nvidia-cuda-toolkit) \
5657
&& \
57-
apt-get clean && rm -rf /var/lib/apt/lists/* && \
58+
apt-get clean && \
59+
apt-get autoremove && \
60+
rm -rf /var/lib/apt/lists/* && \
5861
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
5962
locale-gen
6063

@@ -130,13 +133,16 @@ RUN \
130133
# Other "our" conda installs
131134
cmake \
132135
#"clangdev=$LLVM_REQUIRED_VERSION" \
133-
'xeus>=2.0,<3.0' \
136+
'xeus>=2.0' \
137+
xeus-zmq \
134138
'nlohmann_json>=3.9.1,<3.10' \
135139
'cppzmq>=4.6.0,<5' \
136140
'xtl>=0.7,<0.8' \
137-
'openssl<2' \
141+
'openssl<4' \
138142
ipykernel \
139143
pugixml \
144+
zlib \
145+
libxml2 \
140146
'cxxopts>=2.2.1,<2.3' \
141147
libuuid \
142148
# Test dependencies
@@ -159,6 +165,9 @@ RUN \
159165
set -x && \
160166
source /home/jovyan/.conda.init && \
161167
conda activate .venv && \
168+
export ARCHITECHURE=$(uname -m) && \
169+
if [ "$ARCHITECHURE" == "x86_64" ] ; \
170+
then \
162171
#
163172
artifact_name="clang-dev" && \
164173
#
@@ -167,9 +176,10 @@ RUN \
167176
echo $PWD && git_remote_origin_url=$(git config --get remote.origin.url) && \
168177
echo "Debug: Remote origin url: $git_remote_origin_url" && \
169178
arr=(${git_remote_origin_url//\// }) && \
170-
gh_repo_owner=${arr[2]} && \
179+
arr2=(${arr[0]//:/ }) && \
180+
gh_repo_owner=${arr2[1]} && \
171181
gh_f_repo_owner="compiler-research" && \
172-
arr=(${arr[3]//./ }) && \
182+
arr=(${arr[1]//./ }) && \
173183
gh_repo_name=${arr[0]} && \
174184
gh_repo="${gh_repo_owner}/${gh_repo_name}" && \
175185
gh_f_repo_name=${gh_repo_name} && \
@@ -193,7 +203,6 @@ RUN \
193203
pushd /home/runner/work/xeus-clang-repl/xeus-clang-repl && \
194204
# repo
195205
echo "Debug: Repo owner/name: ${gh_repo_owner} / ${gh_repo_name}" && \
196-
197206
#RUN \
198207
# set -x && \
199208
source /home/jovyan/.conda.init && \
@@ -231,26 +240,45 @@ RUN \
231240
popd && \
232241
#
233242
echo "Debug clang path: $PATH_TO_CLANG_DEV" && \
234-
export PATH_TO_LLVM_BUILD=$PATH_TO_CLANG_DEV/inst && \
243+
export PATH_TO_LLVM_BUILD=$PATH_TO_CLANG_DEV/inst/ && \
244+
export PATH_TO_LLVM_CONFIG=$PATH_TO_CLANG_DEV/inst/lib/cmake/llvm/ && \
245+
export PATH_TO_CLANG_CONFIG=$PATH_TO_CLANG_DEV/inst/lib/cmake/clang/ ; \
246+
fi && \
235247
export VENV=${CONDA_DIR}/envs/.venv && \
236-
export PATH=${VENV}/bin:${CONDA_DIR}/bin:$PATH_TO_LLVM_BUILD/bin:$PATH && \
237-
export LD_LIBRARY_PATH=$PATH_TO_LLVM_BUILD/lib:$LD_LIBRARY_PATH && \
238248
echo "export VENV=$VENV" >> ~/.profile && \
239-
echo "export PATH=$PATH" >> ~/.profile && \
240249
echo "export EDITOR=emacs" >> ~/.profile && \
241250
#
242-
# Build CppInterOp
243-
#
251+
# Build LLVM (if on arm) & CppInterOp
252+
#
244253
sys_incs=$(LC_ALL=C c++ -xc++ -E -v /dev/null 2>&1 | LC_ALL=C sed -ne '/starts here/,/End of/p' | LC_ALL=C sed '/^ /!d' | cut -c2- | tr '\n' ':') && \
245254
export CPLUS_INCLUDE_PATH="${PATH_TO_LLVM_BUILD}/include/llvm:${PATH_TO_LLVM_BUILD}/include/clange:$CPLUS_INCLUDE_PATH:${sys_incs%:}" && \
246255
git clone https://github.com/compiler-research/CppInterOp.git && \
256+
if [ "$ARCHITECHURE" == "aarch64" ] ; \
257+
then \
258+
export CC=/usr/bin/clang-15 && \
259+
export CXX=/usr/bin/clang++-15 && \
260+
git clone --depth=1 --branch release/16.x https://github.com/llvm/llvm-project.git && \
261+
cd ./llvm-project/ && \
262+
mkdir build && \
263+
export LLVM_DIR=$(pwd) && \
264+
compgen -G "../CppInterOp/patches/llvm/clang16-*.patch" > /dev/null && find ../CppInterOp/patches/llvm/clang16-*.patch -printf "%f\n" && git apply ../CppInterOp/patches/llvm/clang16-*.patch && \
265+
cd build && \
266+
cmake -DLLVM_ENABLE_PROJECTS=clang -DLLVM_TARGETS_TO_BUILD="host;NVPTX" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_USE_LINKER=gold -DCLANG_ENABLE_STATIC_ANALYZER=OFF -DCLANG_ENABLE_ARCMT=OFF -DCLANG_ENABLE_FORMAT=OFF -DCLANG_ENABLE_BOOTSTRAP=OFF ../llvm && \
267+
cmake --build . --target clang clang-repl --parallel $(nproc --all) && \
268+
export PATH_TO_LLVM_CONFIG=$LLVM_DIR/build/lib/cmake/llvm/ && \
269+
export PATH_TO_CLANG_CONFIG=$LLVM_DIR/build/lib/cmake/clang/ && \
270+
export PATH_TO_LLVM_BUILD=$LLVM_DIR/build && \
271+
cd ../../ ; \
272+
fi && \
273+
export PATH=${VENV}/bin:${CONDA_DIR}/bin:$PATH_TO_LLVM_BUILD/bin:$PATH && \
274+
export LD_LIBRARY_PATH=$PATH_TO_LLVM_BUILD/lib:$LD_LIBRARY_PATH && \
275+
echo "export PATH=$PATH" >> ~/.profile && \
247276
export CB_PYTHON_DIR="$PWD/cppyy-backend/python" && \
248277
export CPPINTEROP_DIR="$CB_PYTHON_DIR/cppyy_backend" && \
249-
cd CppInterOp && \
250-
mkdir build && \
251-
cd build && \
278+
mkdir CppInterOp/build && \
279+
cd CppInterOp/build && \
252280
export CPPINTEROP_BUILD_DIR=$PWD && \
253-
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DUSE_CLING=OFF -DUSE_REPL=ON -DLLVM_DIR=$PATH_TO_LLVM_BUILD -DLLVM_USE_LINKER=gold -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR .. && \
281+
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DUSE_CLING=OFF -DUSE_REPL=ON -DLLVM_DIR=$PATH_TO_LLVM_CONFIG -DClang_DIR=$PATH_TO_CLANG_CONFIG -DLLVM_USE_LINKER=gold -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR .. && \
254282
cmake --build . --parallel $(nproc --all) && \
255283
#make install -j$(nproc --all)
256284
export CPLUS_INCLUDE_PATH="$CPPINTEROP_DIR/include:$CPLUS_INCLUDE_PATH" && \
@@ -260,9 +288,10 @@ RUN \
260288
#
261289
# Build and Install cppyy-backend
262290
#
263-
git clone https://github.com/compiler-research/cppyy-backend.git && \
291+
git clone --depth=1 https://github.com/compiler-research/cppyy-backend.git && \
264292
cd cppyy-backend && \
265-
mkdir -p $CPPINTEROP_DIR/lib build && cd build && \
293+
mkdir -p $CPPINTEROP_DIR/lib build && \
294+
cd build && \
266295
# Install CppInterOp
267296
(cd $CPPINTEROP_BUILD_DIR && cmake --build . --target install --parallel $(nproc --all)) && \
268297
# Build and Install cppyy-backend
@@ -274,9 +303,9 @@ RUN \
274303
# Build and Install CPyCppyy
275304
#
276305
# Install CPyCppyy
277-
git clone https://github.com/compiler-research/CPyCppyy.git && \
278-
cd CPyCppyy && \
279-
mkdir build && cd build && \
306+
git clone --depth=1 https://github.com/compiler-research/CPyCppyy.git && \
307+
mkdir CPyCppyy/build && \
308+
cd CPyCppyy/build && \
280309
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE .. && \
281310
cmake --build . --parallel $(nproc --all) && \
282311
export CPYCPPYY_DIR=$PWD && \
@@ -285,7 +314,7 @@ RUN \
285314
# Build and Install cppyy
286315
#
287316
# Install cppyy
288-
git clone https://github.com/compiler-research/cppyy.git && \
317+
git clone --depth=1 https://github.com/compiler-research/cppyy.git && \
289318
cd cppyy && \
290319
python -m pip install --upgrade . --no-deps && \
291320
cd .. && \
@@ -294,9 +323,9 @@ RUN \
294323
export PYTHONPATH=$PYTHONPATH:$CPYCPPYY_DIR:$CB_PYTHON_DIR:/home/jovyan && \
295324
echo "export PYTHONPATH=$PYTHONPATH" >> ~/.profile && \
296325
export CPLUS_INCLUDE_PATH="/home/jovyan/CPyCppyy/include/:$CPLUS_INCLUDE_PATH" && \
297-
# FIXME: Remove the hardcoded version of python here.
326+
export PYTHON_VERSION=$(python --version | cut -c8- | cut -f1,2 -d'.') && \
298327
export CPLUS_INCLUDE_PATH="/home/jovyan/clad/include:$CPLUS_INCLUDE_PATH" && \
299-
export CPLUS_INCLUDE_PATH="${VENV}/include:${VENV}/include/python3.10:$CPLUS_INCLUDE_PATH" && \
328+
export CPLUS_INCLUDE_PATH="${VENV}/include:${VENV}/include/python${PYTHON_VERSION}:$CPLUS_INCLUDE_PATH" && \
300329
python -c "import cppyy" && \
301330
#
302331
# Build and Install xeus-clang-repl
@@ -312,13 +341,11 @@ RUN \
312341
# Build and Install Clad
313342
#
314343
git clone --depth=1 https://github.com/vgvassilev/clad.git && \
315-
cd clad && \
316-
mkdir build && \
317-
cd build && \
318-
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE .. -DClang_DIR=${PATH_TO_LLVM_BUILD}/lib/cmake/clang/ -DLLVM_DIR=${PATH_TO_LLVM_BUILD}/lib/cmake/llvm/ -DCMAKE_INSTALL_PREFIX=${CONDA_DIR} -DLLVM_EXTERNAL_LIT="$(which lit)" && \
319-
#make -j$(nproc --all) && \
320-
make && \
321-
make install && \
344+
mkdir clad/build && \
345+
cd clad/build && \
346+
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE .. -DClang_DIR=$PATH_TO_CLANG_CONFIG -DLLVM_DIR=$PATH_TO_LLVM_CONFIG -DCMAKE_INSTALL_PREFIX=${CONDA_DIR} -DLLVM_EXTERNAL_LIT="$(which lit)" && \
347+
make -j$(nproc --all) && \
348+
make install -j$(nproc --all) && \
322349
### install clad in all exist kernels
323350
##for i in "$KERNEL_PYTHON_PREFIX"/share/jupyter/kernels/*; do if [[ $i =~ .*/clad-xcpp.* ]]; then jq '.argv += ["-fplugin=$KERNEL_PYTHON_PREFIX/lib/clad.so"] | .display_name += " (with clad)"' "$i"/kernel.json > tmp.$$.json && mv tmp.$$.json "$i"/kernel.json; fi; done && \
324351
###
@@ -339,8 +366,8 @@ RUN \
339366
k="/opt/conda/share/jupyter/kernels/python3/kernel.json" && \
340367
jq ".argv[0] = \"${VENV}/bin/python\"" $k > $k.$$.tmp && mv $k.$$.tmp $k && \
341368
# xtensor
342-
git clone https://github.com/xtensor-stack/xtensor.git && \
343-
cd xtensor && \
344-
mkdir build && cd build && \
369+
git clone --depth=1 https://github.com/xtensor-stack/xtensor.git && \
370+
mkdir xtensor/build && \
371+
cd xtensor/build && \
345372
cmake -DCMAKE_INSTALL_PREFIX=$KERNEL_PYTHON_PREFIX .. && \
346-
make install
373+
make install -j$(nproc --all)

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ link:
77

88
### Xeus-Clang-REPL
99

10-
Clone the repository locally and execute ./run-docker.sh
11-
1210
## Description
1311

1412
`xeus-clang-repl` integrates clang-repl with the xeus protocol and is a platform for C++ usage in Jupyter Notebooks. The demo developed in this repository shows a Python - CPP integraton in Jupyter Notebooks, where variables can be transfered between Python and CPP.
@@ -26,7 +24,7 @@ fresh environment. It is also needed to use a
2624
You will first need to install dependencies
2725

2826
```bash
29-
mamba install cmake cxx-compiler nlohmann_json cppzmq xtl jupyterlab clangdev=14 cxxopts pugixml -c conda-forge
27+
mamba install xeus xeus-zmq cmake cxx-compiler nlohmann_json cppzmq xtl jupyterlab clangdev=14 cxxopts pugixml -c conda-forge
3028
```
3129

3230
**Note:** Use a mamba environment with python version >= 3.11 for fetching clang-versions
@@ -47,9 +45,9 @@ mamba install`xeus-clang-repl` notebook -c conda-forge
4745
``` -->
4846

4947
```bash
50-
git clone https://github.com/llvm/llvm-project
48+
git clone --depth=1 --branch release/15.0x https://github.com/llvm/llvm-project
5149

52-
git checkout -b release/15.0x
50+
cd llvm-project
5351

5452
git apply patches/llvm/clang15-D127284.patch
5553

@@ -75,6 +73,18 @@ cmake ../ -DClang_DIR=/usr/lib/llvm-15/build/lib/cmake/clang\
7573
make -j n
7674
```
7775

76+
## Docker
77+
It is possible to build xeus-clang-repl within a Docker container. On an arm based Apple machine with docker, docker-compose and colima installed, you can try out xeus-clang-repl using the following commands (cpu represents number of cores, and memory is in GiB, so adjust according to your machine)
78+
```bash
79+
git clone https://github.com/compiler-research/xeus-clang-repl.git
80+
cd xeus-clang-repl
81+
colima start --cpu 8 --memory 8 --arch aarch64 --vm-type=vz --vz-rosetta
82+
chmod a+x ./build-and-run-docker.sh
83+
./build-and-run-docker.sh
84+
```
85+
Once the bash script finishes running, you can experiment with xeus-clang-repl by opening up your browser and visiting http://127.0.0.1:8888/lab
86+
87+
7888
## Try it online (for developers)
7989

8090
To try out xeus-clang-repl interactively in your web browser, just click on the binder

build-and-run-docker.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
docker build . -t xeus-clang-repl
4+
5+
export OS=$(uname -s)
6+
7+
if [ "$OS" == "Darwin" ]
8+
then
9+
docker run --publish 8888:8888 --name xeus-clang-repl-c -i -t xeus-clang-repl "start-notebook.sh"
10+
else
11+
docker container run --rm -i hadolint/hadolint hadolint - < Dockerfile
12+
13+
jupyter-repo2docker \
14+
--no-run \
15+
--user-name=jovyan \
16+
--image-name xeus-clang-repl \
17+
.
18+
19+
docker run --gpus all --publish 8888:8888 --name xeus-clang-repl-c -i -t xeus-clang-repl "start-notebook.sh"
20+
#docker run --rm --runtime=nvidia --gpus all --publish 8888:8888 --name xeus-clang-repl-c -i -t xeus-clang-repl "start-notebook.sh"
21+
22+
# --editable \
23+
# --ref InterOpIntegration \
24+
# https://github.com/alexander-penev/xeus-clang-repl.git \
25+
26+
fi

include/xeus-clang-repl/xmanager.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "nlohmann/json.hpp"
2222

23+
#include <iostream>
2324
#include <map>
2425
#include <memory>
2526
#include <regex>

run-docker.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "xeus/xkernel.hpp"
1616
#include "xeus/xkernel_configuration.hpp"
17-
#include "xeus/xserver_zmq.hpp"
17+
#include "xeus-zmq/xserver_zmq.hpp"
1818

1919
#include "xeus-clang-repl/xeus_clang-repl_config.hpp"
2020
#include "xeus-clang-repl/xinterpreter.hpp"

0 commit comments

Comments
 (0)