Skip to content

Upgrade to latest CppInterOp #19029

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

Merged
merged 2 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion core/metacling/src/TCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ clang/LLVM technology.
#include "cling/Utils/SourceNormalization.h"
#include "cling/Interpreter/Exception.h"

#include "clang/Interpreter/CppInterOp.h"
#include <CppInterOp/CppInterOp.h>

#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/Module.h"
Expand Down
2 changes: 1 addition & 1 deletion core/metacling/src/TClingDataMemberInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ from the Clang C++ compiler, not CINT.
#include "clang/AST/RecordLayout.h"
#include "clang/AST/Type.h"

#include "clang/Interpreter/CppInterOp.h"
#include <CppInterOp/CppInterOp.h>

#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"
Expand Down
2 changes: 1 addition & 1 deletion core/metacling/src/TClingTypeInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ but the type metadata comes from the Clang C++ compiler, not CINT.
#include "clang/AST/PrettyPrinter.h"
#include "clang/Frontend/CompilerInstance.h"

#include "clang/Interpreter/CppInterOp.h"
#include <CppInterOp/CppInterOp.h>

#include <cstdio>
#include <string>
Expand Down
10 changes: 5 additions & 5 deletions interpreter/CppInterOp/.readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ sphinx:
builder: html

build:
os: "ubuntu-22.04"
os: "ubuntu-24.04"
tools:
python: "3.11"
apt_packages:
- clang-13
- clang-16
- cmake
- libclang-13-dev
- llvm-13-dev
- llvm-13-tools
- libclang-16-dev
- llvm-16-dev
- llvm-16-tools
39 changes: 21 additions & 18 deletions interpreter/CppInterOp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,25 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
include(GNUInstallDirs)
## Define supported version of clang and llvm

set(CLANG_MIN_SUPPORTED 13.0)
if (CPPINTEROP_USE_CLING)
set(CLANG_MIN_SUPPORTED 18.0)
else()
set(CLANG_MIN_SUPPORTED 16.0)
endif(CPPINTEROP_USE_CLING)
set(CLANG_MAX_SUPPORTED "20.1.x")
set(CLANG_VERSION_UPPER_BOUND 21.0.0)
set(LLD_MIN_SUPPORTED 13.0)
if (CPPINTEROP_USE_CLING)
set(LLD_MIN_SUPPORTED 18.0)
else()
set(LLD_MIN_SUPPORTED 16.0)
endif(CPPINTEROP_USE_CLING)
set(LLD_MAX_SUPPORTED "20.1.x")
set(LLD_VERSION_UPPER_BOUND 21.0.0)
set(LLVM_MIN_SUPPORTED 13.0)
if (CPPINTEROP_USE_CLING)
set(LLVM_MIN_SUPPORTED 18.0)
else()
set(LLVM_MIN_SUPPORTED 16.0)
endif(CPPINTEROP_USE_CLING)
set(LLVM_MAX_SUPPORTED "20.1.x")
set(LLVM_VERSION_UPPER_BOUND 21.0.0)

Expand Down Expand Up @@ -230,21 +242,12 @@ endif()
message(STATUS "Found supported version: Clang ${CLANG_PACKAGE_VERSION}")
message(STATUS "Using ClangConfig.cmake in: ${Clang_DIR}")

## Clang 13 require c++14 or later, Clang 16 require c++17 or later.
if (CLANG_VERSION_MAJOR GREATER_EQUAL 16)
if (NOT CMAKE_CXX_STANDARD)
set (CMAKE_CXX_STANDARD 17)
endif()
if (CMAKE_CXX_STANDARD LESS 17)
message(fatal "LLVM/CppInterOp requires c++17 or later")
endif()
elseif (CLANG_VERSION_MAJOR GREATER_EQUAL 13)
if (NOT CMAKE_CXX_STANDARD)
set (CMAKE_CXX_STANDARD 14)
endif()
if (CMAKE_CXX_STANDARD LESS 14)
message(fatal "LLVM/CppInterOp requires c++14 or later")
endif()
## Clang 16 require c++17 or later.
if (NOT CMAKE_CXX_STANDARD)
set (CMAKE_CXX_STANDARD 17)
endif()
if (CMAKE_CXX_STANDARD LESS 17)
message(fatal "LLVM/CppInterOp requires c++17 or later")
endif()

## Find supported Cling
Expand Down
15 changes: 11 additions & 4 deletions interpreter/CppInterOp/Emscripten-build-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ emmake make -j $(nproc --all) install
## Xeus-cpp-lite Wasm Build Instructions

A project which makes use of the wasm build of CppInterOp is xeus-cpp. xeus-cpp is a C++ Jupyter kernel. Assuming you are in
the CppInterOp build folder, you can build the wasm version of xeus-cpp by executing
the CppInterOp build folder, you can build the wasm version of xeus-cpp by executing (replace $LLVM_VERSION with the version
of llvm you are building against)

