From 4eac1caa49d86ce9e51da1d46bfe38675f57444c Mon Sep 17 00:00:00 2001 From: Alexander Penev Date: Sun, 19 Nov 2023 14:37:18 +0000 Subject: [PATCH 01/59] Fix Cmake package return info --- CMakeLists.txt | 2 +- cmake/CppInterOp/CppInterOpConfig.cmake.in | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b85b2c0b..d8b340a43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -312,7 +312,7 @@ include_directories(BEFORE SYSTEM ) -file(READ "VERSION" CPPINTEROP_VERSION) +file(STRINGS "VERSION" CPPINTEROP_VERSION) string(REGEX MATCH "([0-9]*)\.([0-9]*)\.([0-9]*)" CPPINTEROP_VERSION_ONLY "${CPPINTEROP_VERSION}") set(CPPINTEROP_VERSION_MAJOR "${CMAKE_MATCH_1}") set(CPPINTEROP_VERSION_MINOR "${CMAKE_MATCH_2}") diff --git a/cmake/CppInterOp/CppInterOpConfig.cmake.in b/cmake/CppInterOp/CppInterOpConfig.cmake.in index f1bc63ded..51f59ef0f 100644 --- a/cmake/CppInterOp/CppInterOpConfig.cmake.in +++ b/cmake/CppInterOp/CppInterOpConfig.cmake.in @@ -10,14 +10,16 @@ get_filename_component(CPPINTEROP_INSTALL_PREFIX "${CPPINTEROP_INSTALL_PREFIX}" if (IS_DIRECTORY "${CPPINTEROP_INSTALL_PREFIX}/include") set(_include "${CPPINTEROP_INSTALL_PREFIX}/include") + set(_libs "${CPPINTEROP_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clangCppInterOp${CMAKE_SHARED_LIBRARY_SUFFIX}") else() set(_include "@CMAKE_CURRENT_SOURCE_DIR@/include") + set(_libs "@CMAKE_CURRENT_SOURCE_DIR@/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clangCppInterOp${CMAKE_SHARED_LIBRARY_SUFFIX}") endif() -if (IS_DIRECTORY "${CPPINTEROP_INSTALL_PREFIX}/cmake") - set(_cmake "${CPPINTEROP_INSTALL_PREFIX}/cmake") +if (IS_DIRECTORY "${CPPINTEROP_INSTALL_PREFIX}/lib/cmake/CppInterOp") + set(_cmake "${CPPINTEROP_INSTALL_PREFIX}/lib/cmake/CppInterOp") else() - set(_cmake "@CMAKE_CURRENT_SOURCE_DIR@/cmake") + set(_cmake "@CMAKE_CURRENT_SOURCE_DIR@/cmake/CppInterOp") endif() ### @@ -25,11 +27,13 @@ endif() set(CPPINTEROP_EXPORTED_TARGETS "clangCppInterOp") set(CPPINTEROP_CMAKE_DIR "${_cmake}") set(CPPINTEROP_INCLUDE_DIRS "${_include}") +set(CPPINTEROP_LIBRARIES "${_libs}") # Provide all our library targets to users. add_library(clangCppInterOp SHARED IMPORTED) -set_property(TARGET clangCppInterOp PROPERTY IMPORTED_LOCATION "${CPPINTEROP_DIR}/lib/libclangCppInterOp.so") set_property(TARGET clangCppInterOp PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${_include}") +set_property(TARGET clangCppInterOp PROPERTY IMPORTED_LOCATION "${_libs}") -unset(_include) unset(_cmake) +unset(_include) +unset(_libs) From 900d311bba6d6d9029f5f3880ba4ede86d91e74b Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Wed, 22 Nov 2023 06:45:41 +0000 Subject: [PATCH 02/59] Added fixes which caused issues building on Apple Silicon (#170) * Fixes issues which occur when building on Apple Silicon Stopped Cuda library been loaded when on Apple and sets CMAKE_SHARED_LIBRARY_SUFFIX without hardcoding --- cmake/CppInterOp/CppInterOpConfig.cmake.in | 3 +++ lib/Interpreter/Compatibility.h | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/cmake/CppInterOp/CppInterOpConfig.cmake.in b/cmake/CppInterOp/CppInterOpConfig.cmake.in index 51f59ef0f..d6565a0a6 100644 --- a/cmake/CppInterOp/CppInterOpConfig.cmake.in +++ b/cmake/CppInterOp/CppInterOpConfig.cmake.in @@ -6,6 +6,9 @@ get_filename_component(CPPINTEROP_INSTALL_PREFIX "${CPPINTEROP_INSTALL_PREFIX}" get_filename_component(CPPINTEROP_INSTALL_PREFIX "${CPPINTEROP_INSTALL_PREFIX}" PATH) get_filename_component(CPPINTEROP_INSTALL_PREFIX "${CPPINTEROP_INSTALL_PREFIX}" PATH) +# Determine CMAKE_SHARED_LIBRARY_SUFFIX based on operating system +include(CMakeSystemSpecificInformation) + ### build/install workaround if (IS_DIRECTORY "${CPPINTEROP_INSTALL_PREFIX}/include") diff --git a/lib/Interpreter/Compatibility.h b/lib/Interpreter/Compatibility.h index 5f7229655..b84579c47 100644 --- a/lib/Interpreter/Compatibility.h +++ b/lib/Interpreter/Compatibility.h @@ -96,7 +96,11 @@ createClangInterpreter(std::vector& args) { }; auto it = std::find_if(args.begin(), args.end(), has_arg); std::vector gpu_args = {it, args.end()}; +#ifdef __APPLE__ + bool CudaEnabled = false; +#else bool CudaEnabled = !gpu_args.empty(); +#endif clang::IncrementalCompilerBuilder CB; CB.SetCompilerArgs({args.begin(), it}); From cf180680cc236c616fe8749b288af039a0f86600 Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:52:20 +0000 Subject: [PATCH 03/59] Update CppInterOpConfig.cmake.in to get correct library location (#171) When referencing config file while building xeus-clang-repl it sets the location of the library to the wrong location. This fix gives the right location. --- cmake/CppInterOp/CppInterOpConfig.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/CppInterOp/CppInterOpConfig.cmake.in b/cmake/CppInterOp/CppInterOpConfig.cmake.in index d6565a0a6..6a2a810a7 100644 --- a/cmake/CppInterOp/CppInterOpConfig.cmake.in +++ b/cmake/CppInterOp/CppInterOpConfig.cmake.in @@ -16,7 +16,7 @@ if (IS_DIRECTORY "${CPPINTEROP_INSTALL_PREFIX}/include") set(_libs "${CPPINTEROP_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clangCppInterOp${CMAKE_SHARED_LIBRARY_SUFFIX}") else() set(_include "@CMAKE_CURRENT_SOURCE_DIR@/include") - set(_libs "@CMAKE_CURRENT_SOURCE_DIR@/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clangCppInterOp${CMAKE_SHARED_LIBRARY_SUFFIX}") + set(_libs "@CMAKE_CURRENT_BINARY_DIR@/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clangCppInterOp${CMAKE_SHARED_LIBRARY_SUFFIX}") endif() if (IS_DIRECTORY "${CPPINTEROP_INSTALL_PREFIX}/lib/cmake/CppInterOp") From 7fc187408a7ae586ebc13ee48b75e4cc6a1b6815 Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Fri, 22 Dec 2023 19:45:30 +0000 Subject: [PATCH 04/59] Update macos and ubuntu ci to be more extensive (#173) * Update CI to run on arm based macos system + run extra tests in CI * Update to have extensive osx x86 tests (turned off arm for the time being, until free m1 github runner tier available) * Fix cppyy issue for cling based runs + try latest version of xcode to pass cppyy tests * Create clang17-1-NewOperator.patch. Add a interpreter-specific overload of operator new for C++. * Temporary disable valgrind error * Update ci.yml to have better names for jobs, and reverse ubuntu os back to ubuntu 22.04 for all cases * Update ci.yml to include cling-version for jobs that require it * Update ci.yml to properly indent cp cppyy-backend library command --------- Co-authored-by: Alexander Penev <7923188+alexander-penev@users.noreply.github.com> --- .github/workflows/ci.yml | 165 +++++++++++++++--- lib/Interpreter/CppInterOpInterpreter.h | 2 + patches/llvm/clang17-1-NewOperator.patch | 205 +++++++++++++++++++++++ 3 files changed, 346 insertions(+), 26 deletions(-) create mode 100644 patches/llvm/clang17-1-NewOperator.patch diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9464cd9e..c96361aed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,13 +22,21 @@ jobs: matrix: include: - name: ubu22-gcc12-clang-repl-17 - os: ubuntu-latest + os: ubuntu-22.04 compiler: gcc-12 clang-runtime: '17' cling: Off cppyy: Off extra_cmake_options: '-DLLVM_USE_LINKER=lld' + - name: ubu22-gcc12-clang-repl-17-cppyy + os: ubuntu-22.04 + compiler: gcc-12 + clang-runtime: '17' + cling: Off + cppyy: On + extra_cmake_options: '-DLLVM_USE_LINKER=lld' + - name: ubu22-gcc9-clang-repl-16 os: ubuntu-22.04 compiler: gcc-9 @@ -38,11 +46,21 @@ jobs: coverage: true extra_cmake_options: '-DLLVM_USE_LINKER=lld' + - name: ubu22-gcc9-clang-repl-16-cppyy + os: ubuntu-22.04 + compiler: gcc-9 + clang-runtime: '16' + cling: Off + cppyy: On + coverage: true + extra_cmake_options: '-DLLVM_USE_LINKER=lld' + - name: ubu22-gcc9-clang13-cling os: ubuntu-22.04 compiler: gcc-9 clang-runtime: '13' cling: On + cling-version: '1.0' cppyy: Off extra_cmake_options: '-DLLVM_USE_LINKER=lld' @@ -51,23 +69,101 @@ jobs: compiler: gcc-9 clang-runtime: '13' cling: On + cling-version: '1.0' cppyy: On extra_cmake_options: '-DLLVM_USE_LINKER=lld' - - name: osx-clang-clang-repl-16 - os: macos-latest + - name: osx13-x86-clang-clang-repl-17 + os: macos-13 + compiler: clang + clang-runtime: '17' + cling: Off + cppyy: Off + + - name: osx13-x86-clang-clang-repl-17-cppyy + os: macos-13 + compiler: clang + clang-runtime: '17' + cling: Off + cppyy: On + + - name: osx13-x86-clang-clang-repl-16 + os: macos-13 compiler: clang clang-runtime: '16' cling: Off cppyy: Off - - name: osx-clang-clang13-cling - os: macos-latest + - name: osx13-x86-clang-clang-repl-16-cppyy + os: macos-13 + compiler: clang + clang-runtime: '16' + cling: Off + cppyy: On + + - name: osx13-x86-clang-clang13-cling + os: macos-13 compiler: clang clang-runtime: '13' cling: On + cling-version: '1.0' cppyy: Off + - name: osx13-x86-clang-clang13-cling-cppyy + os: macos-13 + compiler: clang + clang-runtime: '13' + cling: On + cling-version: '1.0' + cppyy: On + + #Block commented out until free tier for m1 + #exists (expected sometime 2024) and key for os + #can be replaced + #- name: osx13-arm64-clang-clang-repl-17 + # os: macos-13-arm64 + # compiler: clang + # clang-runtime: '17' + # cling: Off + # cppyy: Off + # + #- name: osx13-arm64-clang-clang-repl-17-cppyy + # os: macos-13-arm64 + # compiler: clang + # clang-runtime: '17' + # cling: Off + # cppyy: On + # + #- name: osx13-arm64-clang-clang-repl-16 + # os: macos-13-arm64 + # compiler: clang + # clang-runtime: '16' + # cling: Off + # cppyy: Off + # + #- name: osx13-arm64-clang-clang-repl-16-cppyy + # os: macos-13-arm64 + # compiler: clang + # clang-runtime: '16' + # cling: Off + # cppyy: On + # + #- name: osx13-arm64-clang-clang13-cling + # os: macos-13-arm64 + # compiler: clang + # clang-runtime: '13' + # cling: On + # cling-version: '1.0' + # cppyy: Off + # + #- name: osx13-arm64-clang-clang13-cling-cppyy + # os: macos-13-arm64 + # compiler: clang + # clang-runtime: '13' + # cling: On + # cling-version: '1.0' + # cppyy: On + steps: - uses: actions/checkout@v3 with: @@ -141,8 +237,11 @@ jobs: echo "CXX=g++-${vers}" >> $GITHUB_ENV else echo "SDKROOT=$(xcrun --sdk macosx --show-sdk-path)" >> $GITHUB_ENV - echo "CC=clang" >> $GITHUB_ENV - echo "CXX=clang++" >> $GITHUB_ENV + #Use clang-15 and clang++-15 compiler that is installed on runner, instead of one + #provided by MacOS (could brew install clang-16/17 to use consistent version + #of clang) + echo "CC=$(brew --prefix llvm@15)/bin/clang" >> $GITHUB_ENV + echo "CXX=$(brew --prefix llvm@15)/bin/clang++" >> $GITHUB_ENV fi env: compiler: ${{ matrix.compiler }} @@ -160,7 +259,12 @@ jobs: - name: Install deps on MacOS if: runner.os == 'macOS' run: | - brew install git gcc gnupg python@3 + #gcc, gnupg and python3 installed on Github runner + #brew install git gcc gnupg python@3 + #Select latest xcode available on macos-13 + sudo xcode-select -s /Applications/Xcode_15.1.app/Contents/Developer + brew update + brew upgrade pip install distro pytest - name: Restore Cache LLVM/Clang runtime build directory @@ -180,7 +284,10 @@ jobs: os="${{ matrix.os }}" cling_on=$(echo "${{ matrix.cling }}" | tr '[:lower:]' '[:upper:]') if [[ "${cling_on}" == "ON" ]]; then - git clone --depth=1 https://github.com/root-project/cling.git + git clone https://github.com/root-project/cling.git + cd ./cling + git checkout tags/v${{ matrix.cling-version }} + cd .. git clone --depth=1 -b cling-llvm${{ matrix.clang-runtime }} https://github.com/root-project/llvm-project.git else # repl git clone --depth=1 -b release/${{ matrix.clang-runtime }}.x https://github.com/llvm/llvm-project.git @@ -283,7 +390,8 @@ jobs: cmake --build . --target check-cppinterop --parallel ${{ env.ncpus }} cppyy_on=$(echo "${{ matrix.cppyy }}" | tr '[:lower:]' '[:upper:]') if [[ ("${cppyy_on}" != "ON") && ("${os}" == "ubuntu"*) ]]; then - valgrind --track-origins=yes --error-exitcode=1 unittests/CppInterOp/CppInterOpTests 2>&1 >/dev/null + # TODO: Remove "|| true" when fix memory issues in LLVM/Clang 17 + valgrind --track-origins=yes --error-exitcode=1 unittests/CppInterOp/CppInterOpTests 2>&1 >/dev/null || true fi cd .. # We need CB_PYTHON_DIR later @@ -294,11 +402,11 @@ jobs: echo "LLVM_BUILD_DIR=$LLVM_BUILD_DIR" >> $GITHUB_ENV echo "CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH" >> $GITHUB_ENV - - name: Build and Install cppyy-backend on Linux - if: ${{ (runner.os == 'Linux') && (matrix.cppyy == 'On') }} + - name: Build and Install cppyy-backend on Unix Systems + if: ${{ (runner.os != 'windows') && (matrix.cppyy == 'On') }} run: | # Download cppyy-backend - git clone https://github.com/compiler-research/cppyy-backend.git + git clone --depth=1 https://github.com/compiler-research/cppyy-backend.git cd cppyy-backend mkdir -p $CPPINTEROP_DIR/lib build && cd build # Install CppInterOp @@ -306,23 +414,28 @@ jobs: # Build and Install cppyy-backend cmake -DCppInterOp_DIR=$CPPINTEROP_DIR .. cmake --build . --parallel $(nproc --all) - cp libcppyy-backend.so $CPPINTEROP_DIR/lib/ + OS=$(uname -s) + if [[ "$OS" == "Darwin" ]]; then + cp libcppyy-backend.dylib $CPPINTEROP_DIR/lib/ + else + cp libcppyy-backend.so $CPPINTEROP_DIR/lib/ + fi ##cling_on="${{ matrix.cling }}" ##if [[ "${cling_on^^}" == "ON" ]]; then ## cp $LLVM_BUILD_DIR/lib/libcling.so $CPPINTEROP_DIR/lib/ ##fi # cd .. - - name: Install CPyCppyy on Linux - if: ${{ (runner.os == 'Linux') && (matrix.cppyy == 'On') }} + - name: Install CPyCppyy on Unix Systems + if: ${{ (runner.os != 'windows') && (matrix.cppyy == 'On') }} run: | # Setup virtual environment python3 -m venv .venv source .venv/bin/activate # Install CPyCppyy - git clone https://github.com/compiler-research/CPyCppyy.git - cd CPyCppyy - mkdir build && cd build + git clone --depth=1 https://github.com/compiler-research/CPyCppyy.git + mkdir CPyCppyy/build + cd CPyCppyy/build cmake .. cmake --build . --parallel $(nproc --all) # @@ -330,18 +443,18 @@ jobs: cd ../.. # We need CPYCPPYY_DIR later echo "CPYCPPYY_DIR=$CPYCPPYY_DIR" >> $GITHUB_ENV - - name: Install cppyy on Linux - if: ${{ (runner.os == 'Linux') && (matrix.cppyy == 'On') }} + - name: Install cppyy on Unix Systems + if: ${{ (runner.os != 'windows') && (matrix.cppyy == 'On') }} run: | # source virtual environment source .venv/bin/activate # Install cppyy - git clone https://github.com/compiler-research/cppyy.git + git clone --depth=1 https://github.com/compiler-research/cppyy.git cd cppyy python -m pip install --upgrade . --no-deps cd .. - - name: Run cppyy on Linux - if: ${{ (runner.os == 'Linux') && (matrix.cppyy == 'On') }} + - name: Run cppyy on Unix Systems + if: ${{ (runner.os != 'windows') && (matrix.cppyy == 'On') }} run: | # Run cppyy source .venv/bin/activate @@ -349,9 +462,9 @@ jobs: python -c "import cppyy" # We need PYTHONPATH later echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV - - name: Run the tests on Linux + - name: Run the tests on Unix Systems continue-on-error: true - if: ${{ (runner.os == 'Linux') && (matrix.cppyy == 'On') }} + if: ${{ (runner.os != 'windows') && (matrix.cppyy == 'On') }} run: | # Run the tests source .venv/bin/activate diff --git a/lib/Interpreter/CppInterOpInterpreter.h b/lib/Interpreter/CppInterOpInterpreter.h index 78e6bcf5d..566c332b9 100644 --- a/lib/Interpreter/CppInterOpInterpreter.h +++ b/lib/Interpreter/CppInterOpInterpreter.h @@ -145,6 +145,8 @@ class Interpreter { llvm::InitializeAllAsmPrinters(); std::vector vargs(argv + 1, argv + argc); + vargs.push_back("-include"); + vargs.push_back("new"); inner = compat::createClangInterpreter(vargs); } diff --git a/patches/llvm/clang17-1-NewOperator.patch b/patches/llvm/clang17-1-NewOperator.patch new file mode 100644 index 000000000..fd32d792c --- /dev/null +++ b/patches/llvm/clang17-1-NewOperator.patch @@ -0,0 +1,205 @@ +From a3f213ef4a7e293152c272cce78ad5d10a3ede52 Mon Sep 17 00:00:00 2001 +From: Vassil Vassilev +Date: Fri, 22 Dec 2023 08:38:23 +0000 +Subject: [PATCH] [clang-repl] Add a interpreter-specific overload of operator + new for C++. + +This patch brings back the basic support for C by inserting the required for +value printing runtime only when we are in C++ mode. Additionally, it defines +a new overload of operator placement new because we can't really forward declare +it in a library-agnostic way. + +Fixes the issue described in llvm/llvm-project#69072. +--- + clang/include/clang/Interpreter/Interpreter.h | 4 +-- + clang/lib/Interpreter/Interpreter.cpp | 33 +++++++++++++++---- + clang/test/Interpreter/incremental-mode.cpp | 3 +- + .../unittests/Interpreter/InterpreterTest.cpp | 29 +++------------- + 4 files changed, 36 insertions(+), 33 deletions(-) + +diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h +index 01858dfcc90ac5..292fa566ae7037 100644 +--- a/clang/include/clang/Interpreter/Interpreter.h ++++ b/clang/include/clang/Interpreter/Interpreter.h +@@ -129,7 +129,7 @@ class Interpreter { + llvm::Expected + getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const; + +- enum InterfaceKind { NoAlloc, WithAlloc, CopyArray }; ++ enum InterfaceKind { NoAlloc, WithAlloc, CopyArray, NewTag }; + + const llvm::SmallVectorImpl &getValuePrintingInfo() const { + return ValuePrintingInfo; +@@ -144,7 +144,7 @@ class Interpreter { + + llvm::DenseMap Dtors; + +- llvm::SmallVector ValuePrintingInfo; ++ llvm::SmallVector ValuePrintingInfo; + }; + } // namespace clang + +diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp +index c9fcef5b5b5af1..9f97a3c6b0be9e 100644 +--- a/clang/lib/Interpreter/Interpreter.cpp ++++ b/clang/lib/Interpreter/Interpreter.cpp +@@ -248,7 +248,7 @@ Interpreter::~Interpreter() { + // can't find the precise resource directory in unittests so we have to hard + // code them. + const char *const Runtimes = R"( +- void* operator new(__SIZE_TYPE__, void* __p) noexcept; ++#ifdef __cplusplus + void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*); + void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*); + void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*); +@@ -256,15 +256,18 @@ const char *const Runtimes = R"( + void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double); + void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double); + void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long long); ++ struct __clang_Interpreter_NewTag{} __ci_newtag; ++ void* operator new(__SIZE_TYPE__, void* __p, __clang_Interpreter_NewTag) noexcept; + template + void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned long Size) { + for (auto Idx = 0; Idx < Size; ++Idx) +- new ((void*)(((T*)Placement) + Idx)) T(Src[Idx]); ++ new ((void*)(((T*)Placement) + Idx), __ci_newtag) T(Src[Idx]); + } + template + void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* Placement, unsigned long Size) { + __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size); + } ++#endif // __cplusplus + )"; + + llvm::Expected> +@@ -279,7 +282,7 @@ Interpreter::create(std::unique_ptr CI) { + if (!PTU) + return PTU.takeError(); + +- Interp->ValuePrintingInfo.resize(3); ++ Interp->ValuePrintingInfo.resize(4); + // FIXME: This is a ugly hack. Undo command checks its availability by looking + // at the size of the PTU list. However we have parsed something in the + // beginning of the REPL so we have to mark them as 'Irrevocable'. +@@ -500,7 +503,7 @@ Interpreter::CompileDtorCall(CXXRecordDecl *CXXRD) { + static constexpr llvm::StringRef MagicRuntimeInterface[] = { + "__clang_Interpreter_SetValueNoAlloc", + "__clang_Interpreter_SetValueWithAlloc", +- "__clang_Interpreter_SetValueCopyArr"}; ++ "__clang_Interpreter_SetValueCopyArr", "__ci_newtag"}; + + bool Interpreter::FindRuntimeInterface() { + if (llvm::all_of(ValuePrintingInfo, [](Expr *E) { return E != nullptr; })) +@@ -530,6 +533,9 @@ bool Interpreter::FindRuntimeInterface() { + if (!LookupInterface(ValuePrintingInfo[CopyArray], + MagicRuntimeInterface[CopyArray])) + return false; ++ if (!LookupInterface(ValuePrintingInfo[NewTag], ++ MagicRuntimeInterface[NewTag])) ++ return false; + return true; + } + +@@ -607,7 +613,9 @@ class RuntimeInterfaceBuilder + .getValuePrintingInfo()[Interpreter::InterfaceKind::CopyArray], + SourceLocation(), Args, SourceLocation()); + } +- Expr *Args[] = {AllocCall.get()}; ++ Expr *Args[] = { ++ AllocCall.get(), ++ Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::NewTag]}; + ExprResult CXXNewCall = S.BuildCXXNew( + E->getSourceRange(), + /*UseGlobal=*/true, /*PlacementLParen=*/SourceLocation(), Args, +@@ -628,8 +636,9 @@ class RuntimeInterfaceBuilder + Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::NoAlloc], + E->getBeginLoc(), Args, E->getEndLoc()); + } ++ default: ++ llvm_unreachable("Unhandled Interpreter::InterfaceKind"); + } +- llvm_unreachable("Unhandled Interpreter::InterfaceKind"); + } + + Interpreter::InterfaceKind VisitRecordType(const RecordType *Ty) { +@@ -814,3 +823,15 @@ __clang_Interpreter_SetValueNoAlloc(void *This, void *OutVal, void *OpaqueType, + VRef = Value(static_cast(This), OpaqueType); + VRef.setLongDouble(Val); + } ++ ++// A trampoline to work around the fact that operator placement new cannot ++// really be forward declared due to libc++ and libstdc++ declaration mismatch. ++// FIXME: __clang_Interpreter_NewTag is ODR violation because we get the same ++// definition in the interpreter runtime. We should move it in a runtime header ++// which gets included by the interpreter and here. ++struct __clang_Interpreter_NewTag {}; ++REPL_EXTERNAL_VISIBILITY void * ++operator new(size_t __sz, void *__p, __clang_Interpreter_NewTag) noexcept { ++ // Just forward to the standard operator placement new. ++ return operator new(__sz, __p); ++} +diff --git a/clang/test/Interpreter/incremental-mode.cpp b/clang/test/Interpreter/incremental-mode.cpp +index e6350d237ef578..d63cee0dd6d15f 100644 +--- a/clang/test/Interpreter/incremental-mode.cpp ++++ b/clang/test/Interpreter/incremental-mode.cpp +@@ -1,3 +1,4 @@ + // RUN: clang-repl -Xcc -E +-// RUN: clang-repl -Xcc -emit-llvm ++// RUN: clang-repl -Xcc -emit-llvm ++// RUN: clang-repl -Xcc -xc + // expected-no-diagnostics +diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp +index 5f2911e9a7adad..1e0854b3c4af46 100644 +--- a/clang/unittests/Interpreter/InterpreterTest.cpp ++++ b/clang/unittests/Interpreter/InterpreterTest.cpp +@@ -248,28 +248,10 @@ TEST(IncrementalProcessing, FindMangledNameSymbol) { + #endif // _WIN32 + } + +-static void *AllocateObject(TypeDecl *TD, Interpreter &Interp) { ++static Value AllocateObject(TypeDecl *TD, Interpreter &Interp) { + std::string Name = TD->getQualifiedNameAsString(); +- const clang::Type *RDTy = TD->getTypeForDecl(); +- clang::ASTContext &C = Interp.getCompilerInstance()->getASTContext(); +- size_t Size = C.getTypeSize(RDTy); +- void *Addr = malloc(Size); +- +- // Tell the interpreter to call the default ctor with this memory. Synthesize: +- // new (loc) ClassName; +- static unsigned Counter = 0; +- std::stringstream SS; +- SS << "auto _v" << Counter++ << " = " +- << "new ((void*)" +- // Windows needs us to prefix the hexadecimal value of a pointer with '0x'. +- << std::hex << std::showbase << (size_t)Addr << ")" << Name << "();"; +- +- auto R = Interp.ParseAndExecute(SS.str()); +- if (!R) { +- free(Addr); +- return nullptr; +- } +- ++ Value Addr; ++ cantFail(Interp.ParseAndExecute("new " + Name + "()", &Addr)); + return Addr; + } + +@@ -317,7 +299,7 @@ TEST(IncrementalProcessing, InstantiateTemplate) { + } + + TypeDecl *TD = cast(LookupSingleName(*Interp, "A")); +- void *NewA = AllocateObject(TD, *Interp); ++ Value NewA = AllocateObject(TD, *Interp); + + // Find back the template specialization + VarDecl *VD = static_cast(*PTUDeclRange.begin()); +@@ -328,8 +310,7 @@ TEST(IncrementalProcessing, InstantiateTemplate) { + typedef int (*TemplateSpecFn)(void *); + auto fn = + cantFail(Interp->getSymbolAddress(MangledName)).toPtr(); +- EXPECT_EQ(42, fn(NewA)); +- free(NewA); ++ EXPECT_EQ(42, fn(NewA.getPtr())); + } + + #ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC From 0e75241440c353ad172483f904b9ac53e7e93aca Mon Sep 17 00:00:00 2001 From: Saqib <130300172+QuillPusher@users.noreply.github.com> Date: Tue, 2 Jan 2024 14:29:49 +0500 Subject: [PATCH 05/59] Added Documentation of cppyy Enhancements and how they relate to LibInterOp (#160) --- docs/UsingCppInterOp.rst | 266 +++++++++++++++++++++++++++++++++++---- 1 file changed, 244 insertions(+), 22 deletions(-) diff --git a/docs/UsingCppInterOp.rst b/docs/UsingCppInterOp.rst index ccc33221f..3d98fb266 100644 --- a/docs/UsingCppInterOp.rst +++ b/docs/UsingCppInterOp.rst @@ -15,7 +15,7 @@ The CppInterop comes with using it is a dynamic shared library, libInterop = ctypes.CDLL("./libclangCppInterOp.so") The above method of usage is for Python; for C, we can include the headers of -the library. Including this library in our programme enables the user to use +the library. Including this library in our program enables the user to use the abilities of CppInterOp. CppInterOp helps programmers with multiple verifications such as isClass, isBoolean, isStruct, and many more in different languages. With the interop layer, we can access the scopes, namespaces of @@ -28,10 +28,10 @@ Using LLVM as external library In CppInterOp, we are leveraging Clang as a library for interoperability purposes. To use Clang, we need to pass the Clang configuration to the CMake build system, -so that the build system recognises the configuration and enables usage of Clang +so that the build system recognizes the configuration and enables usage of Clang and LLVM. We can consider clang-repl as a state manager, where CppInterOp allows you to -query the state from the state manager. Thereafter, Cppyy uses this to create +query the state from the state manager. Thereafter, cppyy uses this to create Python objects for C++. .. code-block:: bash @@ -65,35 +65,257 @@ robust (simple function calls, no inheritance, etc.). The goal is to make it as close to the compiler API as possible, and each routine should do just one thing. that it was designed for. -Further Enhancing the Dynamic/Automatic bindings in CPPYY -========================================================= -The main use case for CppInterOp is the CPPYY service. CPPYY is an -automatic run-time bindings generator for Python and C++, and supports a wide -range of C++ features (e.g., template instantiation). It operates on demand and -generates only what is necessary. It requires a compiler (Cling or Clang-REPL). -that can be available during programme runtime. +How cppyy leverages CppInterOp +=============================== + +cppyy is a run-time Python-C++ bindings generator for calling C++ from Python +and Python from C++. Interestingly, it uses C++ interactively by using the +compiler as a service. This is made possible by the CppInterOp library. +Following are some of the ways cppyy leverages CppInterOp for better +performance and usability. + +1. **CppInterOp enables interoperability with C++ code**: CppInterOp provides a + minimalist and robust interface for language interoperability on the fly, + which helps CPPYY generate dynamic Python-C++ bindings by using a C++ + interpreter (e.g., Clang-REPL/Cling) and LLVM. + +2. **Reducing dependencies**: Reducing domain-specific dependencies of cppyy + (e.g., on the Cling interpreter and the ROOT framework) to enable more + generalized usage. + +3. **LLVM Integration**: CppInterOp is designed to be used as a part of the + LLVM toolchain (as part of Clang-REPL) that can then be used as a runtime + compiler for CPPYY. This simplifies the codebase of CPPYY and enhances its + performance. + + 4. **Making C++ More Social**: CppInterOp and cppyy help data scientists that + are working with legacy C++ code experiment with simpler, more interactive + languages, while also interacting with larger communities. + +**CppInterOp enables interoperability with C++ code** + +cppyy is a major use case for CppInterOp. cppyy is an automatic run-time +bindings generator for Python and C++, and supports a wide range of C++ +features, including template instantiation. It operates on demand and generates +only what is necessary. It requires a compiler (Cling or Clang-REPL) that can +be available during program runtime. + +**Reducing Dependencies** + +Recent work done on cppyy has been focused on reducing dependencies on +domain-specific infrastructure (e.g., the ROOT framework). Using an independent +library such as CppInterOp helps accomplish that, while also improving the code +consistency in cppyy. + +The CppInterOp library can be configured to use the newly developed Clang-Repl +backend available in LLVM upstream (or to use the Cling legacy backend, for +compatibility with High Energy Physics applications). + +Only a small set of APIs are needed to connect to the interpreter (Clang-Repl/ +Cling), since other APIs are already available in the standard compiler. This +is one of the reasons that led to the creation of CppInterOp (a library of +helper functions), that can help extract out things that are unnecessary for +for core cppyy functionality. + +The cppyy API surface is now incomparably smaller and simpler than what it used +to be. + +**LLVM Integration** Once CppInterOp is integrated with LLVM's Clang-REPL component (that can then -be used as a runtime compiler for CPPYY), it will further enhance CPPYY's +be used as a runtime compiler for cppyy), it will further enhance cppyy's performance in the following ways: -**Simpler codebase:** The removal of string parsing logic will lead to a simpler -code base. +- *Simpler codebase:* The removal of string parsing logic will lead to a + simpler code base. + +- *Built into the LLVM toolchain:* The CppInterOp depends only on the LLVM + toolchain (as part of Clang-REPL). + +- *Better C++ Support:* Finer-grained control over template instantiation is + available through CppInterOp. + +- *Fewer Lines of Code:* A lot of dependencies and workarounds will be + removed, reducing the lines of code required to execute cppyy. + +- *Well tested interoperability Layer:* The CppInterOp interfaces have full + unit test coverage. + +**Making C++ More Social** + +cppyy is the first use case demonstrating how CppInterOp can enable C++ to be +more easily interoperable with other languages. This helps many data scientists +that are working with legacy C++ code and would like to use simpler, more +interactive languages. + +The goal of these enhancements is to eventually land these interoperability +tools (including CppInterOp) to broader communities like LLVM and Clang, to +enable C++ to interact with other languages besides Python. + +Example: Template Instantiation +------------------------------- + +The developmental cppyy version can run basic examples such as the one +here. Features such as standalone functions and basic classes are also +supported. + +C++ code (Tmpl.h) + +:: + + template + struct Tmpl { + T m_num; + T add (T n) { + return m_num + n; + } + }; + +Python Interpreter + +:: + + >>> import cppyy + >>> cppyy.include("Tmpl.h") + >>> tmpl = Tmpl[int]() + >>> tmpl.m_num = 4 + >>> print(tmpl.add(5)) + 9 + >>> tmpl = Tmpl[float]() + >>> tmpl.m_num = 3.0 + >>> print(tmpl.add(4.0)) + 7.0 + +Where does the cppyy code reside? +--------------------------------- + +Following are the main components where cppyy logic (with Compiler Research +Organization’s customizations started by `sudo-panda`_) resides: + +- `cppyy `_ +- `cppyy-backend `_ +- `CPyCppyy `_ + +.. + + Note: These are forks of the `upstream cppyy`_ repos created by `wlav`_. + +CppInterOp is a separate library that helps these packages communicate with C++ +code. + +- `CppInterOp `_ -**LLVM Integration:** The CppInterOp interfaces will be part of the LLVM -toolchain (as part of Clang-REPL). +How cppyy components interact with each other +--------------------------------------------- -**Better C++ Support:** C++ features such as Partial Template Specialisation will -be available through CppInterOp. +cppyy is made up of the following packages: -**Fewer Lines of Code:** A lot of dependencies and workarounds will be removed, -reducing the lines of code required to execute CPPYY. +- A frontend: cppyy, -**Well tested interoperability Layer:** The CppInterOp interfaces have full -unit test coverage. +- A backend: cppyy-backend, and +- An extension: CPyCppyy. + +Besides these, the ``CppInterOp`` library serves as an additional layer on top +of Cling/Clang-REPL that helps these packages in communicating with C++ code. + +**1. cppyy-backend** + +The `cppyy-backend`_ package forms a layer over ``cppyy``, for example, +modifying some functionality to provide the functions required for +``CPyCppyy``. + + `CPyCppyy`_ is a CPython extension module built on top of the same backend + API as PyPy/_cppyy. It thus requires the installation of the cppyy-backend + for use, which will pull in Cling. + +``cppyy-backend`` also adds some `utilities`_ to help with repackaging and +redistribution. + +For example, ``cppyy-backend`` initializes the interpreter (using the +``clingwrapper::ApplicationStarter`` function), adds the required ``include`` +paths, and adds the headers required for cppyy to work. It also adds some +checks and combines two or more functions to help CPyCppyy work. + +These changes help ensure that any change in ``cppyy`` doesn’t directly +affect ``CPyCppyy``, and the API for ``CPyCppyy`` remains unchanged. + +**2. CPyCppyy** + +The ``CPyCppyy`` package uses the functionality provided by ``cppyy-backend`` +and provides Python objects for C++ entities. ``CPyCppyy`` uses separate proxy +classes for each type of object. It also includes helper classes, for example, +``Converters.cxx`` helps convert Python type objects to C++ type objects, while +``Executors.cxx`` is used to execute a function and convert its return value to +a Python object, so that it can be used inside Python. + +**3. cppyy** + +The cppyy package provides the front-end for Python. It is `included in code`_ +(using ``import cppyy``) to import cppyy in Python. It initializes things on +the backend side, provides helper functions (e.g., ``cppdef()``, ``cppexec()``, +etc.) that the user can utilize, and it calls the relevant backend functions +required to initialize cppyy. + + +Further Reading +--------------- + +- `High-performance Python-C++ bindings with PyPy and + Cling `_ + +- `Efficient and Accurate Automatic Python Bindings with cppyy & + Cling `_ + +- cppyy documentation: + `cppyy.readthedocs.io `_. + +- Notebook-based tutorial: `Cppyy + Tutorial `_. + +- `C++ Language Interoperability + Layer `_ + +**Credits:** + +- `Wim Lavrijsen `_ (Lawrence Berkeley National Lab.) + for his original work in cppyy and mentorship towards student contributors. + +- `Vassil Vasilev `_ (Princeton University) + for his mentorship towards Compiler Research Org's student contributors. + +- `Baidyanath Kundu `_ (Princeton University) + for his research work on cppyy and Numba with `Compiler Research Organization`_ + (as discussed in this document). + +- `Aaron Jomy `_ (Princeton University) for + continuing this research work with `Compiler Research Organization`_. In case you haven't already installed CppInterop, please do so before proceeding with the Installation And Usage Guide. -:doc:`Installation and usage ` \ No newline at end of file +:doc:`Installation and usage ` + +.. _Compiler Research Organization: https://compiler-research.org/ + +.. _upstream cppyy: https://github.com/wlav/cppyy + +.. _wlav: https://github.com/wlav + +.. _utilities: https://cppyy.readthedocs.io/en/latest/utilities.html + +.. _included in code: https://cppyy.readthedocs.io/en/latest/starting.html + +.. _sudo-panda: https://github.com/sudo-panda + +.. _cppyy: https://cppyy.readthedocs.io/en/latest/index.html + +.. _CppInterOp: https://github.com/compiler-research/CppInterOp + +.. _ROOT meta: https://github.com/root-project/root/tree/master/core/meta + +.. _enhancements in cppyy: https://arxiv.org/abs/2304.02712 + +.. _CPyCppyy: https://github.com/wlav/CPyCppyy + +.. _cppyy-backend: https://github.com/wlav/cppyy-backend \ No newline at end of file From 47ca167423ac725155524cc7183167a02bcfcb69 Mon Sep 17 00:00:00 2001 From: Shreyas Atre Date: Thu, 4 Jan 2024 01:09:39 +0530 Subject: [PATCH 06/59] [Tests] CppInterOp: Revert the get_wrapper_code failure - Remove macro guard for GetFunctionAddress Signed-off-by: Shreyas Atre --- unittests/CppInterOp/FunctionReflectionTest.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/unittests/CppInterOp/FunctionReflectionTest.cpp b/unittests/CppInterOp/FunctionReflectionTest.cpp index d15cb1c02..96be337e6 100644 --- a/unittests/CppInterOp/FunctionReflectionTest.cpp +++ b/unittests/CppInterOp/FunctionReflectionTest.cpp @@ -553,11 +553,7 @@ TEST(FunctionReflectionTest, IsStaticMethod) { EXPECT_TRUE(Cpp::IsStaticMethod(SubDecls[2])); } -#ifdef __APPLE__ -TEST(FunctionReflectionTest, DISABLED_GetFunctionAddress) { -#else TEST(FunctionReflectionTest, GetFunctionAddress) { -#endif std::vector Decls, SubDecls; std::string code = "int f1(int i) { return i * i; }"; From d294b0790318522fd1eb0b0a2c786a4ba0347a58 Mon Sep 17 00:00:00 2001 From: Shreyas Atre Date: Thu, 4 Jan 2024 01:24:10 +0530 Subject: [PATCH 07/59] [CI] Fix macOS brew upgrade failing Signed-off-by: Shreyas Atre --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c96361aed..f54169294 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -264,6 +264,11 @@ jobs: #Select latest xcode available on macos-13 sudo xcode-select -s /Applications/Xcode_15.1.app/Contents/Developer brew update + # workaround for https://github.com/actions/setup-python/issues/577 + for pkg in $(brew list | grep '^python@'); do + brew unlink "$pkg" + brew link --overwrite "$pkg" + done brew upgrade pip install distro pytest From 0023d8615f5a395ec8ea3b258bb3542467909b12 Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Thu, 11 Jan 2024 14:12:46 +0000 Subject: [PATCH 08/59] Update README.md build instructions (#179) --- README.md | 179 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 138 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 64540c03a..3cb9ee2d4 100644 --- a/README.md +++ b/README.md @@ -58,20 +58,30 @@ goals of CppInterOp is to stay backward compatible and be adopted in the High framework. Over time, parts of the Root framework can be swapped by this API, adding speed and resilience with it. -### Build Instructions for Linux -Build instructions for CppInterOp and its dependencies are as follows. +### Build Instructions for Unix Systems +Build instructions for CppInterOp and its dependencies are as follows. CppInterOP can be built with either Cling and Clang-REPL, so instructions will differ slightly depending on which option you would like to build, but should be clear from the section title which instructions to follow. -#### Setup Clang-REPL -Clone and checkout the LLVM project repository. +#### Clone CppInterOp and cppyy-backend +First clone the CppInterOp repository, as this contains patches that need to be applied to the subsequently cloned llvm-project repo (if building CppInterOP with Clang-REPL) ``` -git clone https://github.com/llvm/llvm-project.git -git checkout release/16.x +git clone --depth=1 https://github.com/compiler-research/CppInterOp.git +``` +and clone cppyy-backend repository where we will be installing the CppInterOp library +``` +git clone --depth=1 https://github.com/compiler-research/cppyy-backend.git +``` + +#### Setup Clang-REPL +Clone the 17.x release of the LLVM project repository. +``` +git clone --depth=1 --branch release/17.x https://github.com/llvm/llvm-project.git +cd llvm-project ``` Get the following patches required for development work. ``` -compgen -G "../patches/llvm/clang16-*.patch" > /dev/null && find ../patches/llvm/clang16-*.patch -printf "%f\n" && git apply ../patches/llvm/clang16-*.patch +compgen -G "../CppInterOp/patches/llvm/clang17-*.patch" > /dev/null && find ../CppInterOp/patches/llvm/clang17-*.patch -printf "%f\n" && git apply ../CppInterOp/patches/llvm/clang17-*.patch ``` -##### Build Clang +##### Build Clang-REPL Clang-REPL is an interpreter that CppInterOp works alongside. Build Clang (and Clang-REPL along with it). ``` @@ -94,28 +104,8 @@ cd ../ export LLVM_DIR=$PWD cd ../ ``` -Next, use the following export commands. -``` -export CB_PYTHON_DIR="$PWD/cppyy-backend/python" -export CPPINTEROP_DIR="$CB_PYTHON_DIR/cppyy_backend" -``` -#### Build 'LLVM-Project' related dependencies -Following steps are required to help build CppInterOp alongside the -LLVM-Project. -``` -mkdir build && cd build -export CPPINTEROP_BUILD_DIR=$PWD -cmake -DCMAKE_BUILD_TYPE=Release \ - -DUSE_CLING=OFF \ - -DUSE_REPL=ON \ - -DLLVM_DIR=$LLVM_BUILD_DIR \ - -DLLVM_USE_LINKER=lld \ - -DBUILD_SHARED_LIBS=ON \ - -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR \ - ../ -cmake --build . --target install --parallel $(nproc --all) -``` -#### Build Cling related dependencies + +#### Build Cling and related dependencies Besides the Clang-REPL interpreter, CppInterOp also works alongside the Cling interpreter. Cling depends on its own customised version of `llvm-project`, hosted under the `root-project` (see the git path below). @@ -123,8 +113,8 @@ Use the following build instructions. ``` git clone --depth=1 https://github.com/root-project/cling.git git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git -cd llvm-project -mkdir build && cd build +mkdir llvm-project/build +cd llvm-project/build cmake -DLLVM_ENABLE_PROJECTS=clang \ -DLLVM_EXTERNAL_PROJECTS=cling \ -DLLVM_EXTERNAL_CLING_SOURCE_DIR=../../cling \ @@ -147,20 +137,127 @@ cd ../ export LLVM_DIR=$PWD cd ../ ``` -Next, export the following directory. + +#### Environment variables +Regardless of whether you are building CppInterOP with Cling or Clang-REPL you will need to define the following Envirnoment variables (as they clear for a new session, it is recommended that you also add these to your .bashrc in linux, or your .bash_profile if on MacOS) ``` -export CPPINTEROP_DIR=$PWD/cppyy-backend/python/cppyy_backend +export CB_PYTHON_DIR="$PWD/cppyy-backend/python" +export CPPINTEROP_DIR="$CB_PYTHON_DIR/cppyy_backend" +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" +export PYTHONPATH=$PYTHONPATH:$CPYCPPYY_DIR:$CB_PYTHON_DIR +``` +If on MacOS you will also need the following envirnoment variable defined +``` +export SDKROOT=`xcrun --show-sdk-path` ``` + #### Build CppInterOp -Finally, clone the CppInterOp repository. +Now CppInterOp can be installed +``` +mkdir CppInterOp/build/ +cd CppInterOp/build/ +``` + +Now if you want to build CppInterOp with Clang-REPL then execute the following commands +``` +cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=ON -DUSE_REPL=Off -DCling_DIR=$LLVM_DIR/build -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR .. +cmake --build . --target install --parallel $(nproc --all) +``` +If alternatively you would like to install CppInterOp with Cling then execute the following commands ``` -git clone https://github.com/compiler-research/CppInterOp.git -cd CppInterOp -mkdir build && cd build -CPPINTEROP_BUILD_DIR=$(PWD) -Execute the following. cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=ON -DUSE_REPL=Off -DCling_DIR=$LLVM_DIR/build -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR .. -cmake --build . --target install +cmake --build . --target install --parallel $(nproc --all) +``` + +#### Testing CppInterOp +To test the built CppInterOp execute the following command in the CppInterOP build folder +``` +cmake --build . --target check-cppinterop --parallel $(nproc --all) +``` +Now go back to the top level directory in which your building CppInterOP +``` +cd ../.. +``` +Now you are in a position to install cppyy following the instructions below. + +#### Building and Install cppyy-backend + +Clone the repo, build it and copy library files into `python/cppyy-backend` directory: + +``` +git clone --depth=1 https://github.com/compiler-research/cppyy-backend.git +cd cppyy-backend +mkdir -p python/cppyy_backend/lib build +cd build +cmake -DCppInterOp_DIR=$CPPINTEROP_DIR .. +cmake --build . +``` +If on a linux system now execute the following command +``` +cp libcppyy-backend.so ../python/cppyy_backend/lib/ +``` +and if on MacOS execute the following command +``` +cp libcppyy-backend.dylib ../python/cppyy_backend/lib/ +``` + +Note go back to the top level build directory +``` +cd ../.. +``` + +#### Install CPyCppyy + +Create virtual environment and activate it: +``` +python3 -m venv .venv +source .venv/bin/activate +``` + +``` +git clone --depth=1 https://github.com/compiler-research/CPyCppyy.git +mkdir CPyCppyy/build +cd CPyCppyy/build +cmake .. +cmake --build . +``` + +Note down the path to the `build` directory as `CPYCPPYY_DIR`: +``` +export CPYCPPYY_DIR=$PWD +cd ../.. +``` + +#### Install cppyy + +``` +git clone --depth=1 https://github.com/compiler-research/cppyy.git +cd cppyy +python -m pip install --upgrade . --no-deps +cd .. +``` + +#### Run cppyy + +Each time you want to run cppyy you need to: +Activate the virtual environment +``` +source .venv/bin/activate +``` + +Now you can `import cppyy` in `python` +``` +python -c "import cppyy" +``` + +#### Run cppyy tests + +**Follow the steps in Run cppyy.** Change to the test directory, make the library files and run pytest: +``` +cd cppyy/test +make all +python -m pip install pytest +python -m pytest -sv ``` --- From 16f1c4bbf724e4308b2a0a618b61d8b2bbcea068 Mon Sep 17 00:00:00 2001 From: Shreyas Atre <61797109+SAtacker@users.noreply.github.com> Date: Thu, 11 Jan 2024 12:57:56 -0600 Subject: [PATCH 09/59] [Symbol Names] Add Global Prefix if set (#177) - Prepend `_` before looking for symbols by default - Use compat::getExecutionEngine for data layout and then get Global Prefix Signed-off-by: Shreyas Atre --- lib/Interpreter/Compatibility.h | 10 ++++++++-- lib/Interpreter/CppInterOp.cpp | 8 +++++++- .../CppInterOp/FunctionReflectionTest.cpp | 17 +---------------- unittests/CppInterOp/InterpreterTest.cpp | 4 ---- unittests/CppInterOp/JitTest.cpp | 4 ---- unittests/CppInterOp/ScopeReflectionTest.cpp | 18 ++---------------- unittests/CppInterOp/TypeReflectionTest.cpp | 4 ---- 7 files changed, 18 insertions(+), 47 deletions(-) diff --git a/lib/Interpreter/Compatibility.h b/lib/Interpreter/Compatibility.h index b84579c47..539bda951 100644 --- a/lib/Interpreter/Compatibility.h +++ b/lib/Interpreter/Compatibility.h @@ -216,10 +216,16 @@ getSymbolAddress(clang::Interpreter& I, clang::GlobalDecl GD) { } inline llvm::Expected -getSymbolAddressFromLinkerName(const clang::Interpreter& I, +getSymbolAddressFromLinkerName(clang::Interpreter& I, llvm::StringRef LinkerName) { #if CLANG_VERSION_MAJOR >= 14 - auto AddrOrErr = I.getSymbolAddressFromLinkerName(LinkerName); + const auto& DL = getExecutionEngine(I)->getDataLayout(); + char GlobalPrefix = DL.getGlobalPrefix(); + std::string LinkerNameTmp(LinkerName); + if (GlobalPrefix != '\0') { + LinkerNameTmp = std::string(1, GlobalPrefix) + LinkerNameTmp; + } + auto AddrOrErr = I.getSymbolAddressFromLinkerName(LinkerNameTmp); if (llvm::Error Err = AddrOrErr.takeError()) return std::move(Err); return AddrOrErr->getValue(); diff --git a/lib/Interpreter/CppInterOp.cpp b/lib/Interpreter/CppInterOp.cpp index 9a0c21e44..ad2e104c8 100644 --- a/lib/Interpreter/CppInterOp.cpp +++ b/lib/Interpreter/CppInterOp.cpp @@ -2661,7 +2661,13 @@ namespace Cpp { // Let's inject it. SymbolMap::iterator It; llvm::orc::SymbolMap InjectedSymbols; - auto Name = ES.intern(linker_mangled_name); + auto& DL = compat::getExecutionEngine(I)->getDataLayout(); + char GlobalPrefix = DL.getGlobalPrefix(); + std::string tmp(linker_mangled_name); + if (GlobalPrefix != '\0') { + tmp = std::string(1, GlobalPrefix) + tmp; + } + auto Name = ES.intern(tmp); InjectedSymbols[Name] = #if CLANG_VERSION_MAJOR < 17 JITEvaluatedSymbol(address, diff --git a/unittests/CppInterOp/FunctionReflectionTest.cpp b/unittests/CppInterOp/FunctionReflectionTest.cpp index 96be337e6..3fcb3533f 100644 --- a/unittests/CppInterOp/FunctionReflectionTest.cpp +++ b/unittests/CppInterOp/FunctionReflectionTest.cpp @@ -592,11 +592,7 @@ TEST(FunctionReflectionTest, IsVirtualMethod) { EXPECT_FALSE(Cpp::IsVirtualMethod(Decls[0])); } -#ifdef __APPLE__ -TEST(FunctionReflectionTest, DISABLED_JitCallAdvanced) { -#else TEST(FunctionReflectionTest, JitCallAdvanced) { -#endif std::vector Decls; std::string code = R"( typedef struct _name { @@ -617,11 +613,8 @@ TEST(FunctionReflectionTest, JitCallAdvanced) { Cpp::Destruct(object, Decls[1]); } -#ifdef __APPLE__ -TEST(FunctionReflectionTest, DISABLED_GetFunctionCallWrapper) { -#else + TEST(FunctionReflectionTest, GetFunctionCallWrapper) { -#endif std::vector Decls; std::string code = R"( int f1(int i) { return i * i; } @@ -784,11 +777,7 @@ TEST(FunctionReflectionTest, GetFunctionArgDefault) { EXPECT_EQ(Cpp::GetFunctionArgDefault(Decls[1], 2), "34126"); } -#ifdef __APPLE__ -TEST(FunctionReflectionTest, DISABLED_Construct) { -#else TEST(FunctionReflectionTest, Construct) { -#endif Cpp::CreateInterpreter(); Interp->declare(R"( @@ -822,11 +811,7 @@ TEST(FunctionReflectionTest, Construct) { EXPECT_EQ(output, "Constructor Executed"); } -#ifdef __APPLE__ -TEST(FunctionReflectionTest, DISABLED_Destruct) { -#else TEST(FunctionReflectionTest, Destruct) { -#endif Cpp::CreateInterpreter(); Interp->declare(R"( diff --git a/unittests/CppInterOp/InterpreterTest.cpp b/unittests/CppInterOp/InterpreterTest.cpp index e64cb8d7c..5c30108b2 100644 --- a/unittests/CppInterOp/InterpreterTest.cpp +++ b/unittests/CppInterOp/InterpreterTest.cpp @@ -49,11 +49,7 @@ TEST(InterpreterTest, Evaluate) { EXPECT_FALSE(HadError) ; } -#ifdef __APPLE__ //Fails for Cling Tests -TEST(InterpreterTest, DISABLED_Process) { -#else TEST(InterpreterTest, Process) { -#endif Cpp::CreateInterpreter(); EXPECT_TRUE(Cpp::Process("") == 0); EXPECT_TRUE(Cpp::Process("int a = 12;") == 0); diff --git a/unittests/CppInterOp/JitTest.cpp b/unittests/CppInterOp/JitTest.cpp index 93edd04a9..9cc1bc38a 100644 --- a/unittests/CppInterOp/JitTest.cpp +++ b/unittests/CppInterOp/JitTest.cpp @@ -11,11 +11,7 @@ static int printf_jit(const char* format, ...) { return 0; } -#ifdef __APPLE__ -TEST(JitTest, DISABLED_InsertOrReplaceJitSymbol) { -#else TEST(JitTest, InsertOrReplaceJitSymbol) { -#endif std::vector Decls; std::string code = R"( extern "C" int printf(const char*,...); diff --git a/unittests/CppInterOp/ScopeReflectionTest.cpp b/unittests/CppInterOp/ScopeReflectionTest.cpp index af88724d5..7549cdaef 100644 --- a/unittests/CppInterOp/ScopeReflectionTest.cpp +++ b/unittests/CppInterOp/ScopeReflectionTest.cpp @@ -99,11 +99,8 @@ TEST(ScopeReflectionTest, SizeOf) { EXPECT_EQ(Cpp::SizeOf(Decls[7]), (size_t)16); } -#ifdef __APPLE__ -TEST(ScopeReflectionTest, DISABLED_IsBuiltin) { -#else + TEST(ScopeReflectionTest, IsBuiltin) { -#endif // static std::set g_builtins = // {"bool", "char", "signed char", "unsigned char", "wchar_t", "short", "unsigned short", // "int", "unsigned int", "long", "unsigned long", "long long", "unsigned long long", @@ -433,11 +430,7 @@ TEST(ScopeReflectionTest, GetScopefromCompleteName) { EXPECT_EQ(Cpp::GetQualifiedName(Cpp::GetScopeFromCompleteName("N1::N2::C::S")), "N1::N2::C::S"); } -#ifdef __APPLE__ -TEST(ScopeReflectionTest, DISABLED_GetNamed) { -#else TEST(ScopeReflectionTest, GetNamed) { -#endif std::string code = R"(namespace N1 { namespace N2 { class C { @@ -761,11 +754,7 @@ TEST(ScopeReflectionTest, InstantiateNNTPClassTemplate) { /*type_size*/ args1.size())); } -#ifdef __APPLE__ -TEST(ScopeReflectionTest, DISABLED_InstantiateTemplateFunctionFromString) { -#else TEST(ScopeReflectionTest, InstantiateTemplateFunctionFromString) { -#endif Cpp::CreateInterpreter(); std::string code = R"(#include )"; Interp->process(code); @@ -905,11 +894,8 @@ TEST(ScopeReflectionTest, GetClassTemplateInstantiationArgs) { EXPECT_TRUE(instance_types.size() == 0); } -#ifdef __APPLE__ -TEST(ScopeReflectionTest, DISABLED_IncludeVector) { -#else + TEST(ScopeReflectionTest, IncludeVector) { -#endif std::string code = R"( #include #include diff --git a/unittests/CppInterOp/TypeReflectionTest.cpp b/unittests/CppInterOp/TypeReflectionTest.cpp index 48c863e6f..34db92306 100644 --- a/unittests/CppInterOp/TypeReflectionTest.cpp +++ b/unittests/CppInterOp/TypeReflectionTest.cpp @@ -522,11 +522,7 @@ TEST(TypeReflectionTest, IsPODType) { EXPECT_FALSE(Cpp::IsPODType(0)); } -#ifdef __APPLE__ -TEST(TypeReflectionTest, DISABLED_IsSmartPtrType) { -#else TEST(TypeReflectionTest, IsSmartPtrType) { -#endif Cpp::CreateInterpreter(); Interp->declare(R"( From aa3521b00af1aab1ae36df60865a998ceb9d1dd7 Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Wed, 17 Jan 2024 20:57:09 +0000 Subject: [PATCH 10/59] Add Windows CppInterOp build to CI (#180) --- .github/workflows/ci.yml | 374 +++++++++++++++++++++++++---- CMakeLists.txt | 3 + README.md | 121 ++++++++-- patches/llvm/clang16-1-Value.patch | 134 +++++------ 4 files changed, 497 insertions(+), 135 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f54169294..e7f230997 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,86 +21,157 @@ jobs: fail-fast: false matrix: include: - - name: ubu22-gcc12-clang-repl-17 + - name: ubu22-x86-gcc12-clang-repl-17 os: ubuntu-22.04 compiler: gcc-12 clang-runtime: '17' cling: Off cppyy: Off - extra_cmake_options: '-DLLVM_USE_LINKER=lld' - - - name: ubu22-gcc12-clang-repl-17-cppyy + coverage: true + - name: ubu22-x86-gcc12-clang-repl-17-cppyy os: ubuntu-22.04 compiler: gcc-12 clang-runtime: '17' cling: Off cppyy: On - extra_cmake_options: '-DLLVM_USE_LINKER=lld' - - - name: ubu22-gcc9-clang-repl-16 + coverage: true + - name: ubu22-x86-gcc9-clang-repl-16 os: ubuntu-22.04 compiler: gcc-9 clang-runtime: '16' cling: Off cppyy: Off coverage: true - extra_cmake_options: '-DLLVM_USE_LINKER=lld' - - - name: ubu22-gcc9-clang-repl-16-cppyy + - name: ubu22-x86-gcc9-clang-repl-16-cppyy os: ubuntu-22.04 compiler: gcc-9 clang-runtime: '16' cling: Off cppyy: On coverage: true - extra_cmake_options: '-DLLVM_USE_LINKER=lld' - - - name: ubu22-gcc9-clang13-cling + - name: ubu22-x86-gcc9-clang13-cling os: ubuntu-22.04 compiler: gcc-9 clang-runtime: '13' cling: On cling-version: '1.0' cppyy: Off - extra_cmake_options: '-DLLVM_USE_LINKER=lld' - - - name: ubu22-gcc9-clang13-cling-cppyy + coverage: true + - name: ubu22-x86-gcc9-clang13-cling-cppyy os: ubuntu-22.04 compiler: gcc-9 clang-runtime: '13' cling: On cling-version: '1.0' cppyy: On - extra_cmake_options: '-DLLVM_USE_LINKER=lld' - + coverage: true + #Commented out until Ubuntu on arm Github runner becomes available + #os key to be replaced once known + #- name: ubu22-arm-gcc12-clang-repl-17 + # os: ubuntu-22.04-arm + # compiler: gcc-12 + # clang-runtime: '17' + # cling: Off + # cppyy: Off + #- name: ubu22-arm-gcc12-clang-repl-17-cppyy + # os: ubuntu-22.04-arm + # compiler: gcc-12 + # clang-runtime: '17' + # cling: Off + # cppyy: On + #- name: ubu22-arm-gcc9-clang-repl-16 + # os: ubuntu-22.04-arm + # compiler: gcc-9 + # clang-runtime: '16' + # cling: Off + # cppyy: Off + # coverage: true + #- name: ubu22-arm-gcc9-clang-repl-16-cppyy + # os: ubuntu-22.04-arm + # compiler: gcc-9 + # clang-runtime: '16' + # cling: Off + # cppyy: On + # coverage: true + #- name: ubu22-arm-gcc9-clang13-cling + # os: ubuntu-22.04-arm + # compiler: gcc-9 + # clang-runtime: '13' + # cling: On + # cling-version: '1.0' + # cppyy: Off + #- name: ubu22-arm-gcc9-clang13-cling-cppyy + # os: ubuntu-22.04-arm + # compiler: gcc-9 + # clang-runtime: '13' + # cling: On + # cling-version: '1.0' + # cppyy: On + - name: win2022-msvc-clang-repl-17 + os: windows-2022 + compiler: msvc + clang-runtime: '17' + cling: Off + cppyy: Off + #Commented out until rest of ci for Windows tested + #- name: win2022-msvc-clang-repl-17-cppyy + # os: windows-2022 + # compiler: msvc + # clang-runtime: '17' + # cling: Off + # cppyy: On + - name: win2022-msvc-clang-repl-16 + os: windows-2022 + compiler: msvc + clang-runtime: '16' + cling: Off + cppyy: Off + #Commented out until rest of ci for Windows tested + #- name: win2022-msvc-clang-repl-16-cppyy + # os: windows-2022 + # compiler: msvc + # clang-runtime: '16' + # cling: Off + # cppyy: On + - name: win2022-msvc-cling + os: windows-2022 + compiler: msvc + clang-runtime: '13' + cling: On + cling-version: '1.0' + cppyy: Off + #Commented out until rest of ci for Windows tested + #- name: win2022-msvc-cling-cppyy + # os: windows-2022 + # compiler: msvc + # clang-runtime: '13' + # cling: On + # cling-version: '1.0' + # cppyy: On - name: osx13-x86-clang-clang-repl-17 os: macos-13 compiler: clang clang-runtime: '17' cling: Off cppyy: Off - - name: osx13-x86-clang-clang-repl-17-cppyy os: macos-13 compiler: clang clang-runtime: '17' cling: Off cppyy: On - - name: osx13-x86-clang-clang-repl-16 os: macos-13 compiler: clang clang-runtime: '16' cling: Off cppyy: Off - - name: osx13-x86-clang-clang-repl-16-cppyy os: macos-13 compiler: clang clang-runtime: '16' cling: Off cppyy: On - - name: osx13-x86-clang-clang13-cling os: macos-13 compiler: clang @@ -108,7 +179,6 @@ jobs: cling: On cling-version: '1.0' cppyy: Off - - name: osx13-x86-clang-clang13-cling-cppyy os: macos-13 compiler: clang @@ -116,7 +186,6 @@ jobs: cling: On cling-version: '1.0' cppyy: On - #Block commented out until free tier for m1 #exists (expected sometime 2024) and key for os #can be replaced @@ -126,28 +195,24 @@ jobs: # clang-runtime: '17' # cling: Off # cppyy: Off - # #- name: osx13-arm64-clang-clang-repl-17-cppyy # os: macos-13-arm64 # compiler: clang # clang-runtime: '17' # cling: Off # cppyy: On - # #- name: osx13-arm64-clang-clang-repl-16 # os: macos-13-arm64 # compiler: clang # clang-runtime: '16' # cling: Off # cppyy: Off - # #- name: osx13-arm64-clang-clang-repl-16-cppyy # os: macos-13-arm64 # compiler: clang # clang-runtime: '16' # cling: Off # cppyy: On - # #- name: osx13-arm64-clang-clang13-cling # os: macos-13-arm64 # compiler: clang @@ -155,7 +220,6 @@ jobs: # cling: On # cling-version: '1.0' # cppyy: Off - # #- name: osx13-arm64-clang-clang13-cling-cppyy # os: macos-13-arm64 # compiler: clang @@ -173,7 +237,8 @@ jobs: with: python-version: '3.10' - - name: Save PR Info + - name: Save PR Info on Unix systems + if: ${{ runner.os != 'windows' }} run: | mkdir -p ./pr echo ${{ github.event.number }} > ./pr/NR @@ -181,14 +246,49 @@ jobs: cling_on=$(echo "${{ matrix.cling }}" | tr '[:lower:]' '[:upper:]') if [[ "$cling_on" == "ON" ]]; then - export CLING_HASH=$(git ls-remote https://github.com/root-project/cling.git HEAD| tr '\t' '-') + export CLING_HASH=$(git ls-remote https://github.com/root-project/cling.git refs/tags/v${{ matrix.cling-version }} | tr '\t' '-') + export LLVM_HASH=$(git ls-remote https://github.com/root-project/llvm-project.git cling-llvm${{ matrix.clang-runtime}} | tr '\t' '-') else export CLING_HASH="Repl" + # May need to revert back to both having same llvm_hash, as below cause llvm to be rebuilt everytime commit is made to llvm/llvm-project for release a.x + # which could be quite often for new releases + export LLVM_HASH=$(git ls-remote https://github.com/llvm/llvm-project.git refs/heads/release/${{ matrix.clang-runtime}}.x | tr '\t' '-') fi - # FIXME: We need something like cling-llvm to bump automatically... - export LLVM_HASH=$(git ls-remote https://github.com/root-project/llvm-project.git cling-llvm${{ matrix.clang-runtime}} | tr '\t' '-') + echo "CLING_HASH=$CLING_HASH" >> $GITHUB_ENV echo "LLVM_HASH=$LLVM_HASH" >> $GITHUB_ENV + + - uses: nelonoel/branch-name@v1.0.1 + + - name: Save PR Info on Windows systems + if: ${{ runner.os == 'windows' }} + run: | + #FIXME: CLING AND LLVM HASH currently hardcoded until windows equivalent of unix commands + #can be found + mkdir ./pr + echo ${{ github.event.number }} > ./pr/NR + echo ${{ github.repository }} > ./pr/REPO + + if ( "${{ matrix.cling }}" -imatch "On" ) + { + $env:CLING_HASH_TEMP = ( git ls-remote https://github.com/root-project/cling.git refs/tags/v${{ matrix.cling-version }} ) + $env:CLING_HASH = $env:CLING_HASH_TEMP -replace "\t","-" + } + else + { + $env:CLING_HASH="Repl" + # May need to revert back to both having same llvm_hash, as below cause llvm to be rebuilt everytime commit is made to llvm/llvm-project for release a.x + # which could be quite often for new releases + $env:LLVM_HASH_TEMP = (git ls-remote https://github.com/llvm/llvm-project.git refs/heads/release/${{ matrix.clang-runtime}}.x ) + $env:LLVM_HASH = $env:LLVM_HASH_TEMP -replace "\t","-" + } + + echo "CLING_HASH=$env:CLING_HASH" + echo "LLVM_HASH=$env:LLVM_HASH" + + echo "CLING_HASH=$env:CLING_HASH" >> $GITHUB_ENV + echo "LLVM_HASH=$env:LLVM_HASH" >> $GITHUB_ENV + - uses: nelonoel/branch-name@v1.0.1 - name: Setup default Build Type on *nux @@ -203,6 +303,14 @@ jobs: echo "ncpus=$(nproc --all)" >> $GITHUB_ENV fi + - name: Setup default Build Type on Windows + if: runner.os == 'windows' + run: | + echo "BUILD_TYPE=Release" >> $GITHUB_ENV + echo "CODE_COVERAGE=0" >> $GITHUB_ENV + echo "ncpus=%NUMBER_OF_PROCESSORS%" + echo "ncpus=%NUMBER_OF_PROCESSORS%" >> $GITHUB_ENV + - name: Setup compiler on Linux if: runner.os == 'Linux' run: | @@ -245,6 +353,31 @@ jobs: fi env: compiler: ${{ matrix.compiler }} + + #Section slightly modified version of + #https://github.com/vgvassilev/clad/blob/40d8bec11bde47b14a281078183a4f6147abeac5/.github/workflows/ci.yml#L510C1-L534C10 + - name: Setup compiler on Windows + if: runner.os == 'windows' + run: | + if ( "${{ matrix.compiler }}" -imatch "clang" ) + { + $ver="${{ matrix.compiler }}".split("-")[1] + choco install llvm --version=$ver --no-progress -my + clang --version + # + $env:CC="clang" + $env:CXX="clang++" + echo "CC=clang" >> $env:GITHUB_ENV + echo "CXX=clang++" >> $env:GITHUB_ENV + } + elseif ( "${{ matrix.compiler }}" -imatch "msvc" ) + { + # MSVC is builtin in container image + } + else + { + echo "Unsupported compiler - fix YAML file" + } - name: Install deps on Linux if: runner.os == 'Linux' @@ -259,10 +392,6 @@ jobs: - name: Install deps on MacOS if: runner.os == 'macOS' run: | - #gcc, gnupg and python3 installed on Github runner - #brew install git gcc gnupg python@3 - #Select latest xcode available on macos-13 - sudo xcode-select -s /Applications/Xcode_15.1.app/Contents/Developer brew update # workaround for https://github.com/actions/setup-python/issues/577 for pkg in $(brew list | grep '^python@'); do @@ -279,14 +408,11 @@ jobs: path: | llvm-project ${{ matrix.cling=='On' && 'cling' || '' }} - #key: ...-.x-patch-${{ hashFiles('patches/llvm/*') }} - #key: ${{ env.CLING_HASH }}-${{ env.LLVM_HASH }}-${{ runner.os }}-${{ matrix.os }}-${{ matrix.compiler }}-clang-${{ matrix.clang-runtime }}.x 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' }} - - name: Build LLVM/Cling on Unix if the cache is invalid + - name: Build LLVM/Cling on Unix systems if the cache is invalid if: ${{ runner.os != 'windows' && steps.cache.outputs.cache-hit != 'true' }} run: | - os="${{ matrix.os }}" cling_on=$(echo "${{ matrix.cling }}" | tr '[:lower:]' '[:upper:]') if [[ "${cling_on}" == "ON" ]]; then git clone https://github.com/root-project/cling.git @@ -298,19 +424,17 @@ jobs: git clone --depth=1 -b release/${{ matrix.clang-runtime }}.x https://github.com/llvm/llvm-project.git fi cd llvm-project - # Apply patches - echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:" - compgen -G "../patches/llvm/clang${{ matrix.clang-runtime }}-*.patch" > /dev/null && find ../patches/llvm/clang${{ matrix.clang-runtime }}-*.patch -exec basename {} \; -print -exec git apply {} \; # Build mkdir build - cd build if [[ "${cling_on}" == "ON" ]]; then + cd build cmake -DLLVM_ENABLE_PROJECTS=clang \ -DLLVM_EXTERNAL_PROJECTS=cling \ -DLLVM_EXTERNAL_CLING_SOURCE_DIR=../../cling \ -DLLVM_TARGETS_TO_BUILD="host;NVPTX" \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_ENABLE_ASSERTIONS=ON \ + -DLLVM_ENABLE_LLD=ON \ -DCLANG_ENABLE_STATIC_ANALYZER=OFF \ -DCLANG_ENABLE_ARCMT=OFF \ -DCLANG_ENABLE_FORMAT=OFF \ @@ -321,10 +445,15 @@ jobs: # Now build gtest.a and gtest_main for CppInterOp to run its tests. cmake --build . --target gtest_main --parallel ${{ env.ncpus }} else + # Apply patches + git apply -v ../patches/llvm/clang${{ matrix.clang-runtime }}-*.patch + echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:" + cd build cmake -DLLVM_ENABLE_PROJECTS=clang \ -DLLVM_TARGETS_TO_BUILD="host;NVPTX" \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_ENABLE_ASSERTIONS=ON \ + -DLLVM_ENABLE_LLD=ON \ -DCLANG_ENABLE_STATIC_ANALYZER=OFF \ -DCLANG_ENABLE_ARCMT=OFF \ -DCLANG_ENABLE_FORMAT=OFF \ @@ -334,6 +463,79 @@ jobs: fi cd ../../ + - name: Build LLVM/Cling on Windows systems if the cache is invalid + if: ${{ runner.os == 'windows' && steps.cache.outputs.cache-hit != 'true' }} + run: | + + if ( "${{ matrix.cling }}" -imatch "On" ) + { + git clone https://github.com/root-project/cling.git + cd ./cling + git checkout tags/v${{ matrix.cling-version }} + cd .. + git clone --depth=1 -b cling-llvm${{ matrix.clang-runtime }} https://github.com/root-project/llvm-project.git + $env:PWD_DIR= $PWD.Path + $env:CLING_DIR="$env:PWD_DIR\cling" + echo "CLING_DIR=$env:CLING_DIR" + } + else + { + git clone --depth=1 -b release/${{ matrix.clang-runtime }}.x https://github.com/llvm/llvm-project.git + } + + cd llvm-project + # Build + mkdir build + if ( "${{ matrix.cling }}" -imatch "On" ) + { + cd build + cmake -DLLVM_ENABLE_PROJECTS=clang ` + -DLLVM_EXTERNAL_PROJECTS=cling ` + -DLLVM_EXTERNAL_CLING_SOURCE_DIR="$env:CLING_DIR" ` + -DLLVM_TARGETS_TO_BUILD="host;NVPTX" ` + -DCMAKE_BUILD_TYPE=Release ` + -DLLVM_ENABLE_ASSERTIONS=ON ` + -DLLVM_ENABLE_LLD=ON ` + -DCLANG_ENABLE_STATIC_ANALYZER=OFF ` + -DCLANG_ENABLE_ARCMT=OFF ` + -DCLANG_ENABLE_FORMAT=OFF ` + -DCLANG_ENABLE_BOOTSTRAP=OFF ` + ../llvm + cmake --build . --target clang --parallel ${{ env.ncpus }} + cmake --build . --target cling --parallel ${{ env.ncpus }} + # Now build gtest.a and gtest_main for CppInterOp to run its tests. + cmake --build . --target gtest_main --parallel ${{ env.ncpus }} + } + else + { + cp -r ..\patches\llvm\clang${{ matrix.clang-runtime }}* + #FIXME: Apply patches without hardcoding + if ( "${{ matrix.clang-runtime }}" -imatch "16" ) + { + git apply -v clang16-1-Value.patch + git apply -v clang16-2-CUDA.patch + git apply -v clang16-3-WeakRef.patch + } + elseif ( "${{ matrix.clang-runtime }}" -imatch "16" ) + { + git apply -v clang17-1-NewOperator.patch + } + cd build + echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:" + cmake -DLLVM_ENABLE_PROJECTS=clang ` + -DLLVM_TARGETS_TO_BUILD="host;NVPTX" ` + -DCMAKE_BUILD_TYPE=Release ` + -DLLVM_ENABLE_ASSERTIONS=ON ` + -DLLVM_ENABLE_LLD=ON ` + -DCLANG_ENABLE_STATIC_ANALYZER=OFF ` + -DCLANG_ENABLE_ARCMT=OFF ` + -DCLANG_ENABLE_FORMAT=OFF ` + -DCLANG_ENABLE_BOOTSTRAP=OFF ` + ../llvm + cmake --build . --target clang clang-repl --parallel ${{ env.ncpus }} + } + cd ../../ + - name: Save Cache LLVM/Clang runtime build directory uses: actions/cache/save@v3 if: ${{ steps.cache.outputs.cache-hit != 'true' }} @@ -350,7 +552,7 @@ jobs: echo "CODE_COVERAGE=1" >> $GITHUB_ENV echo "BUILD_TYPE=Debug" >> $GITHUB_ENV - - name: Build and Test/Install CppInterOp on Unix Systems + - name: Build and Test/Install CppInterOp on Unix systems if: ${{ runner.os != 'windows' }} run: | LLVM_DIR="$(pwd)/llvm-project" @@ -376,7 +578,8 @@ jobs: -DUSE_CLING=ON \ -DUSE_REPL=OFF \ -DCling_DIR=$LLVM_BUILD_DIR/tools/cling \ - -DLLVM_DIR=$LLVM_BUILD_DIR \ + -DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm \ + -DClang_DIR=$LLVM_BUILD_DIR/lib/cmake/clang \ -DBUILD_SHARED_LIBS=ON \ -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \ -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR \ @@ -385,7 +588,8 @@ jobs: cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \ -DUSE_CLING=OFF \ -DUSE_REPL=ON \ - -DLLVM_DIR=$LLVM_BUILD_DIR \ + -DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm \ + -DClang_DIR=$LLVM_BUILD_DIR/lib/cmake/clang \ -DBUILD_SHARED_LIBS=ON \ -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \ -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR \ @@ -407,6 +611,74 @@ jobs: echo "LLVM_BUILD_DIR=$LLVM_BUILD_DIR" >> $GITHUB_ENV echo "CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH" >> $GITHUB_ENV + - name: Build and Test/Install CppInterOp on Windows systems + if: ${{ runner.os == 'windows' }} + run: | + $env:PWD_DIR= $PWD.Path + + $env:LLVM_DIR="$env:PWD_DIR\llvm-project" + echo "LLVM_DIR=$env:LLVM_DIR" + echo "LLVM_DIR=$env:LLVM_DIR" >> $env:GITHUB_ENV + + $env:LLVM_BUILD_DIR="$env:PWD_DIR\llvm-project\build" + echo "LLVM_BUILD_DIR=$env:LLVM_BUILD_DIR" + echo "LLVM_BUILD_DIR=$env:LLVM_BUILD_DIR" >> $env:GITHUB_ENV + + if ( "${{ matrix.cling }}" -imatch "On" ) + { + $env:CLING_DIR="$env:PWD_DIR\cling" + echo "CLING_DIR=$env:CLING_DIR" + echo "CLING_DIR=$env:CLING_DIR" >> $env:GITHUB_ENV + + $env:CLING_BUILD_DIR="$env:PWD_DIR\cling\build" + echo "CLING_BUILD_DIR=$env:CLING_BUILD_DIR" + echo "CLING_BUILD_DIR=$env:CLING_BUILD_DIR" >> $env:GITHUB_ENV + + $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;" + echo "CPLUS_INCLUDE_PATH=$env:CPLUS_INCLUDE_PATH" + echo "CPLUS_INCLUDE_PATH=$env:CPLUS_INCLUDE_PATH" >> $env:GITHUB_ENV + } + else + { + $env:CPLUS_INCLUDE_PATH="$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;" + echo "CPLUS_INCLUDE_PATH=$env:CPLUS_INCLUDE_PATH" + echo "CPLUS_INCLUDE_PATH=$env:CPLUS_INCLUDE_PATH" >> $env:GITHUB_ENV + } + + $env:CB_PYTHON_DIR="$env:PWD_DIR\cppyy-backend\python" + echo "CB_PYTHON_DIR=$env:CB_PYTHON_DIR" + echo "CB_PYTHON_DIR=$env:CB_PYTHON_DIR" >> $env:GITHUB_ENV + + $env:CPPINTEROP_DIR="$env:CB_PYTHON_DIR\cppyy-backend" + echo "CPPINTEROP_DIR=$env:CPPINTEROP_DIR" + echo "CPPINTEROP_DIR=$env:CPPINTEROP_DIR" >> $env:GITHUB_ENV + + # Build CppInterOp next to cling and llvm-project. + mkdir build + cd build + $env:CPPINTEROP_BUILD_DIR="$env:PWD_DIR" + echo "CPPINTEROP_BUILD_DIR=$env:CPPINTEROP_BUILD_DIR" + echo "CPPINTEROP_BUILD_DIR=$env:CPPINTEROP_BUILD_DIR" >> $env:GITHUB_ENV + if ( "${{ matrix.cling }}" -imatch "On" ) + { + cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} ` + -DUSE_CLING=ON ` + -DUSE_REPL=OFF ` + -DCling_DIR="$env:LLVM_BUILD_DIR\tools\cling" ` + -DLLVM_DIR="$env:LLVM_BUILD_DIR" ` + -DClang_DIR="$env:LLVM_BUILD_DIR" -DBUILD_SHARED_LIBS=ON -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} -DCMAKE_INSTALL_PREFIX="$env:CPPINTEROP_DIR" ..\ + } + else + { + cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} ` + -DUSE_CLING=OFF ` + -DUSE_REPL=ON ` + -DLLVM_DIR="$env:LLVM_BUILD_DIR\lib\cmake\llvm" ` + -DClang_DIR="$env:LLVM_BUILD_DIR\lib\cmake\clang" -DBUILD_SHARED_LIBS=ON -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} -DCMAKE_INSTALL_PREFIX="$env:CPPINTEROP_DIR" ..\ + } + cmake --build . --target check-cppinterop --parallel ${{ env.ncpus }} + cd .. + - name: Build and Install cppyy-backend on Unix Systems if: ${{ (runner.os != 'windows') && (matrix.cppyy == 'On') }} run: | @@ -425,12 +697,8 @@ jobs: else cp libcppyy-backend.so $CPPINTEROP_DIR/lib/ fi - ##cling_on="${{ matrix.cling }}" - ##if [[ "${cling_on^^}" == "ON" ]]; then - ## cp $LLVM_BUILD_DIR/lib/libcling.so $CPPINTEROP_DIR/lib/ - ##fi - # cd .. + - name: Install CPyCppyy on Unix Systems if: ${{ (runner.os != 'windows') && (matrix.cppyy == 'On') }} run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index d8b340a43..9fe401013 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -206,6 +206,9 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) endif() + ##Replace \ with / in LLVM_DIR (attempt to fix path parsing issue Windows) + string(REPLACE "\\" "/" LLVM_DIR "${LLVM_DIR}") + # When in debug mode the llvm package thinks it is built with -frtti. # For consistency we should set it to the correct value. set(LLVM_CONFIG_HAS_RTTI NO CACHE BOOL "" FORCE) diff --git a/README.md b/README.md index 3cb9ee2d4..e850bd421 100644 --- a/README.md +++ b/README.md @@ -77,15 +77,23 @@ Clone the 17.x release of the LLVM project repository. git clone --depth=1 --branch release/17.x https://github.com/llvm/llvm-project.git cd llvm-project ``` -Get the following patches required for development work. +Get the following patches required for development work. To apply these patches on Linux and MacOS execute the following command ``` -compgen -G "../CppInterOp/patches/llvm/clang17-*.patch" > /dev/null && find ../CppInterOp/patches/llvm/clang17-*.patch -printf "%f\n" && git apply ../CppInterOp/patches/llvm/clang17-*.patch +git apply -v ..\patches\llvm\clang${{ matrix.clang-runtime }}-*.patch ``` +and +``` +cp -r ..\patches\llvm\clang17* +git apply -v clang17-1-NewOperator.patch +``` +on Windows. ##### Build Clang-REPL Clang-REPL is an interpreter that CppInterOp works alongside. Build Clang (and -Clang-REPL along with it). +Clang-REPL along with it). On Linux and MaxOS you do this by executing the following +command ``` -mkdir build && cd build +mkdir build \ +cd build \ cmake -DLLVM_ENABLE_PROJECTS=clang \ -DLLVM_TARGETS_TO_BUILD="host;NVPTX" \ -DCMAKE_BUILD_TYPE=Release \ @@ -98,18 +106,40 @@ cmake -DLLVM_ENABLE_PROJECTS=clang \ ../llvm cmake --build . --target clang clang-repl --parallel $(nproc --all) ``` -Note the 'llvm-project' directory location. +On Windows you would do this by executing the following +``` +$env:ncpus = %NUMBER_OF_PROCESSORS% +mkdir build ` +cd build ` +cmake -DLLVM_ENABLE_PROJECTS=clang ` + -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 + cmake --build . --target clang clang-repl --parallel $env:ncpus +``` +Note the 'llvm-project' directory location. On linux and MacOS you execute the following ``` cd ../ export LLVM_DIR=$PWD cd ../ ``` +On Windows you execute the following +``` +cd ..\ +$env:LLVM_DIR= $PWD.Path +cd ..\ +``` #### Build Cling and related dependencies Besides the Clang-REPL interpreter, CppInterOp also works alongside the Cling interpreter. Cling depends on its own customised version of `llvm-project`, hosted under the `root-project` (see the git path below). -Use the following build instructions. +Use the following build instructions to build on Linux and MacOS ``` git clone --depth=1 https://github.com/root-project/cling.git git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git @@ -131,15 +161,46 @@ cmake --build . --target clang --parallel $(nproc --all) cmake --build . --target cling --parallel $(nproc --all) cmake --build . --target gtest_main --parallel $(nproc --all) ``` -Note the 'llvm-project' directory location. +Use the following build instructions to build on Windows +``` +git clone --depth=1 https://github.com/root-project/cling.git +git clone --depth=1 -b cling-llvm13 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" +mkdir llvm-project\build +cd llvm-project\build +cmake -DLLVM_ENABLE_PROJECTS=clang ` + -DLLVM_EXTERNAL_PROJECTS=cling ` + -DLLVM_EXTERNAL_CLING_SOURCE_DIR="$env:CLING_DIR" ` + -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 +cmake --build . --target clang --parallel $env:ncpus +cmake --build . --target cling --parallel $env:ncpus +# Now build gtest.a and gtest_main for CppInterOp to run its tests. +cmake --build . --target gtest_main --parallel $env:ncpus +``` +Note the 'llvm-project' directory location. On linux and MacOS you execute the following ``` cd ../ export LLVM_DIR=$PWD cd ../ ``` +On Windows you execute the following +``` +cd ..\ +$env:LLVM_DIR= $PWD.Path +cd ..\ +``` #### Environment variables -Regardless of whether you are building CppInterOP with Cling or Clang-REPL you will need to define the following Envirnoment variables (as they clear for a new session, it is recommended that you also add these to your .bashrc in linux, or your .bash_profile if on MacOS) +Regardless of whether you are building CppInterOP with Cling or Clang-REPL you will need to define the following Envirnoment variables (as they clear for a new session, it is recommended that you also add these to your .bashrc in linux, .bash_profile if on MacOS, or profile.ps1 on Windows). On Linux and MacOS you define as follows ``` export CB_PYTHON_DIR="$PWD/cppyy-backend/python" export CPPINTEROP_DIR="$CB_PYTHON_DIR/cppyy_backend" @@ -150,35 +211,65 @@ If on MacOS you will also need the following envirnoment variable defined ``` export SDKROOT=`xcrun --show-sdk-path` ``` +On Windows you define as follows (assumes you have defined $env:PWD_DIR= $PWD.Path ) +``` +$env:CB_PYTHON_DIR="$env:PWD_DIR\cppyy-backend\python" +$env:CPPINTEROP_DIR="$env:CB_PYTHON_DIR\cppyy_backend" +$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" +$env:PYTHONPATH="$env:PYTHONPATH;$env:CPYCPPYY_DIR;$env:CB_PYTHON_DIR" +``` #### Build CppInterOp -Now CppInterOp can be installed +Now CppInterOp can be installed. On Linux and MacOS execute ``` mkdir CppInterOp/build/ cd CppInterOp/build/ ``` +On Windows execute +``` +mkdir CppInterOp\build\ +cd CppInterOp\build\ +``` -Now if you want to build CppInterOp with Clang-REPL then execute the following commands +Now if you want to build CppInterOp with Clang-REPL then execute the following commands on Linux and MacOS ``` -cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=ON -DUSE_REPL=Off -DCling_DIR=$LLVM_DIR/build -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR .. +cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=Off -DUSE_REPL=ON -DCling_DIR=$LLVM_DIR/build -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR .. cmake --build . --target install --parallel $(nproc --all) ``` -If alternatively you would like to install CppInterOp with Cling then execute the following commands +and +``` +cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=Off -DUSE_REPL=ON -DCling_DIR=$LLVM_DIR\build -DCMAKE_INSTALL_PREFIX=$env:CPPINTEROP_DIR .. +cmake --build . --target install --parallel $env:ncpus +``` +on Windows. If alternatively you would like to install CppInterOp with Cling then execute the following commands on Linux and MacOS ``` cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=ON -DUSE_REPL=Off -DCling_DIR=$LLVM_DIR/build -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR .. cmake --build . --target install --parallel $(nproc --all) ``` +and +``` +cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=ON -DUSE_REPL=Off -DCling_DIR=$LLVM_DIR\build -DCMAKE_INSTALL_PREFIX=$env:CPPINTEROP_DIR .. +cmake --build . --target install --parallel $env:ncpus +``` #### Testing CppInterOp -To test the built CppInterOp execute the following command in the CppInterOP build folder +To test the built CppInterOp execute the following command in the CppInterOP build folder on Linux and MacOS ``` cmake --build . --target check-cppinterop --parallel $(nproc --all) ``` -Now go back to the top level directory in which your building CppInterOP +and +``` +cmake --build . --target check-cppinterop --parallel $env:ncpus +``` +on Windows. Now go back to the top level directory in which your building CppInterOP. On Linux and MacOS you do this by executing ``` cd ../.. ``` -Now you are in a position to install cppyy following the instructions below. +and +``` +cd ..\.. +``` +on Windows. Now you are in a position to install cppyy following the instructions below. #### Building and Install cppyy-backend diff --git a/patches/llvm/clang16-1-Value.patch b/patches/llvm/clang16-1-Value.patch index 9d702ee84..854077c7a 100644 --- a/patches/llvm/clang16-1-Value.patch +++ b/patches/llvm/clang16-1-Value.patch @@ -4,10 +4,10 @@ index 863f6ac57..feb6db113 100644 +++ b/clang/include/clang/AST/Decl.h @@ -4308,6 +4308,7 @@ class TopLevelStmtDecl : public Decl { friend class ASTDeclWriter; - + Stmt *Statement = nullptr; + bool IsSemiMissing = false; - + TopLevelStmtDecl(DeclContext *DC, SourceLocation L, Stmt *S) : Decl(TopLevelStmt, DC, L), Statement(S) {} @@ -4321,6 +4322,12 @@ public: @@ -20,7 +20,7 @@ index 863f6ac57..feb6db113 100644 + } + bool isSemiMissing() const { return IsSemiMissing; } + void setSemiMissing(bool Missing = true) { IsSemiMissing = Missing; } - + static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == TopLevelStmt; } diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def @@ -30,7 +30,7 @@ index 96feae991..752629855 100644 @@ -936,6 +936,9 @@ ANNOTATION(module_end) // into the name of a header unit. ANNOTATION(header_unit) - + +// Annotation for end of input in clang-repl. +ANNOTATION(repl_input_end) + @@ -44,14 +44,14 @@ index fd22af976..e68021845 100644 @@ -14,13 +14,15 @@ #ifndef LLVM_CLANG_INTERPRETER_INTERPRETER_H #define LLVM_CLANG_INTERPRETER_INTERPRETER_H - + -#include "clang/Interpreter/PartialTranslationUnit.h" - +#include "clang/AST/Decl.h" #include "clang/AST/GlobalDecl.h" +#include "clang/Interpreter/PartialTranslationUnit.h" +#include "clang/Interpreter/Value.h" - + +#include "llvm/ADT/DenseMap.h" #include "llvm/ExecutionEngine/JITSymbol.h" +#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h" @@ -59,7 +59,7 @@ index fd22af976..e68021845 100644 - #include #include - + @@ -28,7 +30,7 @@ namespace llvm { namespace orc { class LLJIT; @@ -67,12 +67,12 @@ index fd22af976..e68021845 100644 -} +} // namespace orc } // namespace llvm - + namespace clang { @@ -52,39 +54,64 @@ class Interpreter { - + Interpreter(std::unique_ptr CI, llvm::Error &Err); - + + llvm::Error CreateExecutor(); + unsigned InitPTUSize = 0; + @@ -103,10 +103,10 @@ index fd22af976..e68021845 100644 - } + llvm::Error ParseAndExecute(llvm::StringRef Code, Value *V = nullptr); + llvm::Expected CompileDtorCall(CXXRecordDecl *CXXRD); - + /// Undo N previous incremental inputs. llvm::Error Undo(unsigned N = 1); - + - /// \returns the \c JITTargetAddress of a \c GlobalDecl. This interface uses + /// Link a dynamic library + llvm::Error LoadDynamicLibrary(const char *name); @@ -116,13 +116,13 @@ index fd22af976..e68021845 100644 /// mangled name. - llvm::Expected getSymbolAddress(GlobalDecl GD) const; + llvm::Expected getSymbolAddress(GlobalDecl GD) const; - + - /// \returns the \c JITTargetAddress of a given name as written in the IR. - llvm::Expected + /// \returns the \c ExecutorAddr of a given name as written in the IR. + llvm::Expected getSymbolAddress(llvm::StringRef IRName) const; - + - /// \returns the \c JITTargetAddress of a given name as written in the object + /// \returns the \c ExecutorAddr of a given name as written in the object /// file. @@ -148,7 +148,7 @@ index fd22af976..e68021845 100644 + llvm::SmallVector ValuePrintingInfo; }; } // namespace clang - + diff --git a/clang/include/clang/Interpreter/Value.h b/clang/include/clang/Interpreter/Value.h new file mode 100644 index 000000000..4df436703 @@ -377,7 +377,7 @@ index 6f9581b9e..6b73f43a1 100644 + Kind == tok::annot_module_end || Kind == tok::annot_module_include || + Kind == tok::annot_repl_input_end; } - + /// Checks if the \p Level is valid for use in a fold expression. diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index ffa85e523..1b262d9e6 100644 @@ -391,7 +391,7 @@ index ffa85e523..1b262d9e6 100644 + !Tok.is(tok::annot_module_begin) && !Tok.is(tok::annot_module_end) && + !Tok.is(tok::annot_repl_input_end))) return; - + // EmittedDirectiveOnThisLine takes priority over RequireSameLine. @@ -819,6 +820,9 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, // -traditional-cpp the lexer keeps /all/ whitespace, including comments. @@ -413,7 +413,7 @@ index c49f22fdd..565e824bf 100644 Interpreter.cpp + InterpreterUtils.cpp + Value.cpp - + DEPENDS intrinsics_gen diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp @@ -423,20 +423,20 @@ index 37d230b61..489ea48e0 100644 @@ -86,7 +86,7 @@ llvm::Error IncrementalExecutor::runCtors() const { return Jit->initialize(Jit->getMainJITDylib()); } - + -llvm::Expected +llvm::Expected IncrementalExecutor::getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const { auto Sym = (NameKind == LinkerName) ? Jit->lookupLinkerMangled(Name) @@ -94,7 +94,7 @@ IncrementalExecutor::getSymbolAddress(llvm::StringRef Name, - + if (!Sym) return Sym.takeError(); - return Sym->getValue(); + return Sym; } - + } // end namespace clang diff --git a/clang/lib/Interpreter/IncrementalExecutor.h b/clang/lib/Interpreter/IncrementalExecutor.h index 54d37c763..dd0a210a0 100644 @@ -447,9 +447,9 @@ index 54d37c763..dd0a210a0 100644 #include "llvm/ADT/StringRef.h" #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h" +#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h" - + #include - + @@ -51,9 +52,10 @@ public: llvm::Error removeModule(PartialTranslationUnit &PTU); llvm::Error runCtors() const; @@ -461,7 +461,7 @@ index 54d37c763..dd0a210a0 100644 + + llvm::orc::LLJIT &GetExecutionEngine() { return *Jit; } }; - + } // end namespace clang diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp index 373e2844b..e43189071 100644 @@ -469,7 +469,7 @@ index 373e2844b..e43189071 100644 +++ b/clang/lib/Interpreter/IncrementalParser.cpp @@ -11,7 +11,6 @@ //===----------------------------------------------------------------------===// - + #include "IncrementalParser.h" - #include "clang/AST/DeclContextInternals.h" @@ -487,9 +487,9 @@ index 373e2844b..e43189071 100644 #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/Error.h" @@ -31,6 +30,79 @@ - + namespace clang { - + +class IncrementalASTConsumer final : public ASTConsumer { + Interpreter &Interp; + std::unique_ptr Consumer; @@ -569,7 +569,7 @@ index 373e2844b..e43189071 100644 @@ -122,7 +194,8 @@ public: } }; - + -IncrementalParser::IncrementalParser(std::unique_ptr Instance, +IncrementalParser::IncrementalParser(Interpreter &Interp, + std::unique_ptr Instance, @@ -588,7 +588,7 @@ index 373e2844b..e43189071 100644 new Parser(CI->getPreprocessor(), CI->getSema(), /*SkipBodies=*/false)); @@ -158,8 +234,8 @@ IncrementalParser::ParseOrWrapTopLevelDecl() { LastPTU.TUPart = C.getTranslationUnitDecl(); - + // Skip previous eof due to last incremental input. - if (P->getCurToken().is(tok::eof)) { - P->ConsumeToken(); @@ -609,7 +609,7 @@ index 373e2844b..e43189071 100644 + assert(AssertTok.is(tok::annot_repl_input_end) && + "Lexer must be EOF when starting incremental parse!"); } - + - Token AssertTok; - PP.Lex(AssertTok); - assert(AssertTok.is(tok::eof) && @@ -619,7 +619,7 @@ index 373e2844b..e43189071 100644 + + return PTU; +} - + +std::unique_ptr IncrementalParser::GenModule() { + static unsigned ID = 0; if (CodeGenerator *CG = getCodeGen(Act.get())) { @@ -635,7 +635,7 @@ index 373e2844b..e43189071 100644 - return PTU; + return nullptr; } - + void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) { diff --git a/clang/lib/Interpreter/IncrementalParser.h b/clang/lib/Interpreter/IncrementalParser.h index 8e45d6b59..99e37588d 100644 @@ -643,7 +643,7 @@ index 8e45d6b59..99e37588d 100644 +++ b/clang/lib/Interpreter/IncrementalParser.h @@ -16,7 +16,6 @@ #include "clang/Interpreter/PartialTranslationUnit.h" - + #include "clang/AST/GlobalDecl.h" - #include "llvm/ADT/ArrayRef.h" @@ -661,18 +661,18 @@ index 8e45d6b59..99e37588d 100644 /// @@ -57,7 +56,8 @@ class IncrementalParser { std::list PTUs; - + public: - IncrementalParser(std::unique_ptr Instance, + IncrementalParser(Interpreter &Interp, + std::unique_ptr Instance, llvm::LLVMContext &LLVMCtx, llvm::Error &Err); ~IncrementalParser(); - + @@ -76,6 +76,8 @@ public: - + std::list &getPTUs() { return PTUs; } - + + std::unique_ptr GenModule(); + private: @@ -685,7 +685,7 @@ index a6f5fdc6e..4391bd008 100644 @@ -16,7 +16,11 @@ #include "IncrementalExecutor.h" #include "IncrementalParser.h" - + +#include "InterpreterUtils.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/Mangle.h" @@ -711,7 +711,7 @@ index a6f5fdc6e..4391bd008 100644 #include "llvm/Support/Host.h" - using namespace clang; - + // FIXME: Figure out how to unify with namespace init_convenience from @@ -176,7 +184,7 @@ Interpreter::Interpreter(std::unique_ptr CI, llvm::ErrorAsOutParameter EAO(&Err); @@ -721,11 +721,11 @@ index a6f5fdc6e..4391bd008 100644 + IncrParser = std::make_unique(*this, std::move(CI), *TSCtx->getContext(), Err); } - + @@ -189,6 +197,29 @@ Interpreter::~Interpreter() { } } - + +// These better to put in a runtime header but we can't. This is because we +// can't find the precise resource directory in unittests so we have to hard +// code them. @@ -767,11 +767,11 @@ index a6f5fdc6e..4391bd008 100644 + Interp->InitPTUSize = Interp->IncrParser->getPTUs().size(); return std::move(Interp); } - + @@ -203,25 +243,53 @@ const CompilerInstance *Interpreter::getCompilerInstance() const { return IncrParser->getCI(); } - + -const llvm::orc::LLJIT *Interpreter::getExecutionEngine() const { - if (IncrExecutor) - return IncrExecutor->getExecutionEngine(); @@ -798,7 +798,7 @@ index a6f5fdc6e..4391bd008 100644 + assert(PTUs.size() >= InitPTUSize && "empty PTU list?"); + return PTUs.size() - InitPTUSize; } - + llvm::Expected Interpreter::Parse(llvm::StringRef Code) { + // Tell the interpreter sliently ignore unused expressions since value @@ -807,7 +807,7 @@ index a6f5fdc6e..4391bd008 100644 + clang::diag::warn_unused_expr, diag::Severity::Ignored, SourceLocation()); return IncrParser->Parse(Code); } - + +llvm::Error Interpreter::CreateExecutor() { + const clang::TargetInfo &TI = + getCompilerInstance()->getASTContext().getTargetInfo(); @@ -834,7 +834,7 @@ index a6f5fdc6e..4391bd008 100644 @@ -235,7 +303,26 @@ llvm::Error Interpreter::Execute(PartialTranslationUnit &T) { return llvm::Error::success(); } - + -llvm::Expected +llvm::Error Interpreter::ParseAndExecute(llvm::StringRef Code, Value *V) { + @@ -862,7 +862,7 @@ index a6f5fdc6e..4391bd008 100644 @@ -245,7 +332,7 @@ Interpreter::getSymbolAddress(GlobalDecl GD) const { return getSymbolAddress(MangledName); } - + -llvm::Expected +llvm::Expected Interpreter::getSymbolAddress(llvm::StringRef IRName) const { @@ -871,7 +871,7 @@ index a6f5fdc6e..4391bd008 100644 @@ -255,7 +342,7 @@ Interpreter::getSymbolAddress(llvm::StringRef IRName) const { return IncrExecutor->getSymbolAddress(IRName, IncrementalExecutor::IRName); } - + -llvm::Expected +llvm::Expected Interpreter::getSymbolAddressFromLinkerName(llvm::StringRef Name) const { @@ -879,7 +879,7 @@ index a6f5fdc6e..4391bd008 100644 return llvm::make_error("Operation failed. " @@ -268,7 +355,7 @@ Interpreter::getSymbolAddressFromLinkerName(llvm::StringRef Name) const { llvm::Error Interpreter::Undo(unsigned N) { - + std::list &PTUs = IncrParser->getPTUs(); - if (N > PTUs.size()) + if (N > getEffectivePTUSize()) @@ -1718,7 +1718,7 @@ index 66168467e..0822f83b5 100644 + } else { + CurLexer->FormTokenWithChars(Result, EndPos, tok::eof); + } - + if (isCodeCompletionEnabled()) { // Inserting the code-completion point increases the source buffer by 1, diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp b/clang/lib/Parse/ParseCXXInlineMethods.cpp @@ -1732,7 +1732,7 @@ index 3a7f5426d..57a3dfba4 100644 + case tok::annot_repl_input_end: // Ran out of tokens. return false; - + @@ -1242,6 +1243,7 @@ bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks, case tok::annot_module_begin: case tok::annot_module_end: @@ -1740,7 +1740,7 @@ index 3a7f5426d..57a3dfba4 100644 + case tok::annot_repl_input_end: // Ran out of tokens. return false; - + diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index e6812ac72..2f193a3b4 100644 --- a/clang/lib/Parse/ParseDecl.cpp @@ -1751,10 +1751,10 @@ index e6812ac72..2f193a3b4 100644 case tok::annot_module_include: + case tok::annot_repl_input_end: return; - + default: @@ -5394,6 +5395,13 @@ Parser::DeclGroupPtrTy Parser::ParseTopLevelStmtDecl() { - + SmallVector DeclsInGroup; DeclsInGroup.push_back(Actions.ActOnTopLevelStmtDecl(R.get())); + @@ -1774,7 +1774,7 @@ index 1c8441faf..d22e1d440 100644 @@ -543,9 +543,22 @@ StmtResult Parser::ParseExprStatement(ParsedStmtContext StmtCtx) { return ParseCaseStatement(StmtCtx, /*MissingCase=*/true, Expr); } - + - // Otherwise, eat the semicolon. - ExpectAndConsumeSemi(diag::err_expected_semi_after_expr); - return handleExprStmt(Expr, StmtCtx); @@ -1795,7 +1795,7 @@ index 1c8441faf..d22e1d440 100644 + + return R; } - + /// ParseSEHTryBlockCommon diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 6db3dc315..7fbb27057 100644 @@ -1812,7 +1812,7 @@ index 6db3dc315..7fbb27057 100644 @@ -612,11 +613,6 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result, Sema::ModuleImportState &ImportState) { DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this); - + - // Skip over the EOF token, flagging end of previous input for incremental - // processing - if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof)) @@ -1823,7 +1823,7 @@ index 6db3dc315..7fbb27057 100644 case tok::annot_pragma_unused: @@ -695,6 +691,7 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result, return false; - + case tok::eof: + case tok::annot_repl_input_end: // Check whether -fmax-tokens= was reached. @@ -1872,7 +1872,7 @@ index b51a18c10..15d7f9439 100644 +++ b/clang/tools/clang-repl/CMakeLists.txt @@ -12,6 +12,7 @@ add_clang_tool(clang-repl ) - + clang_target_link_libraries(clang-repl PRIVATE + clangAST clangBasic @@ -1893,7 +1893,7 @@ index 401a31d34..33faf3fab 100644 + } + continue; + } - + if (auto Err = Interp->ParseAndExecute(*Line)) { llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: "); diff --git a/clang/unittests/Interpreter/CMakeLists.txt b/clang/unittests/Interpreter/CMakeLists.txt @@ -1915,7 +1915,7 @@ index f54c65568..6d0433a98 100644 #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/TargetSelect.h" -#include "llvm-c/Error.h" - + #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -116,7 +115,8 @@ extern "C" int throw_exception() { @@ -1939,11 +1939,11 @@ index d4900a0e4..330fd18ab 100644 +#include "clang/Interpreter/Value.h" #include "clang/Sema/Lookup.h" #include "clang/Sema/Sema.h" - + @@ -33,6 +34,11 @@ using namespace clang; #define CLANG_INTERPRETER_NO_SUPPORT_EXEC #endif - + +int Global = 42; +// JIT reports symbol not found on Windows without the visibility attribute. +REPL_EXTERNAL_VISIBILITY int getGlobal() { return Global; } @@ -1953,7 +1953,7 @@ index d4900a0e4..330fd18ab 100644 using Args = std::vector; static std::unique_ptr @@ -225,7 +231,7 @@ TEST(IncrementalProcessing, FindMangledNameSymbol) { - + std::string MangledName = MangleName(FD); auto Addr = cantFail(Interp->getSymbolAddress(MangledName)); - EXPECT_NE(0U, Addr); @@ -1964,7 +1964,7 @@ index d4900a0e4..330fd18ab 100644 @@ -276,8 +282,7 @@ TEST(IncrementalProcessing, InstantiateTemplate) { std::vector Args = {"-fno-delayed-template-parsing"}; std::unique_ptr Interp = createInterpreter(Args); - + - llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);" - "extern \"C\" int printf(const char*,...);" + llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);" @@ -1972,7 +1972,7 @@ index d4900a0e4..330fd18ab 100644 "struct B {" " template" @@ -309,9 +314,109 @@ TEST(IncrementalProcessing, InstantiateTemplate) { - + std::string MangledName = MangleName(TmpltSpec); typedef int (*TemplateSpecFn)(void *); - auto fn = (TemplateSpecFn)cantFail(Interp->getSymbolAddress(MangledName)); @@ -1981,7 +1981,7 @@ index d4900a0e4..330fd18ab 100644 EXPECT_EQ(42, fn(NewA)); free(NewA); } - + +#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC +TEST(InterpreterTest, DISABLED_Value) { +#else From c9877692f3b29c52e405286bb961fbe34c654089 Mon Sep 17 00:00:00 2001 From: fsfod Date: Mon, 15 Jan 2024 12:08:07 +0000 Subject: [PATCH 11/59] Fix rvalue error for std::string in DynamicLibraryManager::isSharedLibrary --- lib/Interpreter/DynamicLibraryManager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Interpreter/DynamicLibraryManager.cpp b/lib/Interpreter/DynamicLibraryManager.cpp index bba7e2113..151f33a04 100644 --- a/lib/Interpreter/DynamicLibraryManager.cpp +++ b/lib/Interpreter/DynamicLibraryManager.cpp @@ -449,7 +449,8 @@ namespace Cpp { // do its work. // TODO: Fix the code upstream and consider going back to calling the // convenience function after a future LLVM upgrade. - std::ifstream in(libFullPath.str(), std::ios::binary); + std::string path = libFullPath.str(); + std::ifstream in(path, std::ios::binary); char header[1024] = {0}; in.read(header, sizeof(header)); if (in.fail()) { From 86f40dfc84b9f19e38fcfeb178f1d30692f7726a Mon Sep 17 00:00:00 2001 From: fsfod Date: Mon, 15 Jan 2024 12:09:00 +0000 Subject: [PATCH 12/59] Fix error from window.h declaring min macro, disabled with NOMINMAX --- lib/Interpreter/DynamicLibraryManagerSymbol.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Interpreter/DynamicLibraryManagerSymbol.cpp b/lib/Interpreter/DynamicLibraryManagerSymbol.cpp index 9db4c2b85..c17b60621 100644 --- a/lib/Interpreter/DynamicLibraryManagerSymbol.cpp +++ b/lib/Interpreter/DynamicLibraryManagerSymbol.cpp @@ -52,6 +52,8 @@ #endif // __APPLE__ #ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX #include #include // For GetModuleFileNameA #include // For VirtualQuery From bed22bb880bb6461d334a768b0f3cab90f075deb Mon Sep 17 00:00:00 2001 From: fsfod Date: Mon, 15 Jan 2024 12:09:52 +0000 Subject: [PATCH 13/59] Fix Dtor_Comdat to clang::Dtor_Comdat in maybeMangleDeclName --- lib/Interpreter/Compatibility.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Interpreter/Compatibility.h b/lib/Interpreter/Compatibility.h index 539bda951..24b9661db 100644 --- a/lib/Interpreter/Compatibility.h +++ b/lib/Interpreter/Compatibility.h @@ -170,7 +170,7 @@ inline void maybeMangleDeclName(const clang::GlobalDecl& GD, #if defined(_WIN32) // MicrosoftMangle.cpp:954 calls llvm_unreachable when mangling Dtor_Comdat if (isa(GD.getDecl()) && - GD.getDtorType() == Dtor_Comdat) { + GD.getDtorType() == clang::Dtor_Comdat) { if (const clang::IdentifierInfo* II = D->getIdentifier()) RawStr << II->getName(); } else From ca35608ad54b3fa60ad8aff8b935ae4fe7f91643 Mon Sep 17 00:00:00 2001 From: fsfod Date: Mon, 15 Jan 2024 12:10:39 +0000 Subject: [PATCH 14/59] Fix isa compile error in Compatibility.h --- lib/Interpreter/Compatibility.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Interpreter/Compatibility.h b/lib/Interpreter/Compatibility.h index 24b9661db..ded7cbde3 100644 --- a/lib/Interpreter/Compatibility.h +++ b/lib/Interpreter/Compatibility.h @@ -16,6 +16,7 @@ #include "llvm/Config/llvm-config.h" #include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/ExecutionEngine/Orc/LLJIT.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Path.h" #ifdef USE_CLING @@ -169,7 +170,7 @@ inline void maybeMangleDeclName(const clang::GlobalDecl& GD, #if defined(_WIN32) // MicrosoftMangle.cpp:954 calls llvm_unreachable when mangling Dtor_Comdat - if (isa(GD.getDecl()) && + if (llvm::isa(GD.getDecl()) && GD.getDtorType() == clang::Dtor_Comdat) { if (const clang::IdentifierInfo* II = D->getIdentifier()) RawStr << II->getName(); From d1482685b280f4eecc0d25bcdcbc616ef35326f5 Mon Sep 17 00:00:00 2001 From: fsfod Date: Mon, 15 Jan 2024 12:11:30 +0000 Subject: [PATCH 15/59] Fix rvalue errors from LookupLibrary returning const std::string --- include/clang/Interpreter/CppInterOp.h | 2 +- lib/Interpreter/CppInterOp.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/clang/Interpreter/CppInterOp.h b/include/clang/Interpreter/CppInterOp.h index 7e1d56d07..8e5521f36 100644 --- a/include/clang/Interpreter/CppInterOp.h +++ b/include/clang/Interpreter/CppInterOp.h @@ -462,7 +462,7 @@ namespace Cpp { /// Looks up the library if access is enabled. ///\returns the path to the library. - const std::string LookupLibrary(const char *lib_name); + std::string LookupLibrary(const char* lib_name); /// Finds \c lib_stem considering the list of search paths and loads it by /// calling dlopen. diff --git a/lib/Interpreter/CppInterOp.cpp b/lib/Interpreter/CppInterOp.cpp index ad2e104c8..68c3ee578 100644 --- a/lib/Interpreter/CppInterOp.cpp +++ b/lib/Interpreter/CppInterOp.cpp @@ -2584,7 +2584,7 @@ namespace Cpp { return compat::convertTo(V); } - const std::string LookupLibrary(const char *lib_name) { + std::string LookupLibrary(const char* lib_name) { return getInterp().getDynamicLibraryManager()->lookupLibrary(lib_name); } From c211cea37abf423d4107c202b8ecc3f0c6cd504e Mon Sep 17 00:00:00 2001 From: fsfod Date: Mon, 15 Jan 2024 20:42:10 +0000 Subject: [PATCH 16/59] Move include of dlfcn.h to non windows only in CppInterOp.cpp --- lib/Interpreter/CppInterOp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Interpreter/CppInterOp.cpp b/lib/Interpreter/CppInterOp.cpp index 68c3ee578..9e2046f1c 100644 --- a/lib/Interpreter/CppInterOp.cpp +++ b/lib/Interpreter/CppInterOp.cpp @@ -30,7 +30,6 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/raw_os_ostream.h" -#include #include #include @@ -38,6 +37,7 @@ #ifdef WIN32 #include #else +#include #include #endif // WIN32 From 4dcdb75b50616cf6eb7ac60607bb7820ebd45474 Mon Sep 17 00:00:00 2001 From: fsfod Date: Mon, 15 Jan 2024 20:42:45 +0000 Subject: [PATCH 17/59] Replace dlsym with llvm::sys::DynamicLibrary::SearchForAddressOfSymbol in GetVariableOffset --- lib/Interpreter/CppInterOp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Interpreter/CppInterOp.cpp b/lib/Interpreter/CppInterOp.cpp index 9e2046f1c..5a7b52b29 100644 --- a/lib/Interpreter/CppInterOp.cpp +++ b/lib/Interpreter/CppInterOp.cpp @@ -1084,7 +1084,8 @@ namespace Cpp { auto GD = GlobalDecl(VD); std::string mangledName; compat::maybeMangleDeclName(GD, mangledName); - auto address = dlsym(/*whole_process=*/0, mangledName.c_str()); + void* address = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol( + mangledName.c_str()); auto &I = getInterp(); if (!address) address = I.getAddressOfGlobal(GD); From 1a4f9814ca81e33f234393769d2eb803ebff158a Mon Sep 17 00:00:00 2001 From: fsfod Date: Mon, 15 Jan 2024 20:43:26 +0000 Subject: [PATCH 18/59] Use llvm::sys::fs::real_path in NormalizePath instead of realpath Change clang::SmallVector to llvm::SmallVector and just set the smaller buffer size directly to 256 instead using platform defines --- lib/Interpreter/Paths.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/Interpreter/Paths.cpp b/lib/Interpreter/Paths.cpp index 1913f4540..fb3cf8a59 100644 --- a/lib/Interpreter/Paths.cpp +++ b/lib/Interpreter/Paths.cpp @@ -91,15 +91,13 @@ bool GetSystemLibraryPaths(llvm::SmallVectorImpl& Paths) { return true; } -#define PATH_MAXC (PATH_MAX+1) - std::string NormalizePath(const std::string& Path) { - char Buf[PATH_MAXC]; - if (const char* Result = ::realpath(Path.c_str(), Buf)) - return std::string(Result); - ::perror("realpath"); - return std::string(); + llvm::SmallVector Buffer; + std::error_code EC = llvm::sys::fs::real_path(Path, Buffer, true); + if (EC) + return std::string(); + return std::string(Buffer.data()); } static void DLErr(std::string* Err) { From 564b0fd56a307a105a01c69a772ec1f313403f95 Mon Sep 17 00:00:00 2001 From: fsfod Date: Tue, 16 Jan 2024 13:59:29 +0000 Subject: [PATCH 19/59] Move dlfcn.h include to be guarded on LLVM_ON_UNIX in Paths.cpp --- lib/Interpreter/Paths.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Interpreter/Paths.cpp b/lib/Interpreter/Paths.cpp index fb3cf8a59..7439949f2 100644 --- a/lib/Interpreter/Paths.cpp +++ b/lib/Interpreter/Paths.cpp @@ -17,7 +17,9 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#if defined(LLVM_ON_UNIX) #include +#endif namespace Cpp { namespace utils { From a13102fc72deea9c798a6d997c66145be37be41c Mon Sep 17 00:00:00 2001 From: fsfod Date: Tue, 16 Jan 2024 15:01:00 +0000 Subject: [PATCH 20/59] Make GetSystemLibraryPaths a nop on windows since PATH was already added by DynamicLibraryManager --- lib/Interpreter/Paths.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Interpreter/Paths.cpp b/lib/Interpreter/Paths.cpp index 7439949f2..3f5278823 100644 --- a/lib/Interpreter/Paths.cpp +++ b/lib/Interpreter/Paths.cpp @@ -65,7 +65,7 @@ bool GetSystemLibraryPaths(llvm::SmallVectorImpl& Paths) { Paths.push_back("/usr/lib64/"); Paths.push_back("/lib64/"); #endif -#else +#elif defined(LLVM_ON_UNIX) llvm::SmallString<1024> Buf; platform::Popen("LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls", Buf, true); const llvm::StringRef Result = Buf.str(); From 0eb188842146d13fd5744a4094591d236ec02bb6 Mon Sep 17 00:00:00 2001 From: fsfod Date: Tue, 16 Jan 2024 14:52:27 +0000 Subject: [PATCH 21/59] Make DyLibHandle non const so we can pass it to llvm API --- lib/Interpreter/DynamicLibraryManager.h | 2 +- lib/Interpreter/Paths.cpp | 12 ++++++------ lib/Interpreter/Paths.h | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Interpreter/DynamicLibraryManager.h b/lib/Interpreter/DynamicLibraryManager.h index bd0691239..17d95c066 100644 --- a/lib/Interpreter/DynamicLibraryManager.h +++ b/lib/Interpreter/DynamicLibraryManager.h @@ -52,7 +52,7 @@ class DynamicLibraryManager { using SearchPathInfos = llvm::SmallVector; private: - typedef const void* DyLibHandle; + typedef void* DyLibHandle; typedef llvm::DenseMap DyLibs; ///\brief DynamicLibraries loaded by this Interpreter. /// diff --git a/lib/Interpreter/Paths.cpp b/lib/Interpreter/Paths.cpp index 3f5278823..bd7972050 100644 --- a/lib/Interpreter/Paths.cpp +++ b/lib/Interpreter/Paths.cpp @@ -109,17 +109,17 @@ static void DLErr(std::string* Err) { *Err = DyLibError; } -const void* DLOpen(const std::string& Path, std::string* Err /* = nullptr */) { +void* DLOpen(const std::string& Path, std::string* Err /* = nullptr */) { void* Lib = ::dlopen(Path.c_str(), RTLD_LAZY|RTLD_GLOBAL); DLErr(Err); return Lib; } -const void* DLSym(const std::string& Name, std::string* Err /* = nullptr*/) { - if (const void* Self = ::dlopen(nullptr, RTLD_GLOBAL)) { +void* DLSym(const std::string& Name, std::string* Err /* = nullptr*/) { + if (void* Self = ::dlopen(nullptr, RTLD_GLOBAL)) { // get dlopen error if there is one DLErr(Err); - const void* Sym = ::dlsym(const_cast(Self), Name.c_str()); + void* Sym = ::dlsym(Self, Name.c_str()); // overwrite error if dlsym caused one DLErr(Err); // only get dlclose error if dlopen & dlsym haven't emited one @@ -130,8 +130,8 @@ const void* DLSym(const std::string& Name, std::string* Err /* = nullptr*/) { return nullptr; } -void DLClose(const void* Lib, std::string* Err /* = nullptr*/) { - ::dlclose(const_cast(Lib)); +void DLClose(void* Lib, std::string* Err /* = nullptr*/) { + ::dlclose(Lib); DLErr(Err); } diff --git a/lib/Interpreter/Paths.h b/lib/Interpreter/Paths.h index 8b88f560f..a0df72494 100644 --- a/lib/Interpreter/Paths.h +++ b/lib/Interpreter/Paths.h @@ -47,9 +47,9 @@ std::string NormalizePath(const std::string& Path); /// /// \returns the library handle /// -const void* DLOpen(const std::string& Path, std::string* Err = nullptr); +void* DLOpen(const std::string& Path, std::string* Err = nullptr); -const void* DLSym(const std::string& Name, std::string* Err = nullptr); +void* DLSym(const std::string& Name, std::string* Err = nullptr); ///\brief Close a handle to a shared library. /// @@ -58,7 +58,7 @@ const void* DLSym(const std::string& Name, std::string* Err = nullptr); /// /// \returns the library handle /// -void DLClose(const void* Lib, std::string* Err = nullptr); +void DLClose(void* Lib, std::string* Err = nullptr); } // namespace platform ///\brief Replace all $TOKENS in a string with environent variable values. From 36a2579f3b0fb4dec403d5cc77a2066a2ed7032a Mon Sep 17 00:00:00 2001 From: fsfod Date: Tue, 16 Jan 2024 15:02:12 +0000 Subject: [PATCH 22/59] Add windows implementations of DLOpen\DLClose using llvm's DynamicLibrary --- lib/Interpreter/Paths.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Interpreter/Paths.cpp b/lib/Interpreter/Paths.cpp index bd7972050..8ce0c6de5 100644 --- a/lib/Interpreter/Paths.cpp +++ b/lib/Interpreter/Paths.cpp @@ -13,6 +13,7 @@ #include "clang/Lex/HeaderSearchOptions.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" @@ -102,6 +103,7 @@ std::string NormalizePath(const std::string& Path) { return std::string(Buffer.data()); } +#if defined(LLVM_ON_UNIX) static void DLErr(std::string* Err) { if (!Err) return; @@ -134,6 +136,21 @@ void DLClose(void* Lib, std::string* Err /* = nullptr*/) { ::dlclose(Lib); DLErr(Err); } +#elif defined(_WIN32) + +void* DLOpen(const std::string& Path, std::string* Err /* = nullptr */) { + auto lib = llvm::sys::DynamicLibrary::getLibrary(Path.c_str(), Err); + return lib.getOSSpecificHandle(); +} + +void DLClose(void* Lib, std::string* Err /* = nullptr*/) { + auto dl = llvm::sys::DynamicLibrary(Lib); + llvm::sys::DynamicLibrary::closeLibrary(dl); + if (Err) { + *Err = std::string(); + } +} +#endif } // namespace platform From 24a93a35d9e76c741675bbcb085e703fec666e45 Mon Sep 17 00:00:00 2001 From: fsfod Date: Tue, 16 Jan 2024 18:09:25 +0000 Subject: [PATCH 23/59] Don't try link dl on windows for clangCppInterOp --- lib/Interpreter/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Interpreter/CMakeLists.txt b/lib/Interpreter/CMakeLists.txt index 028ee567d..bf47986f0 100644 --- a/lib/Interpreter/CMakeLists.txt +++ b/lib/Interpreter/CMakeLists.txt @@ -34,9 +34,12 @@ set(link_libs clangFrontend clangLex clangSema - dl ) + if(NOT WIN32) + list(APPEND link_libs dl) + endif() + # Get rid of libLLVM-X.so which is appended to the list of static libraries. if (LLVM_LINK_LLVM_DYLIB) set(new_libs ${link_libs}) From 8739e96bd76efe54abb3963bf46b9fc4eaf8d3c3 Mon Sep 17 00:00:00 2001 From: fsfod Date: Wed, 17 Jan 2024 15:48:02 +0000 Subject: [PATCH 24/59] Implement IsDLL in the same style as identify_magic --- lib/Interpreter/DynamicLibraryManager.cpp | 27 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/Interpreter/DynamicLibraryManager.cpp b/lib/Interpreter/DynamicLibraryManager.cpp index 151f33a04..6ec0e329b 100644 --- a/lib/Interpreter/DynamicLibraryManager.cpp +++ b/lib/Interpreter/DynamicLibraryManager.cpp @@ -17,6 +17,11 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#if defined(_WIN32) +#include "llvm/BinaryFormat/COFF.h" +#include "llvm/Support/Endian.h" +#endif + #include #include #include @@ -429,6 +434,21 @@ namespace Cpp { } } +#if defined(_WIN32) + static bool IsDLL(llvm::StringRef headers) { + using namespace llvm::support::endian; + + uint32_t headeroffset = read32le(headers.data() + 0x3c); + auto peheader = headers.substr(headeroffset, 24); + if (peheader.size() != 24) { + return false; + } + // Read Characteristics from the coff header + uint32_t characteristics = read16le(peheader.data() + 22); + return (characteristics & llvm::COFF::IMAGE_FILE_DLL) != 0; + } +#endif + bool DynamicLibraryManager::isSharedLibrary(StringRef libFullPath, bool* exists /*=0*/) { using namespace llvm; @@ -475,10 +495,9 @@ namespace Cpp { (Magic == file_magic::elf_shared_object) #endif #elif defined(_WIN32) - // We should only include dll libraries without including executables, - // object code and others... - (Magic == file_magic::pecoff_executable && - platform::IsDLL(libFullPath.str())) + // We should only include dll libraries without including executables, + // object code and others... + (Magic == file_magic::pecoff_executable && IsDLL(headerStr)) #else # error "Unsupported platform." #endif From ec83a7cdfd0c698b5ea888af6924caef5602e950 Mon Sep 17 00:00:00 2001 From: fsfod Date: Wed, 17 Jan 2024 15:50:37 +0000 Subject: [PATCH 25/59] Only declare Popen in Paths.cpp for LLVM_ON_UNIX --- lib/Interpreter/Paths.cpp | 77 ++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/lib/Interpreter/Paths.cpp b/lib/Interpreter/Paths.cpp index 8ce0c6de5..97e75e3f2 100644 --- a/lib/Interpreter/Paths.cpp +++ b/lib/Interpreter/Paths.cpp @@ -34,24 +34,27 @@ namespace platform { #error "Unknown platform (environmental delimiter)" #endif -bool Popen(const std::string& Cmd, llvm::SmallVectorImpl& Buf, bool RdE) { - if (FILE *PF = ::popen(RdE ? (Cmd + " 2>&1").c_str() : Cmd.c_str(), "r")) { - Buf.resize(0); - const size_t Chunk = Buf.capacity_in_bytes(); - while (true) { - const size_t Len = Buf.size(); - Buf.resize(Len + Chunk); - const size_t R = ::fread(&Buf[Len], sizeof(char), Chunk, PF); - if (R < Chunk) { - Buf.resize(Len + R); - break; +#if defined(LLVM_ON_UNIX) + bool Popen(const std::string& Cmd, llvm::SmallVectorImpl& Buf, + bool RdE) { + if (FILE* PF = ::popen(RdE ? (Cmd + " 2>&1").c_str() : Cmd.c_str(), "r")) { + Buf.resize(0); + const size_t Chunk = Buf.capacity_in_bytes(); + while (true) { + const size_t Len = Buf.size(); + Buf.resize(Len + Chunk); + const size_t R = ::fread(&Buf[Len], sizeof(char), Chunk, PF); + if (R < Chunk) { + Buf.resize(Len + R); + break; + } } + ::pclose(PF); + return !Buf.empty(); } - ::pclose(PF); - return !Buf.empty(); - } - return false; + return false; } +#endif bool GetSystemLibraryPaths(llvm::SmallVectorImpl& Paths) { #if defined(__APPLE__) || defined(__CYGWIN__) @@ -67,29 +70,29 @@ bool GetSystemLibraryPaths(llvm::SmallVectorImpl& Paths) { Paths.push_back("/lib64/"); #endif #elif defined(LLVM_ON_UNIX) - llvm::SmallString<1024> Buf; - platform::Popen("LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls", Buf, true); - const llvm::StringRef Result = Buf.str(); - - const std::size_t NPos = std::string::npos; - const std::size_t LD = Result.find("(LD_LIBRARY_PATH)"); - std::size_t From = Result.find("search path=", LD == NPos ? 0 : LD); - if (From != NPos) { - std::size_t To = Result.find("(system search path)", From); - if (To != NPos) { - From += 12; - while (To > From && isspace(Result[To - 1])) - --To; - std::string SysPath = Result.substr(From, To-From).str(); - SysPath.erase(std::remove_if(SysPath.begin(), SysPath.end(), ::isspace), - SysPath.end()); - - llvm::SmallVector CurPaths; - SplitPaths(SysPath, CurPaths); - for (const auto& Path : CurPaths) - Paths.push_back(Path.str()); + llvm::SmallString<1024> Buf; + platform::Popen("LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls", Buf, true); + const llvm::StringRef Result = Buf.str(); + + const std::size_t NPos = std::string::npos; + const std::size_t LD = Result.find("(LD_LIBRARY_PATH)"); + std::size_t From = Result.find("search path=", LD == NPos ? 0 : LD); + if (From != NPos) { + std::size_t To = Result.find("(system search path)", From); + if (To != NPos) { + From += 12; + while (To > From && isspace(Result[To - 1])) + --To; + std::string SysPath = Result.substr(From, To - From).str(); + SysPath.erase(std::remove_if(SysPath.begin(), SysPath.end(), ::isspace), + SysPath.end()); + + llvm::SmallVector CurPaths; + SplitPaths(SysPath, CurPaths); + for (const auto& Path : CurPaths) + Paths.push_back(Path.str()); + } } - } #endif return true; } From 8251a19d3bb0f213ab54e01c4c0cc1cae1f10acf Mon Sep 17 00:00:00 2001 From: fsfod Date: Wed, 17 Jan 2024 23:00:37 +0000 Subject: [PATCH 26/59] Fix unit tests failing because NormalizePath was not using SmallString for fs::real_path output --- lib/Interpreter/Paths.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/Interpreter/Paths.cpp b/lib/Interpreter/Paths.cpp index 97e75e3f2..292d9e0d5 100644 --- a/lib/Interpreter/Paths.cpp +++ b/lib/Interpreter/Paths.cpp @@ -53,22 +53,22 @@ namespace platform { return !Buf.empty(); } return false; -} + } #endif -bool GetSystemLibraryPaths(llvm::SmallVectorImpl& Paths) { + bool GetSystemLibraryPaths(llvm::SmallVectorImpl& Paths) { #if defined(__APPLE__) || defined(__CYGWIN__) - Paths.push_back("/usr/local/lib/"); - Paths.push_back("/usr/X11R6/lib/"); - Paths.push_back("/usr/lib/"); - Paths.push_back("/lib/"); - - #ifndef __APPLE__ - Paths.push_back("/lib/x86_64-linux-gnu/"); - Paths.push_back("/usr/local/lib64/"); - Paths.push_back("/usr/lib64/"); - Paths.push_back("/lib64/"); - #endif + Paths.push_back("/usr/local/lib/"); + Paths.push_back("/usr/X11R6/lib/"); + Paths.push_back("/usr/lib/"); + Paths.push_back("/lib/"); + +#ifndef __APPLE__ + Paths.push_back("/lib/x86_64-linux-gnu/"); + Paths.push_back("/usr/local/lib64/"); + Paths.push_back("/usr/lib64/"); + Paths.push_back("/lib64/"); +#endif #elif defined(LLVM_ON_UNIX) llvm::SmallString<1024> Buf; platform::Popen("LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls", Buf, true); @@ -94,16 +94,16 @@ bool GetSystemLibraryPaths(llvm::SmallVectorImpl& Paths) { } } #endif - return true; + return true; } std::string NormalizePath(const std::string& Path) { - llvm::SmallVector Buffer; + llvm::SmallString<256> Buffer; std::error_code EC = llvm::sys::fs::real_path(Path, Buffer, true); if (EC) return std::string(); - return std::string(Buffer.data()); + return std::string(Buffer.str()); } #if defined(LLVM_ON_UNIX) From 521f2fd12dd5809285a927f5426c0645f710e98b Mon Sep 17 00:00:00 2001 From: fsfod Date: Thu, 18 Jan 2024 00:52:47 +0000 Subject: [PATCH 27/59] Define STDOUT_FILENO to 1 for windows if not already defined --- lib/Interpreter/CppInterOp.cpp | 3 +++ lib/Interpreter/Paths.cpp | 46 +++++++++++++++++----------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/Interpreter/CppInterOp.cpp b/lib/Interpreter/CppInterOp.cpp index 5a7b52b29..fbdb01041 100644 --- a/lib/Interpreter/CppInterOp.cpp +++ b/lib/Interpreter/CppInterOp.cpp @@ -36,6 +36,9 @@ // Stream redirect. #ifdef WIN32 #include +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif #else #include #include diff --git a/lib/Interpreter/Paths.cpp b/lib/Interpreter/Paths.cpp index 292d9e0d5..014e3bcd5 100644 --- a/lib/Interpreter/Paths.cpp +++ b/lib/Interpreter/Paths.cpp @@ -95,23 +95,23 @@ namespace platform { } #endif return true; -} + } -std::string NormalizePath(const std::string& Path) { + std::string NormalizePath(const std::string& Path) { - llvm::SmallString<256> Buffer; - std::error_code EC = llvm::sys::fs::real_path(Path, Buffer, true); - if (EC) - return std::string(); - return std::string(Buffer.str()); -} + llvm::SmallString<256> Buffer; + std::error_code EC = llvm::sys::fs::real_path(Path, Buffer, true); + if (EC) + return std::string(); + return std::string(Buffer.str()); + } #if defined(LLVM_ON_UNIX) -static void DLErr(std::string* Err) { - if (!Err) - return; - if (const char* DyLibError = ::dlerror()) - *Err = DyLibError; + static void DLErr(std::string* Err) { + if (!Err) + return; + if (const char* DyLibError = ::dlerror()) + *Err = DyLibError; } void* DLOpen(const std::string& Path, std::string* Err /* = nullptr */) { @@ -141,18 +141,18 @@ void DLClose(void* Lib, std::string* Err /* = nullptr*/) { } #elif defined(_WIN32) -void* DLOpen(const std::string& Path, std::string* Err /* = nullptr */) { - auto lib = llvm::sys::DynamicLibrary::getLibrary(Path.c_str(), Err); - return lib.getOSSpecificHandle(); -} + void* DLOpen(const std::string& Path, std::string* Err /* = nullptr */) { + auto lib = llvm::sys::DynamicLibrary::getLibrary(Path.c_str(), Err); + return lib.getOSSpecificHandle(); + } -void DLClose(void* Lib, std::string* Err /* = nullptr*/) { - auto dl = llvm::sys::DynamicLibrary(Lib); - llvm::sys::DynamicLibrary::closeLibrary(dl); - if (Err) { - *Err = std::string(); + void DLClose(void* Lib, std::string* Err /* = nullptr*/) { + auto dl = llvm::sys::DynamicLibrary(Lib); + llvm::sys::DynamicLibrary::closeLibrary(dl); + if (Err) { + *Err = std::string(); + } } -} #endif } // namespace platform From f76275f45e9b7c2b6417c3dc8382725e7163d57a Mon Sep 17 00:00:00 2001 From: fsfod Date: Thu, 18 Jan 2024 00:55:08 +0000 Subject: [PATCH 28/59] Fix git apply patch command in README.md --- README.md | 2 +- lib/Interpreter/Paths.cpp | 44 +++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index e850bd421..05b8f90f4 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ cd llvm-project ``` Get the following patches required for development work. To apply these patches on Linux and MacOS execute the following command ``` -git apply -v ..\patches\llvm\clang${{ matrix.clang-runtime }}-*.patch +git apply -v .../patches/llvm/clang17-*.patch ``` and ``` diff --git a/lib/Interpreter/Paths.cpp b/lib/Interpreter/Paths.cpp index 014e3bcd5..1a5abbd27 100644 --- a/lib/Interpreter/Paths.cpp +++ b/lib/Interpreter/Paths.cpp @@ -112,33 +112,33 @@ namespace platform { return; if (const char* DyLibError = ::dlerror()) *Err = DyLibError; -} - -void* DLOpen(const std::string& Path, std::string* Err /* = nullptr */) { - void* Lib = ::dlopen(Path.c_str(), RTLD_LAZY|RTLD_GLOBAL); - DLErr(Err); - return Lib; -} + } -void* DLSym(const std::string& Name, std::string* Err /* = nullptr*/) { - if (void* Self = ::dlopen(nullptr, RTLD_GLOBAL)) { - // get dlopen error if there is one + void* DLOpen(const std::string& Path, std::string* Err /* = nullptr */) { + void* Lib = ::dlopen(Path.c_str(), RTLD_LAZY | RTLD_GLOBAL); DLErr(Err); - void* Sym = ::dlsym(Self, Name.c_str()); - // overwrite error if dlsym caused one + return Lib; + } + + void* DLSym(const std::string& Name, std::string* Err /* = nullptr*/) { + if (void* Self = ::dlopen(nullptr, RTLD_GLOBAL)) { + // get dlopen error if there is one + DLErr(Err); + void* Sym = ::dlsym(Self, Name.c_str()); + // overwrite error if dlsym caused one + DLErr(Err); + // only get dlclose error if dlopen & dlsym haven't emited one + DLClose(Self, Err && Err->empty() ? Err : nullptr); + return Sym; + } DLErr(Err); - // only get dlclose error if dlopen & dlsym haven't emited one - DLClose(Self, Err && Err->empty() ? Err : nullptr); - return Sym; + return nullptr; } - DLErr(Err); - return nullptr; -} -void DLClose(void* Lib, std::string* Err /* = nullptr*/) { - ::dlclose(Lib); - DLErr(Err); -} + void DLClose(void* Lib, std::string* Err /* = nullptr*/) { + ::dlclose(Lib); + DLErr(Err); + } #elif defined(_WIN32) void* DLOpen(const std::string& Path, std::string* Err /* = nullptr */) { From d1021ba1f85dede0368f6ca60a6e7bd27ac786e5 Mon Sep 17 00:00:00 2001 From: fsfod Date: Thu, 18 Jan 2024 18:08:15 +0000 Subject: [PATCH 29/59] Only link pthread for unit tests on non windows platforms --- unittests/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index ac0a20bbc..b99747d1c 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -24,8 +24,11 @@ function(add_cppinterop_unittest name) target_include_directories(${name} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${GTEST_INCLUDE_DIR}) set_property(TARGET ${name} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +if(WIN32) + target_link_libraries(${name} PUBLIC ${ARG_LIBRARIES} ${gtest_libs}) +else() target_link_libraries(${name} PUBLIC ${ARG_LIBRARIES} ${gtest_libs} pthread) - +endif() add_test(NAME cppinterop-${name} COMMAND ${name}) set_tests_properties(cppinterop-${name} PROPERTIES TIMEOUT "${TIMEOUT_VALUE}" From 7aeec37b16c7b465ee37abf5925caba6bf5b7033 Mon Sep 17 00:00:00 2001 From: fsfod Date: Thu, 18 Jan 2024 19:59:04 +0000 Subject: [PATCH 30/59] Fix gtest library link paths on windows --- cmake/modules/GoogleTest.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/modules/GoogleTest.cmake b/cmake/modules/GoogleTest.cmake index a56aa93d8..fcc7b363b 100644 --- a/cmake/modules/GoogleTest.cmake +++ b/cmake/modules/GoogleTest.cmake @@ -59,7 +59,11 @@ file(MAKE_DIRECTORY ${GTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR}) # Libraries ExternalProject_Get_Property(googletest binary_dir) -set(_G_LIBRARY_PATH ${binary_dir}/lib/) +if(WIN32) + set(_G_LIBRARY_PATH ${_gtest_byproduct_binary_dir}/lib) +else() + set(_G_LIBRARY_PATH ${binary_dir}/lib/) +endif() # Use gmock_main instead of gtest_main because it initializes gtest as well. # Note: The libraries are listed in reverse order of their dependancies. From dcbd816850f7b5fb8eb4cea34e4ef8b1c743459a Mon Sep 17 00:00:00 2001 From: fsfod Date: Thu, 18 Jan 2024 20:07:32 +0000 Subject: [PATCH 31/59] Fix TestSharedLib not exporting ret_zero on windows --- unittests/CppInterOp/TestSharedLib/TestSharedLib.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/unittests/CppInterOp/TestSharedLib/TestSharedLib.h b/unittests/CppInterOp/TestSharedLib/TestSharedLib.h index 41fe7f758..65b1d2fde 100644 --- a/unittests/CppInterOp/TestSharedLib/TestSharedLib.h +++ b/unittests/CppInterOp/TestSharedLib/TestSharedLib.h @@ -1,7 +1,11 @@ #ifndef UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H #define UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H -// Avoid having to mangle/demangle the symbol name in tests. +// Avoid having to mangle/demangle the symbol name in tests +#ifdef WIN32 +extern "C" __declspec(dllexport) int ret_zero(); +#else extern "C" int ret_zero(); +#endif #endif // UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H From 6bd096fe20ab29726910bef27b63d85be26f08cc Mon Sep 17 00:00:00 2001 From: fsfod Date: Fri, 19 Jan 2024 15:44:33 +0000 Subject: [PATCH 32/59] Don't use BUILD_SHARED_LIB for windows --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7f230997..5861fd0bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -666,7 +666,7 @@ jobs: -DUSE_REPL=OFF ` -DCling_DIR="$env:LLVM_BUILD_DIR\tools\cling" ` -DLLVM_DIR="$env:LLVM_BUILD_DIR" ` - -DClang_DIR="$env:LLVM_BUILD_DIR" -DBUILD_SHARED_LIBS=ON -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} -DCMAKE_INSTALL_PREFIX="$env:CPPINTEROP_DIR" ..\ + -DClang_DIR="$env:LLVM_BUILD_DIR" -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} -DCMAKE_INSTALL_PREFIX="$env:CPPINTEROP_DIR" ..\ } else { @@ -674,7 +674,7 @@ jobs: -DUSE_CLING=OFF ` -DUSE_REPL=ON ` -DLLVM_DIR="$env:LLVM_BUILD_DIR\lib\cmake\llvm" ` - -DClang_DIR="$env:LLVM_BUILD_DIR\lib\cmake\clang" -DBUILD_SHARED_LIBS=ON -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} -DCMAKE_INSTALL_PREFIX="$env:CPPINTEROP_DIR" ..\ + -DClang_DIR="$env:LLVM_BUILD_DIR\lib\cmake\clang" -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} -DCMAKE_INSTALL_PREFIX="$env:CPPINTEROP_DIR" ..\ } cmake --build . --target check-cppinterop --parallel ${{ env.ncpus }} cd .. From 66d3a313da700f18444ed4f88fe50ab7cd3bd193 Mon Sep 17 00:00:00 2001 From: fsfod Date: Fri, 19 Jan 2024 17:34:23 +0000 Subject: [PATCH 33/59] Set an build config to run tests since VS is multi-config generator --- unittests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index b99747d1c..ad8337661 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -40,7 +40,7 @@ endfunction() add_subdirectory(CppInterOp) -add_custom_target(check-cppinterop COMMAND ${CMAKE_CTEST_COMMAND} -V +add_custom_target(check-cppinterop COMMAND ${CMAKE_CTEST_COMMAND} -V --build-config $ DEPENDS CppInterOpUnitTests WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_target_properties(check-cppinterop PROPERTIES FOLDER "CppInterOp tests") From 79931138764b42435199050d3ca9dc268df49e7b Mon Sep 17 00:00:00 2001 From: fsfod Date: Fri, 19 Jan 2024 18:12:27 +0000 Subject: [PATCH 34/59] Don't build gtest with different runtime library type/build config on windows --- cmake/modules/GoogleTest.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/modules/GoogleTest.cmake b/cmake/modules/GoogleTest.cmake index fcc7b363b..50d69bfaa 100644 --- a/cmake/modules/GoogleTest.cmake +++ b/cmake/modules/GoogleTest.cmake @@ -7,14 +7,16 @@ set(_gtest_byproducts ${_gtest_byproduct_binary_dir}/lib/libgmock_main.a ) +set(gtestbuild "Release") if(MSVC) + set(gtestbuild $) set(EXTRA_GTEST_OPTS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=${_gtest_byproduct_binary_dir}/lib/ -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL:PATH=${_gtest_byproduct_binary_dir}/lib/ -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=${_gtest_byproduct_binary_dir}/lib/ -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO:PATH=${_gtest_byproduct_binary_dir}/lib/ -Dgtest_force_shared_crt=ON - BUILD_COMMAND ${CMAKE_COMMAND} --build --config Release) + BUILD_COMMAND ${CMAKE_COMMAND} --build --config $) elseif(APPLE) set(EXTRA_GTEST_OPTS -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}) endif() @@ -32,7 +34,7 @@ ExternalProject_Add( # -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs # -Dgtest_force_shared_crt=ON CMAKE_ARGS -G ${CMAKE_GENERATOR} - -DCMAKE_BUILD_TYPE=Release + -DCMAKE_BUILD_TYPE=${gtestbuild} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} From c0082394122a6d7e64af23180ab41dcfde1ba1a3 Mon Sep 17 00:00:00 2001 From: fsfod Date: Fri, 19 Jan 2024 18:34:01 +0000 Subject: [PATCH 35/59] Just build gtest using the current config on all platforms --- cmake/modules/GoogleTest.cmake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmake/modules/GoogleTest.cmake b/cmake/modules/GoogleTest.cmake index 50d69bfaa..c2d3fffba 100644 --- a/cmake/modules/GoogleTest.cmake +++ b/cmake/modules/GoogleTest.cmake @@ -7,9 +7,7 @@ set(_gtest_byproducts ${_gtest_byproduct_binary_dir}/lib/libgmock_main.a ) -set(gtestbuild "Release") if(MSVC) - set(gtestbuild $) set(EXTRA_GTEST_OPTS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=${_gtest_byproduct_binary_dir}/lib/ -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL:PATH=${_gtest_byproduct_binary_dir}/lib/ @@ -34,7 +32,7 @@ ExternalProject_Add( # -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs # -Dgtest_force_shared_crt=ON CMAKE_ARGS -G ${CMAKE_GENERATOR} - -DCMAKE_BUILD_TYPE=${gtestbuild} + -DCMAKE_BUILD_TYPE=$ -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} From bf29fcd56f12e7a7f62d8ebd7284f437629b43f1 Mon Sep 17 00:00:00 2001 From: fsfod Date: Fri, 19 Jan 2024 20:34:59 +0000 Subject: [PATCH 36/59] Make the DynamicLibraryManagerTests pass --- unittests/CppInterOp/CMakeLists.txt | 2 ++ unittests/CppInterOp/DynamicLibraryManagerTest.cpp | 3 ++- unittests/CppInterOp/TestSharedLib/CMakeLists.txt | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/unittests/CppInterOp/CMakeLists.txt b/unittests/CppInterOp/CMakeLists.txt index 7ca5e5dfa..75dccf556 100644 --- a/unittests/CppInterOp/CMakeLists.txt +++ b/unittests/CppInterOp/CMakeLists.txt @@ -28,6 +28,8 @@ target_link_libraries(DynamicLibraryManagerTests clangCppInterOp ) +set_output_directory(DynamicLibraryManagerTests BINARY_DIR ${CMAKE_BINARY_DIR}/unittests/bin/$/) + add_dependencies(DynamicLibraryManagerTests TestSharedLib) #export_executable_symbols_for_plugins(TestSharedLib) add_subdirectory(TestSharedLib) diff --git a/unittests/CppInterOp/DynamicLibraryManagerTest.cpp b/unittests/CppInterOp/DynamicLibraryManagerTest.cpp index d9dc7b35c..01624ef78 100644 --- a/unittests/CppInterOp/DynamicLibraryManagerTest.cpp +++ b/unittests/CppInterOp/DynamicLibraryManagerTest.cpp @@ -41,7 +41,8 @@ TEST(DynamicLibraryManagerTest, Sanity) { << "'"; EXPECT_TRUE(Cpp::LoadLibrary(PathToTestSharedLib.c_str())); - + // Force ExecutionEngine to be created. + Cpp::Process(""); // FIXME: Conda returns false to run this code on osx. #ifndef __APPLE__ EXPECT_TRUE(Cpp::GetFunctionAddress("ret_zero")); diff --git a/unittests/CppInterOp/TestSharedLib/CMakeLists.txt b/unittests/CppInterOp/TestSharedLib/CMakeLists.txt index 0c5d45818..9fbf2296c 100644 --- a/unittests/CppInterOp/TestSharedLib/CMakeLists.txt +++ b/unittests/CppInterOp/TestSharedLib/CMakeLists.txt @@ -5,7 +5,7 @@ add_llvm_library(TestSharedLib TestSharedLib.cpp) # Put TestSharedLib next to the unit test executable. set_output_directory(TestSharedLib - BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../ - LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../ + BINARY_DIR ${CMAKE_BINARY_DIR}/unittests/bin/$/ + LIBRARY_DIR ${CMAKE_BINARY_DIR}/unittests/bin/$/ ) set_target_properties(TestSharedLib PROPERTIES FOLDER "Tests") From 7b9c2a331f0cc026afd1bd200e85f5f22da47aff Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Sat, 20 Jan 2024 18:41:39 +0000 Subject: [PATCH 37/59] Update README.md build instructions to fix typos and mistakes --- README.md | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 05b8f90f4..f65cb84f5 100644 --- a/README.md +++ b/README.md @@ -58,11 +58,11 @@ goals of CppInterOp is to stay backward compatible and be adopted in the High framework. Over time, parts of the Root framework can be swapped by this API, adding speed and resilience with it. -### Build Instructions for Unix Systems +### Build Instructions (Includes instructions both Unix systems and Windows) Build instructions for CppInterOp and its dependencies are as follows. CppInterOP can be built with either Cling and Clang-REPL, so instructions will differ slightly depending on which option you would like to build, but should be clear from the section title which instructions to follow. #### Clone CppInterOp and cppyy-backend -First clone the CppInterOp repository, as this contains patches that need to be applied to the subsequently cloned llvm-project repo (if building CppInterOP with Clang-REPL) +First clone the CppInterOp repository, as this contains patches that need to be applied to the subsequently cloned llvm-project repo (these patches are only applied if building CppInterOp with Clang-REPL) ``` git clone --depth=1 https://github.com/compiler-research/CppInterOp.git ``` @@ -79,21 +79,22 @@ cd llvm-project ``` Get the following patches required for development work. To apply these patches on Linux and MacOS execute the following command ``` -git apply -v .../patches/llvm/clang17-*.patch +git apply -v ../CppInterOp/patches/llvm/clang17-*.patch ``` and ``` -cp -r ..\patches\llvm\clang17* +cp -r ..\CppInterOp\patches\llvm\clang17* . git apply -v clang17-1-NewOperator.patch ``` on Windows. + ##### Build Clang-REPL Clang-REPL is an interpreter that CppInterOp works alongside. Build Clang (and Clang-REPL along with it). On Linux and MaxOS you do this by executing the following command ``` -mkdir build \ -cd build \ +mkdir build +cd build cmake -DLLVM_ENABLE_PROJECTS=clang \ -DLLVM_TARGETS_TO_BUILD="host;NVPTX" \ -DCMAKE_BUILD_TYPE=Release \ @@ -109,8 +110,8 @@ cmake --build . --target clang clang-repl --parallel $(nproc --all) On Windows you would do this by executing the following ``` $env:ncpus = %NUMBER_OF_PROCESSORS% -mkdir build ` -cd build ` +mkdir build +cd build cmake -DLLVM_ENABLE_PROJECTS=clang ` -DLLVM_TARGETS_TO_BUILD="host;NVPTX" ` -DCMAKE_BUILD_TYPE=Release ` @@ -119,7 +120,7 @@ cmake -DLLVM_ENABLE_PROJECTS=clang ` -DCLANG_ENABLE_ARCMT=OFF ` -DCLANG_ENABLE_FORMAT=OFF ` -DCLANG_ENABLE_BOOTSTRAP=OFF ` - ../llvm + ..\llvm cmake --build . --target clang clang-repl --parallel $env:ncpus ``` Note the 'llvm-project' directory location. On linux and MacOS you execute the following @@ -142,6 +143,9 @@ hosted under the `root-project` (see the git path below). Use the following build instructions to build on Linux and MacOS ``` git clone --depth=1 https://github.com/root-project/cling.git +cd ./cling/ +git checkout tags/v1.0 +cd .. git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git mkdir llvm-project/build cd llvm-project/build @@ -164,6 +168,9 @@ cmake --build . --target gtest_main --parallel $(nproc --all) Use the following build instructions to build on Windows ``` git clone --depth=1 https://github.com/root-project/cling.git +cd .\cling\ +git checkout tags/v1.0 +cd .. git clone --depth=1 -b cling-llvm13 https://github.com/root-project/llvm-project.git $env:ncpus = %NUMBER_OF_PROCESSORS% $env:PWD_DIR= $PWD.Path @@ -183,7 +190,6 @@ cmake -DLLVM_ENABLE_PROJECTS=clang ` ../llvm cmake --build . --target clang --parallel $env:ncpus cmake --build . --target cling --parallel $env:ncpus -# Now build gtest.a and gtest_main for CppInterOp to run its tests. cmake --build . --target gtest_main --parallel $env:ncpus ``` Note the 'llvm-project' directory location. On linux and MacOS you execute the following @@ -233,22 +239,22 @@ cd CppInterOp\build\ Now if you want to build CppInterOp with Clang-REPL then execute the following commands on Linux and MacOS ``` -cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=Off -DUSE_REPL=ON -DCling_DIR=$LLVM_DIR/build -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR .. +cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=Off -DUSE_REPL=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) ``` and ``` -cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=Off -DUSE_REPL=ON -DCling_DIR=$LLVM_DIR\build -DCMAKE_INSTALL_PREFIX=$env:CPPINTEROP_DIR .. +cmake -DUSE_CLING=Off -DUSE_REPL=ON -DLLVM_DIR=$LLVM_DIR\build\lib\cmake\llvm -DClang_DIR=$LLVM_DIR\build\lib\cmake\clang -DCMAKE_INSTALL_PREFIX=$env:CPPINTEROP_DIR .. cmake --build . --target install --parallel $env:ncpus ``` on Windows. If alternatively you would like to install CppInterOp with Cling then execute the following commands on Linux and MacOS ``` -cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=ON -DUSE_REPL=Off -DCling_DIR=$LLVM_DIR/build -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR .. +cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=ON -DUSE_REPL=Off -DCling_DIR=$LLVM_DIR/build/tools/cling -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) ``` and ``` -cmake -DBUILD_SHARED_LIBS=ON -DUSE_CLING=ON -DUSE_REPL=Off -DCling_DIR=$LLVM_DIR\build -DCMAKE_INSTALL_PREFIX=$env:CPPINTEROP_DIR .. +cmake -DUSE_CLING=ON -DUSE_REPL=Off -DCling_DIR=$LLVM_DIR\build\tools\cling -DLLVM_DIR=$LLVM_DIR\build\lib\cmake\llvm -DClang_DIR=$LLVM_DIR\build\lib\cmake\clang -DCMAKE_INSTALL_PREFIX=$env:CPPINTEROP_DIR .. cmake --build . --target install --parallel $env:ncpus ``` @@ -276,7 +282,6 @@ on Windows. Now you are in a position to install cppyy following the instruction Clone the repo, build it and copy library files into `python/cppyy-backend` directory: ``` -git clone --depth=1 https://github.com/compiler-research/cppyy-backend.git cd cppyy-backend mkdir -p python/cppyy_backend/lib build cd build From 240f6a6181a35c7c5c2caa6023bcccb88fbba6e6 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Sat, 20 Jan 2024 21:36:03 +0200 Subject: [PATCH 38/59] Specify the build configuration when building on Windows The windows cache artifacts are bigger than the unix ones. This is likely because when building on windows we always need to specify the build configuration. --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5861fd0bb..a15122929 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -501,10 +501,10 @@ jobs: -DCLANG_ENABLE_FORMAT=OFF ` -DCLANG_ENABLE_BOOTSTRAP=OFF ` ../llvm - cmake --build . --target clang --parallel ${{ env.ncpus }} - cmake --build . --target cling --parallel ${{ env.ncpus }} + cmake --build . --config Release --target clang --parallel ${{ env.ncpus }} + cmake --build . --config Release --target cling --parallel ${{ env.ncpus }} # Now build gtest.a and gtest_main for CppInterOp to run its tests. - cmake --build . --target gtest_main --parallel ${{ env.ncpus }} + cmake --build . --config Release --target gtest_main --parallel ${{ env.ncpus }} } else { @@ -532,7 +532,7 @@ jobs: -DCLANG_ENABLE_FORMAT=OFF ` -DCLANG_ENABLE_BOOTSTRAP=OFF ` ../llvm - cmake --build . --target clang clang-repl --parallel ${{ env.ncpus }} + cmake --build . --config Release --target clang clang-repl --parallel ${{ env.ncpus }} } cd ../../ @@ -676,7 +676,7 @@ jobs: -DLLVM_DIR="$env:LLVM_BUILD_DIR\lib\cmake\llvm" ` -DClang_DIR="$env:LLVM_BUILD_DIR\lib\cmake\clang" -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} -DCMAKE_INSTALL_PREFIX="$env:CPPINTEROP_DIR" ..\ } - cmake --build . --target check-cppinterop --parallel ${{ env.ncpus }} + cmake --build . --config ${{ env.BUILD_TYPE }} --target check-cppinterop --parallel ${{ env.ncpus }} cd .. - name: Build and Install cppyy-backend on Unix Systems From 5225d17ba48bf3d2b84bb1aa7811099bdf84fcd4 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Sun, 21 Jan 2024 18:59:05 +0000 Subject: [PATCH 39/59] [ci] Allow rerunning gh actions with debug logging. In this case we open an ssh session for 30 mins. --- .github/workflows/ci.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a15122929..85df2cb12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -781,16 +781,12 @@ jobs: tail -n1 test_xfailed.log echo "Return Code: ${RETCODE}" exit $RETCODE + - name: Show debug info - if: ${{ failure() }} + if: ${{ failure() && (runner.os != 'windows') }} run: | export echo $GITHUB_ENV - - name: Setup tmate session - if: ${{ failure() }} - uses: mxschmitt/action-tmate@v3 - # When debugging increase to a suitable value! - timeout-minutes: ${{ github.event.pull_request && 1 || 20 }} - name: Prepare code coverage report if: ${{ success() && (matrix.coverage == true) }} @@ -808,3 +804,9 @@ jobs: uses: codecov/codecov-action@v3 with: file: ./coverage.info + + - name: Setup tmate session + if: ${{ failure() && runner.debug }} + uses: mxschmitt/action-tmate@v3 + # When debugging increase to a suitable value! + timeout-minutes: 30 From e16be69b99db4a6bc966277370ff716802c37050 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Sun, 21 Jan 2024 19:48:04 +0000 Subject: [PATCH 40/59] [ci] Quote the github.event.number which can be empty when it's not a PR. This should fix our cache upload problems on the main branch. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85df2cb12..4c656f606 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -266,7 +266,7 @@ jobs: #FIXME: CLING AND LLVM HASH currently hardcoded until windows equivalent of unix commands #can be found mkdir ./pr - echo ${{ github.event.number }} > ./pr/NR + echo "${{ github.event.number }}" > ./pr/NR echo ${{ github.repository }} > ./pr/REPO if ( "${{ matrix.cling }}" -imatch "On" ) From 6ed1c1b0b6d347bc97d2d7280c211caef111b02f Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Sun, 21 Jan 2024 20:36:41 +0000 Subject: [PATCH 41/59] Fix exporting variables for Windows. --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c656f606..2faa961b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -306,8 +306,8 @@ jobs: - name: Setup default Build Type on Windows if: runner.os == 'windows' run: | - echo "BUILD_TYPE=Release" >> $GITHUB_ENV - echo "CODE_COVERAGE=0" >> $GITHUB_ENV + echo "BUILD_TYPE=Release" >> $env:GITHUB_ENV + echo "CODE_COVERAGE=0" >> $env:GITHUB_ENV echo "ncpus=%NUMBER_OF_PROCESSORS%" echo "ncpus=%NUMBER_OF_PROCESSORS%" >> $GITHUB_ENV From 206251c15564a8a58818ae84ebbbd623f9d22d65 Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Fri, 26 Jan 2024 08:57:56 +0000 Subject: [PATCH 42/59] Add xeus-clang-repl build to ci (#189) --- .github/workflows/ci.yml | 195 ++++++++++++++++++++++++++++++++++++--- README.md | 6 +- 2 files changed, 185 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2faa961b4..2ff6497c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,14 @@ jobs: cling: Off cppyy: On coverage: true + - name: ubu22-x86-gcc12-clang-repl-17-xeus-clang-repl + os: ubuntu-22.04 + compiler: gcc-12 + clang-runtime: '17' + cling: Off + cppyy: On + xeus-clang-repl: On + coverage: true - name: ubu22-x86-gcc9-clang-repl-16 os: ubuntu-22.04 compiler: gcc-9 @@ -49,6 +57,14 @@ jobs: cling: Off cppyy: On coverage: true + - name: ubu22-x86-gcc9-clang-repl-16-xeus-clang-repl + os: ubuntu-22.04 + compiler: gcc-9 + clang-runtime: '16' + cling: Off + cppyy: On + xeus-clang-repl: On + coverage: true - name: ubu22-x86-gcc9-clang13-cling os: ubuntu-22.04 compiler: gcc-9 @@ -65,6 +81,15 @@ jobs: cling-version: '1.0' cppyy: On coverage: true + - name: ubu22-x86-gcc9-clang13-cling-xeus-clang-repl + os: ubuntu-22.04 + compiler: gcc-9 + clang-runtime: '13' + cling: On + cling-version: '1.0' + cppyy: On + xeus-clang-repl: On + coverage: true #Commented out until Ubuntu on arm Github runner becomes available #os key to be replaced once known #- name: ubu22-arm-gcc12-clang-repl-17 @@ -79,6 +104,13 @@ jobs: # clang-runtime: '17' # cling: Off # cppyy: On + #- name: ubu22-arm-gcc12-clang-repl-17-xeus-clang-repl + # os: ubuntu-22.04-arm + # compiler: gcc-12 + # clang-runtime: '17' + # cling: Off + # cppyy: On + # xeus-clang-repl: On #- name: ubu22-arm-gcc9-clang-repl-16 # os: ubuntu-22.04-arm # compiler: gcc-9 @@ -93,6 +125,13 @@ jobs: # cling: Off # cppyy: On # coverage: true + #- name: ubu22-arm-gcc9-clang-repl-16-xeus-clang-repl + # os: ubuntu-22.04-arm + # compiler: gcc-9 + # clang-runtime: '16' + # cling: Off + # cppyy: On + # xeus-clang-repl: On #- name: ubu22-arm-gcc9-clang13-cling # os: ubuntu-22.04-arm # compiler: gcc-9 @@ -100,6 +139,14 @@ jobs: # cling: On # cling-version: '1.0' # cppyy: Off + #- name: ubu22-arm-gcc9-clang13-cling-xeus-clang-repl + # os: ubuntu-22.04-arm + # compiler: gcc-9 + # clang-runtime: '13' + # cling: On + # cling-version: '1.0' + # cppyy: On + # xeus-clang-repl: On #- name: ubu22-arm-gcc9-clang13-cling-cppyy # os: ubuntu-22.04-arm # compiler: gcc-9 @@ -107,6 +154,14 @@ jobs: # cling: On # cling-version: '1.0' # cppyy: On + #- name: ubu22-arm-gcc9-clang13-cling-xeus-clang-repl + # os: ubuntu-22.04-arm + # compiler: gcc-9 + # clang-runtime: '13' + # cling: On + # cling-version: '1.0' + # cppyy: On + # xeus-clang-repl: On - name: win2022-msvc-clang-repl-17 os: windows-2022 compiler: msvc @@ -160,6 +215,13 @@ jobs: clang-runtime: '17' cling: Off cppyy: On + - name: osx13-x86-clang-clang-repl-17-xeus-clang-repl + os: macos-13 + compiler: clang + clang-runtime: '17' + cling: Off + cppyy: On + xeus-clang-repl: On - name: osx13-x86-clang-clang-repl-16 os: macos-13 compiler: clang @@ -172,6 +234,13 @@ jobs: clang-runtime: '16' cling: Off cppyy: On + - name: osx13-x86-clang-clang-repl-16-xeus-clang-repl + os: macos-13 + compiler: clang + clang-runtime: '16' + cling: Off + cppyy: On + xeus-clang-repl: On - name: osx13-x86-clang-clang13-cling os: macos-13 compiler: clang @@ -186,6 +255,14 @@ jobs: cling: On cling-version: '1.0' cppyy: On + - name: osx13-x86-clang-clang13-cling-xeus-clang-repl + os: macos-13 + compiler: clang + clang-runtime: '13' + cling: On + cling-version: '1.0' + cppyy: On + xeus-clang-repl: On #Block commented out until free tier for m1 #exists (expected sometime 2024) and key for os #can be replaced @@ -201,6 +278,13 @@ jobs: # clang-runtime: '17' # cling: Off # cppyy: On + #- name: osx13-arm64-clang-clang-repl-17-xeus-clang-repl + # os: macos-13-arm64 + # compiler: clang + # clang-runtime: '17' + # cling: Off + # cppyy: On + # xeus-clang-repl: On #- name: osx13-arm64-clang-clang-repl-16 # os: macos-13-arm64 # compiler: clang @@ -213,6 +297,13 @@ jobs: # clang-runtime: '16' # cling: Off # cppyy: On + #- name: osx13-arm64-clang-clang-repl-16-xeus-clang-repl + # os: macos-13-arm64 + # compiler: clang + # clang-runtime: '16' + # cling: Off + # cppyy: On + # xeus-clang-repl: On #- name: osx13-arm64-clang-clang13-cling # os: macos-13-arm64 # compiler: clang @@ -227,7 +318,15 @@ jobs: # cling: On # cling-version: '1.0' # cppyy: On - + #- name: osx13-arm64-clang-clang13-cling-xeus-clang-repl + # os: macos-13-arm64 + # compiler: clang + # clang-runtime: '13' + # cling: On + # cling-version: '1.0' + # cppyy: On + # xeus-clang-repl: On + steps: - uses: actions/checkout@v3 with: @@ -385,9 +484,8 @@ jobs: # Install deps sudo apt update sudo apt install git g++ debhelper devscripts gnupg python3 valgrind - conda install -y -q -c conda-forge \ - distro \ - pytest + sudo apt autoremove + sudo apt clean - name: Install deps on MacOS if: runner.os == 'macOS' @@ -687,10 +785,10 @@ jobs: cd cppyy-backend mkdir -p $CPPINTEROP_DIR/lib build && cd build # Install CppInterOp - (cd $CPPINTEROP_BUILD_DIR && cmake --build . --target install --parallel $(nproc --all)) + (cd $CPPINTEROP_BUILD_DIR && cmake --build . --target install --parallel ${{ env.ncpus }} ) # Build and Install cppyy-backend cmake -DCppInterOp_DIR=$CPPINTEROP_DIR .. - cmake --build . --parallel $(nproc --all) + cmake --build . --parallel ${{ env.ncpus }} OS=$(uname -s) if [[ "$OS" == "Darwin" ]]; then cp libcppyy-backend.dylib $CPPINTEROP_DIR/lib/ @@ -702,15 +800,50 @@ jobs: - name: Install CPyCppyy on Unix Systems if: ${{ (runner.os != 'windows') && (matrix.cppyy == 'On') }} run: | - # Setup virtual environment - python3 -m venv .venv - source .venv/bin/activate + # Setup and activate virtual environment (mamba envirnoment if building xeus-clang-repl) + xeus_clang_repl_on=$(echo "${{ matrix.xeus-clang-repl }}" | tr '[:lower:]' '[:upper:]') + if [[ "$xeus_clang_repl_on" == "ON" ]]; then + echo "Installing dependencies related to xeus-clang-repl build" + wget -O Miniforge3.sh "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" + bash Miniforge3.sh -b -p "${HOME}/conda" + source "${HOME}/conda/etc/profile.d/conda.sh" + source "${HOME}/conda/etc/profile.d/mamba.sh" + mamba create -y -n .venv python=3.10.6 + mamba activate .venv + mamba install --quiet --yes -c conda-forge \ + cmake \ + 'xeus>=2.0' \ + xeus-zmq \ + 'nlohmann_json>=3.9.1,<3.10' \ + 'cppzmq>=4.6.0,<5' \ + 'xtl>=0.7,<0.8' \ + 'openssl<4' \ + ipykernel \ + pugixml \ + zlib \ + libxml2 \ + 'cxxopts>=2.2.1,<2.3' \ + libuuid \ + pytest \ + jupyter_kernel_test + mamba install -y jupyter + hash -r + pip install ipython + jupyter notebook --generate-config -y + mamba clean --all -f -y + npm cache clean --force + jupyter lab clean + else + python3 -m venv .venv + source .venv/bin/activate + fi + # Install CPyCppyy git clone --depth=1 https://github.com/compiler-research/CPyCppyy.git mkdir CPyCppyy/build cd CPyCppyy/build cmake .. - cmake --build . --parallel $(nproc --all) + cmake --build . --parallel ${{ env.ncpus }} # export CPYCPPYY_DIR=$PWD cd ../.. @@ -720,7 +853,14 @@ jobs: if: ${{ (runner.os != 'windows') && (matrix.cppyy == 'On') }} run: | # source virtual environment - source .venv/bin/activate + xeus_clang_repl_on=$(echo "${{ matrix.xeus-clang-repl }}" | tr '[:lower:]' '[:upper:]') + if [[ "$xeus_clang_repl_on" == "ON" ]]; then + source "${HOME}/conda/etc/profile.d/conda.sh" + source "${HOME}/conda/etc/profile.d/mamba.sh" + mamba activate .venv + else + source .venv/bin/activate + fi # Install cppyy git clone --depth=1 https://github.com/compiler-research/cppyy.git cd cppyy @@ -730,14 +870,21 @@ jobs: if: ${{ (runner.os != 'windows') && (matrix.cppyy == 'On') }} run: | # Run cppyy - source .venv/bin/activate + xeus_clang_repl_on=$(echo "${{ matrix.xeus-clang-repl }}" | tr '[:lower:]' '[:upper:]') + if [[ "$xeus_clang_repl_on" == "ON" ]]; then + source "${HOME}/conda/etc/profile.d/conda.sh" + source "${HOME}/conda/etc/profile.d/mamba.sh" + mamba activate .venv + else + source .venv/bin/activate + fi export PYTHONPATH=$PYTHONPATH:$CPYCPPYY_DIR:$CB_PYTHON_DIR python -c "import cppyy" # We need PYTHONPATH later echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV - name: Run the tests on Unix Systems continue-on-error: true - if: ${{ (runner.os != 'windows') && (matrix.cppyy == 'On') }} + if: ${{ (runner.os != 'windows') && (matrix.cppyy == 'On') && (matrix.xeus-clang-repl != 'On') }} run: | # Run the tests source .venv/bin/activate @@ -782,6 +929,28 @@ jobs: echo "Return Code: ${RETCODE}" exit $RETCODE + - name: Build xeus-clang-repl on Unix Systems + if: ${{ (runner.os != 'windows') && (matrix.xeus-clang-repl == 'On') }} + run: | + source "${HOME}/conda/etc/profile.d/conda.sh" + source "${HOME}/conda/etc/profile.d/mamba.sh" + mamba activate .venv + #Build xeus-clang-repl + LLVM_BUILD_DIR="$(pwd)/llvm-project/build" + git clone --depth=1 https://github.com/compiler-research/xeus-clang-repl.git + mkdir ./xeus-clang-repl/build/ + cd ./xeus-clang-repl/build/ + cmake -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_CMAKE_DIR=$LLVM_BUILD_DIR \ + -DCMAKE_PREFIX_PATH=$(python -m site --user-site) \ + -DCMAKE_INSTALL_PREFIX=$(python -m site --user-site) \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DLLVM_CONFIG_EXTRA_PATH_HINTS=$LLVM_BUILD_DIR/lib \ + -DCPPINTEROP_DIR=$CPPINTEROP_BUILD_DIR \ + -DLLVM_USE_LINKER=lld \ + .. + make install -j ${{ env.ncpus }} + - name: Show debug info if: ${{ failure() && (runner.os != 'windows') }} run: | diff --git a/README.md b/README.md index f65cb84f5..5a48f4443 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ interpreter. Cling depends on its own customised version of `llvm-project`, hosted under the `root-project` (see the git path below). Use the following build instructions to build on Linux and MacOS ``` -git clone --depth=1 https://github.com/root-project/cling.git +git clone https://github.com/root-project/cling.git cd ./cling/ git checkout tags/v1.0 cd .. @@ -167,7 +167,7 @@ cmake --build . --target gtest_main --parallel $(nproc --all) ``` Use the following build instructions to build on Windows ``` -git clone --depth=1 https://github.com/root-project/cling.git +git clone https://github.com/root-project/cling.git cd .\cling\ git checkout tags/v1.0 cd .. @@ -279,7 +279,7 @@ on Windows. Now you are in a position to install cppyy following the instruction #### Building and Install cppyy-backend -Clone the repo, build it and copy library files into `python/cppyy-backend` directory: +Cd into the cppyy-backend directory, build it and copy library files into `python/cppyy-backend` directory: ``` cd cppyy-backend From 10097e015b6357f065b727d6427b0de1d72803f3 Mon Sep 17 00:00:00 2001 From: Aaron Jomy <75925957+maximusron@users.noreply.github.com> Date: Fri, 26 Jan 2024 12:30:33 +0100 Subject: [PATCH 43/59] [ci] Extend the CI to run full test suite (#190) --- .github/workflows/ci.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ff6497c9..1dc96df6f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -894,7 +894,26 @@ jobs: python -m pip install --upgrade pip python -m pip install pytest python -m pip install pytest-xdist + python -m pip install numba echo ::endgroup:: + echo ::group::Run complete test suite + python -m pytest --tb=short -ra -sv> pytest_dump.log 2>&1 || : + last_line=$(tail -n 1 pytest_dump.log) + passed=$(echo "$last_line" | grep -oP "\d+ passed") + failed=$(echo "$last_line" | grep -oP "\d+ failed") + skipped=$(echo "$last_line" | grep -oP "\d+ skipped") + xpassed=$(echo "$last_line" | grep -oP "\d+ xpassed") + xfailed=$(echo "$last_line" | grep -oP "\d+ xfailed") + errors=$(echo "$last_line" | grep -oP "\d+ errors") + echo -e "\e[32mPASS: $passed\e[0m" + echo -e "\e[31mFAIL: $failed\e[0m" + echo -e "\e[33mSKIP: $skipped\e[0m" + echo -e "\e[33mXPASS: $xpassed\e[0m" + echo -e "\e[33mXFAIL: $xfailed\e[0m" + echo -e "\e[33mERRORS: $errors\e[0m" + echo ::endgroup:: + echo "Cppyy Test Logs:" + tail -n1 pytest_dump.log echo ::group::Crashing Test Logs # See if we don't have a crash that went away # Comment out all xfails but the ones that have a run=False condition. From e61e7ca3a7daaa9031785baf0f8cf974e02d21d4 Mon Sep 17 00:00:00 2001 From: Shreyas Atre Date: Sat, 27 Jan 2024 14:30:45 -0600 Subject: [PATCH 44/59] Remove unsued function Signed-off-by: Shreyas Atre --- lib/Interpreter/DynamicLibraryManagerSymbol.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/Interpreter/DynamicLibraryManagerSymbol.cpp b/lib/Interpreter/DynamicLibraryManagerSymbol.cpp index c17b60621..57837a546 100644 --- a/lib/Interpreter/DynamicLibraryManagerSymbol.cpp +++ b/lib/Interpreter/DynamicLibraryManagerSymbol.cpp @@ -580,13 +580,6 @@ namespace Cpp { return result; } - void CombinePaths(std::string& P1, const char* P2) { - if (!P2 || !P2[0]) return; - if (!P1.empty()) - P1 += llvm::sys::EnvPathSeparator; - P1 += P2; - } - template void HandleDynTab(const ELFFile* Elf, StringRef FileName, SmallVector& RPath, From 59530582a4133bf4719898648930792796cbd17e Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Fri, 2 Feb 2024 16:31:38 +0000 Subject: [PATCH 45/59] Add ability to compile CppInterOp and tests on Windows with different compiler (#195) --- .github/workflows/ci.yml | 132 +++++++++--------- README.md | 4 +- cmake/modules/GoogleTest.cmake | 2 +- lib/Interpreter/CppInterOp.cpp | 2 +- .../CppInterOp/TestSharedLib/TestSharedLib.h | 2 +- 5 files changed, 70 insertions(+), 72 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1dc96df6f..0abcc5335 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -162,13 +162,14 @@ jobs: # cling-version: '1.0' # cppyy: On # xeus-clang-repl: On + #FIXME: Windows CppInterOp tests expected to fail + #until https://github.com/compiler-research/CppInterOp/issues/188 is solved - name: win2022-msvc-clang-repl-17 os: windows-2022 compiler: msvc clang-runtime: '17' cling: Off cppyy: Off - #Commented out until rest of ci for Windows tested #- name: win2022-msvc-clang-repl-17-cppyy # os: windows-2022 # compiler: msvc @@ -181,7 +182,6 @@ jobs: clang-runtime: '16' cling: Off cppyy: Off - #Commented out until rest of ci for Windows tested #- name: win2022-msvc-clang-repl-16-cppyy # os: windows-2022 # compiler: msvc @@ -195,7 +195,6 @@ jobs: cling: On cling-version: '1.0' cppyy: Off - #Commented out until rest of ci for Windows tested #- name: win2022-msvc-cling-cppyy # os: windows-2022 # compiler: msvc @@ -203,6 +202,66 @@ jobs: # cling: On # cling-version: '1.0' # cppyy: On + - name: osx14-arm-clang-clang-repl-17 + os: macos-14 + compiler: clang + clang-runtime: '17' + cling: Off + cppyy: Off + - name: osx14-arm-clang-clang-repl-17-cppyy + os: macos-14 + compiler: clang + clang-runtime: '17' + cling: Off + cppyy: On + - name: osx14-arm-clang-clang-repl-17-xeus-clang-repl + os: macos-14 + compiler: clang + clang-runtime: '17' + cling: Off + cppyy: On + xeus-clang-repl: On + - name: osx14-arm-clang-clang-repl-16 + os: macos-14 + compiler: clang + clang-runtime: '16' + cling: Off + cppyy: Off + - name: osx14-arm-clang-clang-repl-16-cppyy + os: macos-14 + compiler: clang + clang-runtime: '16' + cling: Off + cppyy: On + - name: osx14-arm-clang-clang-repl-16-xeus-clang-repl + os: macos-14 + compiler: clang + clang-runtime: '16' + cling: Off + cppyy: On + xeus-clang-repl: On + - name: osx14-arm-clang-clang13-cling + os: macos-14 + compiler: clang + clang-runtime: '13' + cling: On + cling-version: '1.0' + cppyy: Off + - name: osx14-arm-clang-clang13-cling-cppyy + os: macos-14 + compiler: clang + clang-runtime: '13' + cling: On + cling-version: '1.0' + cppyy: On + - name: osx14-arm-clang-clang13-cling-xeus-clang-repl + os: macos-14 + compiler: clang + clang-runtime: '13' + cling: On + cling-version: '1.0' + cppyy: On + xeus-clang-repl: On - name: osx13-x86-clang-clang-repl-17 os: macos-13 compiler: clang @@ -263,69 +322,6 @@ jobs: cling-version: '1.0' cppyy: On xeus-clang-repl: On - #Block commented out until free tier for m1 - #exists (expected sometime 2024) and key for os - #can be replaced - #- name: osx13-arm64-clang-clang-repl-17 - # os: macos-13-arm64 - # compiler: clang - # clang-runtime: '17' - # cling: Off - # cppyy: Off - #- name: osx13-arm64-clang-clang-repl-17-cppyy - # os: macos-13-arm64 - # compiler: clang - # clang-runtime: '17' - # cling: Off - # cppyy: On - #- name: osx13-arm64-clang-clang-repl-17-xeus-clang-repl - # os: macos-13-arm64 - # compiler: clang - # clang-runtime: '17' - # cling: Off - # cppyy: On - # xeus-clang-repl: On - #- name: osx13-arm64-clang-clang-repl-16 - # os: macos-13-arm64 - # compiler: clang - # clang-runtime: '16' - # cling: Off - # cppyy: Off - #- name: osx13-arm64-clang-clang-repl-16-cppyy - # os: macos-13-arm64 - # compiler: clang - # clang-runtime: '16' - # cling: Off - # cppyy: On - #- name: osx13-arm64-clang-clang-repl-16-xeus-clang-repl - # os: macos-13-arm64 - # compiler: clang - # clang-runtime: '16' - # cling: Off - # cppyy: On - # xeus-clang-repl: On - #- name: osx13-arm64-clang-clang13-cling - # os: macos-13-arm64 - # compiler: clang - # clang-runtime: '13' - # cling: On - # cling-version: '1.0' - # cppyy: Off - #- name: osx13-arm64-clang-clang13-cling-cppyy - # os: macos-13-arm64 - # compiler: clang - # clang-runtime: '13' - # cling: On - # cling-version: '1.0' - # cppyy: On - #- name: osx13-arm64-clang-clang13-cling-xeus-clang-repl - # os: macos-13-arm64 - # compiler: clang - # clang-runtime: '13' - # cling: On - # cling-version: '1.0' - # cppyy: On - # xeus-clang-repl: On steps: - uses: actions/checkout@v3 @@ -362,7 +358,6 @@ jobs: - name: Save PR Info on Windows systems if: ${{ runner.os == 'windows' }} run: | - #FIXME: CLING AND LLVM HASH currently hardcoded until windows equivalent of unix commands #can be found mkdir ./pr echo "${{ github.event.number }}" > ./pr/NR @@ -710,8 +705,11 @@ jobs: echo "CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH" >> $GITHUB_ENV - name: Build and Test/Install CppInterOp on Windows systems + continue-on-error: true if: ${{ runner.os == 'windows' }} run: | + #FIXME: Windows CppInterOp tests expected to fail + #until https://github.com/compiler-research/CppInterOp/issues/188 is solved $env:PWD_DIR= $PWD.Path $env:LLVM_DIR="$env:PWD_DIR\llvm-project" diff --git a/README.md b/README.md index 5a48f4443..6493dde44 100644 --- a/README.md +++ b/README.md @@ -244,7 +244,7 @@ cmake --build . --target install --parallel $(nproc --all) ``` and ``` -cmake -DUSE_CLING=Off -DUSE_REPL=ON -DLLVM_DIR=$LLVM_DIR\build\lib\cmake\llvm -DClang_DIR=$LLVM_DIR\build\lib\cmake\clang -DCMAKE_INSTALL_PREFIX=$env:CPPINTEROP_DIR .. +cmake -DUSE_CLING=Off -DUSE_REPL=ON -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 ``` on Windows. If alternatively you would like to install CppInterOp with Cling then execute the following commands on Linux and MacOS @@ -254,7 +254,7 @@ cmake --build . --target install --parallel $(nproc --all) ``` and ``` -cmake -DUSE_CLING=ON -DUSE_REPL=Off -DCling_DIR=$LLVM_DIR\build\tools\cling -DLLVM_DIR=$LLVM_DIR\build\lib\cmake\llvm -DClang_DIR=$LLVM_DIR\build\lib\cmake\clang -DCMAKE_INSTALL_PREFIX=$env:CPPINTEROP_DIR .. +cmake -DUSE_CLING=ON -DUSE_REPL=Off -DCling_DIR=$env:LLVM_DIR\build\tools\cling -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 ``` diff --git a/cmake/modules/GoogleTest.cmake b/cmake/modules/GoogleTest.cmake index c2d3fffba..035289f47 100644 --- a/cmake/modules/GoogleTest.cmake +++ b/cmake/modules/GoogleTest.cmake @@ -7,7 +7,7 @@ set(_gtest_byproducts ${_gtest_byproduct_binary_dir}/lib/libgmock_main.a ) -if(MSVC) +if(WIN32) set(EXTRA_GTEST_OPTS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=${_gtest_byproduct_binary_dir}/lib/ -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL:PATH=${_gtest_byproduct_binary_dir}/lib/ diff --git a/lib/Interpreter/CppInterOp.cpp b/lib/Interpreter/CppInterOp.cpp index fbdb01041..f70bc6443 100644 --- a/lib/Interpreter/CppInterOp.cpp +++ b/lib/Interpreter/CppInterOp.cpp @@ -34,7 +34,7 @@ #include // Stream redirect. -#ifdef WIN32 +#ifdef _WIN32 #include #ifndef STDOUT_FILENO #define STDOUT_FILENO 1 diff --git a/unittests/CppInterOp/TestSharedLib/TestSharedLib.h b/unittests/CppInterOp/TestSharedLib/TestSharedLib.h index 65b1d2fde..92633cdb7 100644 --- a/unittests/CppInterOp/TestSharedLib/TestSharedLib.h +++ b/unittests/CppInterOp/TestSharedLib/TestSharedLib.h @@ -2,7 +2,7 @@ #define UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H // Avoid having to mangle/demangle the symbol name in tests -#ifdef WIN32 +#ifdef _WIN32 extern "C" __declspec(dllexport) int ret_zero(); #else extern "C" int ret_zero(); From 8d00731d186a80a8eba14630b6b215b85fbf114a Mon Sep 17 00:00:00 2001 From: fsfod Date: Sat, 3 Feb 2024 16:21:43 +0000 Subject: [PATCH 46/59] Work around asserts in Sema::PushDeclContext for Windows by setting -fno-delayed-template-parsing --- lib/Interpreter/CppInterOp.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Interpreter/CppInterOp.cpp b/lib/Interpreter/CppInterOp.cpp index f70bc6443..1bc9a2ffd 100644 --- a/lib/Interpreter/CppInterOp.cpp +++ b/lib/Interpreter/CppInterOp.cpp @@ -2463,6 +2463,10 @@ namespace Cpp { std::vector ClingArgv = {"-resource-dir", ResourceDir.c_str(), "-std=c++14"}; ClingArgv.insert(ClingArgv.begin(), MainExecutableName.c_str()); +#ifdef _WIN32 + // FIXME : Workaround Sema::PushDeclContext assert on windows + ClingArgv.push_back("-fno-delayed-template-parsing"); +#endif ClingArgv.insert(ClingArgv.end(), Args.begin(), Args.end()); // To keep the Interpreter creation interface between cling and clang-repl // to some extent compatible we should put Args and GpuArgs together. On the From ce37fa486b82031ab1cee8583017ce84ea98bc04 Mon Sep 17 00:00:00 2001 From: fsfod Date: Sat, 3 Feb 2024 03:46:21 +0000 Subject: [PATCH 47/59] Export MSVC library symbols from clangCppInterOp so STL can be compiled without export errors --- CMakeLists.txt | 49 ++++++++++++++++++++++++++++++++++++++++ unittests/CMakeLists.txt | 1 + 2 files changed, 50 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fe401013..f248be12f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -373,6 +373,55 @@ option(CPPINTEROP_ENABLE_DOXYGEN "Use doxygen to generate CppInterOp interal API option(CPPINTEROP_ENABLE_SPHINX "Use sphinx to generage CppInterOp user documentation") option(CPPINTEROP_ENABLE_TESTING "Enables the testing infrastructure." ON) +if(MSVC) + + set(MSVC_EXPORTLIST + ??_7type_info@@6B@ + ?nothrow@std@@3Unothrow_t@1@B + _Init_thread_header + _Init_thread_footer + ??_7type_info@@6B@ + ?_Facet_Register@std@@YAXPEAV_Facet_base@1@@Z + ) + + set(MSVC_EXPORTLIST ${MSVC_EXPORTLIST} + ??2@YAPEAX_K@Z + ??3@YAXPEAX@Z + ??3@YAXPEAX_K@Z + ??_U@YAPEAX_K@Z + ??_V@YAXPEAX@Z + ??_V@YAXPEAX_K@Z + ??2@YAPEAX_KAEBUnothrow_t@std@@@Z + ??_U@YAPEAX_KAEBUnothrow_t@std@@@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@H@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@M@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@N@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@PEBX@Z + ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@P6AAEAV01@AEAV01@@Z@Z + ??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@D@Z + ??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z + ?_Facet_Register@std@@YAXPEAV_Facet_base@1@@Z + ) + + if(MSVC_VERSION LESS 1914) + set(MSVC_EXPORTLIST ${MSVC_EXPORTLIST} ??3@YAXPAX0@Z ??_V@YAXPAX0@Z) + endif() + + if(MSVC_VERSION GREATER_EQUAL 1936) + set(MSVC_EXPORTLIST ${MSVC_EXPORTLIST} + __std_find_trivial_1 + __std_find_trivial_2 + __std_find_trivial_4 + __std_find_trivial_8 + ) + endif() + +foreach(sym ${MSVC_EXPORTLIST}) + set(MSVC_EXPORTS "${MSVC_EXPORTS} /EXPORT:${sym}") +endforeach(sym ${MSVC_EXPORTLIST}) + +endif() + if (CPPINTEROP_INCLUDE_DOCS) add_subdirectory(docs) endif() diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index ad8337661..6fe08a061 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -26,6 +26,7 @@ function(add_cppinterop_unittest name) if(WIN32) target_link_libraries(${name} PUBLIC ${ARG_LIBRARIES} ${gtest_libs}) + set_property(TARGET ${name} APPEND_STRING PROPERTY LINK_FLAGS "${MSVC_EXPORTS}") else() target_link_libraries(${name} PUBLIC ${ARG_LIBRARIES} ${gtest_libs} pthread) endif() From b04375987d37750b4786f8fd580293c2da2f8902 Mon Sep 17 00:00:00 2001 From: fsfod Date: Mon, 5 Feb 2024 14:34:04 +0000 Subject: [PATCH 48/59] Fix assert crash from the error from getSymbolName CoffObj export_directory iterator in Dyld::BuildBloomFilter --- lib/Interpreter/DynamicLibraryManagerSymbol.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Interpreter/DynamicLibraryManagerSymbol.cpp b/lib/Interpreter/DynamicLibraryManagerSymbol.cpp index 57837a546..e523d10b5 100644 --- a/lib/Interpreter/DynamicLibraryManagerSymbol.cpp +++ b/lib/Interpreter/DynamicLibraryManagerSymbol.cpp @@ -911,8 +911,17 @@ namespace Cpp { // All the symbols are already flagged as exported. // We cannot really ignore symbols based on flags as we do on unix. StringRef Name; - if (I->getSymbolName(Name)) + auto Err = I->getSymbolName(Name); + + if (Err) { + std::string Message; + handleAllErrors(std::move(Err), [&](llvm::ErrorInfoBase& EIB) { + Message += EIB.message() + "; "; + }); + LLVM_DEBUG(dbgs() << "Dyld::BuildBloomFilter: Failed to read symbol " + << Message << "\n"); continue; + } if (Name.empty()) continue; From eb2f4ef2c0e743441f76fb3e99032d72a4e35735 Mon Sep 17 00:00:00 2001 From: fsfod Date: Mon, 5 Feb 2024 15:27:32 +0000 Subject: [PATCH 49/59] Fix some enum tests for windows where the default enum base type is int --- unittests/CppInterOp/EnumReflectionTest.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/unittests/CppInterOp/EnumReflectionTest.cpp b/unittests/CppInterOp/EnumReflectionTest.cpp index 59d6eefab..3ec03e136 100644 --- a/unittests/CppInterOp/EnumReflectionTest.cpp +++ b/unittests/CppInterOp/EnumReflectionTest.cpp @@ -124,7 +124,12 @@ TEST(EnumReflectionTest, GetIntegerTypeFromEnumScope) { EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetIntegerTypeFromEnumScope(Decls[1])), "char"); EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetIntegerTypeFromEnumScope(Decls[2])), "int"); EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetIntegerTypeFromEnumScope(Decls[3])), "long long"); +#ifdef _WIN32 + EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetIntegerTypeFromEnumScope(Decls[4])), + "int"); +#else EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetIntegerTypeFromEnumScope(Decls[4])), "unsigned int"); +#endif EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetIntegerTypeFromEnumScope(Decls[5])),"NULL TYPE"); } @@ -180,7 +185,11 @@ TEST(EnumReflectionTest, GetIntegerTypeFromEnumType) { EXPECT_EQ(get_int_type_from_enum_var(Decls[7]), "char"); EXPECT_EQ(get_int_type_from_enum_var(Decls[8]), "int"); EXPECT_EQ(get_int_type_from_enum_var(Decls[9]), "long long"); +#ifdef _WIN32 + EXPECT_EQ(get_int_type_from_enum_var(Decls[10]), "int"); +#else EXPECT_EQ(get_int_type_from_enum_var(Decls[10]), "unsigned int"); +#endif EXPECT_EQ(get_int_type_from_enum_var(Decls[11]), "NULL TYPE"); // When a non Enum Type variable is used } From 5408538e87093bd4bb877e33fe26548607ee17f0 Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Thu, 8 Feb 2024 21:36:33 +0000 Subject: [PATCH 50/59] Remove redundant ci jobs (#197) --- .github/workflows/ci.yml | 91 +--------------------------------------- README.md | 2 +- 2 files changed, 2 insertions(+), 91 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0abcc5335..f0c139cca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,13 +21,6 @@ jobs: fail-fast: false matrix: include: - - name: ubu22-x86-gcc12-clang-repl-17 - os: ubuntu-22.04 - compiler: gcc-12 - clang-runtime: '17' - cling: Off - cppyy: Off - coverage: true - name: ubu22-x86-gcc12-clang-repl-17-cppyy os: ubuntu-22.04 compiler: gcc-12 @@ -43,13 +36,6 @@ jobs: cppyy: On xeus-clang-repl: On coverage: true - - name: ubu22-x86-gcc9-clang-repl-16 - os: ubuntu-22.04 - compiler: gcc-9 - clang-runtime: '16' - cling: Off - cppyy: Off - coverage: true - name: ubu22-x86-gcc9-clang-repl-16-cppyy os: ubuntu-22.04 compiler: gcc-9 @@ -65,14 +51,6 @@ jobs: cppyy: On xeus-clang-repl: On coverage: true - - name: ubu22-x86-gcc9-clang13-cling - os: ubuntu-22.04 - compiler: gcc-9 - clang-runtime: '13' - cling: On - cling-version: '1.0' - cppyy: Off - coverage: true - name: ubu22-x86-gcc9-clang13-cling-cppyy os: ubuntu-22.04 compiler: gcc-9 @@ -92,12 +70,6 @@ jobs: coverage: true #Commented out until Ubuntu on arm Github runner becomes available #os key to be replaced once known - #- name: ubu22-arm-gcc12-clang-repl-17 - # os: ubuntu-22.04-arm - # compiler: gcc-12 - # clang-runtime: '17' - # cling: Off - # cppyy: Off #- name: ubu22-arm-gcc12-clang-repl-17-cppyy # os: ubuntu-22.04-arm # compiler: gcc-12 @@ -111,13 +83,6 @@ jobs: # cling: Off # cppyy: On # xeus-clang-repl: On - #- name: ubu22-arm-gcc9-clang-repl-16 - # os: ubuntu-22.04-arm - # compiler: gcc-9 - # clang-runtime: '16' - # cling: Off - # cppyy: Off - # coverage: true #- name: ubu22-arm-gcc9-clang-repl-16-cppyy # os: ubuntu-22.04-arm # compiler: gcc-9 @@ -132,21 +97,6 @@ jobs: # cling: Off # cppyy: On # xeus-clang-repl: On - #- name: ubu22-arm-gcc9-clang13-cling - # os: ubuntu-22.04-arm - # compiler: gcc-9 - # clang-runtime: '13' - # cling: On - # cling-version: '1.0' - # cppyy: Off - #- name: ubu22-arm-gcc9-clang13-cling-xeus-clang-repl - # os: ubuntu-22.04-arm - # compiler: gcc-9 - # clang-runtime: '13' - # cling: On - # cling-version: '1.0' - # cppyy: On - # xeus-clang-repl: On #- name: ubu22-arm-gcc9-clang13-cling-cppyy # os: ubuntu-22.04-arm # compiler: gcc-9 @@ -202,12 +152,6 @@ jobs: # cling: On # cling-version: '1.0' # cppyy: On - - name: osx14-arm-clang-clang-repl-17 - os: macos-14 - compiler: clang - clang-runtime: '17' - cling: Off - cppyy: Off - name: osx14-arm-clang-clang-repl-17-cppyy os: macos-14 compiler: clang @@ -221,12 +165,6 @@ jobs: cling: Off cppyy: On xeus-clang-repl: On - - name: osx14-arm-clang-clang-repl-16 - os: macos-14 - compiler: clang - clang-runtime: '16' - cling: Off - cppyy: Off - name: osx14-arm-clang-clang-repl-16-cppyy os: macos-14 compiler: clang @@ -240,13 +178,6 @@ jobs: cling: Off cppyy: On xeus-clang-repl: On - - name: osx14-arm-clang-clang13-cling - os: macos-14 - compiler: clang - clang-runtime: '13' - cling: On - cling-version: '1.0' - cppyy: Off - name: osx14-arm-clang-clang13-cling-cppyy os: macos-14 compiler: clang @@ -262,12 +193,6 @@ jobs: cling-version: '1.0' cppyy: On xeus-clang-repl: On - - name: osx13-x86-clang-clang-repl-17 - os: macos-13 - compiler: clang - clang-runtime: '17' - cling: Off - cppyy: Off - name: osx13-x86-clang-clang-repl-17-cppyy os: macos-13 compiler: clang @@ -281,12 +206,6 @@ jobs: cling: Off cppyy: On xeus-clang-repl: On - - name: osx13-x86-clang-clang-repl-16 - os: macos-13 - compiler: clang - clang-runtime: '16' - cling: Off - cppyy: Off - name: osx13-x86-clang-clang-repl-16-cppyy os: macos-13 compiler: clang @@ -300,13 +219,6 @@ jobs: cling: Off cppyy: On xeus-clang-repl: On - - name: osx13-x86-clang-clang13-cling - os: macos-13 - compiler: clang - clang-runtime: '13' - cling: On - cling-version: '1.0' - cppyy: Off - name: osx13-x86-clang-clang13-cling-cppyy os: macos-13 compiler: clang @@ -690,8 +602,7 @@ jobs: fi os="${{ matrix.os }}" cmake --build . --target check-cppinterop --parallel ${{ env.ncpus }} - cppyy_on=$(echo "${{ matrix.cppyy }}" | tr '[:lower:]' '[:upper:]') - if [[ ("${cppyy_on}" != "ON") && ("${os}" == "ubuntu"*) ]]; then + if [[ ("${os}" == "ubuntu"*) ]]; then # TODO: Remove "|| true" when fix memory issues in LLVM/Clang 17 valgrind --track-origins=yes --error-exitcode=1 unittests/CppInterOp/CppInterOpTests 2>&1 >/dev/null || true fi diff --git a/README.md b/README.md index 6493dde44..baf14f778 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # CppInterOp -[![Biuld Statuses](https://github.com/compiler-research/CppInterOp/workflows/Main/badge.svg)](https://github.com/compiler-research/CppInterOp/actions?query=workflow%3AMain) +[![Build Status](https://github.com/compiler-research/CppInterOp/actions/workflows/ci.yml/badge.svg)](https://github.com/compiler-research/CppInterOp/actions/workflows/ci.yml) [![codecov]( https://codecov.io/gh/compiler-research/CppInterOp/branch/main/graph/badge.svg)](https://codecov.io/gh/compiler-research/CppInterOp) From 1d653d064696f8e3e74a9e51b5965d52585836a1 Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Mon, 12 Feb 2024 21:40:52 +0000 Subject: [PATCH 51/59] Add wasm support to ci --- .github/workflows/ci.yml | 319 ++++++++++++++++++++++++++++++++++--- CMakeLists.txt | 10 +- environment-wasm-build.yml | 7 + environment-wasm.yml | 5 + 4 files changed, 319 insertions(+), 22 deletions(-) create mode 100644 environment-wasm-build.yml create mode 100644 environment-wasm.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0c139cca..5d8c46470 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -433,18 +433,21 @@ jobs: mkdir build if [[ "${cling_on}" == "ON" ]]; then cd build - cmake -DLLVM_ENABLE_PROJECTS=clang \ - -DLLVM_EXTERNAL_PROJECTS=cling \ - -DLLVM_EXTERNAL_CLING_SOURCE_DIR=../../cling \ - -DLLVM_TARGETS_TO_BUILD="host;NVPTX" \ - -DCMAKE_BUILD_TYPE=Release \ - -DLLVM_ENABLE_ASSERTIONS=ON \ - -DLLVM_ENABLE_LLD=ON \ - -DCLANG_ENABLE_STATIC_ANALYZER=OFF \ - -DCLANG_ENABLE_ARCMT=OFF \ - -DCLANG_ENABLE_FORMAT=OFF \ - -DCLANG_ENABLE_BOOTSTRAP=OFF \ + cmake -DLLVM_ENABLE_PROJECTS="clang;lld" \ + -DLLVM_EXTERNAL_PROJECTS=cling \ + -DLLVM_EXTERNAL_CLING_SOURCE_DIR=../../cling \ + -DLLVM_TARGETS_TO_BUILD="WebAssembly;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 \ + -DLLVM_ENABLE_ZSTD=OFF \ + -DLLVM_ENABLE_TERMINFO=OFF \ + -DLLVM_ENABLE_LIBXML2=OFF \ ../llvm + cmake --build . --target lld --parallel ${{ env.ncpus }} cmake --build . --target clang --parallel ${{ env.ncpus }} cmake --build . --target cling --parallel ${{ env.ncpus }} # Now build gtest.a and gtest_main for CppInterOp to run its tests. @@ -454,17 +457,19 @@ jobs: git apply -v ../patches/llvm/clang${{ matrix.clang-runtime }}-*.patch echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:" cd build - cmake -DLLVM_ENABLE_PROJECTS=clang \ - -DLLVM_TARGETS_TO_BUILD="host;NVPTX" \ - -DCMAKE_BUILD_TYPE=Release \ - -DLLVM_ENABLE_ASSERTIONS=ON \ - -DLLVM_ENABLE_LLD=ON \ - -DCLANG_ENABLE_STATIC_ANALYZER=OFF \ - -DCLANG_ENABLE_ARCMT=OFF \ - -DCLANG_ENABLE_FORMAT=OFF \ - -DCLANG_ENABLE_BOOTSTRAP=OFF \ + cmake -DLLVM_ENABLE_PROJECTS="clang;lld" \ + -DLLVM_TARGETS_TO_BUILD="WebAssembly;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 \ + -DLLVM_ENABLE_ZSTD=OFF \ + -DLLVM_ENABLE_TERMINFO=OFF \ + -DLLVM_ENABLE_LIBXML2=OFF \ ../llvm - cmake --build . --target clang clang-repl --parallel ${{ env.ncpus }} + cmake --build . --target all --parallel ${{ env.ncpus }} fi cd ../../ @@ -907,3 +912,275 @@ jobs: uses: mxschmitt/action-tmate@v3 # When debugging increase to a suitable value! timeout-minutes: 30 + + emscripten_wasm: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - name: ubu22-x86-gcc12-clang-repl-17-emscripten_wasm + os: ubuntu-22.04 + compiler: gcc-12 + clang-runtime: '17' + cling: Off + - name: ubu22-x86-gcc12-clang-repl-16-emscripten_wasm + os: ubuntu-22.04 + compiler: gcc-12 + clang-runtime: '16' + cling: Off + - name: ubu22-x86-gcc9-clang13-cling-emscripten_wasm + os: ubuntu-22.04 + compiler: gcc-9 + clang-runtime: '13' + cling: On + cling-version: '1.0' + - name: osx14-arm-clang-clang-repl-17-emscripten_wasm + os: macos-14 + compiler: clang + clang-runtime: '17' + cling: Off + - name: osx14-arm-clang-clang-repl-16-emscripten_wasm + os: macos-14 + compiler: clang + clang-runtime: '16' + cling: Off + - name: osx14-arm-clang-clang13-cling-emscripten_wasm + os: macos-14 + compiler: clang + clang-runtime: '13' + cling: On + cling-version: '1.0' + - name: osx13-x86-clang-clang-repl-17-emscripten_wasm + os: macos-13 + compiler: clang + clang-runtime: '17' + cling: Off + - name: osx13-x86-clang-clang-repl-16-emscripten_wasm + os: macos-13 + compiler: clang + clang-runtime: '16' + cling: Off + - name: osx13-x86-clang-clang13-cling-emscripten_wasm + os: macos-13 + compiler: clang + clang-runtime: '13' + cling: On + cling-version: '1.0' + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Save PR Info on Unix systems + if: ${{ runner.os != 'windows' }} + run: | + mkdir -p ./pr + echo ${{ github.event.number }} > ./pr/NR + echo ${{ github.repository }} > ./pr/REPO + + cling_on=$(echo "${{ matrix.cling }}" | tr '[:lower:]' '[:upper:]') + if [[ "$cling_on" == "ON" ]]; then + export CLING_HASH=$(git ls-remote https://github.com/root-project/cling.git refs/tags/v${{ matrix.cling-version }} | tr '\t' '-') + export LLVM_HASH=$(git ls-remote https://github.com/root-project/llvm-project.git cling-llvm${{ matrix.clang-runtime}} | tr '\t' '-') + else + export CLING_HASH="Repl" + # May need to revert back to both having same llvm_hash, as below cause llvm to be rebuilt everytime commit is made to llvm/llvm-project for release a.x + # which could be quite often for new releases + export LLVM_HASH=$(git ls-remote https://github.com/llvm/llvm-project.git refs/heads/release/${{ matrix.clang-runtime}}.x | tr '\t' '-') + fi + + echo "CLING_HASH=$CLING_HASH" >> $GITHUB_ENV + echo "LLVM_HASH=$LLVM_HASH" >> $GITHUB_ENV + + - uses: nelonoel/branch-name@v1.0.1 + + - name: Setup default Build Type on *nux + if: runner.os != 'windows' + run: | + echo "BUILD_TYPE=Release" >> $GITHUB_ENV + echo "CODE_COVERAGE=0" >> $GITHUB_ENV + os="${{ matrix.os }}" + if [[ "${os}" == "macos"* ]]; then + echo "ncpus=$(sysctl -n hw.ncpu)" >> $GITHUB_ENV + else + echo "ncpus=$(nproc --all)" >> $GITHUB_ENV + fi + + - name: Install deps on Linux + if: runner.os == 'Linux' + run: | + # Install deps + sudo apt update + sudo apt install git g++ debhelper devscripts gnupg python3 valgrind + sudo apt autoremove + sudo apt clean + + - name: Install mamba + uses: mamba-org/provision-with-micromamba@main + with: + environment-file: environment-wasm-build.yml + environment-name: CppInterOp-wasm-build + + - name: Setup emsdk + shell: bash -l {0} + run: | + emsdk install 3.1.45 + + - name: Restore Cache LLVM/Clang runtime build directory + uses: actions/cache/restore@v3 + 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' }} + + - name: Build LLVM/Cling on Unix systems if the cache is invalid + if: ${{ runner.os != 'windows' && steps.cache.outputs.cache-hit != 'true' }} + run: | + cling_on=$(echo "${{ matrix.cling }}" | tr '[:lower:]' '[:upper:]') + if [[ "${cling_on}" == "ON" ]]; then + git clone https://github.com/root-project/cling.git + cd ./cling + git checkout tags/v${{ matrix.cling-version }} + cd .. + git clone --depth=1 -b cling-llvm${{ matrix.clang-runtime }} https://github.com/root-project/llvm-project.git + else # repl + git clone --depth=1 -b release/${{ matrix.clang-runtime }}.x https://github.com/llvm/llvm-project.git + fi + cd llvm-project + # Build + mkdir build + if [[ "${cling_on}" == "ON" ]]; then + cd build + cmake -DLLVM_ENABLE_PROJECTS="clang;lld" \ + -DLLVM_EXTERNAL_PROJECTS=cling \ + -DLLVM_EXTERNAL_CLING_SOURCE_DIR=../../cling \ + -DLLVM_TARGETS_TO_BUILD="WebAssembly;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 \ + -DLLVM_ENABLE_ZSTD=OFF \ + -DLLVM_ENABLE_TERMINFO=OFF \ + -DLLVM_ENABLE_LIBXML2=OFF \ + ../llvm + cmake --build . --target lld --parallel ${{ env.ncpus }} + cmake --build . --target clang --parallel ${{ env.ncpus }} + cmake --build . --target cling --parallel ${{ env.ncpus }} + # Now build gtest.a and gtest_main for CppInterOp to run its tests. + cmake --build . --target gtest_main --parallel ${{ env.ncpus }} + else + # Apply patches + git apply -v ../patches/llvm/clang${{ matrix.clang-runtime }}-*.patch + echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:" + cd build + cmake -DLLVM_ENABLE_PROJECTS="clang;lld" \ + -DLLVM_TARGETS_TO_BUILD="WebAssembly;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 \ + -DLLVM_ENABLE_ZSTD=OFF \ + -DLLVM_ENABLE_TERMINFO=OFF \ + -DLLVM_ENABLE_LIBXML2=OFF \ + ../llvm + cmake --build . --target all --parallel ${{ env.ncpus }} + fi + cd ../../ + + - name: Save Cache LLVM/Clang runtime build directory + uses: actions/cache/save@v3 + if: ${{ steps.cache.outputs.cache-hit != 'true' }} + with: + path: | + llvm-project + ${{ matrix.cling=='On' && 'cling' || '' }} + key: ${{ steps.cache.outputs.cache-primary-key }} + + - name: Emscripten build of CppInterOp on Unix systems + if: ${{ runner.os != 'windows' }} + shell: bash -l {0} + run: | + emsdk activate 3.1.45 + source $CONDA_EMSDK_DIR/emsdk_env.sh + micromamba create -f environment-wasm.yml --platform=emscripten-wasm32 + + export EMPACK_PREFIX=$MAMBA_ROOT_PREFIX/envs/CppInterOp-wasm-build + #FIXME: Remove hardcoding of PREFIX path + os="${{ matrix.os }}" + if [[ "${os}" == "macos"* ]]; then + export PREFIX=/Users/runner/micromamba-root/envs/CppInterOp-wasm + else + export PREFIX=/home/runner/micromamba-root/envs/CppInterOp-wasm + fi + export CMAKE_PREFIX_PATH=$PREFIX + export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX + + LLVM_DIR="$(pwd)/llvm-project" + LLVM_BUILD_DIR="$(pwd)/llvm-project/build" + cling_on=$(echo "${{ matrix.cling }}" | tr '[:lower:]' '[:upper:]') + if [[ "${cling_on}" == "ON" ]]; then + CLING_DIR="$(pwd)/cling" + CLING_BUILD_DIR="$(pwd)/cling/build" + 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" + else + CPLUS_INCLUDE_PATH="${LLVM_DIR}/llvm/include:${LLVM_DIR}/clang/include:${LLVM_BUILD_DIR}/include:${LLVM_BUILD_DIR}/tools/clang/include:$PWD/include" + fi + + # Build CppInterOp next to cling and llvm-project. + mkdir build + cd build + export CPPINTEROP_BUILD_DIR=$PWD + + if [[ "${cling_on}" == "ON" ]]; then + emcmake cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \ + -DUSE_CLING=ON \ + -DUSE_REPL=OFF \ + -DCMAKE_PREFIX_PATH=$PREFIX \ + -DCling_DIR=$LLVM_BUILD_DIR/tools/cling \ + -DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm \ + -DClang_DIR=$LLVM_BUILD_DIR/lib/cmake/clang \ + -DBUILD_SHARED_LIBS=ON \ + -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \ + -DCMAKE_INSTALL_PREFIX=$PREFIX \ + -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \ + -DZLIB_INCLUDE_DIR=$PREFIX/include \ + -DZLIB_LIBRARY=$PREFIX/lib/ \ + ../ + else + emcmake cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \ + -DUSE_CLING=OFF \ + -DUSE_REPL=ON \ + -DCMAKE_PREFIX_PATH="/home/runner/micromamba-root/envs/CppInterOp-wasm/" \ + -DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm \ + -DClang_DIR=$LLVM_BUILD_DIR/lib/cmake/clang \ + -DBUILD_SHARED_LIBS=OFF \ + -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \ + -DCMAKE_INSTALL_PREFIX=$PREFIX \ + -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \ + -DZLIB_INCLUDE_DIR=$PREFIX/include \ + -DZLIB_LIBRARY=$PREFIX/lib/ \ + ../ + fi + + EMCC_CFLAGS='-sERROR_ON_UNDEFINED_SYMBOLS=0' emmake make -j ${{ env.ncpus }} + + cd .. + + echo "CB_PYTHON_DIR=$CB_PYTHON_DIR" >> $GITHUB_ENV + echo "CPPINTEROP_BUILD_DIR=$CPPINTEROP_BUILD_DIR" >> $GITHUB_ENV + echo "CPPINTEROP_DIR=$CPPINTEROP_DIR" >> $GITHUB_ENV + echo "LLVM_BUILD_DIR=$LLVM_BUILD_DIR" >> $GITHUB_ENV + echo "CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH" >> $GITHUB_ENV diff --git a/CMakeLists.txt b/CMakeLists.txt index f248be12f..548e535f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -371,7 +371,15 @@ endif() option(CPPINTEROP_INCLUDE_DOCS "Generate build targets for the CppInterOp docs.") option(CPPINTEROP_ENABLE_DOXYGEN "Use doxygen to generate CppInterOp interal API documentation.") option(CPPINTEROP_ENABLE_SPHINX "Use sphinx to generage CppInterOp user documentation") -option(CPPINTEROP_ENABLE_TESTING "Enables the testing infrastructure." ON) + + +if(EMSCRIPTEN) + message("Build with emscripten") + option(CPPINTEROP_ENABLE_TESTING "Enables the testing infrastructure." OFF) +else() + message("Build with cmake") + option(CPPINTEROP_ENABLE_TESTING "Enables the testing infrastructure." ON) +endif() if(MSVC) diff --git a/environment-wasm-build.yml b/environment-wasm-build.yml new file mode 100644 index 000000000..ce5cbfa58 --- /dev/null +++ b/environment-wasm-build.yml @@ -0,0 +1,7 @@ +name: CppInterOp-wasm-build +channels: + - conda-forge +dependencies: + - cmake + - emsdk >=3.1.11 + - empack >=2.0.1 \ No newline at end of file diff --git a/environment-wasm.yml b/environment-wasm.yml new file mode 100644 index 000000000..cfc05d217 --- /dev/null +++ b/environment-wasm.yml @@ -0,0 +1,5 @@ +name: CppInterOp-wasm +channels: + - https://repo.mamba.pm/emscripten-forge +dependencies: + - zlib From 30ffcc2f2aadbdf519170937b9bc7211196386ab Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Fri, 1 Mar 2024 08:27:56 +0000 Subject: [PATCH 52/59] Prepare for release v1.2.0 --- VERSION | 2 +- docs/ReleaseNotes.md | 39 ++++++++++----------------------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/VERSION b/VERSION index 6a0b8705c..26aaba0e8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.0;dev +1.2.0 diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index c9f927734..32ac4f663 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -35,39 +35,16 @@ External Dependencies * clang17 -Introspection -------------- - -* - - -Just-in-Time Compilation ------------------------- - -* - - -Incremental C++ ---------------- - -* - - Misc ---- -* +* Add support for Windows +* Add support for Wasm Fixed Bugs ---------- -[XXX](https://github.com/compiler-research/CppInterOp/issues/XXX) - - - Special Kudos ============= @@ -78,7 +55,11 @@ FirstName LastName (#commits) A B (N) - +fsfod (30) +mcbarton (10) +Vassil Vassilev (6) +Shreyas Atre (4) +Alexander Penev (2) +Saqib (1) +Aaron Jomy (1) + From 28e981791e94a1037d60228eea2ea2965f989a0b Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Fri, 1 Mar 2024 20:01:14 +0000 Subject: [PATCH 53/59] Bump CppInterOp version to 1.3.0 --- VERSION | 2 +- docs/ReleaseNotes.md | 43 +++++++++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/VERSION b/VERSION index 26aaba0e8..64615d2c9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.0 +1.3.0;dev diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 32ac4f663..9099548f8 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -2,7 +2,7 @@ Introduction ============ This document contains the release notes for the language interoperability -library CppInterOp, release 1.2.0. CppInterOp is built on top of +library CppInterOp, release 1.3.0. CppInterOp is built on top of [Clang](http://clang.llvm.org) and [LLVM](http://llvm.org>) compiler infrastructure. Here we describe the status of CppInterOp in some detail, including major improvements from the previous release and new feature work. @@ -18,7 +18,7 @@ the necessary introspection information to the other side helping the language cross talk. -What's New in CppInterOp 1.2.0? +What's New in CppInterOp 1.3.0? ============================= Some of the major new features and improvements to Clad are listed here. Generic @@ -35,16 +35,39 @@ External Dependencies * clang17 +Introspection +------------- + +* + + +Just-in-Time Compilation +------------------------ + +* + + +Incremental C++ +--------------- + +* + + Misc ---- -* Add support for Windows -* Add support for Wasm +* Fixed Bugs ---------- +[XXX](https://github.com/compiler-research/CppInterOp/issues/XXX) + + + Special Kudos ============= @@ -55,11 +78,7 @@ FirstName LastName (#commits) A B (N) -fsfod (30) -mcbarton (10) -Vassil Vassilev (6) -Shreyas Atre (4) -Alexander Penev (2) -Saqib (1) -Aaron Jomy (1) - + From 60fc310dab84c0078cd0a5fdf596504d49762f76 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Sun, 3 Mar 2024 20:32:15 +0000 Subject: [PATCH 54/59] [cmake] Work around a bug in the llvm config. In short we use variables which require including `GNUInstallDirs` but we are expecting somebody else to include it for us. See llvm/llvm-project#83802 --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 548e535f0..f4efb0eed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.13) +include(GNUInstallDirs) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake" From bd72e91a5f34a8a9507801b6302e91b82b1aa1f8 Mon Sep 17 00:00:00 2001 From: Alexander Penev Date: Tue, 5 Mar 2024 07:38:33 +0000 Subject: [PATCH 55/59] Fix Cmake install folder --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f4efb0eed..b8ab68251 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -331,7 +331,7 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CppInterOp/CppInterOpConfigVersion.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/CppInterOp/CppInterOpConfigVersion.cmake @ONLY) -install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/CppInterOp +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/CppInterOp/ DESTINATION lib/cmake/CppInterOp FILES_MATCHING PATTERN "*.cmake" From 1334558c5c21247d5cdc234a31a81702b4720860 Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Wed, 6 Mar 2024 15:40:42 +0000 Subject: [PATCH 56/59] Support llvm 18 --- .github/workflows/ci.yml | 91 +++++++++++++++++++++-- CMakeLists.txt | 8 +- lib/Interpreter/DynamicLibraryManager.cpp | 8 +- 3 files changed, 95 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d8c46470..e05d35561 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,21 @@ jobs: fail-fast: false matrix: include: + - name: ubu22-x86-gcc12-clang-repl-18-cppyy + os: ubuntu-22.04 + compiler: gcc-12 + clang-runtime: '18' + cling: Off + cppyy: On + coverage: true + - name: ubu22-x86-gcc12-clang-repl-18-xeus-clang-repl + os: ubuntu-22.04 + compiler: gcc-12 + clang-runtime: '18' + cling: Off + cppyy: On + xeus-clang-repl: On + coverage: true - name: ubu22-x86-gcc12-clang-repl-17-cppyy os: ubuntu-22.04 compiler: gcc-12 @@ -70,6 +85,19 @@ jobs: coverage: true #Commented out until Ubuntu on arm Github runner becomes available #os key to be replaced once known + #- name: ubu22-arm-gcc12-clang-repl-18-cppyy + # os: ubuntu-22.04-arm + # compiler: gcc-12 + # clang-runtime: '18' + # cling: Off + # cppyy: On + #- name: ubu22-arm-gcc12-clang-repl-18-xeus-clang-repl + # os: ubuntu-22.04-arm + # compiler: gcc-12 + # clang-runtime: '18' + # cling: Off + # cppyy: On + # xeus-clang-repl: On #- name: ubu22-arm-gcc12-clang-repl-17-cppyy # os: ubuntu-22.04-arm # compiler: gcc-12 @@ -114,6 +142,12 @@ jobs: # xeus-clang-repl: On #FIXME: Windows CppInterOp tests expected to fail #until https://github.com/compiler-research/CppInterOp/issues/188 is solved + - name: win2022-msvc-clang-repl-18 + os: windows-2022 + compiler: msvc + clang-runtime: '18' + cling: Off + cppyy: Off - name: win2022-msvc-clang-repl-17 os: windows-2022 compiler: msvc @@ -152,6 +186,19 @@ jobs: # cling: On # cling-version: '1.0' # cppyy: On + - name: osx14-arm-clang-clang-repl-18-cppyy + os: macos-14 + compiler: clang + clang-runtime: '18' + cling: Off + cppyy: On + - name: osx14-arm-clang-clang-repl-18-xeus-clang-repl + os: macos-14 + compiler: clang + clang-runtime: '18' + cling: Off + cppyy: On + xeus-clang-repl: On - name: osx14-arm-clang-clang-repl-17-cppyy os: macos-14 compiler: clang @@ -193,6 +240,19 @@ jobs: cling-version: '1.0' cppyy: On xeus-clang-repl: On + - name: osx13-x86-clang-clang-repl-18-cppyy + os: macos-13 + compiler: clang + clang-runtime: '18' + cling: Off + cppyy: On + - name: osx13-x86-clang-clang-repl-18-xeus-clang-repl + os: macos-13 + compiler: clang + clang-runtime: '18' + cling: Off + cppyy: On + xeus-clang-repl: On - name: osx13-x86-clang-clang-repl-17-cppyy os: macos-13 compiler: clang @@ -454,8 +514,11 @@ jobs: cmake --build . --target gtest_main --parallel ${{ env.ncpus }} else # Apply patches - git apply -v ../patches/llvm/clang${{ matrix.clang-runtime }}-*.patch - echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:" + llvm_vers=$(echo "${{ matrix.clang-runtime }}" | tr '[:lower:]' '[:upper:]') + if [[ "${llvm_vers}" != "18" ]]; then + git apply -v ../patches/llvm/clang${{ matrix.clang-runtime }}-*.patch + echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:" + fi cd build cmake -DLLVM_ENABLE_PROJECTS="clang;lld" \ -DLLVM_TARGETS_TO_BUILD="WebAssembly;host;NVPTX" \ @@ -526,7 +589,7 @@ jobs: git apply -v clang16-2-CUDA.patch git apply -v clang16-3-WeakRef.patch } - elseif ( "${{ matrix.clang-runtime }}" -imatch "16" ) + elseif ( "${{ matrix.clang-runtime }}" -imatch "17" ) { git apply -v clang17-1-NewOperator.patch } @@ -920,6 +983,11 @@ jobs: fail-fast: false matrix: include: + - name: ubu22-x86-gcc12-clang-repl-18-emscripten_wasm + os: ubuntu-22.04 + compiler: gcc-12 + clang-runtime: '18' + cling: Off - name: ubu22-x86-gcc12-clang-repl-17-emscripten_wasm os: ubuntu-22.04 compiler: gcc-12 @@ -936,6 +1004,11 @@ jobs: clang-runtime: '13' cling: On cling-version: '1.0' + - name: osx14-arm-clang-clang-repl-18-emscripten_wasm + os: macos-14 + compiler: clang + clang-runtime: '18' + cling: Off - name: osx14-arm-clang-clang-repl-17-emscripten_wasm os: macos-14 compiler: clang @@ -952,6 +1025,11 @@ jobs: clang-runtime: '13' cling: On cling-version: '1.0' + - name: osx13-x86-clang-clang-repl-18-emscripten_wasm + os: macos-13 + compiler: clang + clang-runtime: '18' + cling: Off - name: osx13-x86-clang-clang-repl-17-emscripten_wasm os: macos-13 compiler: clang @@ -1081,8 +1159,11 @@ jobs: cmake --build . --target gtest_main --parallel ${{ env.ncpus }} else # Apply patches - git apply -v ../patches/llvm/clang${{ matrix.clang-runtime }}-*.patch - echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:" + llvm_vers=$(echo "${{ matrix.clang-runtime }}" | tr '[:lower:]' '[:upper:]') + if [[ "${llvm_vers}" != "18" ]]; then + git apply -v ../patches/llvm/clang${{ matrix.clang-runtime }}-*.patch + echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:" + fi cd build cmake -DLLVM_ENABLE_PROJECTS="clang;lld" \ -DLLVM_TARGETS_TO_BUILD="WebAssembly;host;NVPTX" \ diff --git a/CMakeLists.txt b/CMakeLists.txt index b8ab68251..55a2f3a99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,11 +56,11 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) ## Define supported version of clang and llvm set(CLANG_MIN_SUPPORTED 13.0) - set(CLANG_MAX_SUPPORTED "17.0.x") - set(CLANG_VERSION_UPPER_BOUND 17.1.0) + set(CLANG_MAX_SUPPORTED "18.1.x") + set(CLANG_VERSION_UPPER_BOUND 19.0.0) set(LLVM_MIN_SUPPORTED 13.0) - set(LLVM_MAX_SUPPORTED "17.0.x") - set(LLVM_VERSION_UPPER_BOUND 17.1.0) + set(LLVM_MAX_SUPPORTED "18.1.x") + set(LLVM_VERSION_UPPER_BOUND 19.0.0) ## Set Cmake packages search order diff --git a/lib/Interpreter/DynamicLibraryManager.cpp b/lib/Interpreter/DynamicLibraryManager.cpp index 6ec0e329b..d2cf5a172 100644 --- a/lib/Interpreter/DynamicLibraryManager.cpp +++ b/lib/Interpreter/DynamicLibraryManager.cpp @@ -69,12 +69,14 @@ namespace Cpp { for (const std::string& P : SysPaths) addSearchPath(P, /*IsUser*/ false); } - +#if LLVM_VERSION_MAJOR < 18 +#define starts_with_insensitive startswith_insensitive +#endif ///\returns substitution of pattern in the front of original with replacement /// Example: substFront("@rpath/abc", "@rpath/", "/tmp") -> "/tmp/abc" static std::string substFront(StringRef original, StringRef pattern, StringRef replacement) { - if (!original.startswith_insensitive(pattern)) + if (!original.starts_with_insensitive(pattern)) return original.str(); SmallString<512> result(replacement); result.append(original.drop_front(pattern.size())); @@ -300,7 +302,7 @@ namespace Cpp { // Subst all known linker variables ($origin, @rpath, etc.) #ifdef __APPLE__ // On MacOS @rpath is preplaced by all paths in RPATH one by one. - if (libStem.startswith_insensitive("@rpath")) { + if (libStem.starts_with_insensitive("@rpath")) { for (auto& P : RPath) { std::string result = substFront(libStem, "@rpath", P); if (isSharedLibrary(result)) From 687ae1899d29de96712fcda28d1f65c3af94fdad Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:00:51 +0000 Subject: [PATCH 57/59] Modify cmake config file to set correct suffix and prefix for library Co-Authored-By: Vassil Vassilev --- .github/workflows/ci.yml | 2 +- cmake/CppInterOp/CppInterOpConfig.cmake.in | 23 +++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e05d35561..a7c43a590 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1233,7 +1233,7 @@ jobs: -DCling_DIR=$LLVM_BUILD_DIR/tools/cling \ -DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm \ -DClang_DIR=$LLVM_BUILD_DIR/lib/cmake/clang \ - -DBUILD_SHARED_LIBS=ON \ + -DBUILD_SHARED_LIBS=OFF \ -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \ -DCMAKE_INSTALL_PREFIX=$PREFIX \ -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \ diff --git a/cmake/CppInterOp/CppInterOpConfig.cmake.in b/cmake/CppInterOp/CppInterOpConfig.cmake.in index 6a2a810a7..414c1c0ad 100644 --- a/cmake/CppInterOp/CppInterOpConfig.cmake.in +++ b/cmake/CppInterOp/CppInterOpConfig.cmake.in @@ -10,19 +10,20 @@ get_filename_component(CPPINTEROP_INSTALL_PREFIX "${CPPINTEROP_INSTALL_PREFIX}" include(CMakeSystemSpecificInformation) ### build/install workaround +if (@BUILD_SHARED_LIBS@) + set(__lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(__lib_prefix ${CMAKE_SHARED_LIBRARY_PREFIX}) +else() + set(__lib_suffix ${CMAKE_STATIC_LIBRARY_SUFFIX}) + set(__lib_prefix ${CMAKE_STATIC_LIBRARY_PREFIX}) +endif() if (IS_DIRECTORY "${CPPINTEROP_INSTALL_PREFIX}/include") set(_include "${CPPINTEROP_INSTALL_PREFIX}/include") - set(_libs "${CPPINTEROP_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clangCppInterOp${CMAKE_SHARED_LIBRARY_SUFFIX}") + set(_libs "${CPPINTEROP_INSTALL_PREFIX}/lib/${__lib_prefix}clangCppInterOp${__lib_suffix}") else() set(_include "@CMAKE_CURRENT_SOURCE_DIR@/include") - set(_libs "@CMAKE_CURRENT_BINARY_DIR@/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clangCppInterOp${CMAKE_SHARED_LIBRARY_SUFFIX}") -endif() - -if (IS_DIRECTORY "${CPPINTEROP_INSTALL_PREFIX}/lib/cmake/CppInterOp") - set(_cmake "${CPPINTEROP_INSTALL_PREFIX}/lib/cmake/CppInterOp") -else() - set(_cmake "@CMAKE_CURRENT_SOURCE_DIR@/cmake/CppInterOp") + set(_libs "@CMAKE_CURRENT_BINARY_DIR@/lib/${__lib_prefix}clangCppInterOp${__lib_suffix}") endif() ### @@ -33,7 +34,11 @@ set(CPPINTEROP_INCLUDE_DIRS "${_include}") set(CPPINTEROP_LIBRARIES "${_libs}") # Provide all our library targets to users. -add_library(clangCppInterOp SHARED IMPORTED) +if (@BUILD_SHARED_LIBS@) + add_library(clangCppInterOp SHARED IMPORTED) +else() + add_library(clangCppInterOp STATIC IMPORTED) +endif() set_property(TARGET clangCppInterOp PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${_include}") set_property(TARGET clangCppInterOp PROPERTY IMPORTED_LOCATION "${_libs}") From a6f001da8e833b384e00dbfad7246d47ac37f498 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Fri, 15 Mar 2024 20:18:02 +0000 Subject: [PATCH 58/59] Implement detection of resource and include dirs. This is useful when deployed CppInterOp needs to create an interpreter. Often the interpreter itself cannot use the clang toolchain logic to discover both the resource-dir and the include paths. This is because CppInterOp is a library and usually put in the `lib` folder whereas the toolchain logic expects things to be relative to the `bin` folder. In such setups, we can ask CppInterOp to detect the resource directory by asking clang about it. In the same vain, of finding C and C++ headers we can ask the system compiler about the include paths. --- include/clang/Interpreter/CppInterOp.h | 15 ++++++ lib/Interpreter/CppInterOp.cpp | 62 ++++++++++++++++++++++++ unittests/CppInterOp/CMakeLists.txt | 3 ++ unittests/CppInterOp/InterpreterTest.cpp | 25 +++++++++- 4 files changed, 104 insertions(+), 1 deletion(-) diff --git a/include/clang/Interpreter/CppInterOp.h b/include/clang/Interpreter/CppInterOp.h index 8e5521f36..96345ffb6 100644 --- a/include/clang/Interpreter/CppInterOp.h +++ b/include/clang/Interpreter/CppInterOp.h @@ -444,6 +444,21 @@ namespace Cpp { /// Returns the resource-dir path (for headers). const char* GetResourceDir(); + /// Uses the underlying clang compiler to detect the resource directory. + /// In essence calling clang -print-resource-dir and checks if it ends with + /// a compatible to CppInterOp version. + ///\param[in] ClangBinaryName - the name (or the full path) of the compiler + /// to ask. + std::string DetectResourceDir(const char* ClangBinaryName = "clang"); + + /// Asks the system compiler for its default include paths. + ///\param[out] Paths - the list of include paths returned by eg. + /// `c++ -xc++ -E -v /dev/null 2>&1` + ///\param[in] CompilerName - the name (or the full path) of the compiler + /// binary file. + void DetectSystemCompilerIncludePaths(std::vector& Paths, + const char* CompilerName = "c++"); + /// Secondary search path for headers, if not found using the /// GetResourceDir() function. void AddIncludePath(const char *dir); diff --git a/lib/Interpreter/CppInterOp.cpp b/lib/Interpreter/CppInterOp.cpp index 1bc9a2ffd..0b93bc8dc 100644 --- a/lib/Interpreter/CppInterOp.cpp +++ b/lib/Interpreter/CppInterOp.cpp @@ -38,6 +38,10 @@ #include #ifndef STDOUT_FILENO #define STDOUT_FILENO 1 +// For exec(). +#include +#define popen(x, y) (_popen(x, y)) +#define pclose (_pclose) #endif #else #include @@ -2534,6 +2538,64 @@ namespace Cpp { return getInterp().getCI()->getHeaderSearchOpts().ResourceDir.c_str(); } + ///\returns 0 on success. + static bool exec(const char* cmd, std::vector& outputs) { +#define DEBUG_TYPE "exec" + + std::array buffer; + std::unique_ptr pipe(popen(cmd, "r"), pclose); + LLVM_DEBUG(dbgs() << "Executing command '" << cmd << "'\n"); + + if (!pipe) { + LLVM_DEBUG(dbgs() << "Execute failed!\n"); + perror("exec: "); + return false; + } + + LLVM_DEBUG(dbgs() << "Execute returned:\n"); + while (fgets(buffer.data(), static_cast(buffer.size()), pipe.get())) { + LLVM_DEBUG(dbgs() << buffer.data()); + llvm::StringRef trimmed = buffer.data(); + outputs.push_back(trimmed.trim().str()); + } + +#undef DEBUG_TYPE + + return true; + } + + std::string DetectResourceDir(const char* ClangBinaryName /* = clang */) { + std::string cmd = std::string(ClangBinaryName) + " -print-resource-dir"; + std::vector outs; + exec(cmd.c_str(), outs); + if (outs.empty() || outs.size() > 1) + return ""; + + std::string detected_resource_dir = outs.back(); + + std::string version = +#if CLANG_VERSION_MAJOR < 16 + CLANG_VERSION_STRING; +#else + CLANG_VERSION_MAJOR_STRING; +#endif + // We need to check if the detected resource directory is compatible. + if (llvm::sys::path::filename(detected_resource_dir) != version) + return ""; + + return detected_resource_dir; + } + + void DetectSystemCompilerIncludePaths(std::vector& Paths, + const char* CompilerName /*= "c++"*/) { + std::string cmd = "LC_ALL=C "; + cmd += CompilerName; + cmd += " -xc++ -E -v /dev/null 2>&1 | sed -n -e '/^.include/,${' -e '/^ " + "\\/.*/p' -e '}'"; + std::vector outs; + exec(cmd.c_str(), Paths); + } + void AddIncludePath(const char *dir) { getInterp().AddIncludePath(dir); } diff --git a/unittests/CppInterOp/CMakeLists.txt b/unittests/CppInterOp/CMakeLists.txt index 75dccf556..00e455605 100644 --- a/unittests/CppInterOp/CMakeLists.txt +++ b/unittests/CppInterOp/CMakeLists.txt @@ -18,6 +18,9 @@ target_link_libraries(CppInterOpTests clangCppInterOp ) +set_source_files_properties(InterpreterTest.cpp PROPERTIES COMPILE_DEFINITIONS + "LLVM_BINARY_DIR=\"${LLVM_BINARY_DIR}\"" + ) export_executable_symbols(CppInterOpTests) unset(LLVM_LINK_COMPONENTS) diff --git a/unittests/CppInterOp/InterpreterTest.cpp b/unittests/CppInterOp/InterpreterTest.cpp index 5c30108b2..19cc1bf11 100644 --- a/unittests/CppInterOp/InterpreterTest.cpp +++ b/unittests/CppInterOp/InterpreterTest.cpp @@ -1,5 +1,8 @@ #include "clang/Interpreter/CppInterOp.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/Path.h" + #include #include "gtest/gtest.h" @@ -14,6 +17,7 @@ TEST(InterpreterTest, DISABLED_DebugFlag) { #else TEST(InterpreterTest, DebugFlag) { #endif // NDEBUG + Cpp::CreateInterpreter(); EXPECT_FALSE(Cpp::IsDebugOutputEnabled()); std::string cerrs; testing::internal::CaptureStderr(); @@ -49,7 +53,7 @@ TEST(InterpreterTest, Evaluate) { EXPECT_FALSE(HadError) ; } -TEST(InterpreterTest, Process) { +TEST(InterpreterTest, Process) { Cpp::CreateInterpreter(); EXPECT_TRUE(Cpp::Process("") == 0); EXPECT_TRUE(Cpp::Process("int a = 12;") == 0); @@ -80,3 +84,22 @@ TEST(InterpreterTest, CreateInterpreter) { EXPECT_TRUE(Cpp::GetNamed("cpp17")); EXPECT_FALSE(Cpp::GetNamed("cppUnknown")); } + +#ifdef LLVM_BINARY_DIR +TEST(InterpreterTest, DetectResourceDir) { +#else +TEST(InterpreterTest, DISABLED_DetectResourceDir) { +#endif // LLVM_BINARY_DIR + Cpp::CreateInterpreter(); + EXPECT_STRNE(Cpp::DetectResourceDir().c_str(), Cpp::GetResourceDir()); + llvm::SmallString<256> Clang(LLVM_BINARY_DIR); + llvm::sys::path::append(Clang, "bin", "clang"); + std::string DetectedPath = Cpp::DetectResourceDir(Clang.str().str().c_str()); + EXPECT_STREQ(DetectedPath.c_str(), Cpp::GetResourceDir()); +} + +TEST(InterpreterTest, DetectSystemCompilerIncludePaths) { + std::vector includes; + Cpp::DetectSystemCompilerIncludePaths(includes); + EXPECT_FALSE(includes.empty()); +} From 468031a4dd7e7275899d84b3a90587ec883c586f Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Mon, 18 Mar 2024 23:57:11 +0200 Subject: [PATCH 59/59] [cmake] Set the language to C++. --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55a2f3a99..ca7a5bd69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.13) +enable_language(CXX) +set(CMAKE_CXX_EXTENSIONS NO) + include(GNUInstallDirs) set(CMAKE_MODULE_PATH