Skip to content

Commit

Permalink
[TCling] Allow InterOp to access ROOT's interpreter
Browse files Browse the repository at this point in the history
by linking clangCppInterOp in libCling
  • Loading branch information
aaronj0 committed Feb 5, 2025
1 parent f23a9ad commit 7461f2c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions core/metacling/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ target_include_directories(MetaCling SYSTEM PRIVATE
${CLANG_INCLUDE_DIRS}
${LLVM_INCLUDE_DIRS}
${CLAD_INCLUDE_DIRS}
${CPPINTEROP_INCLUDE_DIRS}
)

target_include_directories(MetaCling PRIVATE
Expand Down Expand Up @@ -74,7 +75,7 @@ if(MSVC)
set_source_files_properties(TCling.cxx COMPILE_FLAGS /bigobj)
endif()

add_dependencies(MetaCling CLING)
add_dependencies(MetaCling CLING clangCppInterOp)

##### libCling #############################################################

Expand Down Expand Up @@ -113,11 +114,15 @@ ROOT_LINKER_LIBRARY(Cling
$<TARGET_OBJECTS:ClingUtils>
$<TARGET_OBJECTS:Dictgen>
$<TARGET_OBJECTS:MetaCling>
LIBRARIES ${CLING_LIBRARIES} ${LINK_LIBS} ${CLING_PLUGIN_LINK_LIBS})
LIBRARIES ${CLING_LIBRARIES} clangCppInterOp ${LINK_LIBS} ${CLING_PLUGIN_LINK_LIBS})

# When these two link at the same time, they can exhaust the RAM on many machines, since they both link against llvm.
add_dependencies(Cling rootcling_stage1)

if(testing)
add_dependencies(Cling CppInterOpUnitTests)
endif()

if(MSVC)
set_target_properties(Cling PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
set(cling_exports ${cling_exports}
Expand Down
7 changes: 7 additions & 0 deletions core/metacling/src/TCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ clang/LLVM technology.
#include "cling/Utils/SourceNormalization.h"
#include "cling/Interpreter/Exception.h"

#include "clang/Interpreter/CppInterOp.h"

#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/Module.h"

Expand Down Expand Up @@ -1539,6 +1541,11 @@ TCling::TCling(const char *name, const char *title, const char* const argv[], vo
if (!fInterpreter->getCI()) { // Compiler instance could not be created. See https://its.cern.ch/jira/browse/ROOT-10239
return;
}

// Tell CppInterOp that the cling::Interpreter instance is managed externally by ROOT
// Sets the interpreter by passing the fInterpreter handle as soon as TCling is initialized
Cpp::UseExternalInterpreter((Cpp::TInterp_t*)fInterpreter.get());

// Don't check whether modules' files exist.
fInterpreter->getCI()->getPreprocessorOpts().DisablePCHOrModuleValidation =
DisableValidationForModuleKind::All;
Expand Down

0 comments on commit 7461f2c

Please sign in to comment.