```bash
cd ../..
Expand All @@ -305,6 +306,7 @@ emcmake cmake \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DXEUS_CPP_RESOURCE_DIR=$LLVM_BUILD_DIR/lib/clang/$LLVM_VERSION \
-DSYSROOT_PATH=$SYSROOT_PATH \
..
emmake make -j $(nproc --all) install
Expand All @@ -314,10 +316,15 @@ To build Jupyter Lite website with this kernel locally that you can use for test

```bash
cd ../..
micromamba create -n xeus-lite-host jupyterlite-core -c conda-forge
micromamba create -n xeus-lite-host jupyterlite-core=0.6 jupyterlite-xeus jupyter_server jupyterlab notebook python-libarchive-c -c conda-forge
micromamba activate xeus-lite-host
python -m pip install jupyterlite-xeus jupyter_server
jupyter lite build --XeusAddon.prefix=$PREFIX --contents xeus-cpp/notebooks/xeus-cpp-lite-demo.ipynb
jupyter lite build --XeusAddon.prefix=$PREFIX \
--contents xeus-cpp/notebooks/xeus-cpp-lite-demo.ipynb \
--contents xeus-cpp/notebooks/smallpt.ipynb \
--contents xeus-cpp/notebooks/images/marie.png \
--contents xeus-cpp/notebooks/audio/audio.wav \
--XeusAddon.mounts="$PREFIX/share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles" \
--XeusAddon.mounts="$PREFIX/etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d"
```

Once the Jupyter Lite site has built you can test the website locally by executing
Expand Down
77 changes: 40 additions & 37 deletions interpreter/CppInterOp/README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,27 @@
# CppInterOp
<div align="center">

[![Build Status](https://github.com/compiler-research/CppInterOp/actions/workflows/Ubuntu.yml/badge.svg)](https://github.com/compiler-research/CppInterOp/actions/workflows/Ubuntu.yml)

[![Build Status](https://github.com/compiler-research/CppInterOp/actions/workflows/Ubuntu-arm.yml/badge.svg)](https://github.com/compiler-research/CppInterOp/actions/workflows/Ubuntu-arm.yml)

[![Build Status](https://github.com/compiler-research/CppInterOp/actions/workflows/MacOS.yml/badge.svg)](https://github.com/compiler-research/CppInterOp/actions/workflows/MacOS.yml)

[![Build Status](https://github.com/compiler-research/CppInterOp/actions/workflows/MacOS-arm.yml/badge.svg)](https://github.com/compiler-research/CppInterOp/actions/workflows/MacOS-arm.yml)

[![Build Status](https://github.com/compiler-research/CppInterOp/actions/workflows/Windows.yml/badge.svg)](https://github.com/compiler-research/CppInterOp/actions/workflows/Windows.yml)

[![Build Status](https://github.com/compiler-research/CppInterOp/actions/workflows/Windows-arm.yml/badge.svg)](https://github.com/compiler-research/CppInterOp/actions/workflows/Windows-arm.yml)

[![Build Status](https://github.com/compiler-research/CppInterOp/actions/workflows/main.yml/badge.svg)](https://github.com/compiler-research/CppInterOp/actions/workflows/main.yml)
[![Build Status](https://github.com/compiler-research/CppInterOp/actions/workflows/emscripten.yml/badge.svg)](https://github.com/compiler-research/CppInterOp/actions/workflows/emscripten.yml)

[![codecov](https://codecov.io/gh/compiler-research/CppInterOp/branch/main/graph/badge.svg)](https://codecov.io/gh/compiler-research/CppInterOp)

[![Conda-Forge](https://img.shields.io/conda/vn/conda-forge/cppinterop)](https://github.com/conda-forge/cppinterop-feedstock)

[![Anaconda-Server Badge](https://anaconda.org/conda-forge/cppinterop/badges/license.svg)](https://github.com/conda-forge/cppinterop-feedstock)

[![Conda Platforms](https://img.shields.io/conda/pn/conda-forge/cppinterop.svg)](https://anaconda.org/conda-forge/cppinterop)

[![Anaconda-Server Badge](https://anaconda.org/conda-forge/cppinterop/badges/downloads.svg)](https://github.com/conda-forge/cppinterop-feedstock)

</div>

CppInterOp exposes API from [Clang](http://clang.llvm.org/) and [LLVM](https://llvm.org) in a backward compatible way.
The API support downstream tools that utilize interactive C++ by using the compiler as a service.
That is, embed Clang and LLVM as a libraries in their codebases.
The API are designed to be minimalistic and aid non-trivial tasks such as language interoperability on the fly.
In such scenarios CppInterOp can be used to provide the necessary introspection information to the other side helping the language cross talk.

[Installation](#build-instructions)
<div align="center">

[Documentation](https://cppinterop.readthedocs.io/en/latest/index.html)
[Installation](#build-instructions) | [Documentation](https://cppinterop.readthedocs.io/en/latest/index.html) | [CppInterOp API Documentation](https://cppinterop.readthedocs.io/en/latest/build/html/index.html) | [![lite-badge](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://compiler-research.github.io/CppInterOp/lab/index.html)

[CppInterOp API Documentation](https://cppinterop.readthedocs.io/en/latest/build/html/index.html)

Try Jupyter Lite CppInterOp demo by clicking below

[![lite-badge](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://compiler-research.github.io/CppInterOp/lab/index.html)
</div>

## CppInterOp Introduction

Expand Down Expand Up @@ -154,9 +137,6 @@ cmake -DLLVM_ENABLE_PROJECTS=clang \
-DCLANG_ENABLE_ARCMT=OFF \
-DCLANG_ENABLE_FORMAT=OFF \
-DCLANG_ENABLE_BOOTSTRAP=OFF \
-DLLVM_ENABLE_ZSTD=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_LIBXML2=OFF \
../llvm
cmake --build . --target clang clang-repl --parallel $(nproc --all)
```
Expand Down Expand Up @@ -205,9 +185,10 @@ Use the following build instructions to build on Linux and MacOS
```bash
git clone https://github.com/root-project/cling.git
cd ./cling/
git checkout tags/v1.0
git checkout tags/v1.2
git apply -v ../CppInterOp/patches/llvm/cling1.2-LookupHelper.patch
cd ..
git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git
git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git
mkdir llvm-project/build
cd llvm-project/build
cmake -DLLVM_ENABLE_PROJECTS=clang \
Expand All @@ -220,24 +201,21 @@ cmake -DLLVM_ENABLE_PROJECTS=clang \
-DCLANG_ENABLE_ARCMT=OFF \
-DCLANG_ENABLE_FORMAT=OFF \
-DCLANG_ENABLE_BOOTSTRAP=OFF \
-DLLVM_ENABLE_ZSTD=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_LIBXML2=OFF \
../llvm
cmake --build . --target clang --parallel $(nproc --all)
cmake --build . --target cling --parallel $(nproc --all)
cmake --build . --target gtest_main --parallel $(nproc --all)
```

