Skip to content

[GSoC 2025] Enabling Out-Of-Process JIT Execution in CppInterOp #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8b1a1e0
redirection with pipes
kr-2003 Jul 2, 2025
90680cc
cppinterop version patch
kr-2003 Jul 2, 2025
3298ada
removing oop jobs
kr-2003 Jul 2, 2025
c00b646
clang-format
kr-2003 Jul 2, 2025
1b854c5
clang-format
kr-2003 Jul 2, 2025
9564225
oop jit tests
kr-2003 Jul 2, 2025
cb60290
oop jit tests
kr-2003 Jul 2, 2025
fc21ac3
requested changes addressed
kr-2003 Jul 2, 2025
e6a6a3b
fixed GetFunctionAddress test
kr-2003 Jul 2, 2025
bad0de4
git-clang-format
kr-2003 Jul 2, 2025
1a8fc62
removed JitCallAdvanced from oop test
kr-2003 Jul 2, 2025
422af5e
adding headers directly
kr-2003 Jul 2, 2025
b6fa873
removed logs from tests
kr-2003 Jul 3, 2025
63993d1
fixed oop patch
kr-2003 Jul 3, 2025
de61d12
oop redirection in interop + win fix
kr-2003 Jul 5, 2025
dd437f9
redirection fix and cling gix
kr-2003 Jul 5, 2025
2f9082e
added oop jobs and win-cling fix
kr-2003 Jul 6, 2025
aa44c2f
added oop jobs and win-cling fix
kr-2003 Jul 6, 2025
95542b9
fixing oop jobs for macos
kr-2003 Jul 6, 2025
31fd43d
whitespace error in patch
kr-2003 Jul 6, 2025
5f4d1e9
linting,more oop jobs
kr-2003 Jul 6, 2025
56a8104
out-of-process for ubuntu machines
kr-2003 Jul 6, 2025
71224cc
checking ubuntu oop jobs
kr-2003 Jul 7, 2025
18e9157
Caching the build
kr-2003 Jul 7, 2025
638e512
checking mac oop
kr-2003 Jul 7, 2025
7386693
checking mac and lin oop
kr-2003 Jul 7, 2025
a054c08
checking mac and lin oop
kr-2003 Jul 7, 2025
5ef087f
removed deleteInterpreter from OOP
kr-2003 Jul 7, 2025
a07fe91
added other machines
kr-2003 Jul 7, 2025
91b561b
added other machines
kr-2003 Jul 7, 2025
70ed0f6
valgrind trace children
kr-2003 Jul 7, 2025
05a5260
removed valgrind from oop
kr-2003 Jul 7, 2025
c172f40
patch change
kr-2003 Jul 8, 2025
c7ae174
llvm version fix
kr-2003 Jul 8, 2025
d835435
patch updated
kr-2003 Jul 8, 2025
e46d9ce
removed mac oop job for now
kr-2003 Jul 8, 2025
ec70e5b
Merge branch 'main' into out-of-process
kr-2003 Jul 8, 2025
5c59fe9
adding oop-jit execution for code coverage
kr-2003 Jul 8, 2025
6561098
removed static members and exposed fn to get nth pid
kr-2003 Jul 9, 2025
75f72fc
using LLVM_BUILT_WITH_OOP_JIT
kr-2003 Jul 9, 2025
2b3ae75
clang-tidy
kr-2003 Jul 9, 2025
798a020
moved codecov to x86
kr-2003 Jul 9, 2025
4bf44b3
clang-format
kr-2003 Jul 9, 2025
443745f
clang-tidy and env var
kr-2003 Jul 9, 2025
610d717
LLVM_BUILT_WITH_OOP_JIT bug fix
kr-2003 Jul 9, 2025
ebce40a
compiler-rt added in oop build
kr-2003 Jul 9, 2025
992c497
patch updated: lambda usage
kr-2003 Jul 9, 2025
1e88c63
Merge branch 'main' into out-of-process
kr-2003 Jul 9, 2025
c740817
patch bug resolved
kr-2003 Jul 9, 2025
0a5d874
patch bug resolved
kr-2003 Jul 9, 2025
baaf759
patch bug resolved
kr-2003 Jul 9, 2025
1bf9c89
patch bug resolved
kr-2003 Jul 9, 2025
fda48a4
oop failing test
kr-2003 Jul 9, 2025
94b671f
addressing issues
kr-2003 Jul 10, 2025
2d7314f
fn-ref-test fix
kr-2003 Jul 10, 2025
9a1bacf
executor pid windows fix
kr-2003 Jul 10, 2025
2ba186b
macos oop job
kr-2003 Jul 10, 2025
77276db
caching oop jobs
kr-2003 Jul 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/actions/Build_LLVM/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ runs:
ninja LLVMOrcDebugging -j ${{ env.ncpus }}
ninja clingInterpreter -j ${{ env.ncpus }}
else
llvm_vers=$(echo "${{ matrix.clang-runtime }}" | tr '[:lower:]' '[:upper:]')
if [[ "${{ matrix.oop-jit }}" == "On" && "${llvm_vers}" == "20" ]]; then
git apply -v ../patches/llvm/clang20-1-out-of-process.patch
echo "Apply clang20-1-out-of-process.patch:"
fi
cd build
cmake -DLLVM_ENABLE_PROJECTS="${{ matrix.llvm_enable_projects}}" \
-DLLVM_TARGETS_TO_BUILD="${{ matrix.llvm_targets_to_build }}" \
Expand All @@ -58,6 +63,14 @@ runs:
-DLLVM_INCLUDE_TESTS=OFF \
../llvm
ninja clang clangInterpreter clangStaticAnalyzerCore -j ${{ env.ncpus }}
if [[ "${{ matrix.oop-jit }}" == "On" ]]; then
if [[ "${{ matrix.os }}" == macos* ]]; then
SUFFIX="_osx"
elif [[ "${{ matrix.os }}" == ubuntu* ]]; then
SUFFIX="-x86_64"
fi
ninja clang-repl llvm-jitlink-executor orc_rt${SUFFIX} -j ${{ env.ncpus }}
fi
cd ./tools/
rm -rf $(find . -maxdepth 1 ! -name "clang" ! -name ".")
cd ..
Expand Down
4 changes: 4 additions & 0 deletions .github/actions/Build_and_Test_CppInterOp/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ runs:
-DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \
-DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR \
-DLLVM_ENABLE_WERROR=On \
-DLLVM_BUILT_WITH_OOP_JIT=${{ matrix.oop-jit }} \
../
fi
docs_on=$(echo "${{ matrix.documentation }}" | tr '[:lower:]' '[:upper:]')
Expand All @@ -60,6 +61,9 @@ runs:
if [[ "${os}" != "macos"* ]]; then
valgrind --show-error-list=yes --track-origins=yes --error-exitcode=1 unittests/CppInterOp/CppInterOpTests/unittests/bin/${{ env.BUILD_TYPE }}/CppInterOpTests
fi
if [[ "${{ matrix.oop-jit }}" == "On" ]]; then
./unittests/CppInterOp/CppInterOpTests/unittests/bin/${{ env.BUILD_TYPE }}/CppInterOpTests --use-oop-jit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be built into the cmake build system, if this flag is needed for some reason when oop is on.

