From ec6ae86565de73be6e37ec4230c41d1b0be83a57 Mon Sep 17 00:00:00 2001 From: mcbarton Date: Sun, 13 Apr 2025 19:30:15 +0100 Subject: [PATCH 1/7] Build CppInterOp as a shared library on Windows --- .github/workflows/Windows.yml | 58 ++++++++++++++++++++++------------ CMakeLists.txt | 12 +++---- lib/Interpreter/CMakeLists.txt | 3 +- 3 files changed, 45 insertions(+), 28 deletions(-) diff --git a/.github/workflows/Windows.yml b/.github/workflows/Windows.yml index addb6e060..3e24ba2b3 100644 --- a/.github/workflows/Windows.yml +++ b/.github/workflows/Windows.yml @@ -21,13 +21,13 @@ jobs: fail-fast: false matrix: include: - - name: win2025-msvc-clang-repl-19 + - name: win2025-shared-lib os: windows-2025 - compiler: msvc - clang-runtime: '19' + compiler: clang + clang-runtime: '20' cling: Off llvm_enable_projects: "clang" - llvm_targets_to_build: "host;NVPTX" + llvm_targets_to_build: "host" steps: - uses: actions/checkout@v4 @@ -73,7 +73,7 @@ jobs: 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' }} + 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' }}-shared-lib lookup-only: true - name: Setup default Build Type on Windows @@ -93,10 +93,10 @@ jobs: 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 + $env:CC="clang-cl" + $env:CXX="clang-cl" + echo "CC=clang-cl" >> $env:GITHUB_ENV + echo "CXX=clang-cl" >> $env:GITHUB_ENV } elseif ( "${{ matrix.compiler }}" -imatch "msvc" ) { @@ -111,7 +111,9 @@ jobs: if: ${{ steps.cache.outputs.cache-hit != 'true' }} run: | choco install findutils + choco install ninja $env:PATH="C:\Program Files (x86)\GnuWin32\bin;$env:PATH" + $env:PATH="C:\Program Files (x86)\Ninja\bin;$env:PATH" - name: Build LLVM/Cling on Windows systems if the cache is invalid if: ${{ steps.cache.outputs.cache-hit != 'true' }} @@ -130,7 +132,7 @@ jobs: } else { - git clone --depth=1 -b release/${{ matrix.clang-runtime }}.x https://github.com/llvm/llvm-project.git + git clone --depth=1 -b llvm-export-api-20.0 https://github.com/fsfod/llvm-project.git } cd llvm-project @@ -174,7 +176,7 @@ jobs: } cd build echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:" - cmake -DLLVM_ENABLE_PROJECTS="${{ matrix.llvm_enable_projects}}" ` + cmake -G Ninja -DLLVM_ENABLE_PROJECTS="${{ matrix.llvm_enable_projects}}" ` -DLLVM_TARGETS_TO_BUILD="${{ matrix.llvm_targets_to_build }}" ` -DCMAKE_BUILD_TYPE=Release ` -DLLVM_ENABLE_ASSERTIONS=ON ` @@ -185,6 +187,15 @@ jobs: -DLLVM_ENABLE_ZSTD=OFF ` -DLLVM_ENABLE_TERMINFO=OFF ` -DLLVM_ENABLE_LIBXML2=OFF ` + -DLLVM_ENABLE_PLUGINS=On ` + -DLLVM_BUILD_LLVM_DYLIB=ON ` + -DLLVM_BUILD_LLVM_DYLIB_VIS=ON ` + -DLLVM_LINK_LLVM_DYLIB=ON ` + -DCLANG_LINK_CLANG_DYLIB=ON ` + -DCMAKE_ASM_MASM_COMPILER=llvm-ml ` + -DCMAKE_ASM_MASM_FLAGS="-m64" ` + -DCMAKE_CXX_COMPILER=clang-cl ` + -DCMAKE_C_COMPILER=clang-cl ` ..\llvm cmake --build . --config Release --target clang clangInterpreter clangStaticAnalyzerCore --parallel ${{ env.ncpus }} } @@ -225,10 +236,10 @@ jobs: fail-fast: false matrix: include: - - name: win2025-msvc-clang-repl-19 + - name: win2025-shared-lib os: windows-2025 - compiler: msvc - clang-runtime: '19' + compiler: clang + clang-runtime: '20' cling: Off cppyy: Off @@ -284,10 +295,10 @@ jobs: 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 + $env:CC="clang-cl" + $env:CXX="clang-cl" + echo "CC=clang-cl" >> $env:GITHUB_ENV + echo "CXX=clang-cl" >> $env:GITHUB_ENV } elseif ( "${{ matrix.compiler }}" -imatch "msvc" ) { @@ -298,6 +309,12 @@ jobs: echo "Unsupported compiler - fix YAML file" } + - name: Install deps on Windows + if: ${{ steps.cache.outputs.cache-hit != 'true' }} + run: | + choco install ninja + $env:PATH="C:\Program Files (x86)\Ninja\bin;$env:PATH" + - name: Restore Cache LLVM/Clang runtime build directory uses: actions/cache/restore@v4 id: cache @@ -305,7 +322,7 @@ jobs: 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' }} + 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' }}-shared-lib - name: Build and Test/Install CppInterOp on Windows systems run: | @@ -367,9 +384,10 @@ jobs: } else { - cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} ` + cmake -G Ninja -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} ` -DLLVM_DIR="$env:LLVM_BUILD_DIR\lib\cmake\llvm" ` -DLLVM_ENABLE_WERROR=On ` + -DBUILD_SHARED_LIBS=ON ` -DClang_DIR="$env:LLVM_BUILD_DIR\lib\cmake\clang" -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} -DCMAKE_INSTALL_PREFIX="$env:CPPINTEROP_DIR" ..\ cmake --build . --config ${{ env.BUILD_TYPE }} --target googletest --parallel ${{ env.ncpus }} } diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cf370790..e2950ae5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,14 +68,14 @@ include(GNUInstallDirs) ## Define supported version of clang and llvm set(CLANG_MIN_SUPPORTED 13.0) - set(CLANG_MAX_SUPPORTED "19.1.x") - set(CLANG_VERSION_UPPER_BOUND 20.0.0) + set(CLANG_MAX_SUPPORTED "20.1.x") + set(CLANG_VERSION_UPPER_BOUND 21.0.0) set(LLD_MIN_SUPPORTED 13.0) - set(LLD_MAX_SUPPORTED "19.1.x") - set(LLD_VERSION_UPPER_BOUND 20.0.0) + set(LLD_MAX_SUPPORTED "20.1.x") + set(LLD_VERSION_UPPER_BOUND 21.0.0) set(LLVM_MIN_SUPPORTED 13.0) - set(LLVM_MAX_SUPPORTED "19.1.x") - set(LLVM_VERSION_UPPER_BOUND 20.0.0) + set(LLVM_MAX_SUPPORTED "20.1.x") + set(LLVM_VERSION_UPPER_BOUND 21.0.0) ## Set Cmake packages search order diff --git a/lib/Interpreter/CMakeLists.txt b/lib/Interpreter/CMakeLists.txt index eccfc39af..1c92a455b 100644 --- a/lib/Interpreter/CMakeLists.txt +++ b/lib/Interpreter/CMakeLists.txt @@ -55,7 +55,6 @@ endif() if(NOT WIN32 AND NOT EMSCRIPTEN) 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) @@ -103,6 +102,7 @@ endif() clangStaticAnalyzerCore ) endif(LLVM_LINK_LLVM_DYLIB) +endif() add_llvm_library(clangCppInterOp DISABLE_LLVM_LINK_LLVM_DYLIB CppInterOp.cpp @@ -112,7 +112,6 @@ endif() ${link_libs} ) - if(EMSCRIPTEN) # FIXME: When dynamically linking the Emscripten shared library to the # unit tests main_module you get errors due to undefined symbols. The reading of the file From 150a2c20ddfdc97e5957c9d3d92df2d8094ad5b7 Mon Sep 17 00:00:00 2001 From: mcbarton Date: Mon, 14 Apr 2025 12:28:34 +0100 Subject: [PATCH 2/7] Update CMakeLists.txt --- lib/Interpreter/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Interpreter/CMakeLists.txt b/lib/Interpreter/CMakeLists.txt index 1c92a455b..e1f56060e 100644 --- a/lib/Interpreter/CMakeLists.txt +++ b/lib/Interpreter/CMakeLists.txt @@ -2,6 +2,7 @@ if(EMSCRIPTEN) set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) set(LLVM_LINK_COMPONENTS "") else() + if(NOT WIN32) set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} BinaryFormat @@ -10,6 +11,9 @@ else() OrcJit Support ) + else() + set(LLVM_LINK_COMPONENTS "") + endif() # FIXME: Investigate why this needs to be conditionally included. if ("LLVMFrontendDriver" IN_LIST LLVM_AVAILABLE_LIBS) list(APPEND LLVM_LINK_COMPONENTS FrontendDriver) From 44a5c0fe9aa33042f7edeb092af91768111b0383 Mon Sep 17 00:00:00 2001 From: mcbarton Date: Mon, 14 Apr 2025 12:38:43 +0100 Subject: [PATCH 3/7] Debug CMakeLists.txt --- lib/Interpreter/CMakeLists.txt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/Interpreter/CMakeLists.txt b/lib/Interpreter/CMakeLists.txt index e1f56060e..84bf0ce4f 100644 --- a/lib/Interpreter/CMakeLists.txt +++ b/lib/Interpreter/CMakeLists.txt @@ -2,7 +2,6 @@ if(EMSCRIPTEN) set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) set(LLVM_LINK_COMPONENTS "") else() - if(NOT WIN32) set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} BinaryFormat @@ -11,9 +10,6 @@ else() OrcJit Support ) - else() - set(LLVM_LINK_COMPONENTS "") - endif() # FIXME: Investigate why this needs to be conditionally included. if ("LLVMFrontendDriver" IN_LIST LLVM_AVAILABLE_LIBS) list(APPEND LLVM_LINK_COMPONENTS FrontendDriver) @@ -107,6 +103,7 @@ endif() ) endif(LLVM_LINK_LLVM_DYLIB) endif() +if(NOT WIN32) add_llvm_library(clangCppInterOp DISABLE_LLVM_LINK_LLVM_DYLIB CppInterOp.cpp @@ -115,6 +112,14 @@ endif() LINK_LIBS ${link_libs} ) +else() + add_llvm_library(clangCppInterOp + DISABLE_LLVM_LINK_LLVM_DYLIB + CppInterOp.cpp + CXCppInterOp.cpp + ${DLM} + ) +endif() if(EMSCRIPTEN) # FIXME: When dynamically linking the Emscripten shared library to the From b0cf479d0d6cc064b5b66f4998aa94d1eee21acf Mon Sep 17 00:00:00 2001 From: mcbarton Date: Mon, 14 Apr 2025 12:47:20 +0100 Subject: [PATCH 4/7] Debug --- lib/Interpreter/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Interpreter/CMakeLists.txt b/lib/Interpreter/CMakeLists.txt index 84bf0ce4f..05461e45c 100644 --- a/lib/Interpreter/CMakeLists.txt +++ b/lib/Interpreter/CMakeLists.txt @@ -113,6 +113,7 @@ if(NOT WIN32) ${link_libs} ) else() + message(STATUS "link_libs is ${link_libs}") add_llvm_library(clangCppInterOp DISABLE_LLVM_LINK_LLVM_DYLIB CppInterOp.cpp From 196c00ff316d9866cb75c8ccb9317af46998a5ef Mon Sep 17 00:00:00 2001 From: mcbarton Date: Mon, 14 Apr 2025 14:58:56 +0100 Subject: [PATCH 5/7] Update CMakeLists.txt --- lib/Interpreter/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Interpreter/CMakeLists.txt b/lib/Interpreter/CMakeLists.txt index 05461e45c..82cb2e43b 100644 --- a/lib/Interpreter/CMakeLists.txt +++ b/lib/Interpreter/CMakeLists.txt @@ -119,6 +119,8 @@ else() CppInterOp.cpp CXCppInterOp.cpp ${DLM} + ${link_libs} + clangAST ) endif() From 9c044696609b5708e7ad31dd4edf471e45dba01f Mon Sep 17 00:00:00 2001 From: mcbarton Date: Mon, 14 Apr 2025 15:04:09 +0100 Subject: [PATCH 6/7] Update CMakeLists.txt --- lib/Interpreter/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Interpreter/CMakeLists.txt b/lib/Interpreter/CMakeLists.txt index 82cb2e43b..93a6be338 100644 --- a/lib/Interpreter/CMakeLists.txt +++ b/lib/Interpreter/CMakeLists.txt @@ -119,7 +119,7 @@ else() CppInterOp.cpp CXCppInterOp.cpp ${DLM} - ${link_libs} + LINK_LIBS clangAST ) endif() From 80a8305de4bdd885552843d86ff3d7ab8cccffda Mon Sep 17 00:00:00 2001 From: mcbarton Date: Mon, 14 Apr 2025 15:11:49 +0100 Subject: [PATCH 7/7] Update CMakeLists.txt --- lib/Interpreter/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Interpreter/CMakeLists.txt b/lib/Interpreter/CMakeLists.txt index 93a6be338..16fa96c6d 100644 --- a/lib/Interpreter/CMakeLists.txt +++ b/lib/Interpreter/CMakeLists.txt @@ -120,7 +120,7 @@ else() CXCppInterOp.cpp ${DLM} LINK_LIBS - clangAST + ${cling_clang_interp} ) endif()