Skip to content

Commit 1fe2ac4

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

File tree

3 files changed

+62
-26
lines changed

3 files changed

+62
-26
lines changed

Diff for: .github/workflows/Windows.yml

+38-20
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
}

Diff for: CMakeLists.txt

+6-6
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

Diff for: lib/Interpreter/Paths.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,29 @@ void CopyIncludePaths(const clang::HeaderSearchOptions& Opts,
175175
if (withFlags) incpaths.push_back("-isystem");
176176
break;
177177

178+
// Option was removed in llvm 20. Git log message below.
179+
// git log --grep="index-header"
180+
// commit 19b4f17d4c0ae12725050d09f04f85bccc686d8e
181+
// Author: Jan Svoboda <[email protected]>
182+
// Date: Thu Oct 31 16:04:35 2024 -0700
183+
//
184+
// [clang][lex] Remove `-index-header-map` (#114459)
185+
//
186+
// This PR removes the `-index-header-map` functionality from Clang.
187+
// AFAIK this was only used internally at Apple and is now dead code.
188+
// The main motivation behind this change is to enable the removal of
189+
// `HeaderFileInfo::Framework` member and reducing the size of that
190+
// data structure.
191+
//
192+
// rdar://84036149
193+
194+
#if CLANG_VERSION_MAJOR < 20
178195
case frontend::IndexHeaderMap:
179196
if (!withSystem) continue;
180197
if (withFlags) incpaths.push_back("-index-header-map");
181198
if (withFlags) incpaths.push_back(E.IsFramework? "-F" : "-I");
182199
break;
200+
#endif
183201

184202
case frontend::CSystem:
185203
if (!withSystem) continue;

0 commit comments

Comments
 (0)