fi
fi
echo "CB_PYTHON_DIR=$CB_PYTHON_DIR" >> $GITHUB_ENV
echo "CPPINTEROP_BUILD_DIR=$CPPINTEROP_BUILD_DIR" >> $GITHUB_ENV
Expand Down
43 changes: 31 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ jobs:
matrix:
include:
# Ubuntu Arm Jobs
- name: ubu22-arm-gcc12-clang-repl-20-coverage
os: ubuntu-22.04-arm
compiler: gcc-12
clang-runtime: '20'
cling: Off
cppyy: Off
llvm_enable_projects: "clang"
llvm_targets_to_build: "host;NVPTX"
coverage: true
- name: ubu24-arm-gcc12-clang-repl-20
os: ubuntu-24.04-arm
compiler: gcc-12
Expand Down Expand Up @@ -66,6 +57,16 @@ jobs:
llvm_enable_projects: "clang"
llvm_targets_to_build: "host;NVPTX"
# Ubuntu X86 Jobs
- name: ubu22-x86-gcc12-clang-repl-20-coverage
os: ubuntu-22.04
compiler: gcc-12
clang-runtime: '20'
cling: Off
cppyy: Off
llvm_enable_projects: "clang;compiler-rt"
llvm_targets_to_build: "host;NVPTX"
coverage: true
oop-jit: On
- name: ubu24-x86-gcc12-clang-repl-20
os: ubuntu-24.04
compiler: gcc-12
Expand All @@ -74,6 +75,15 @@ jobs:
cppyy: Off
llvm_enable_projects: "clang"
llvm_targets_to_build: "host;NVPTX"
- name: ubu24-x86-gcc12-clang-repl-20-out-of-process
os: ubuntu-24.04
compiler: gcc-12
clang-runtime: '20'
cling: Off
cppyy: Off
llvm_enable_projects: "clang;compiler-rt"
llvm_targets_to_build: "host;NVPTX"
oop-jit: On
- name: ubu24-x86-gcc12-clang-repl-19-cppyy
os: ubuntu-24.04
compiler: gcc-12
Expand All @@ -100,6 +110,15 @@ jobs:
llvm_enable_projects: "clang"
llvm_targets_to_build: "host;NVPTX"
# MacOS Arm Jobs
- name: osx15-arm-clang-clang-repl-20-out-of-process
os: macos-15
compiler: clang
clang-runtime: '20'
cling: Off
cppyy: Off
llvm_enable_projects: "clang;compiler-rt"
llvm_targets_to_build: "host"
oop-jit: On
- name: osx15-arm-clang-clang-repl-20
os: macos-15
compiler: clang
Expand Down Expand Up @@ -218,9 +237,9 @@ jobs:
id: cache
with:
path: |
llvm-project
${{ matrix.cling=='On' && 'cling' || '' }}
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' }}
llvm-project
${{ matrix.cling=='On' && 'cling' || '' }}
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' }}${{ matrix.oop-jit == 'On' && '-oop' || '' }}

