Skip to content

Commit 0023d86

Browse files
authored
Update README.md build instructions (compiler-research#179)
1 parent d294b07 commit 0023d86

File tree

1 file changed

+138
-41
lines changed

1 file changed

+138
-41
lines changed

README.md

Lines changed: 138 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,30 @@ goals of CppInterOp is to stay backward compatible and be adopted in the High
5858
framework. Over time, parts of the Root framework can be swapped by this API,
5959
adding speed and resilience with it.
6060

61-
### Build Instructions for Linux
62-
Build instructions for CppInterOp and its dependencies are as follows.
61+
### Build Instructions for Unix Systems
62+
Build instructions for CppInterOp and its dependencies are as follows. CppInterOP can be built with either Cling and Clang-REPL, so instructions will differ slightly depending on which option you would like to build, but should be clear from the section title which instructions to follow.
6363

64-
#### Setup Clang-REPL
65-
Clone and checkout the LLVM project repository.
64+
#### Clone CppInterOp and cppyy-backend
65+
First clone the CppInterOp repository, as this contains patches that need to be applied to the subsequently cloned llvm-project repo (if building CppInterOP with Clang-REPL)
6666
```
67-
git clone https://github.com/llvm/llvm-project.git
68-
git checkout release/16.x
67+
git clone --depth=1 https://github.com/compiler-research/CppInterOp.git
68+
```
69+
and clone cppyy-backend repository where we will be installing the CppInterOp library
70+
```
71+
git clone --depth=1 https://github.com/compiler-research/cppyy-backend.git
72+
```
73+
74+
#### Setup Clang-REPL
75+
Clone the 17.x release of the LLVM project repository.
76+
```
77+
git clone --depth=1 --branch release/17.x https://github.com/llvm/llvm-project.git
78+
cd llvm-project
6979
```
7080
Get the following patches required for development work.
7181
```
72-
compgen -G "../patches/llvm/clang16-*.patch" > /dev/null && find ../patches/llvm/clang16-*.patch -printf "%f\n" && git apply ../patches/llvm/clang16-*.patch
82+
compgen -G "../CppInterOp/patches/llvm/clang17-*.patch" > /dev/null && find ../CppInterOp/patches/llvm/clang17-*.patch -printf "%f\n" && git apply ../CppInterOp/patches/llvm/clang17-*.patch
7383
```
74-
##### Build Clang
84+
##### Build Clang-REPL
7585
Clang-REPL is an interpreter that CppInterOp works alongside. Build Clang (and
7686
Clang-REPL along with it).
7787
```
@@ -94,37 +104,17 @@ cd ../
94104
export LLVM_DIR=$PWD
95105
cd ../
96106
```
97-
Next, use the following export commands.
98-
```
99-
export CB_PYTHON_DIR="$PWD/cppyy-backend/python"
100-
export CPPINTEROP_DIR="$CB_PYTHON_DIR/cppyy_backend"
101-
```
102-
#### Build 'LLVM-Project' related dependencies
103-
Following steps are required to help build CppInterOp alongside the
104-
LLVM-Project.
105-
```
106-
mkdir build && cd build
107-
export CPPINTEROP_BUILD_DIR=$PWD
108-
cmake -DCMAKE_BUILD_TYPE=Release \
109-
-DUSE_CLING=OFF \
110-
-DUSE_REPL=ON \
111-
-DLLVM_DIR=$LLVM_BUILD_DIR \
112-
-DLLVM_USE_LINKER=lld \
113-
-DBUILD_SHARED_LIBS=ON \
114-
-DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR \
115-
../
116-
cmake --build . --target install --parallel $(nproc --all)
117-
```
118-
#### Build Cling related dependencies
107+
108+
#### Build Cling and related dependencies
119109
Besides the Clang-REPL interpreter, CppInterOp also works alongside the Cling
120110
interpreter. Cling depends on its own customised version of `llvm-project`,
121111
hosted under the `root-project` (see the git path below).
122112
Use the following build instructions.
123113
```
124114
git clone --depth=1 https://github.com/root-project/cling.git
125115
git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git
126-
cd llvm-project
127-
mkdir build && cd build
116+
mkdir llvm-project/build
117+
cd llvm-project/build
128118
cmake -DLLVM_ENABLE_PROJECTS=clang \
129119
-DLLVM_EXTERNAL_PROJECTS=cling \
130120
-DLLVM_EXTERNAL_CLING_SOURCE_DIR=../../cling \
@@ -147,20 +137,127 @@ cd ../
147137
export LLVM_DIR=$PWD
148138
cd ../
149139
```
150-
Next, export the following directory.
140+
141+
#### Environment variables
142+
Regardless of whether you are building CppInterOP with Cling or Clang-REPL you will need to define the following Envirnoment variables (as they clear for a new session, it is recommended that you also add these to your .bashrc in linux, or your .bash_profile if on MacOS)
151143
```
152-
export CPPINTEROP_DIR=$PWD/cppyy-backend/python/cppyy_backend
144+
export CB_PYTHON_DIR="$PWD/cppyy-backend/python"
145+
export CPPINTEROP_DIR="$CB_PYTHON_DIR/cppyy_backend"
146+
export CPLUS_INCLUDE_PATH="${CPLUS_INCLUDE_PATH}:${LLVM_DIR}/llvm/include:${LLVM_DIR}/clang/include:${LLVM_DIR}/build/include:${LLVM_DIR}/build/tools/clang/include"
147+
export PYTHONPATH=$PYTHONPATH:$CPYCPPYY_DIR:$CB_PYTHON_DIR
148+
```
149+
If on MacOS you will also need the following envirnoment variable defined
150+
```
151+
export SDKROOT=`xcrun --show-sdk-path`
153152
```
153+
154154
#### Build CppInterOp
155-
Finally, clone the CppInterOp repository.
155+
Now CppInterOp can be installed
156+
```
157+
mkdir CppInterOp/build/
158+
cd CppInterOp/build/
159+
```
160+
161+
Now if you want to build CppInterOp with Clang-REPL then execute the following commands
162+
```
163+
cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=ON -DUSE_REPL=Off -DCling_DIR=$LLVM_DIR/build -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR ..
164+
cmake --build . --target install --parallel $(nproc --all)
165+
```
166+
If alternatively you would like to install CppInterOp with Cling then execute the following commands
156167
```
157-
git clone https://github.com/compiler-research/CppInterOp.git
158-
cd CppInterOp
159-
mkdir build && cd build
160-
CPPINTEROP_BUILD_DIR=$(PWD)
161-
Execute the following.
162168
cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=ON -DUSE_REPL=Off -DCling_DIR=$LLVM_DIR/build -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR ..
163-
cmake --build . --target install
169+
cmake --build . --target install --parallel $(nproc --all)
170+
```
171+
172+
#### Testing CppInterOp
173+
To test the built CppInterOp execute the following command in the CppInterOP build folder
174+
```
175+
cmake --build . --target check-cppinterop --parallel $(nproc --all)
176+
```
177+
Now go back to the top level directory in which your building CppInterOP
178+
```
179+
cd ../..
180+
```
181+
Now you are in a position to install cppyy following the instructions below.
182+
183+
#### Building and Install cppyy-backend
184+
185+
Clone the repo, build it and copy library files into `python/cppyy-backend` directory:
186+
187+
```
188+
git clone --depth=1 https://github.com/compiler-research/cppyy-backend.git
189+
cd cppyy-backend
190+
mkdir -p python/cppyy_backend/lib build
191+
cd build
192+
cmake -DCppInterOp_DIR=$CPPINTEROP_DIR ..
193+
cmake --build .
194+
```
195+
If on a linux system now execute the following command
196+
```
197+
cp libcppyy-backend.so ../python/cppyy_backend/lib/
198+
```
199+
and if on MacOS execute the following command
200+
```
201+
cp libcppyy-backend.dylib ../python/cppyy_backend/lib/
202+
```
203+
204+
Note go back to the top level build directory
205+
```
206+
cd ../..
207+
```
208+
209+
#### Install CPyCppyy
210+
211+
Create virtual environment and activate it:
212+
```
213+
python3 -m venv .venv
214+
source .venv/bin/activate
215+
```
216+
217+
```
218+
git clone --depth=1 https://github.com/compiler-research/CPyCppyy.git
219+
mkdir CPyCppyy/build
220+
cd CPyCppyy/build
221+
cmake ..
222+
cmake --build .
223+
```
224+
225+
Note down the path to the `build` directory as `CPYCPPYY_DIR`:
226+
```
227+
export CPYCPPYY_DIR=$PWD
228+
cd ../..
229+
```
230+
231+
#### Install cppyy
232+
233+
```
234+
git clone --depth=1 https://github.com/compiler-research/cppyy.git
235+
cd cppyy
236+
python -m pip install --upgrade . --no-deps
237+
cd ..
238+
```
239+
240+
#### Run cppyy
241+
242+
Each time you want to run cppyy you need to:
243+
Activate the virtual environment
244+
```
245+
source .venv/bin/activate
246+
```
247+
248+
Now you can `import cppyy` in `python`
249+
```
250+
python -c "import cppyy"
251+
```
252+
253+
#### Run cppyy tests
254+
255+
**Follow the steps in Run cppyy.** Change to the test directory, make the library files and run pytest:
256+
```
257+
cd cppyy/test
258+
make all
259+
python -m pip install pytest
260+
python -m pytest -sv
164261
```
165262

166263
---

0 commit comments

Comments
 (0)