Skip to content

Remove cling 1.0 support + Make llvm 16 minimum version #581

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 5 commits into
base: main
Choose a base branch
from
Open
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
27 changes: 9 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
include(GNUInstallDirs)
## Define supported version of clang and llvm

set(CLANG_MIN_SUPPORTED 13.0)
set(CLANG_MIN_SUPPORTED 16.0)
Copy link
Collaborator Author

@mcbarton mcbarton May 28, 2025

Choose a reason for hiding this comment

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

Could possibly make a change to this PR so CLANG_MIN_SUPPORTED, LLD_MIN_SUPPORTED and LLVM_MIN_SUPPORTED decided based on whether your using cling or clang-repl, to stop people trying to build against cling based on roots llvm 16.

set(CLANG_MAX_SUPPORTED "20.1.x")
set(CLANG_VERSION_UPPER_BOUND 21.0.0)
set(LLD_MIN_SUPPORTED 13.0)
set(LLD_MIN_SUPPORTED 16.0)
set(LLD_MAX_SUPPORTED "20.1.x")
set(LLD_VERSION_UPPER_BOUND 21.0.0)
set(LLVM_MIN_SUPPORTED 13.0)
set(LLVM_MIN_SUPPORTED 16.0)
set(LLVM_MAX_SUPPORTED "20.1.x")
set(LLVM_VERSION_UPPER_BOUND 21.0.0)

Expand Down Expand Up @@ -230,21 +230,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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,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 @@ -214,17 +215,17 @@ cmake -DLLVM_ENABLE_PROJECTS=clang \
../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
git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git
$env:ncpus = %NUMBER_OF_PROCESSORS%
$env:PWD_DIR= $PWD.Path
$env:CLING_DIR="$env:PWD_DIR\cling"
Expand All @@ -243,7 +244,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 Down
12 changes: 6 additions & 6 deletions docs/DevelopersDocumentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ build instructions to build on Linux and MacOS

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 @@ -153,17 +154,17 @@ build instructions to build on Linux and MacOS
../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

.. code:: 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
git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git
$env:ncpus = %NUMBER_OF_PROCESSORS%
$env:PWD_DIR= $PWD.Path
$env:CLING_DIR="$env:PWD_DIR\cling"
Expand All @@ -182,7 +183,6 @@ Use the following build instructions to build on Windows
../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 Down
12 changes: 6 additions & 6 deletions docs/InstallationAndUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ build instructions to build on Linux and MacOS
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 @@ -153,17 +154,17 @@ build instructions to build on Linux and MacOS
../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

