Skip to content

Commit 5a05154

Browse files
committed
Build CppInterOp as a shared library on Windows
1 parent ddd67a2 commit 5a05154

File tree

3 files changed

+45
-28
lines changed

3 files changed

+45
-28
lines changed

.github/workflows/Windows.yml

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
include:
24-
- name: win2025-msvc-clang-repl-19
24+
- name: win2025-shared-lib
2525
os: windows-2025
26-
compiler: msvc
27-
clang-runtime: '19'
26+
compiler: clang
27+
clang-runtime: '20'
2828
cling: Off
2929
llvm_enable_projects: "clang"
30-
llvm_targets_to_build: "host;NVPTX"
30+
llvm_targets_to_build: "host"
3131

3232
steps:
3333
- uses: actions/checkout@v4
@@ -73,7 +73,7 @@ jobs:
7373
path: |
7474
llvm-project
7575
${{ matrix.cling=='On' && 'cling' || '' }}
76-
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' }}
76+
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
7777
lookup-only: true
7878

7979
- name: Setup default Build Type on Windows
@@ -93,10 +93,10 @@ jobs:
9393
choco install llvm --version=$ver --no-progress -my
9494
clang --version
9595
#
96-
$env:CC="clang"
97-
$env:CXX="clang++"
98-
echo "CC=clang" >> $env:GITHUB_ENV
99-
echo "CXX=clang++" >> $env:GITHUB_ENV
96+
$env:CC="clang-cl"
97+
$env:CXX="clang-cl"
98+
echo "CC=clang-cl" >> $env:GITHUB_ENV
99+
echo "CXX=clang-cl" >> $env:GITHUB_ENV
100100
}
101101
elseif ( "${{ matrix.compiler }}" -imatch "msvc" )
102102
{
@@ -111,7 +111,9 @@ jobs:
111111
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
112112
run: |
113113
choco install findutils
114+
choco install ninja
114115
$env:PATH="C:\Program Files (x86)\GnuWin32\bin;$env:PATH"
116+
$env:PATH="C:\Program Files (x86)\Ninja\bin;$env:PATH"
115117
116118
- name: Build LLVM/Cling on Windows systems if the cache is invalid
117119
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
@@ -130,7 +132,7 @@ jobs:
130132
}
131133
else
132134
{
133-
git clone --depth=1 -b release/${{ matrix.clang-runtime }}.x https://github.com/llvm/llvm-project.git
135+
git clone --depth=1 -b llvm-export-api-20.0 https://github.com/fsfod/llvm-project.git
134136
}
135137
136138
cd llvm-project
@@ -174,7 +176,7 @@ jobs:
174176
}
175177
cd build
176178
echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:"
177-
cmake -DLLVM_ENABLE_PROJECTS="${{ matrix.llvm_enable_projects}}" `
179+
cmake -G Ninja -DLLVM_ENABLE_PROJECTS="${{ matrix.llvm_enable_projects}}" `
178180
-DLLVM_TARGETS_TO_BUILD="${{ matrix.llvm_targets_to_build }}" `
179181
-DCMAKE_BUILD_TYPE=Release `
180182
-DLLVM_ENABLE_ASSERTIONS=ON `
@@ -185,6 +187,15 @@ jobs:
185187
-DLLVM_ENABLE_ZSTD=OFF `
186188
-DLLVM_ENABLE_TERMINFO=OFF `
187189
-DLLVM_ENABLE_LIBXML2=OFF `
190+
-DLLVM_ENABLE_PLUGINS=On `
191+
-DLLVM_BUILD_LLVM_DYLIB=ON `
192+
-DLLVM_BUILD_LLVM_DYLIB_VIS=ON `
193+
-DLLVM_LINK_LLVM_DYLIB=ON `
194+
-DCLANG_LINK_CLANG_DYLIB=ON `
195+
-DCMAKE_ASM_MASM_COMPILER=llvm-ml `
196+
-DCMAKE_ASM_MASM_FLAGS="-m64" `
197+
-DCMAKE_CXX_COMPILER=clang-cl `
198+
-DCMAKE_C_COMPILER=clang-cl `
188199
..\llvm
189200
cmake --build . --config Release --target clang clangInterpreter clangStaticAnalyzerCore --parallel ${{ env.ncpus }}
190201
}
@@ -225,10 +236,10 @@ jobs:
225236
fail-fast: false
226237
matrix:
227238
include:
228-
- name: win2025-msvc-clang-repl-19
239+
- name: win2025-shared-lib
229240
os: windows-2025
230-
compiler: msvc
231-
clang-runtime: '19'
241+
compiler: clang
242+
clang-runtime: '20'
232243
cling: Off
233244
cppyy: Off
234245

@@ -284,10 +295,10 @@ jobs:
284295
choco install llvm --version=$ver --no-progress -my
285296
clang --version
286297
#
287-
$env:CC="clang"
288-
$env:CXX="clang++"
289-
echo "CC=clang" >> $env:GITHUB_ENV
290-
echo "CXX=clang++" >> $env:GITHUB_ENV
298+
$env:CC="clang-cl"
299+
$env:CXX="clang-cl"
300+
echo "CC=clang-cl" >> $env:GITHUB_ENV
301+
echo "CXX=clang-cl" >> $env:GITHUB_ENV
291302
}
292303
elseif ( "${{ matrix.compiler }}" -imatch "msvc" )
293304
{
@@ -298,14 +309,20 @@ jobs:
298309
echo "Unsupported compiler - fix YAML file"
299310
}
300311
312+
- name: Install deps on Windows
313+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
314+
run: |
315+
choco install ninja
316+
$env:PATH="C:\Program Files (x86)\Ninja\bin;$env:PATH"
317+
301318
- name: Restore Cache LLVM/Clang runtime build directory
302319
uses: actions/cache/restore@v4
303320
id: cache
304321
with:
305322
path: |
306323
llvm-project
307324
${{ matrix.cling=='On' && 'cling' || '' }}
308-
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' }}
325+
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
309326

310327
- name: Build and Test/Install CppInterOp on Windows systems
311328
run: |
@@ -367,9 +384,10 @@ jobs:
367384
}
368385
else
369386
{
370-
cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} `
387+
cmake -G Ninja -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} `
371388
-DLLVM_DIR="$env:LLVM_BUILD_DIR\lib\cmake\llvm" `
372389
-DLLVM_ENABLE_WERROR=On `
390+
-DBUILD_SHARED_LIBS=ON `
373391
-DClang_DIR="$env:LLVM_BUILD_DIR\lib\cmake\clang" -DCODE_COVERAGE=${{ env.CODE_COVERAGE }} -DCMAKE_INSTALL_PREFIX="$env:CPPINTEROP_DIR" ..\
374392
cmake --build . --config ${{ env.BUILD_TYPE }} --target googletest --parallel ${{ env.ncpus }}
375393
}

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ include(GNUInstallDirs)
6868
## Define supported version of clang and llvm
6969