Use the following build instructions to build on Windows

```powershell
git clone https://github.com/root-project/cling.git
cd .\cling\
git checkout tags/v1.0
git checkout tags/v1.2
git apply -v ..\CppInterOp\patches\llvm\cling1.2-LookupHelper.patch
cd ..
git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git
$env:ncpus = %NUMBER_OF_PROCESSORS%
git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git
$env:ncpus = $([Environment]::ProcessorCount)
$env:PWD_DIR= $PWD.Path
$env:CLING_DIR="$env:PWD_DIR\cling"
mkdir llvm-project\build
Expand All @@ -255,7 +233,6 @@ cmake -DLLVM_ENABLE_PROJECTS=clang `
../llvm
cmake --build . --target clang --parallel $env:ncpus
cmake --build . --target cling --parallel $env:ncpus
cmake --build . --target gtest_main --parallel $env:ncpus
```

Note the 'llvm-project' directory location. On linux and MacOS you execute the following
Expand All @@ -281,9 +258,22 @@ Regardless of whether you are building CppInterOP with Cling or Clang-REPL you w
```bash
export CB_PYTHON_DIR="$PWD/cppyy-backend/python"
export CPPINTEROP_DIR="$CB_PYTHON_DIR/cppyy_backend"
```

If building CppInterOp against clang-repl you will need to define the following

```bash
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"
```

and if building against cling you will need to define the following

```bash
export CLING_DIR="$(pwd)/cling"
export CLING_BUILD_DIR="$(pwd)/cling/build"
export 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:$PWD/include"
```

If on MacOS you will also need the following environment variable defined

```bash
Expand All @@ -295,9 +285,22 @@ On Windows you define as follows (assumes you have defined $env:PWD_DIR= $PWD.Pa
```powershell
$env:CB_PYTHON_DIR="$env:PWD_DIR\cppyy-backend\python"
$env:CPPINTEROP_DIR="$env:CB_PYTHON_DIR\cppyy_backend"
```

If building against clang-repl you will have the following defined

```powershell
$env:CPLUS_INCLUDE_PATH="$env:CPLUS_INCLUDE_PATH;$env:LLVM_DIR\llvm\include;$env:LLVM_DIR\clang\include;$env:LLVM_DIR\build\include;$env:LLVM_DIR\build\tools\clang\include"
```

and if building against cling

```powershell
$env:CLING_DIR="$env:PWD_DIR\cling"
$env:CLING_BUILD_DIR="$env:PWD_DIR\cling\build"
$env:CPLUS_INCLUDE_PATH="$env:CLING_DIR\tools\cling\include;$env:CLING_BUILD_DIR\include;$env:LLVM_DIR\llvm\include;$env:LLVM_DIR\clang\include;$env:LLVM_BUILD_DIR\include;$env:LLVM_BUILD_DIR\tools\clang\include;$env:PWD_DIR\include;"
```

#### Build CppInterOp

Now CppInterOp can be installed. On Linux and MacOS execute
Expand Down
2 changes: 1 addition & 1 deletion interpreter/CppInterOp/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.0
1.8.0;dev
2 changes: 1 addition & 1 deletion interpreter/CppInterOp/cppinterop-version.tag
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.7.0
130dd30548b59d8f618339158ab917c083184968
Loading
Loading