Skip to content

Commit a2b28b4

Browse files
sudo-pandavgvassilev
authored andcommitted
Initial implementation based on InterOp
1 parent 10d12e7 commit a2b28b4

File tree

597 files changed

+2707
-208359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

597 files changed

+2707
-208359
lines changed

.github/workflows/ci.yml

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
name: Main
2+
on:
3+
pull_request:
4+
branches: [master]
5+
push:
6+
branches: [master]
7+
release:
8+
types: [published]
9+
schedule:
10+
- cron: '30 20 * * *' # Warning: Timezone dep - 20:00 is 1:00
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
build:
18+
name: ${{ matrix.name }}
19+
runs-on: ${{ matrix.os }}
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
include:
24+
- name: ubu22-gcc9-clang13
25+
os: ubuntu-22.04
26+
compiler: gcc-9
27+
clang-runtime: '13'
28+
# - name: ubu22-gcc9-clang14
29+
# os: ubuntu-22.04
30+
# compiler: gcc-9
31+
# clang-runtime: '14'
32+
steps:
33+
- uses: actions/checkout@v3
34+
with:
35+
fetch-depth: 0
36+
- name: Set up Python
37+
uses: actions/setup-python@v4
38+
with:
39+
python-version: '3.10'
40+
- name: Save PR Info
41+
run: |
42+
mkdir -p ./pr
43+
echo ${{ github.event.number }} > ./pr/NR
44+
echo ${{ github.repository }} > ./pr/REPO
45+
46+
export CLING_HASH=$(git ls-remote https://github.com/root-project/cling.git HEAD| tr '\t' '-')
47+
# FIXME: We need something like cling-llvm to bump automatically...
48+
export LLVM_HASH=$(git ls-remote https://github.com/root-project/llvm-project.git cling-llvm13 | tr '\t' '-')
49+
echo "CLING_HASH=$CLING_HASH" >> $GITHUB_ENV
50+
echo "LLVM_HASH=$LLVM_HASH" >> $GITHUB_ENV
51+
52+
- uses: nelonoel/[email protected]
53+
- name: Setup compiler on Linux
54+
if: runner.os == 'Linux'
55+
run: |
56+
# https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
57+
vers="${compiler#*-}"
58+
os_codename="`cat /etc/os-release | grep UBUNTU_CODENAME | cut -d = -f 2`"
59+
sudo apt update
60+
if [[ "${{ matrix.compiler }}" == *"gcc"* ]]; then
61+
sudo apt install -y gcc-${vers} g++-${vers} lld
62+
echo "CC=gcc-${vers}" >> $GITHUB_ENV
63+
echo "CXX=g++-${vers}" >> $GITHUB_ENV
64+
else
65+
if ! sudo apt install -y clang-${vers}; then
66+
curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
67+
echo "deb https://apt.llvm.org/${os_codename}/ llvm-toolchain-${os_codename}-${vers} main" | sudo tee -a /etc/apt/sources.list
68+
sudo apt update
69+
sudo apt install -y clang-${vers}
70+
fi
71+
echo "CC=clang-${vers}" >> $GITHUB_ENV
72+
echo "CXX=clang++-${vers}" >> $GITHUB_ENV
73+
fi
74+
env:
75+
compiler: ${{ matrix.compiler }}
76+
- name: Install deps on Linux
77+
if: runner.os == 'Linux'
78+
run: |
79+
# Install deps
80+
sudo apt-get update
81+
sudo apt-get install git g++ debhelper devscripts gnupg python3
82+
conda install -y -q -c conda-forge \
83+
distro \
84+
pytest
85+
- name: Restore Cache LLVM/Clang runtime build directory
86+
uses: actions/cache/restore@v3
87+
id: cache
88+
with:
89+
path: |
90+
llvm-project/
91+
cling/
92+
#key: ...-.x-patch-${{ hashFiles('patches/llvm/*') }}
93+
#key: ${{ env.CLING_HASH }}-${{ env.LLVM_HASH }}-${{ runner.os }}-${{ matrix.os }}-${{ matrix.compiler }}-clang-${{ matrix.clang-runtime }}.x
94+
key: ${{ env.CLING_HASH }}-${{ runner.os }}-${{ matrix.os }}-${{ matrix.compiler }}-clang-${{ matrix.clang-runtime }}.x
95+
- name: Build Cling on Linux if the cache is invalid
96+
if: ${{ runner.os == 'Linux' && steps.cache.outputs.cache-hit != 'true' }}
97+
run: |
98+
#if [[ "${{ steps.cling-build-cache.outputs.cache-hit }}" != "true" ]]; then
99+
git clone --depth=1 https://github.com/root-project/cling.git
100+
git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git
101+
cd llvm-project
102+
mkdir build
103+
cd build
104+
cmake -DLLVM_ENABLE_PROJECTS=clang \
105+
-DLLVM_EXTERNAL_PROJECTS=cling \
106+
-DLLVM_EXTERNAL_CLING_SOURCE_DIR=../../cling \
107+
-DLLVM_TARGETS_TO_BUILD="host;NVPTX" \
108+
-DCMAKE_BUILD_TYPE=Release \
109+
-DLLVM_ENABLE_ASSERTIONS=ON \
110+
-DLLVM_USE_LINKER=lld \
111+
-DCLANG_ENABLE_STATIC_ANALYZER=OFF \
112+
-DCLANG_ENABLE_ARCMT=OFF \
113+
-DCLANG_ENABLE_FORMAT=OFF \
114+
-DCLANG_ENABLE_BOOTSTRAP=OFF \
115+
../llvm
116+
cmake --build . --target clang --parallel $(nproc --all)
117+
cmake --build . --target cling --parallel $(nproc --all)
118+
cmake --build . --target libcling --parallel $(nproc --all)
119+
# Now build gtest.a and gtest_main for InterOp to run its tests.
120+
cmake --build . --target gtest_main --parallel $(nproc --all)
121+
cd ../../
122+
#fi
123+
- name: Save Cache LLVM/Clang runtime build directory
124+
uses: actions/cache/save@v3
125+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
126+
with:
127+
path: |
128+
llvm-project/
129+
cling/
130+
key: ${{ steps.cache.outputs.cache-primary-key }}
131+
- name: Build and Install InterOp on Linux
132+
if: runner.os == 'Linux'
133+
run: |
134+
# Build InterOp next to cling and llvm-project.
135+
LLVM_DIR="$(realpath llvm-project)"
136+
LLVM_BUILD_DIR="$(realpath llvm-project/build)"
137+
CLING_DIR="$(realpath cling)"
138+
CLING_BUILD_DIR="$(realpath cling/build)"
139+
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"
140+
git clone https://github.com/compiler-research/InterOp.git
141+
cd InterOp
142+
pwd
143+
mkdir build install
144+
export INTEROP_DIR="$(realpath install)"
145+
cd build
146+
cmake -DUSE_CLING=ON -DCling_DIR=$LLVM_BUILD_DIR -DCMAKE_INSTALL_PREFIX=$INTEROP_DIR ../
147+
#cmake --build . --target check-interop --parallel $(nproc --all)
148+
cmake --build . --target install --parallel $(nproc --all)
149+
cd ../..
150+
# We need INTEROP_DIR, LLVM_BUILD_DIR and CPLUS_INCLUDE_PATH later
151+
echo "INTEROP_DIR=$INTEROP_DIR" >> $GITHUB_ENV
152+
echo "LLVM_BUILD_DIR=$LLVM_BUILD_DIR" >> $GITHUB_ENV
153+
echo "CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH" >> $GITHUB_ENV
154+
- name: Build and Install cppyy-backend on Linux
155+
if: runner.os == 'Linux'
156+
run: |
157+
# Install cppyy-backend
158+
mkdir python/cppyy_backend/lib build && cd build
159+
cmake -DInterOp_DIR=$INTEROP_DIR ..
160+
cmake --build . --parallel $(nproc --all)
161+
cp libcppyy-backend.so ../python/cppyy_backend/lib/
162+
cp $LLVM_BUILD_DIR/lib/libcling.so ../python/cppyy_backend/lib/
163+
#
164+
cd ../python
165+
export CB_PYTHON_DIR=$PWD
166+
cd ../..
167+
# We need CB_PYTHON_DIR later
168+
echo "CB_PYTHON_DIR=$CB_PYTHON_DIR" >> $GITHUB_ENV
169+
- name: Install CPyCppyy on Linux
170+
if: runner.os == 'Linux'
171+
run: |
172+
# Setup virtual environment
173+
python3 -m venv .venv
174+
source .venv/bin/activate
175+
# Install CPyCppyy
176+
git clone https://github.com/compiler-research/CPyCppyy.git
177+
cd CPyCppyy
178+
mkdir build && cd build
179+
cmake ..
180+
cmake --build . --parallel $(nproc --all)
181+
#
182+
export CPYCPPYY_DIR=$PWD
183+
cd ../..
184+
# We need CPYCPPYY_DIR later
185+
echo "CPYCPPYY_DIR=$CPYCPPYY_DIR" >> $GITHUB_ENV
186+
- name: Install cppyy on Linux
187+
if: runner.os == 'Linux'
188+
run: |
189+
# source virtual environment
190+
source .venv/bin/activate
191+
# Install cppyy
192+
git clone https://github.com/compiler-research/cppyy.git
193+
cd cppyy
194+
python -m pip install --upgrade . --no-deps
195+
cd ..
196+
- name: Run cppyy on Linux
197+
if: runner.os == 'Linux'
198+
run: |
199+
# Run cppyy
200+
source .venv/bin/activate
201+
export PYTHONPATH=$PYTHONPATH:$CPYCPPYY_DIR:$CB_PYTHON_DIR
202+
python -c "import cppyy"
203+
# We need PYTHONPATH later
204+
echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV
205+
- name: Run the tests on Linux
206+
continue-on-error: true
207+
if: runner.os == 'Linux'
208+
run: |
209+
# Run the tests
210+
source .venv/bin/activate
211+
cd cppyy/test
212+
make all || true
213+
python -m pip install --upgrade pip
214+
python -m pip install pytest
215+
python -m pip install pytest-xdist
216+
217+
echo ::group::Test Logs
218+
python -m pytest -n auto -sv --max-worker-restart 512 | tee test.log 2>&1
219+
echo ::endgroup::
220+
221+
echo "TEST SUMMARY: \n"
222+
tail -n1 test.log
223+
echo "OF TOTAL $(python3 -m pytest --collect-only -q | tail -n1)"
224+
- name: Setup tmate session
225+
if: ${{ failure() }}
226+
uses: mxschmitt/action-tmate@v3
227+
# When debugging increase to a suitable value!

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ releases/
22
root-*/
33
cling/src/interpreter
44
builddir/
5+
build/
6+
.cling/
7+
.clingwrapper/
58

69
# Byte-compiled / optimized / DLL files
710
__pycache__/
@@ -103,3 +106,5 @@ ENV/
103106

104107
# mypy
105108
.mypy_cache/
109+
110+
.vscode

CMakeLists.txt

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
project(cppyy-backend)
2+
cmake_minimum_required(VERSION 3.10)
3+
include(ExternalProject)
4+
5+
set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
6+
set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
7+
8+
add_library(cppyy-backend SHARED
9+
clingwrapper/src/clingwrapper.cxx
10+
)
11+
12+
# set_target_properties(cppyy-backend PROPERTIES VERSION ${PROJECT_VERSION})
13+
14+
# set_target_properties(cppyy-backend PROPERTIES PUBLIC_HEADER include/cpp_cppyy.h)
15+
16+
target_include_directories(cppyy-backend PRIVATE clingwrapper/src)
17+
18+
19+
add_library(libInterOp IMPORTED STATIC GLOBAL)
20+
21+
set(_interop_static_archive_name ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}${CMAKE_STATIC_LIBRARY_PREFIX}clangInterOp${CMAKE_STATIC_LIBRARY_SUFFIX})
22+
if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
23+
set(_interop_byproducts ${_interop_static_archive_name})
24+
endif()
25+
26+
if(DEFINED InterOp_DIR)
27+
set(_interop_install_dir ${InterOp_DIR})
28+
else()
29+
set(_interop_install_dir ${CMAKE_BINARY_DIR}/InterOp/install)
30+
31+
if(DEFINED USE_CLING)
32+
list(APPEND _interop_cmake_args "-DUSE_CLING=${USE_CLING}")
33+
endif()
34+
35+
if(DEFINED Cling_DIR)
36+
list(APPEND _interop_cmake_args "-DCling_DIR=${Cling_DIR}")
37+
endif()
38+
39+
if(DEFINED LLVM_DIR)
40+
list(APPEND _interop_cmake_args "-DLLVM_DIR=${LLVM_DIR}")
41+
endif()
42+
43+
if(DEFINED Clang_DIR)
44+
list(APPEND _interop_cmake_args "-DClang_DIR=${Clang_DIR}")
45+
endif()
46+
47+
list(APPEND _interop_cmake_args "-DCMAKE_INSTALL_PREFIX=${_interop_install_dir}")
48+
49+
set(_interop_build_type ${CMAKE_CFG_INTDIR})
50+
set(_interop_cmake_logging_settings
51+
LOG_DOWNLOAD ON
52+
LOG_CONFIGURE ON
53+
LOG_BUILD ON
54+
LOG_INSTALL ON
55+
LOG_OUTPUT_ON_FAILURE ON
56+
)
57+
58+
ExternalProject_Add(InterOp
59+
GIT_REPOSITORY https://github.com/compiler-research/InterOp.git
60+
GIT_TAG main
61+
PREFIX "InterOp"
62+
CMAKE_ARGS ${_interop_cmake_args}
63+
BUILD_BYPRODUCTS ${_interop_byproducts}
64+
${_interop_cmake_logging_settings}
65+
)
66+
67+
add_dependencies(libInterOp InterOp)
68+
endif()
69+
70+
set_source_files_properties(clingwrapper/src/clingwrapper.cxx
71+
PROPERTIES COMPILE_DEFINITIONS "INTEROP_DIR=\"${_interop_install_dir}\"")
72+
73+
set_property(TARGET libInterOp PROPERTY IMPORTED_LOCATION ${_interop_install_dir}/lib/${_interop_static_archive_name})
74+
75+
if (APPLE)
76+
set(_interop_link_flags -Wl,-force_load $<TARGET_FILE:libInterOp> -Wl)
77+
elseif(MSVC)
78+
set(_interop_link_flags "-WHOLEARCHIVE:" $<TARGET_FILE:libInterOp>)
79+
else()
80+
set(_interop_link_flags -Wl,--whole-archive $<TARGET_FILE:libInterOp> -Wl,--no-whole-archive)
81+
endif()
82+
target_link_libraries(cppyy-backend PUBLIC ${_interop_link_flags})
83+
84+
add_dependencies(cppyy-backend libInterOp)
85+
86+
# set(CLING_LIBS
87+
# ${PROJECT_SOURCE_DIR}/../cling/builddir/lib/libclingInterpreter.a
88+
# # clangAST
89+
# # clangBasic
90+
# # clangLex
91+
# )
92+
93+
target_include_directories(cppyy-backend PUBLIC ${_interop_install_dir}/include)
94+
95+
# target_link_libraries(cppyy-backend ${CLING_LIBS})
96+
# target_link_libraries(cppyy-backend ${PROJECT_SOURCE_DIR}/../cling/builddir/lib/libcling.so)
97+
98+
# get_cmake_property(_variableNames VARIABLES)
99+
# list (SORT _variableNames)
100+
# foreach (_variableName ${_variableNames})
101+
# message(STATUS "${_variableName}=${${_variableName}}")
102+
# endforeach()

0 commit comments

Comments
 (0)