- name: Setup default Build Type
uses: ./.github/actions/Miscellaneous/Select_Default_Build_Type
Expand Down
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,18 @@ include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})

string(REGEX REPLACE "/build/lib/cmake/llvm$" "" LLVM_SOURCE_DIR "${LLVM_DIR}")
add_definitions(-DLLVM_SOURCE_DIR="${LLVM_SOURCE_DIR}")

if(LLVM_BUILT_WITH_OOP_JIT)
if((CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64") OR
(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64"))
add_definitions(-DLLVM_BUILT_WITH_OOP_JIT)
else()
message(FATAL_ERROR "LLVM_BUILT_WITH_OOP_JIT is only supported on Darwin arm64 or Linux x86_64. Build aborted.")
endif()
endif()

# If the llvm sources are present add them with higher priority.
if (LLVM_BUILD_MAIN_SRC_DIR)
# LLVM_INCLUDE_DIRS contains the include paths to both LLVM's source and
Expand Down Expand Up @@ -379,6 +391,7 @@ string(REPLACE "-Wcovered-switch-default" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}

file(STRINGS "VERSION" CPPINTEROP_VERSION)
string(REPLACE "." ";" VERSION_LIST "${CPPINTEROP_VERSION}")

list(GET VERSION_LIST 0 CPPINTEROP_VERSION_MAJOR)
list(GET VERSION_LIST 1 CPPINTEROP_VERSION_MINOR)
list(GET VERSION_LIST 2 CPPINTEROP_VERSION_PATCH)
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,28 @@ $env:LLVM_DIR= $PWD.Path
cd ..\
```

##### Build Clang-REPL with Out-of-Process JIT Execution

To have ``Out-of-Process JIT Execution`` enabled, run following commands to build clang and clang-repl to support this feature:
> Only for Linux x86_64 and Macos amr64
```bash
mkdir build
cd build
cmake -DLLVM_ENABLE_PROJECTS="clang;compiler-rt" \
-DLLVM_TARGETS_TO_BUILD="host;NVPTX" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCLANG_ENABLE_STATIC_ANALYZER=OFF \
-DCLANG_ENABLE_ARCMT=OFF \
-DCLANG_ENABLE_FORMAT=OFF \
-DCLANG_ENABLE_BOOTSTRAP=OFF \
../llvm

## For Linux x86_64
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt-x86_64 --parallel $(nproc --all)
## For MacOS arm64
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt_osx --parallel $(sysctl -n hw.ncpu)

#### Build Cling and related dependencies

Besides the Clang-REPL interpreter, CppInterOp also works alongside the Cling
Expand Down Expand Up @@ -311,6 +333,8 @@ cmake --build . --target install --parallel $(nproc --all)

and

> Do make sure to pass ``DLLVM_BUILT_WITH_OOP_JIT=ON``, if you want to have out-of-process JIT execution feature enabled.

```powershell
cmake -DLLVM_DIR=$env:LLVM_DIR\build\lib\cmake\llvm -DClang_DIR=$env:LLVM_DIR\build\lib\cmake\clang -DCMAKE_INSTALL_PREFIX=$env:CPPINTEROP_DIR ..
cmake --build . --target install --parallel $env:ncpus
Expand Down
34 changes: 34 additions & 0 deletions docs/InstallationAndUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,36 @@ On Windows you execute the following
$env:LLVM_DIR= $PWD.Path
cd ..\

***************************************************
Build Clang-REPL with Out-of-Process JIT Execution
***************************************************

To have `Out-of-Process JIT Execution` enabled, run following commands to build clang and clang-repl to support this feature:

.. note::

Only for Linux x86_64 and Macos arm64

.. code:: bash

mkdir build
cd build
cmake -DLLVM_ENABLE_PROJECTS="clang;compiler-rt" \
-DLLVM_TARGETS_TO_BUILD="host;NVPTX" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCLANG_ENABLE_STATIC_ANALYZER=OFF \
-DCLANG_ENABLE_ARCMT=OFF \
-DCLANG_ENABLE_FORMAT=OFF \
-DCLANG_ENABLE_BOOTSTRAP=OFF \
../llvm

# For Linux x86_64
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt-x86_64 --parallel $(nproc --all)

# For MacOS arm64
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt_osx --parallel $(sysctl -n hw.ncpu)

**************************************
Build Cling and related dependencies
**************************************
Expand Down Expand Up @@ -263,6 +293,10 @@ commands on Linux and MacOS
cmake -DBUILD_SHARED_LIBS=ON -DLLVM_DIR=$LLVM_DIR/build/lib/cmake/llvm -DClang_DIR=$LLVM_DIR/build/lib/cmake/clang -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR ..
cmake --build . --target install --parallel $(nproc --all)

.. note::

Do make sure to pass ``DLLVM_BUILT_WITH_OOP_JIT=ON``, if you want to have out-of-process JIT execution feature enabled.

and

.. code:: powershell
Expand Down
11 changes: 11 additions & 0 deletions include/CppInterOp/CppInterOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cstdint>
#include <set>
#include <string>
#include <sys/types.h>
#include <vector>

// The cross-platform CPPINTEROP_API macro definition
Expand Down Expand Up @@ -907,6 +908,16 @@ CPPINTEROP_API void CodeComplete(std::vector<std::string>& Results,
///\returns 0 on success, non-zero on failure.
CPPINTEROP_API int Undo(unsigned N = 1);

#ifndef _WIN32
/// Returns the process ID of the executor process.
/// \returns the PID of the executor process.
CPPINTEROP_API pid_t GetExecutorPID();

/// Returns the process ID of the nth executor process.
/// \returns the PID of the nth executor process.
CPPINTEROP_API pid_t GetNthExecutorPID(int n);
#endif

} // end namespace Cpp

#endif // CPPINTEROP_CPPINTEROP_H
Loading
Loading