Skip to content

Commit dd50000

Browse files
authored
Remove cling 1.0 support + Make llvm 16 minimum version (#581)
1 parent 90ad431 commit dd50000

File tree

10 files changed

+47
-115
lines changed

10 files changed

+47
-115
lines changed

CMakeLists.txt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,25 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
6767
include(GNUInstallDirs)
6868
## Define supported version of clang and llvm
6969

70-
set(CLANG_MIN_SUPPORTED 13.0)
70+
if (CPPINTEROP_USE_CLING)
71+
set(CLANG_MIN_SUPPORTED 18.0)
72+
else()
73+
set(CLANG_MIN_SUPPORTED 16.0)
74+
endif(CPPINTEROP_USE_CLING)
7175
set(CLANG_MAX_SUPPORTED "20.1.x")
7276
set(CLANG_VERSION_UPPER_BOUND 21.0.0)
73-
set(LLD_MIN_SUPPORTED 13.0)
77+
if (CPPINTEROP_USE_CLING)
78+
set(LLD_MIN_SUPPORTED 18.0)
79+
else()
80+
set(LLD_MIN_SUPPORTED 16.0)
81+
endif(CPPINTEROP_USE_CLING)
7482
set(LLD_MAX_SUPPORTED "20.1.x")
7583
set(LLD_VERSION_UPPER_BOUND 21.0.0)
76-
set(LLVM_MIN_SUPPORTED 13.0)
84+
if (CPPINTEROP_USE_CLING)
85+
set(LLVM_MIN_SUPPORTED 18.0)
86+
else()
87+
set(LLVM_MIN_SUPPORTED 16.0)
88+
endif(CPPINTEROP_USE_CLING)
7789
set(LLVM_MAX_SUPPORTED "20.1.x")
7890
set(LLVM_VERSION_UPPER_BOUND 21.0.0)
7991

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

233-
## Clang 13 require c++14 or later, Clang 16 require c++17 or later.
234-
if (CLANG_VERSION_MAJOR GREATER_EQUAL 16)
235-
if (NOT CMAKE_CXX_STANDARD)
236-
set (CMAKE_CXX_STANDARD 17)
237-
endif()
238-
if (CMAKE_CXX_STANDARD LESS 17)
239-
message(fatal "LLVM/CppInterOp requires c++17 or later")
240-
endif()
241-
elseif (CLANG_VERSION_MAJOR GREATER_EQUAL 13)
242-
if (NOT CMAKE_CXX_STANDARD)
243-
set (CMAKE_CXX_STANDARD 14)
244-
endif()
245-
if (CMAKE_CXX_STANDARD LESS 14)
246-
message(fatal "LLVM/CppInterOp requires c++14 or later")
247-
endif()
245+
## Clang 16 require c++17 or later.
246+
if (NOT CMAKE_CXX_STANDARD)
247+
set (CMAKE_CXX_STANDARD 17)
248+
endif()
249+
if (CMAKE_CXX_STANDARD LESS 17)
250+
message(fatal "LLVM/CppInterOp requires c++17 or later")
248251
endif()
249252

250253
## Find supported Cling

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ Use the following build instructions to build on Linux and MacOS
190190
```bash
191191
git clone https://github.com/root-project/cling.git
192192
cd ./cling/
193-
git checkout tags/v1.0
193+
git checkout tags/v1.2
194+
git apply -v ../CppInterOp/patches/llvm/cling1.2-LookupHelper.patch
194195
cd ..
195-
git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git
196+
git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git
196197
mkdir llvm-project/build
197198
cd llvm-project/build
198199
cmake -DLLVM_ENABLE_PROJECTS=clang \
@@ -208,17 +209,17 @@ cmake -DLLVM_ENABLE_PROJECTS=clang \
208209
../llvm
209210
cmake --build . --target clang --parallel $(nproc --all)
210211
cmake --build . --target cling --parallel $(nproc --all)
211-
cmake --build . --target gtest_main --parallel $(nproc --all)
212212
```
213213

214214
Use the following build instructions to build on Windows
215215

216216
```powershell
217217
git clone https://github.com/root-project/cling.git
218218
cd .\cling\
219-
git checkout tags/v1.0
219+
git checkout tags/v1.2
220+
git apply -v ..\CppInterOp\patches\llvm\cling1.2-LookupHelper.patch
220221
cd ..
221-
git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git
222+
git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git
222223
$env:ncpus = %NUMBER_OF_PROCESSORS%
223224
$env:PWD_DIR= $PWD.Path
224225
$env:CLING_DIR="$env:PWD_DIR\cling"
@@ -237,7 +238,6 @@ cmake -DLLVM_ENABLE_PROJECTS=clang `
237238
../llvm
238239
cmake --build . --target clang --parallel $env:ncpus
239240
cmake --build . --target cling --parallel $env:ncpus
240-
cmake --build . --target gtest_main --parallel $env:ncpus
241241
```
242242

243243
Note the 'llvm-project' directory location. On linux and MacOS you execute the following

docs/DevelopersDocumentation.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ build instructions to build on Linux and MacOS
129129
130130
git clone https://github.com/root-project/cling.git
131131
cd ./cling/
132-
git checkout tags/v1.0
132+
git checkout tags/v1.2
133+
git apply -v ../CppInterOp/patches/llvm/cling1.2-LookupHelper.patch
133134
cd ..
134-
git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git
135+
git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git
135136
mkdir llvm-project/build
136137
cd llvm-project/build
137138
cmake -DLLVM_ENABLE_PROJECTS=clang \
@@ -147,17 +148,17 @@ build instructions to build on Linux and MacOS
147148
../llvm
148149
cmake --build . --target clang --parallel $(nproc --all)
149150
cmake --build . --target cling --parallel $(nproc --all)
150-
cmake --build . --target gtest_main --parallel $(nproc --all)
151151
152152
Use the following build instructions to build on Windows
153153

154154
.. code:: powershell
155155
156156
git clone https://github.com/root-project/cling.git
157157
cd .\cling\
158-
git checkout tags/v1.0
158+
git checkout tags/v1.2
159+
git apply -v ..\CppInterOp\patches\llvm\cling1.2-LookupHelper.patch
159160
cd ..
160-
git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git
161+
git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git
161162
$env:ncpus = %NUMBER_OF_PROCESSORS%
162163
$env:PWD_DIR= $PWD.Path
163164
$env:CLING_DIR="$env:PWD_DIR\cling"
@@ -176,7 +177,6 @@ Use the following build instructions to build on Windows
176177
../llvm
177178
cmake --build . --target clang --parallel $env:ncpus
178179
cmake --build . --target cling --parallel $env:ncpus
179-
cmake --build . --target gtest_main --parallel $env:ncpus
180180
181181
Note the 'llvm-project' directory location. On linux and MacOS you execute the
182182
following

docs/InstallationAndUsage.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ build instructions to build on Linux and MacOS
129129
130130
git clone https://github.com/root-project/cling.git
131131
cd ./cling/
132-
git checkout tags/v1.0
132+
git checkout tags/v1.2
133+
git apply -v ../CppInterOp/patches/llvm/cling1.2-LookupHelper.patch
133134
cd ..
134-
git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git
135+
git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git
135136
mkdir llvm-project/build
136137
cd llvm-project/build
137138
cmake -DLLVM_ENABLE_PROJECTS=clang \
@@ -147,17 +148,17 @@ build instructions to build on Linux and MacOS
147148
../llvm
148149
cmake --build . --target clang --parallel $(nproc --all)
149150
cmake --build . --target cling --parallel $(nproc --all)
150-
cmake --build . --target gtest_main --parallel $(nproc --all)
151151
152152
Use the following build instructions to build on Windows
153153

154154
.. code:: powershell
155155
156156
git clone https://github.com/root-project/cling.git
157157
cd .\cling\
158-
git checkout tags/v1.0
158+
git checkout tags/v1.2
159+
git apply -v ..\CppInterOp\patches\llvm\cling1.2-LookupHelper.patch
159160
cd ..
160-
git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git
161+
git clone --depth=1 -b cling-llvm18 https://github.com/root-project/llvm-project.git
161162
$env:ncpus = %NUMBER_OF_PROCESSORS%
162163
$env:PWD_DIR= $PWD.Path
163164
$env:CLING_DIR="$env:PWD_DIR\cling"
@@ -176,7 +177,6 @@ Use the following build instructions to build on Windows
176177
../llvm
177178
cmake --build . --target clang --parallel $env:ncpus
178179
cmake --build . --target cling --parallel $env:ncpus
179-
cmake --build . --target gtest_main --parallel $env:ncpus
180180
181181
Note the 'llvm-project' directory location. On linux and MacOS you execute the
182182
following

lib/CppInterOp/CXCppInterOp.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ CXTypeKind cxtype_GetTypeKind(QualType T) {
200200
TKCASE(Elaborated);
201201
TKCASE(Pipe);
202202
TKCASE(Attributed);
203-
#if CLANG_VERSION_MAJOR >= 16
204203
TKCASE(BTFTagAttributed);
205-
#endif
206204
TKCASE(Atomic);
207205
default:
208206
return CXType_Unexposed;

lib/CppInterOp/Compatibility.h

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,8 @@ getSymbolAddress(cling::Interpreter& I, llvm::StringRef IRName) {
122122
llvm::orc::SymbolNameVector Names;
123123
llvm::orc::ExecutionSession& ES = Jit.getExecutionSession();
124124
Names.push_back(ES.intern(IRName));
125-
#if CLANG_VERSION_MAJOR < 16
126-
return llvm::make_error<llvm::orc::SymbolsNotFound>(Names);
127-
#else
128125
return llvm::make_error<llvm::orc::SymbolsNotFound>(ES.getSymbolStringPool(),
129126
std::move(Names));
130-
#endif // CLANG_VERSION_MAJOR
131127
}
132128

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

209205
inline std::unique_ptr<clang::Interpreter>
210206
createClangInterpreter(std::vector<const char*>& args) {
211-
#if CLANG_VERSION_MAJOR < 16
212-
auto ciOrErr = clang::IncrementalCompilerBuilder::create(args);
213-
#else
214207
auto has_arg = [](const char* x, llvm::StringRef match = "cuda") {
215208
llvm::StringRef Arg = x;
216209
Arg = Arg.trim().ltrim('-');
@@ -240,23 +233,18 @@ createClangInterpreter(std::vector<const char*>& args) {
240233
DeviceCI = std::move(*devOrErr);
241234
}
242235
auto ciOrErr = CudaEnabled ? CB.CreateCudaHost() : CB.CreateCpp();
243-
#endif // CLANG_VERSION_MAJOR < 16
244236
if (!ciOrErr) {
245237
llvm::logAllUnhandledErrors(ciOrErr.takeError(), llvm::errs(),
246238
"Failed to build Incremental compiler:");
247239
return nullptr;
248240
}
249-
#if CLANG_VERSION_MAJOR < 16
250-
auto innerOrErr = clang::Interpreter::create(std::move(*ciOrErr));
251-
#else
252241
(*ciOrErr)->LoadRequestedPlugins();
253242
if (CudaEnabled)
254243
DeviceCI->LoadRequestedPlugins();
255244
auto innerOrErr =
256245
CudaEnabled ? clang::Interpreter::createWithCUDA(std::move(*ciOrErr),
257246
std::move(DeviceCI))
258247
: clang::Interpreter::create(std::move(*ciOrErr));
259-
#endif // CLANG_VERSION_MAJOR < 16
260248

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

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

312296
inline llvm::orc::LLJIT* getExecutionEngine(clang::Interpreter& I) {
313-
#if CLANG_VERSION_MAJOR >= 14
314297
auto* engine = &llvm::cantFail(I.getExecutionEngine());
315298
return const_cast<llvm::orc::LLJIT*>(engine);
316-
#else
317-
assert(0 && "Not implemented in Clang <14!");
318-
return nullptr;
319-
#endif
320299
}
321300

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

330304
auto AddrOrErr = I.getSymbolAddress(IRName);
331305
if (llvm::Error Err = AddrOrErr.takeError())
@@ -343,7 +317,6 @@ getSymbolAddress(clang::Interpreter& I, clang::GlobalDecl GD) {
343317
inline llvm::Expected<llvm::JITTargetAddress>
344318
getSymbolAddressFromLinkerName(clang::Interpreter& I,
345319
llvm::StringRef LinkerName) {
346-
#if CLANG_VERSION_MAJOR >= 14
347320
const auto& DL = getExecutionEngine(I)->getDataLayout();
348321
char GlobalPrefix = DL.getGlobalPrefix();
349322
std::string LinkerNameTmp(LinkerName);
@@ -354,21 +327,10 @@ getSymbolAddressFromLinkerName(clang::Interpreter& I,
354327
if (llvm::Error Err = AddrOrErr.takeError())
355328
return std::move(Err);
356329
return AddrOrErr->getValue();
357-
#else
358-
assert(0 && "Not implemented in Clang <14!");
359-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
360-
"Not implemented in Clang <14!");
361-
#endif
362330
}
363331

364332
inline llvm::Error Undo(clang::Interpreter& I, unsigned N = 1) {
365-
#if CLANG_VERSION_MAJOR >= 15
366333
return I.Undo(N);
367-
#else
368-
assert(0 && "Not implemented in Clang <15!");
369-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
370-
"Not implemented in Clang <15!");
371-
#endif
372334
}
373335

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

423385
// Clang >= 14 change type name to string (spaces formatting problem)
424-
#if CLANG_VERSION_MAJOR >= 14
425386
inline std::string FixTypeName(const std::string type_name) {
426387
return type_name;
427388
}
428-
#else
429-
inline std::string FixTypeName(const std::string type_name) {
430-
std::string result = type_name;
431-
size_t pos = 0;
432-
while ((pos = result.find(" [", pos)) != std::string::npos) {
433-
result.erase(pos, 1);
434-
pos++;
435-
}
436-
return result;
437-
}
438-
#endif
439389

440-
// Clang >= 16 change CLANG_LIBDIR_SUFFIX to CLANG_INSTALL_LIBDIR_BASENAME
441-
#if CLANG_VERSION_MAJOR < 16
442-
#define CLANG_INSTALL_LIBDIR_BASENAME (llvm::Twine("lib") + CLANG_LIBDIR_SUFFIX)
443-
#endif
444390
inline std::string MakeResourceDir(llvm::StringRef Dir) {
445391
llvm::SmallString<128> P(Dir);
446392
llvm::sys::path::append(P, CLANG_INSTALL_LIBDIR_BASENAME, "clang",
447-
#if CLANG_VERSION_MAJOR < 16
448-
CLANG_VERSION_STRING
449-
#else
450-
CLANG_VERSION_MAJOR_STRING
451-
#endif
452-
);
393+
CLANG_VERSION_MAJOR_STRING);
453394
return std::string(P.str());
454395
}
455396

lib/CppInterOp/CppInterOp.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,12 +3071,7 @@ std::string DetectResourceDir(const char* ClangBinaryName /* = clang */) {
30713071

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

3074-
std::string version =
3075-
#if CLANG_VERSION_MAJOR < 16
3076-
CLANG_VERSION_STRING;
3077-
#else
3078-
CLANG_VERSION_MAJOR_STRING;
3079-
#endif
3074+
std::string version = CLANG_VERSION_MAJOR_STRING;
30803075
// We need to check if the detected resource directory is compatible.
30813076
if (llvm::sys::path::filename(detected_resource_dir) != version)
30823077
return "";

unittests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ if(EMSCRIPTEN)
1111
set(gtest_libs gtest gmock)
1212
else()
1313
set(gtest_libs gtest gtest_main)
14-
# Clang prior than clang13 (I think) merges both gmock into gtest.
1514
if (TARGET gmock)
1615
list(APPEND gtest_libs gmock gmock_main)
1716
endif()

unittests/CppInterOp/CUDATest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ using namespace TestUtils;
1010

1111
static bool HasCudaSDK() {
1212
auto supportsCudaSDK = []() {
13-
#if CLANG_VERSION_MAJOR < 16
13+
#ifdef CPPINTEROP_USE_CLING
1414
// FIXME: Enable this for cling.
1515
return false;
16-
#endif // CLANG_VERSION_MAJOR < 16
16+
#endif
1717
if (!Cpp::CreateInterpreter({}, {"--cuda"}))
1818
return false;
1919
return Cpp::Declare("__global__ void test_func() {}"
@@ -25,10 +25,10 @@ static bool HasCudaSDK() {
2525

2626
static bool HasCudaRuntime() {
2727
auto supportsCuda = []() {
28-
#if CLANG_VERSION_MAJOR < 16
28+
#ifdef CPPINTEROP_USE_CLING
2929
// FIXME: Enable this for cling.
3030
return false;
31-
#endif //CLANG_VERSION_MAJOR < 16
31+
#endif
3232
if (!HasCudaSDK())
3333
return false;
3434

@@ -44,11 +44,11 @@ static bool HasCudaRuntime() {
4444
return hasCuda;
4545
}
4646

47-
#if CLANG_VERSION_MAJOR < 16
47+
#ifdef CPPINTEROP_USE_CLING
4848
TEST(DISABLED_CUDATest, Sanity) {
4949
#else
5050
TEST(CUDATest, Sanity) {
51-
#endif // CLANG_VERSION_MAJOR < 16
51+
#endif
5252
#ifdef _WIN32
5353
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
5454
#endif

0 commit comments

Comments
 (0)