Skip to content

Commit 95c79c4

Browse files
awakecodingCopilot
andcommitted
Add shared LLVM core libs packages
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ed455f7 commit 95c79c4

3 files changed

Lines changed: 168 additions & 48 deletions

File tree

‎.github/workflows/llvm-core-libs.yml‎

Lines changed: 148 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ on:
99
- "cmake/llvm-core-libs.cmake"
1010
jobs:
1111
build:
12-
name: LLVM core libs ${{matrix.version}} [${{matrix.arch}}-${{matrix.os}}${{matrix.package_suffix}}]
12+
name: LLVM core libs ${{matrix.version}} [${{matrix.arch}}-${{matrix.os}}-${{matrix.linkage}}${{matrix.package_suffix}}]
1313
runs-on: ${{matrix.runner}}
1414
strategy:
1515
fail-fast: false
1616
matrix:
1717
arch: [ x86_64, aarch64 ]
1818
os: [ windows, macos, ubuntu-22.04, ubuntu-24.04 ]
1919
version: [ 20.1.8, 22.1.4 ]
20+
linkage: [ static, shared ]
2021
crt: [ default, mt, md ]
2122

2223
exclude:
@@ -161,9 +162,7 @@ jobs:
161162
$CMakeArgs = @(
162163
"-DBUILD_SHARED_LIBS=OFF",
163164
"-DLLVM_TARGETS_TO_BUILD=AArch64;X86",
164-
"-DLLVM_BUILD_LLVM_DYLIB=OFF",
165165
"-DLLVM_BUILD_LLVM_C_DYLIB=OFF",
166-
"-DLLVM_LINK_LLVM_DYLIB=OFF",
167166
"-DLLVM_ENABLE_LIBXML2=OFF",
168167
"-DLLVM_ENABLE_ZLIB=OFF",
169168
"-DLLVM_ENABLE_ZSTD=OFF"
@@ -177,6 +176,35 @@ jobs:
177176
$CMakeArgs += "-DCMAKE_OSX_ARCHITECTURES=${{matrix.osx_arch}}"
178177
}
179178
179+
$DevelopmentComponents = "llvm-config;cmake-exports;llvm-headers"
180+
$StaticComponents = "LLVMBitReader;LLVMCore;LLVMRemarks;LLVMBitstreamReader;LLVMBinaryFormat;LLVMTargetParser;LLVMSupport;LLVMDemangle"
181+
182+
if ('${{matrix.linkage}}' -eq 'shared') {
183+
$CMakeArgs += @(
184+
"-DLLVM_BUILD_LLVM_DYLIB=ON",
185+
"-DLLVM_LINK_LLVM_DYLIB=ON",
186+
"-DLLVM_DYLIB_COMPONENTS=core;bitreader",
187+
"-DLLVM_DISTRIBUTION_COMPONENTS=$DevelopmentComponents;LLVM"
188+
)
189+
190+
if ('${{matrix.os}}' -eq 'windows') {
191+
$CMakeArgs += "-DLLVM_BUILD_LLVM_DYLIB_VIS=ON"
192+
} elseif ('${{matrix.os}}' -eq 'macos') {
193+
$CMakeArgs += @(
194+
"-DCMAKE_INSTALL_NAME_DIR=@rpath",
195+
"-DCMAKE_INSTALL_RPATH=@loader_path/../lib"
196+
)
197+
} else {
198+
$CMakeArgs += '-DCMAKE_INSTALL_RPATH=$ORIGIN/../lib'
199+
}
200+
} else {
201+
$CMakeArgs += @(
202+
"-DLLVM_BUILD_LLVM_DYLIB=OFF",
203+
"-DLLVM_LINK_LLVM_DYLIB=OFF",
204+
"-DLLVM_DISTRIBUTION_COMPONENTS=$DevelopmentComponents;$StaticComponents"
205+
)
206+
}
207+
180208
cmake -G Ninja -S llvm-project/llvm -B llvm-build $CMakeArgs `
181209
-DCMAKE_INSTALL_PREFIX=llvm-install `
182210
-DCMAKE_TOOLCHAIN_FILE="$CMakeToolchainFile" `
@@ -188,7 +216,7 @@ jobs:
188216
- name: Stage LLVM core libs
189217
shell: pwsh
190218
run: |
191-
$PackageName = "llvm-core-libs-${{matrix.version}}-${{matrix.arch}}-${{matrix.os}}${{matrix.package_suffix}}"
219+
$PackageName = "llvm-core-libs-${{matrix.version}}-${{matrix.arch}}-${{matrix.os}}-${{matrix.linkage}}${{matrix.package_suffix}}"
192220
$PackageRoot = Join-Path $PWD $PackageName
193221
$PackageBinDir = Join-Path $PackageRoot "bin"
194222
$PackageIncludeDir = Join-Path $PackageRoot "include"
@@ -219,9 +247,28 @@ jobs:
219247
"LLVMDemangle"
220248
)
221249
222-
foreach ($RequiredLib in $RequiredLibs) {
223-
$RequiredLibFile = if ($IsWindows) { "$RequiredLib.lib" } else { "lib$RequiredLib.a" }
224-
Copy-Item -Path (Join-Path "llvm-install/lib" $RequiredLibFile) -Destination $PackageLibDir -Force
250+
if ('${{matrix.linkage}}' -eq 'static') {
251+
foreach ($RequiredLib in $RequiredLibs) {
252+
$RequiredLibFile = if ($IsWindows) { "$RequiredLib.lib" } else { "lib$RequiredLib.a" }
253+
Copy-Item -Path (Join-Path "llvm-install/lib" $RequiredLibFile) -Destination $PackageLibDir -Force
254+
}
255+
} else {
256+
if ($IsWindows) {
257+
Copy-Item -Path llvm-install/bin/LLVM.dll -Destination $PackageBinDir -Force
258+
Copy-Item -Path llvm-install/lib/LLVM.lib -Destination $PackageLibDir -Force
259+
} elseif ($IsMacOS) {
260+
$SharedLibraries = @(Get-ChildItem -Path llvm-install/lib -Filter "libLLVM*.dylib" -File)
261+
if ($SharedLibraries.Count -eq 0) {
262+
throw "No libLLVM dylib was installed"
263+
}
264+
Copy-Item -Path $SharedLibraries.FullName -Destination $PackageLibDir -Force
265+
} else {
266+
$SharedLibraries = @(Get-ChildItem -Path llvm-install/lib -Filter "libLLVM*.so*" -File)
267+
if ($SharedLibraries.Count -eq 0) {
268+
throw "No libLLVM shared object was installed"
269+
}
270+
Copy-Item -Path $SharedLibraries.FullName -Destination $PackageLibDir -Force
271+
}
225272
}
226273
227274
$MsvcRuntime = if ('${{matrix.os}}' -eq 'windows') { "${{matrix.msvc_runtime_label}}" } else { "N/A" }
@@ -231,10 +278,12 @@ jobs:
231278
"LLVM_VERSION=${{matrix.version}}"
232279
"LLVM_REF=${{matrix.ref}}"
233280
"TARGET=${{matrix.arch}}-${{matrix.os}}"
281+
"LINKAGE=${{matrix.linkage}}"
234282
"MSVC_RUNTIME=$MsvcRuntime"
235283
"MSVC_CRT=$MsvcCrt"
236284
"CMAKE_MSVC_RUNTIME_LIBRARY=$CMakeMsvcRuntime"
237285
) | Set-Content -Path (Join-Path $PackageRoot "VERSION.txt") -Encoding ASCII
286+
echo "PACKAGE_NAME=$PackageName" >> $Env:GITHUB_ENV
238287
239288
- name: Validate LLVM core libs
240289
shell: pwsh
@@ -248,11 +297,19 @@ jobs:
248297
}
249298
250299
if ($Value.StartsWith("-l")) {
251-
return $Value.Substring(2)
300+
$LibraryName = $Value.Substring(2)
301+
if ($LibraryName -match '^LLVM(?:[-\d].*)?$') {
302+
return "LLVM"
303+
}
304+
return $LibraryName
252305
}
253306
254307
if ($Value.EndsWith(".lib", [System.StringComparison]::OrdinalIgnoreCase)) {
255-
return [System.IO.Path]::GetFileNameWithoutExtension($Value)
308+
$LibraryName = [System.IO.Path]::GetFileNameWithoutExtension($Value)
309+
if ($LibraryName -match '^LLVM(?:[-\d].*)?$') {
310+
return "LLVM"
311+
}
312+
return $LibraryName
256313
}
257314
258315
if ($Value.EndsWith(".a", [System.StringComparison]::OrdinalIgnoreCase)) {
@@ -263,6 +320,10 @@ jobs:
263320
return $FileName
264321
}
265322
323+
if ($Value -match 'lib(LLVM(?:[-\d].*)?)\.(?:dylib|so)') {
324+
return "LLVM"
325+
}
326+
266327
return $null
267328
}
268329
@@ -300,11 +361,12 @@ jobs:
300361
}
301362
}
302363
303-
$PackageName = "llvm-core-libs-${{matrix.version}}-${{matrix.arch}}-${{matrix.os}}${{matrix.package_suffix}}"
364+
$PackageName = $Env:PACKAGE_NAME
304365
$PackageRoot = Join-Path $PWD $PackageName
305366
$ExeExt = if ($IsWindows) { ".exe" } else { "" }
306367
$LlvmConfig = Join-Path $PackageRoot "bin/llvm-config$ExeExt"
307368
$PackageLibDir = Join-Path $PackageRoot "lib"
369+
$Linkage = "${{matrix.linkage}}"
308370
$RunnerArch = if ($Env:RUNNER_ARCH -eq "ARM64") { "aarch64" } else { "x86_64" }
309371
$CanRunTargetTools = ($RunnerArch -eq "${{matrix.arch}}")
310372
@@ -333,7 +395,7 @@ jobs:
333395
}
334396
}
335397
336-
$ExpectedLlvmComponents = @(
398+
$StaticLlvmComponents = @(
337399
"LLVMBitReader",
338400
"LLVMCore",
339401
"LLVMRemarks",
@@ -343,11 +405,13 @@ jobs:
343405
"LLVMSupport",
344406
"LLVMDemangle"
345407
)
408+
$ExpectedLlvmComponents = if ($Linkage -eq "shared") { @("LLVM") } else { $StaticLlvmComponents }
409+
$LinkCommand = if ($Linkage -eq "shared") { "--link-shared" } else { "--link-static" }
346410
347411
if ($CanRunTargetTools) {
348-
$LibTokens = @((& $LlvmConfig --link-static --libs core bitreader) -split '\s+' | ForEach-Object { Convert-ToLlvmComponentName $_ })
412+
$LibTokens = @((& $LlvmConfig $LinkCommand --libs core bitreader) -split '\s+' | ForEach-Object { Convert-ToLlvmComponentName $_ })
349413
if ($LASTEXITCODE -ne 0) {
350-
throw "llvm-config --link-static --libs core bitreader failed"
414+
throw "llvm-config $LinkCommand --libs core bitreader failed"
351415
}
352416
353417
$ReportedLlvmComponents = @($LibTokens | Where-Object { $_ -like "LLVM*" })
@@ -356,17 +420,33 @@ jobs:
356420
$ReportedLlvmComponents = $ExpectedLlvmComponents
357421
}
358422
359-
foreach ($ExpectedComponent in $ExpectedLlvmComponents) {
360-
$ExpectedLibFile = if ($IsWindows) { "$ExpectedComponent.lib" } else { "lib$ExpectedComponent.a" }
361-
if (-not (Test-Path (Join-Path $PackageLibDir $ExpectedLibFile))) {
362-
throw "Package is missing '$ExpectedLibFile'"
423+
if ($Linkage -eq "static") {
424+
foreach ($ExpectedComponent in $ExpectedLlvmComponents) {
425+
$ExpectedLibFile = if ($IsWindows) { "$ExpectedComponent.lib" } else { "lib$ExpectedComponent.a" }
426+
if (-not (Test-Path (Join-Path $PackageLibDir $ExpectedLibFile))) {
427+
throw "Package is missing '$ExpectedLibFile'"
428+
}
429+
}
430+
} else {
431+
if ($IsWindows) {
432+
foreach ($ExpectedSharedFile in @("bin/LLVM.dll", "lib/LLVM.lib")) {
433+
if (-not (Test-Path (Join-Path $PackageRoot $ExpectedSharedFile))) {
434+
throw "Package is missing '$ExpectedSharedFile'"
435+
}
436+
}
437+
} elseif ($IsMacOS) {
438+
if (@(Get-ChildItem -Path $PackageLibDir -Filter "libLLVM*.dylib" -File).Count -eq 0) {
439+
throw "Package is missing libLLVM dylib"
440+
}
441+
} elseif (@(Get-ChildItem -Path $PackageLibDir -Filter "libLLVM*.so*" -File).Count -eq 0) {
442+
throw "Package is missing libLLVM shared object"
363443
}
364444
}
365445
366446
if ($CanRunTargetTools) {
367-
$SystemLibTokens = @((& $LlvmConfig --link-static --system-libs core bitreader) -split '\s+' | ForEach-Object { Convert-ToSystemLibToken $_ })
447+
$SystemLibTokens = @((& $LlvmConfig $LinkCommand --system-libs core bitreader) -split '\s+' | ForEach-Object { Convert-ToSystemLibToken $_ })
368448
if ($LASTEXITCODE -ne 0) {
369-
throw "llvm-config --link-static --system-libs core bitreader failed"
449+
throw "llvm-config $LinkCommand --system-libs core bitreader failed"
370450
}
371451
372452
$ReportedSystemLibs = @($SystemLibTokens | Where-Object { $_ })
@@ -404,28 +484,58 @@ jobs:
404484
)
405485
Compare-LibSet -Expected $ExpectedSystemLibs -Actual $ReportedSystemLibs -Label "System libs"
406486
407-
$DumpbinOutput = & dumpbin /directives (Join-Path $PackageLibDir "LLVMCore.lib")
408-
if ($LASTEXITCODE -ne 0) {
409-
throw "dumpbin /directives LLVMCore.lib failed"
410-
}
487+
if ($Linkage -eq "static") {
488+
$DumpbinOutput = & dumpbin /directives (Join-Path $PackageLibDir "LLVMCore.lib")
489+
if ($LASTEXITCODE -ne 0) {
490+
throw "dumpbin /directives LLVMCore.lib failed"
491+
}
411492
412-
$DumpbinText = $DumpbinOutput -join "`n"
413-
if ($DumpbinText -notmatch '${{matrix.runtime_directive}}') {
414-
throw "LLVMCore.lib does not contain ${{matrix.runtime_directive}}"
415-
}
493+
$DumpbinText = $DumpbinOutput -join "`n"
494+
if ($DumpbinText -notmatch '${{matrix.runtime_directive}}') {
495+
throw "LLVMCore.lib does not contain ${{matrix.runtime_directive}}"
496+
}
497+
498+
if ($DumpbinText -match '${{matrix.forbidden_runtime_directive}}') {
499+
throw "LLVMCore.lib contains ${{matrix.forbidden_runtime_directive}}"
500+
}
501+
} else {
502+
$DumpbinOutput = & dumpbin /dependents (Join-Path $PackageRoot "bin/LLVM.dll")
503+
if ($LASTEXITCODE -ne 0) {
504+
throw "dumpbin /dependents LLVM.dll failed"
505+
}
416506
417-
if ($DumpbinText -match '${{matrix.forbidden_runtime_directive}}') {
418-
throw "LLVMCore.lib contains ${{matrix.forbidden_runtime_directive}}"
507+
$DumpbinText = $DumpbinOutput -join "`n"
508+
$DynamicCrtPattern = 'VCRUNTIME|MSVCP|CONCRT'
509+
if ('${{matrix.crt}}' -eq 'md' -and $DumpbinText -notmatch $DynamicCrtPattern) {
510+
throw "LLVM.dll does not appear to depend on the dynamic MSVC runtime"
511+
}
512+
513+
if ('${{matrix.crt}}' -eq 'mt' -and $DumpbinText -match $DynamicCrtPattern) {
514+
throw "LLVM.dll appears to depend on the dynamic MSVC runtime"
515+
}
419516
}
420517
}
421518
422519
$DynamicLibs = @(Get-ChildItem -Path $PackageRoot -Recurse -File | Where-Object {
423-
$_.Extension -in @(".dll", ".dylib", ".so")
520+
($_.Extension -in @(".dll", ".dylib", ".so")) -or ($_.Name -like "*.so.*")
424521
})
425-
if ($DynamicLibs.Count -ne 0) {
522+
if ($Linkage -eq "static" -and $DynamicLibs.Count -ne 0) {
426523
throw "Package contains dynamic libraries: $($DynamicLibs.FullName -join ', ')"
427524
}
428525
526+
if ($Linkage -eq "shared" -and $DynamicLibs.Count -eq 0) {
527+
throw "Shared package does not contain a dynamic library"
528+
}
529+
530+
if ($Linkage -eq "shared") {
531+
foreach ($StaticComponent in $StaticLlvmComponents) {
532+
$StaticComponentFile = if ($IsWindows) { "$StaticComponent.lib" } else { "lib$StaticComponent.a" }
533+
if (Test-Path (Join-Path $PackageLibDir $StaticComponentFile)) {
534+
throw "Shared package contains static component library '$StaticComponentFile'"
535+
}
536+
}
537+
}
538+
429539
$MsvcRuntimeLine = if ($IsWindows) { "MSVC runtime: ${{matrix.msvc_runtime_label}}" } else { "MSVC runtime: N/A" }
430540
$LlvmConfigValidationLine = if ($CanRunTargetTools) {
431541
"Target llvm-config validation: enabled"
@@ -437,19 +547,20 @@ jobs:
437547
$ManifestLines.Add("LLVM core libs link manifest")
438548
$ManifestLines.Add("LLVM version: $Version")
439549
$ManifestLines.Add("Target: ${{matrix.arch}}-${{matrix.os}}")
550+
$ManifestLines.Add("Linkage: $Linkage")
440551
$ManifestLines.Add($MsvcRuntimeLine)
441552
$ManifestLines.Add($LlvmConfigValidationLine)
442553
$ManifestLines.Add("")
443554
$ManifestLines.Add("Command:")
444-
$ManifestLines.Add(" bin/llvm-config$ExeExt --link-static --libs core bitreader")
555+
$ManifestLines.Add(" bin/llvm-config$ExeExt $LinkCommand --libs core bitreader")
445556
$ManifestLines.Add("")
446557
$ManifestLines.Add("LLVM libs:")
447558
foreach ($ExpectedLlvmComponent in $ExpectedLlvmComponents) {
448559
$ManifestLines.Add($ExpectedLlvmComponent)
449560
}
450561
$ManifestLines.Add("")
451562
$ManifestLines.Add("Command:")
452-
$ManifestLines.Add(" bin/llvm-config$ExeExt --link-static --system-libs core bitreader")
563+
$ManifestLines.Add(" bin/llvm-config$ExeExt $LinkCommand --system-libs core bitreader")
453564
$ManifestLines.Add("")
454565
$ManifestLines.Add("System libs:")
455566
foreach ($ReportedSystemLib in ($ReportedSystemLibs | Sort-Object)) {
@@ -460,17 +571,17 @@ jobs:
460571
- name: Package LLVM core libs
461572
if: runner.os != 'Windows'
462573
run: |
463-
tar -cJf llvm-core-libs-${{matrix.version}}-${{matrix.arch}}-${{matrix.os}}${{matrix.package_suffix}}.tar.xz llvm-core-libs-${{matrix.version}}-${{matrix.arch}}-${{matrix.os}}${{matrix.package_suffix}}
574+
tar -cJf "$PACKAGE_NAME.tar.xz" "$PACKAGE_NAME"
464575
465576
- name: Package LLVM core libs
466577
if: runner.os == 'Windows'
467578
shell: pwsh
468579
run: |
469-
$PackageName = "llvm-core-libs-${{matrix.version}}-${{matrix.arch}}-${{matrix.os}}${{matrix.package_suffix}}"
580+
$PackageName = $Env:PACKAGE_NAME
470581
cmd.exe /c "7z a -ttar -snl -so $PackageName.tar $PackageName | 7z a -si $PackageName.tar.xz"
471582
472583
- name: Upload LLVM core libs package
473584
uses: actions/upload-artifact@v7
474585
with:
475-
name: llvm-core-libs-${{matrix.version}}-${{matrix.arch}}-${{matrix.os}}${{matrix.package_suffix}}
476-
path: llvm-core-libs-${{matrix.version}}-${{matrix.arch}}-${{matrix.os}}${{matrix.package_suffix}}.tar.xz
586+
name: ${{ env.PACKAGE_NAME }}
587+
path: ${{ env.PACKAGE_NAME }}.tar.xz

‎README.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ clang+llvm-<version>-<arch>-<os>.tar.xz
2525

2626
### LLVM core libs
2727

28-
The LLVM core libs workflow builds small static-library packages for linking against the LLVM Core and BitReader C APIs. Windows packages are produced for both MSVC CRT modes: static CRT (`/MT`) and dynamic CRT (`/MD`). Each Windows package verifies `LLVMCore.lib` contains the expected `RuntimeLibrary` directive and does not contain the opposite CRT directive.
28+
The LLVM core libs workflow builds small static and shared-library packages for linking against the LLVM Core and BitReader C APIs. Windows packages are produced for both MSVC CRT modes: static CRT (`/MT`) and dynamic CRT (`/MD`). Static Windows packages verify `LLVMCore.lib` contains the expected `RuntimeLibrary` directive and does not contain the opposite CRT directive; shared Windows packages verify the packaged LLVM DLL dependencies match the selected CRT mode.
2929

3030
Currently built LLVM core libs versions: `20.1.8`, `22.1.4`.
3131

3232
Artifacts are named:
3333

3434
```text
35-
llvm-core-libs-<version>-<arch>-<os>.tar.xz
36-
llvm-core-libs-<version>-<arch>-windows-mt.tar.xz
37-
llvm-core-libs-<version>-<arch>-windows-md.tar.xz
35+
llvm-core-libs-<version>-<arch>-<os>-static.tar.xz
36+
llvm-core-libs-<version>-<arch>-<os>-shared.tar.xz
37+
llvm-core-libs-<version>-<arch>-windows-static-mt.tar.xz
38+
llvm-core-libs-<version>-<arch>-windows-static-md.tar.xz
39+
llvm-core-libs-<version>-<arch>-windows-shared-mt.tar.xz
40+
llvm-core-libs-<version>-<arch>-windows-shared-md.tar.xz
3841
```
3942

4043
### Halide

0 commit comments

Comments
 (0)