Skip to content

Commit 6d0448a

Browse files
committed
fix(ci): bundle only required windows runtime DLLs
1 parent a802f05 commit 6d0448a

2 files changed

Lines changed: 95 additions & 19 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -174,25 +174,7 @@ jobs:
174174
- name: Bundle runtime DLLs
175175
shell: pwsh
176176
run: |
177-
$candidateBinDirs = @(
178-
(Join-Path $env:GITHUB_WORKSPACE "build/vcpkg_installed/x64-windows/bin"),
179-
(Join-Path $env:GITHUB_WORKSPACE "vcpkg_installed/x64-windows/bin"),
180-
(Join-Path $env:VCPKG_ROOT "installed/x64-windows/bin")
181-
)
182-
183-
$runtimeBinDir = $candidateBinDirs | Where-Object { Test-Path $_ } | Select-Object -First 1
184-
if (-not $runtimeBinDir) {
185-
Write-Error "Could not find vcpkg runtime DLL directory. Checked: $($candidateBinDirs -join ', ')"
186-
exit 1
187-
}
188-
189-
$runtimeDlls = Get-ChildItem -Path $runtimeBinDir -Filter *.dll -File
190-
if (-not $runtimeDlls) {
191-
Write-Error "No runtime DLLs found in '$runtimeBinDir'."
192-
exit 1
193-
}
194-
195-
Copy-Item $runtimeDlls.FullName -Destination build -Force
177+
./scripts/bundle_windows_runtime_dlls.ps1 -BuildDir build -VcpkgRoot "$env:VCPKG_ROOT"
196178
197179
- name: Upload artifact
198180
uses: actions/upload-artifact@v4
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
param(
2+
[Parameter(Mandatory = $true)]
3+
[string]$BuildDir,
4+
[Parameter(Mandatory = $true)]
5+
[string]$VcpkgRoot
6+
)
7+
8+
$ErrorActionPreference = "Stop"
9+
10+
$buildDirAbs = (Resolve-Path $BuildDir).Path
11+
$exePath = Join-Path $buildDirAbs "OpenGothicStarter.exe"
12+
if (-not (Test-Path $exePath)) {
13+
throw "Launcher executable not found: $exePath"
14+
}
15+
16+
$candidateRuntimeDirs = @(
17+
(Join-Path $buildDirAbs "vcpkg_installed/x64-windows/bin"),
18+
(Join-Path $VcpkgRoot "installed/x64-windows/bin")
19+
)
20+
21+
if ($env:GITHUB_WORKSPACE) {
22+
$candidateRuntimeDirs += (Join-Path $env:GITHUB_WORKSPACE "vcpkg_installed/x64-windows/bin")
23+
}
24+
25+
$runtimeDirs = $candidateRuntimeDirs | Where-Object { $_ -and (Test-Path $_) } | Select-Object -Unique
26+
if (-not $runtimeDirs) {
27+
throw "Could not find any vcpkg runtime directories. Checked: $($candidateRuntimeDirs -join ', ')"
28+
}
29+
30+
function Get-DllDependents {
31+
param([string]$BinaryPath)
32+
33+
$output = & dumpbin /dependents $BinaryPath 2>$null
34+
if ($LASTEXITCODE -ne 0) {
35+
throw "dumpbin failed for '$BinaryPath'"
36+
}
37+
38+
return $output |
39+
ForEach-Object { $_.Trim() } |
40+
Where-Object { $_ -match '^[A-Za-z0-9._-]+\.dll$' } |
41+
Sort-Object -Unique
42+
}
43+
44+
function Find-RuntimeDllPath {
45+
param(
46+
[string]$DllName,
47+
[string[]]$SearchDirs
48+
)
49+
50+
foreach ($dir in $SearchDirs) {
51+
$candidate = Join-Path $dir $DllName
52+
if (Test-Path $candidate) {
53+
return $candidate
54+
}
55+
}
56+
57+
return $null
58+
}
59+
60+
$seenDllNames = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)
61+
$queuedBinaries = [System.Collections.Generic.Queue[string]]::new()
62+
$queuedBinaries.Enqueue($exePath)
63+
$bundledCount = 0
64+
$bundledDllNames = [System.Collections.Generic.List[string]]::new()
65+
66+
while ($queuedBinaries.Count -gt 0) {
67+
$binary = $queuedBinaries.Dequeue()
68+
foreach ($dllName in Get-DllDependents -BinaryPath $binary) {
69+
if (-not $seenDllNames.Add($dllName)) {
70+
continue
71+
}
72+
73+
$sourceDll = Find-RuntimeDllPath -DllName $dllName -SearchDirs $runtimeDirs
74+
if (-not $sourceDll) {
75+
continue
76+
}
77+
78+
$destDll = Join-Path $buildDirAbs $dllName
79+
Copy-Item $sourceDll $destDll -Force
80+
$bundledCount += 1
81+
$bundledDllNames.Add($dllName)
82+
$queuedBinaries.Enqueue($destDll)
83+
}
84+
}
85+
86+
if ($bundledCount -eq 0) {
87+
throw "No vcpkg runtime DLLs were bundled for '$exePath'."
88+
}
89+
90+
$bundledDllNames.Sort()
91+
Write-Host "Bundled $bundledCount runtime DLL(s) into '$buildDirAbs':"
92+
foreach ($dllName in $bundledDllNames) {
93+
Write-Host " - $dllName"
94+
}

0 commit comments

Comments
 (0)