7070
set(CLANG_MIN_SUPPORTED 13.0)
71-
set(CLANG_MAX_SUPPORTED "19.1.x")
72-
set(CLANG_VERSION_UPPER_BOUND 20.0.0)
71+
set(CLANG_MAX_SUPPORTED "20.1.x")
72+
set(CLANG_VERSION_UPPER_BOUND 21.0.0)
7373
set(LLD_MIN_SUPPORTED 13.0)
74-
set(LLD_MAX_SUPPORTED "19.1.x")
75-
set(LLD_VERSION_UPPER_BOUND 20.0.0)
74+
set(LLD_MAX_SUPPORTED "20.1.x")
75+
set(LLD_VERSION_UPPER_BOUND 21.0.0)
7676
set(LLVM_MIN_SUPPORTED 13.0)
77-
set(LLVM_MAX_SUPPORTED "19.1.x")
78-
set(LLVM_VERSION_UPPER_BOUND 20.0.0)
77+
set(LLVM_MAX_SUPPORTED "20.1.x")
78+
set(LLVM_VERSION_UPPER_BOUND 21.0.0)
7979

8080
## Set Cmake packages search order
8181

lib/Interpreter/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ endif()
5555

5656
if(NOT WIN32 AND NOT EMSCRIPTEN)
5757
list(APPEND link_libs dl)
58-
endif()
5958

6059
# Get rid of libLLVM-X.so which is appended to the list of static libraries.
6160
if (LLVM_LINK_LLVM_DYLIB)
@@ -103,6 +102,7 @@ endif()
103102
clangStaticAnalyzerCore
104103
)
105104
endif(LLVM_LINK_LLVM_DYLIB)
105+
endif()
106106
add_llvm_library(clangCppInterOp
107107
DISABLE_LLVM_LINK_LLVM_DYLIB
108108
CppInterOp.cpp
@@ -112,7 +112,6 @@ endif()
112112
${link_libs}
113113
)
114114

115-
116115
if(EMSCRIPTEN)
117116
# FIXME: When dynamically linking the Emscripten shared library to the
118117
# unit tests main_module you get errors due to undefined symbols. The reading of the file

0 commit comments

Comments
 (0)