Skip to content

Commit 9a00131

Browse files
authored
Fixes issues which occur when building on Apple Silicon (#77)
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 Added fixme messages to Dockerfile due to issues with arm based build and clang-17
1 parent aeb22a7 commit 9a00131

File tree

8 files changed

+119
-58
lines changed

8 files changed

+119
-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: 67 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ RUN \
4545
###libomp-dev \
4646
# Other "our" apt installs (development and testing)
4747
build-essential \
48+
#FIXME: Update to clang-17 once available in apt repository (expected with next LTS version of Ubuntu April 2024)
49+
# to be use a consistent version of clang throughout
50+
clang-15 \
4851
git \
4952
nano-tiny \
5053
less \
@@ -54,7 +57,9 @@ RUN \
5457
#cuda \
5558
$([ -n "$_CUDA_" ] && echo nvidia-cuda-toolkit) \
5659
&& \
57-
apt-get clean && rm -rf /var/lib/apt/lists/* && \
60+
apt-get clean && \
61+
apt-get autoremove && \
62+
rm -rf /var/lib/apt/lists/* && \
5863
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
5964
locale-gen
6065

@@ -130,13 +135,16 @@ RUN \
130135
# Other "our" conda installs
131136
cmake \
132137
#"clangdev=$LLVM_REQUIRED_VERSION" \
133-
'xeus>=2.0,<3.0' \
138+
'xeus>=2.0' \
139+
xeus-zmq \
134140
'nlohmann_json>=3.9.1,<3.10' \
135141
'cppzmq>=4.6.0,<5' \
136142
'xtl>=0.7,<0.8' \
137-
'openssl<2' \
143+
'openssl<4' \
138144
ipykernel \
139145
pugixml \
146+
zlib \
147+
libxml2 \
140148
'cxxopts>=2.2.1,<2.3' \
141149
libuuid \
142150
# Test dependencies
@@ -159,6 +167,9 @@ RUN \
159167
set -x && \
160168
source /home/jovyan/.conda.init && \
161169
conda activate .venv && \
170+
export ARCHITECHURE=$(uname -m) && \
171+
if [ "$ARCHITECHURE" == "x86_64" ] ; \
172+
then \
162173
#
163174
artifact_name="clang-dev" && \
164175
#
@@ -167,9 +178,10 @@ RUN \
167178
echo $PWD && git_remote_origin_url=$(git config --get remote.origin.url) && \
168179
echo "Debug: Remote origin url: $git_remote_origin_url" && \
169180
arr=(${git_remote_origin_url//\// }) && \
170-
gh_repo_owner=${arr[2]} && \
181+
arr2=(${arr[0]//:/ }) && \
182+
gh_repo_owner=${arr2[1]} && \
171183
gh_f_repo_owner="compiler-research" && \
172-
arr=(${arr[3]//./ }) && \
184+
arr=(${arr[1]//./ }) && \
173185
gh_repo_name=${arr[0]} && \
174186
gh_repo="${gh_repo_owner}/${gh_repo_name}" && \
175187
gh_f_repo_name=${gh_repo_name} && \
@@ -193,7 +205,6 @@ RUN \
193205
pushd /home/runner/work/xeus-clang-repl/xeus-clang-repl && \
194206
# repo
195207
echo "Debug: Repo owner/name: ${gh_repo_owner} / ${gh_repo_name}" && \
196-
197208
#RUN \
198209
# set -x && \
199210
source /home/jovyan/.conda.init && \
@@ -231,26 +242,48 @@ RUN \
231242
popd && \
232243
#
233244
echo "Debug clang path: $PATH_TO_CLANG_DEV" && \
234-
export PATH_TO_LLVM_BUILD=$PATH_TO_CLANG_DEV/inst && \
245+
export PATH_TO_LLVM_BUILD=$PATH_TO_CLANG_DEV/inst/ && \
246+
export PATH_TO_LLVM_CONFIG=$PATH_TO_CLANG_DEV/inst/lib/cmake/llvm/ && \
247+
export PATH_TO_CLANG_CONFIG=$PATH_TO_CLANG_DEV/inst/lib/cmake/clang/ ; \
248+
fi && \
235249
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 && \
238250
echo "export VENV=$VENV" >> ~/.profile && \
239-
echo "export PATH=$PATH" >> ~/.profile && \
240251
echo "export EDITOR=emacs" >> ~/.profile && \
241252
#
242-
# Build CppInterOp
243-
#
253+
# Build LLVM (if on arm) & CppInterOp
254+
#
244255
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' ':') && \
245256
export CPLUS_INCLUDE_PATH="${PATH_TO_LLVM_BUILD}/include/llvm:${PATH_TO_LLVM_BUILD}/include/clange:$CPLUS_INCLUDE_PATH:${sys_incs%:}" && \
246257
git clone https://github.com/compiler-research/CppInterOp.git && \
258+
if [ "$ARCHITECHURE" == "aarch64" ] ; \
259+
then \
260+
#FIXME: Update to clang-17 once clang-17 is available in apt repository (expected with next LTS version of Ubuntu
261+
# around April 2024)
262+
export CC=/usr/bin/clang-15 && \
263+
export CXX=/usr/bin/clang++-15 && \
264+
#FIXME: Currently build with version 16.x on arm due to issue mentioned here https://github.com/compiler-research/xeus-clang-repl/issues/78
265+
git clone --depth=1 --branch release/16.x https://github.com/llvm/llvm-project.git && \
266+
cd ./llvm-project/ && \
267+
mkdir build && \
268+
export LLVM_DIR=$(pwd) && \
269+
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 && \
270+
cd build && \
271+
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 && \
272+
cmake --build . --target clang clang-repl --parallel $(nproc --all) && \
273+
export PATH_TO_LLVM_CONFIG=$LLVM_DIR/build/lib/cmake/llvm/ && \
274+
export PATH_TO_CLANG_CONFIG=$LLVM_DIR/build/lib/cmake/clang/ && \
275+
export PATH_TO_LLVM_BUILD=$LLVM_DIR/build && \
276+
cd ../../ ; \
277+
fi && \
278+
export PATH=${VENV}/bin:${CONDA_DIR}/bin:$PATH_TO_LLVM_BUILD/bin:$PATH && \
279+
export LD_LIBRARY_PATH=$PATH_TO_LLVM_BUILD/lib:$LD_LIBRARY_PATH && \
280+
echo "export PATH=$PATH" >> ~/.profile && \
247281
export CB_PYTHON_DIR="$PWD/cppyy-backend/python" && \
248282
export CPPINTEROP_DIR="$CB_PYTHON_DIR/cppyy_backend" && \
249-
cd CppInterOp && \
250-
mkdir build && \
251-
cd build && \
283+
mkdir CppInterOp/build && \
284+
cd CppInterOp/build && \
252285
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 .. && \
286+
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 .. && \
254287
cmake --build . --parallel $(nproc --all) && \
255288
#make install -j$(nproc --all)
256289
export CPLUS_INCLUDE_PATH="$CPPINTEROP_DIR/include:$CPLUS_INCLUDE_PATH" && \
@@ -260,9 +293,10 @@ RUN \
260293
#
261294
# Build and Install cppyy-backend
262295
#
263-
git clone https://github.com/compiler-research/cppyy-backend.git && \
296+
git clone --depth=1 https://github.com/compiler-research/cppyy-backend.git && \
264297
cd cppyy-backend && \
265-
mkdir -p $CPPINTEROP_DIR/lib build && cd build && \
298+
mkdir -p $CPPINTEROP_DIR/lib build && \
299+
cd build && \
266300
# Install CppInterOp
267301
(cd $CPPINTEROP_BUILD_DIR && cmake --build . --target install --parallel $(nproc --all)) && \
268302
# Build and Install cppyy-backend
@@ -274,9 +308,9 @@ RUN \
274308
# Build and Install CPyCppyy
275309
#
276310
# Install CPyCppyy
277-
git clone https://github.com/compiler-research/CPyCppyy.git && \
278-
cd CPyCppyy && \
279-
mkdir build && cd build && \
311+
git clone --depth=1 https://github.com/compiler-research/CPyCppyy.git && \
312+
mkdir CPyCppyy/build && \
313+
cd CPyCppyy/build && \
280314
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE .. && \
281315
cmake --build . --parallel $(nproc --all) && \
282316
export CPYCPPYY_DIR=$PWD && \
@@ -285,7 +319,7 @@ RUN \
285319
# Build and Install cppyy
286320
#
287321
# Install cppyy
288-
git clone https://github.com/compiler-research/cppyy.git && \
322+
git clone --depth=1 https://github.com/compiler-research/cppyy.git && \
289323
cd cppyy && \
290324
python -m pip install --upgrade . --no-deps && \
291325
cd .. && \
@@ -294,9 +328,9 @@ RUN \
294328
export PYTHONPATH=$PYTHONPATH:$CPYCPPYY_DIR:$CB_PYTHON_DIR:/home/jovyan && \
295329
echo "export PYTHONPATH=$PYTHONPATH" >> ~/.profile && \
296330
export CPLUS_INCLUDE_PATH="/home/jovyan/CPyCppyy/include/:$CPLUS_INCLUDE_PATH" && \
297-
# FIXME: Remove the hardcoded version of python here.
331+
export PYTHON_VERSION=$(python --version | cut -c8- | cut -f1,2 -d'.') && \
298332
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" && \
333+
export CPLUS_INCLUDE_PATH="${VENV}/include:${VENV}/include/python${PYTHON_VERSION}:$CPLUS_INCLUDE_PATH" && \
300334
python -c "import cppyy" && \
301335
#
302336
# Build and Install xeus-clang-repl
@@ -312,13 +346,11 @@ RUN \
312346
# Build and Install Clad
313347
#
314348
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 && \
349+
mkdir clad/build && \
350+
cd clad/build && \
351+
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)" && \
352+
make -j$(nproc --all) && \
353+
make install -j$(nproc --all) && \
322354
### install clad in all exist kernels
323355
##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 && \
324356
###
@@ -339,8 +371,8 @@ RUN \
339371
k="/opt/conda/share/jupyter/kernels/python3/kernel.json" && \
340372
jq ".argv[0] = \"${VENV}/bin/python\"" $k > $k.$$.tmp && mv $k.$$.tmp $k && \
341373
# xtensor
342-
git clone https://github.com/xtensor-stack/xtensor.git && \
343-
cd xtensor && \
344-
mkdir build && cd build && \
374+
git clone --depth=1 https://github.com/xtensor-stack/xtensor.git && \
375+
mkdir xtensor/build && \
376+
cd xtensor/build && \
345377
cmake -DCMAKE_INSTALL_PREFIX=$KERNEL_PYTHON_PREFIX .. && \
346-
make install
378+
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)