.. code:: 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
git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git
$env:ncpus = %NUMBER_OF_PROCESSORS%
$env:PWD_DIR= $PWD.Path
$env:CLING_DIR="$env:PWD_DIR\cling"
Expand All @@ -182,7 +183,6 @@ Use the following build instructions to build on Windows
../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 Down
2 changes: 0 additions & 2 deletions lib/CppInterOp/CXCppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ CXTypeKind cxtype_GetTypeKind(QualType T) {
TKCASE(Elaborated);
TKCASE(Pipe);
TKCASE(Attributed);
#if CLANG_VERSION_MAJOR >= 16
TKCASE(BTFTagAttributed);
#endif
TKCASE(Atomic);
default:
return CXType_Unexposed;
Expand Down
61 changes: 1 addition & 60 deletions lib/CppInterOp/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,8 @@ getSymbolAddress(cling::Interpreter& I, llvm::StringRef IRName) {
llvm::orc::SymbolNameVector Names;
llvm::orc::ExecutionSession& ES = Jit.getExecutionSession();
Names.push_back(ES.intern(IRName));
#if CLANG_VERSION_MAJOR < 16
return llvm::make_error<llvm::orc::SymbolsNotFound>(Names);
#else
return llvm::make_error<llvm::orc::SymbolsNotFound>(ES.getSymbolStringPool(),
std::move(Names));
#endif // CLANG_VERSION_MAJOR
}

inline void codeComplete(std::vector<std::string>& Results,
Expand Down Expand Up @@ -208,9 +204,6 @@ namespace compat {

inline std::unique_ptr<clang::Interpreter>
createClangInterpreter(std::vector<const char*>& args) {
#if CLANG_VERSION_MAJOR < 16
auto ciOrErr = clang::IncrementalCompilerBuilder::create(args);
#else
auto has_arg = [](const char* x, llvm::StringRef match = "cuda") {
llvm::StringRef Arg = x;
Arg = Arg.trim().ltrim('-');
Expand Down Expand Up @@ -240,23 +233,18 @@ createClangInterpreter(std::vector<const char*>& args) {
DeviceCI = std::move(*devOrErr);
}
auto ciOrErr = CudaEnabled ? CB.CreateCudaHost() : CB.CreateCpp();
#endif // CLANG_VERSION_MAJOR < 16
if (!ciOrErr) {
llvm::logAllUnhandledErrors(ciOrErr.takeError(), llvm::errs(),
"Failed to build Incremental compiler:");
return nullptr;
}
#if CLANG_VERSION_MAJOR < 16
auto innerOrErr = clang::Interpreter::create(std::move(*ciOrErr));
#else
(*ciOrErr)->LoadRequestedPlugins();
if (CudaEnabled)
DeviceCI->LoadRequestedPlugins();
auto innerOrErr =
CudaEnabled ? clang::Interpreter::createWithCUDA(std::move(*ciOrErr),
std::move(DeviceCI))
: clang::Interpreter::create(std::move(*ciOrErr));
#endif // CLANG_VERSION_MAJOR < 16

if (!innerOrErr) {
llvm::logAllUnhandledErrors(innerOrErr.takeError(), llvm::errs(),
Expand Down Expand Up @@ -303,29 +291,15 @@ inline void maybeMangleDeclName(const clang::GlobalDecl& GD,
RawStr.flush();
}

// Clang 13 - Initial implementation of Interpreter and clang-repl
// Clang 14 - Add new Interpreter methods: getExecutionEngine,
// getSymbolAddress, getSymbolAddressFromLinkerName
// Clang 15 - Add new Interpreter methods: Undo
// Clang 18 - Add new Interpreter methods: CodeComplete

inline llvm::orc::LLJIT* getExecutionEngine(clang::Interpreter& I) {
#if CLANG_VERSION_MAJOR >= 14
auto* engine = &llvm::cantFail(I.getExecutionEngine());
return const_cast<llvm::orc::LLJIT*>(engine);
#else
assert(0 && "Not implemented in Clang <14!");
return nullptr;
#endif
}

inline llvm::Expected<llvm::JITTargetAddress>
getSymbolAddress(clang::Interpreter& I, llvm::StringRef IRName) {
#if CLANG_VERSION_MAJOR < 14
assert(0 && "Not implemented in Clang <14!");
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Not implemented in Clang <14!");
#endif // CLANG_VERSION_MAJOR < 14

auto AddrOrErr = I.getSymbolAddress(IRName);
if (llvm::Error Err = AddrOrErr.takeError())
Expand All @@ -343,7 +317,6 @@ getSymbolAddress(clang::Interpreter& I, clang::GlobalDecl GD) {
inline llvm::Expected<llvm::JITTargetAddress>
getSymbolAddressFromLinkerName(clang::Interpreter& I,
llvm::StringRef LinkerName) {
#if CLANG_VERSION_MAJOR >= 14
const auto& DL = getExecutionEngine(I)->getDataLayout();
char GlobalPrefix = DL.getGlobalPrefix();
std::string LinkerNameTmp(LinkerName);
Expand All @@ -354,21 +327,10 @@ getSymbolAddressFromLinkerName(clang::Interpreter& I,
if (llvm::Error Err = AddrOrErr.takeError())
return std::move(Err);
return AddrOrErr->getValue();
#else
assert(0 && "Not implemented in Clang <14!");
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Not implemented in Clang <14!");
#endif
}

inline llvm::Error Undo(clang::Interpreter& I, unsigned N = 1) {
#if CLANG_VERSION_MAJOR >= 15
return I.Undo(N);
#else
assert(0 && "Not implemented in Clang <15!");
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Not implemented in Clang <15!");
#endif
}

inline void codeComplete(std::vector<std::string>& Results,
Expand Down Expand Up @@ -421,35 +383,14 @@ using Interpreter = Cpp::Interpreter;
namespace compat {

// Clang >= 14 change type name to string (spaces formatting problem)
#if CLANG_VERSION_MAJOR >= 14
inline std::string FixTypeName(const std::string type_name) {
return type_name;
}
#else
inline std::string FixTypeName(const std::string type_name) {
std::string result = type_name;
size_t pos = 0;
while ((pos = result.find(" [", pos)) != std::string::npos) {
result.erase(pos, 1);
pos++;
}
return result;
}
#endif

// Clang >= 16 change CLANG_LIBDIR_SUFFIX to CLANG_INSTALL_LIBDIR_BASENAME
#if CLANG_VERSION_MAJOR < 16
#define CLANG_INSTALL_LIBDIR_BASENAME (llvm::Twine("lib") + CLANG_LIBDIR_SUFFIX)
#endif
inline std::string MakeResourceDir(llvm::StringRef Dir) {
llvm::SmallString<128> P(Dir);
llvm::sys::path::append(P, CLANG_INSTALL_LIBDIR_BASENAME, "clang",
#if CLANG_VERSION_MAJOR < 16
CLANG_VERSION_STRING
#else
CLANG_VERSION_MAJOR_STRING
#endif
);
CLANG_VERSION_MAJOR_STRING);
return std::string(P.str());
}

Expand Down
7 changes: 1 addition & 6 deletions lib/CppInterOp/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2991,12 +2991,7 @@ std::string DetectResourceDir(const char* ClangBinaryName /* = clang */) {

std::string detected_resource_dir = outs.back();

std::string version =
#if CLANG_VERSION_MAJOR < 16
CLANG_VERSION_STRING;
#else
CLANG_VERSION_MAJOR_STRING;
#endif
std::string version = CLANG_VERSION_MAJOR_STRING;
// We need to check if the detected resource directory is compatible.
if (llvm::sys::path::filename(detected_resource_dir) != version)
return "";
Expand Down
1 change: 0 additions & 1 deletion unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ if(EMSCRIPTEN)
set(gtest_libs gtest gmock)
else()
set(gtest_libs gtest gtest_main)
# Clang prior than clang13 (I think) merges both gmock into gtest.
if (TARGET gmock)
list(APPEND gtest_libs gmock gmock_main)
endif()
Expand Down
12 changes: 0 additions & 12 deletions unittests/CppInterOp/CUDATest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ using namespace TestUtils;

static bool HasCudaSDK() {
auto supportsCudaSDK = []() {
#if CLANG_VERSION_MAJOR < 16
// FIXME: Enable this for cling.
return false;
#endif // CLANG_VERSION_MAJOR < 16
if (!Cpp::CreateInterpreter({}, {"--cuda"}))
return false;
return Cpp::Declare("__global__ void test_func() {}"
Expand All @@ -25,10 +21,6 @@ static bool HasCudaSDK() {

static bool HasCudaRuntime() {
auto supportsCuda = []() {
#if CLANG_VERSION_MAJOR < 16
// FIXME: Enable this for cling.
return false;
#endif //CLANG_VERSION_MAJOR < 16
if (!HasCudaSDK())
return false;

Expand All @@ -44,11 +36,7 @@ static bool HasCudaRuntime() {
return hasCuda;
}

#if CLANG_VERSION_MAJOR < 16
TEST(DISABLED_CUDATest, Sanity) {
#else
TEST(CUDATest, Sanity) {
#endif // CLANG_VERSION_MAJOR < 16
#ifdef _WIN32
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
#endif
Expand Down
4 changes: 0 additions & 4 deletions unittests/CppInterOp/ScopeReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,14 +859,10 @@ template<class T> constexpr T pi = T(3.1415926535897932385L);
auto* VD = cast<VarTemplateSpecializationDecl>((Decl*)Instance1);
VarTemplateDecl* VDTD1 = VD->getSpecializedTemplate();
EXPECT_TRUE(VDTD1->isThisDeclarationADefinition());
#if CLANG_VERSION_MAJOR > 13
#if CLANG_VERSION_MAJOR <= 18
TemplateArgument TA1 = (*VD->getTemplateArgsInfo())[0].getArgument();
#else
TemplateArgument TA1 = (*VD->getTemplateArgsAsWritten())[0].getArgument();
#endif // CLANG_VERSION_MAJOR
#else
TemplateArgument TA1 = VD->getTemplateArgsInfo()[0].getArgument();
#endif // CLANG_VERSION_MAJOR
EXPECT_TRUE(TA1.getAsType()->isIntegerType());
}
Expand Down
Loading