Skip to content

Commit 62fbc0f

Browse files
authored
build: ship a static-CRT Windows package (#217)
Windows release DLLs currently depend on the VC Runtime installed on the build host. This change selects static CRT linkage across the Rust and native dependency graph, preserves the exact public export policy, and makes the installed static-library contract explicitly Release `/MT`. The CMake source build defaults to static CRT for Windows MSVC and supports an explicit opt-out. Windows prebuilt installs must declare `LANCE_C_CRT_STATIC=ON` or `OFF` to match their input; installation does not convert libraries. The package exposes `LanceC_STATIC_CRT`, and consumers select their CRT explicitly. The stale Corrosion dynamic-CRT directive is removed without `/NODEFAULTLIB` or warning suppression. Direct Cargo builds still need their own documented CRT flag. Validation of `335dbacad90786a486ac69e7f9bf089ab63ea751` in [run 43167179892](https://github.com/lance-format/lance-c/actions/runs/43167179892): - Native Windows Server 2022 x64 and Windows 11 ARM64, Rust 1.94.0: full Release build/install and static/shared consumers passed. Consumers exercised create/reopen/scan, Arrow callback ownership, error strings and clone lifetime. - Both artifacts contain exactly 878 header-declared DLL exports and 878 import-library symbols, 16 distinct OS/API-set dependencies and no delay imports. Static archive and consumer CRT checks passed without CRT-conflict warnings. Loaded-module guards rejected redistributable runtime families while allowing the exact Windows OS modules `msvcp_win.dll` and `msvcrt.dll`. - Missing/ON/OFF prebuilt-CRT configuration tests passed on both architectures. Downloaded ZIP hashes, PE machines, export/import sets, dependency tables, installed headers and `LanceC_STATIC_CRT=ON` were independently checked. - macOS Rust/native tests and installed static/shared consumers passed. Intel build, staging guards and installed consumers were reported successful before the runner lost communication during artifact upload; its overall job failed and no final Intel artifact is claimed. - Linux and Clippy failed at dependency installation before exercising project code. The inherited mirror problem was separately fixed and validated in merged #218. Main's only delta since this candidate's base is that four-job Ubuntu mirror repair; Rust inputs and the Windows package path are unchanged. These failed jobs are not reported as passing. Artifact ZIP SHA-256: x64 `fe61e185210f25d6aae94bf4b8eedc857227d043e659e397edba82b24a69cbef`; ARM64 `676b7530f36b5c84d71495d13c4eded35864d4b504f48f520c992f4c4ef4b76c`. This establishes the native package contract on the exercised OS baselines. It does not claim a fresh-machine lab, older Windows support, a published release, or downstream Go adoption. The Lance pin, native source and public ABI are unchanged. Fixes #215. Part of #174.
1 parent 26d29ba commit 62fbc0f

12 files changed

Lines changed: 565 additions & 39 deletions

‎.github/scripts/test-windows-runtime-dependencies.ps1‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,80 @@ try {
4040
Write-Host " $($case.Dependency) -> $actual"
4141
}
4242

43+
$dumpbinSample = @'
44+
Image has the following dependencies:
45+
46+
KERNEL32.dll
47+
api-ms-win-core-synch-l1-2-0.dll
48+
49+
Image has the following delay load dependencies:
50+
51+
USER32.dll
52+
VCRUNTIME140.dll
53+
'@
54+
$parsed = Get-PeDependencies -DependentsText $dumpbinSample
55+
if ($parsed.Direct.Count -ne 2 -or
56+
$parsed.Direct -notcontains 'KERNEL32.dll' -or
57+
$parsed.Direct -notcontains 'api-ms-win-core-synch-l1-2-0.dll') {
58+
throw "direct dependency parsing failed: $($parsed.Direct -join ', ')"
59+
}
60+
if ($parsed.Delay.Count -ne 2 -or
61+
$parsed.Delay -notcontains 'USER32.dll' -or
62+
$parsed.Delay -notcontains 'VCRUNTIME140.dll') {
63+
throw "delay dependency parsing failed: $($parsed.Delay -join ', ')"
64+
}
65+
66+
Assert-NoRedistributableRuntimeDependencies `
67+
-Dependencies $parsed.Direct `
68+
-Description 'direct dependency fixture'
69+
Assert-NoRedistributableRuntimeDependencies `
70+
-Dependencies @('msvcp_win.dll', 'MSVCP_WIN.DLL', 'msvcrt.dll', 'ucrtbase.dll') `
71+
-Description 'Windows OS module fixture'
72+
$redistributableNames = @(
73+
'VCRUNTIME140.dll',
74+
'VCRUNTIME140_1.dll',
75+
'VCRUNTIME140D.dll',
76+
'MSVCP140.dll',
77+
'MSVCP140_ATOMIC_WAIT.dll',
78+
'MSVCP140_CODECVT_IDS.dll',
79+
'MSVCP140D.dll',
80+
'MSVCR120.dll',
81+
'CONCRT140.dll',
82+
'VCOMP140.dll'
83+
)
84+
foreach ($name in $redistributableNames) {
85+
$rejected = $false
86+
try {
87+
Assert-NoRedistributableRuntimeDependencies `
88+
-Dependencies @($name) `
89+
-Description 'redistributable fixture' | Out-Null
90+
} catch {
91+
$rejected = $true
92+
if ($_.Exception.Message -notmatch [regex]::Escape($name)) {
93+
throw
94+
}
95+
}
96+
if (-not $rejected) {
97+
throw "redistributable runtime $name was not rejected"
98+
}
99+
}
100+
101+
$vcxprojFixture = Join-Path $fixture 'acceptance.vcxproj'
102+
Set-Content -LiteralPath $vcxprojFixture -Value @'
103+
<ItemDefinitionGroup>
104+
<ClCompile>
105+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
106+
</ClCompile>
107+
</ItemDefinitionGroup>
108+
'@
109+
$runtimeLibraries = @(
110+
Get-MsvcRuntimeLibraries -ProjectPath $vcxprojFixture
111+
)
112+
if ($runtimeLibraries.Count -ne 1 -or
113+
$runtimeLibraries[0] -ne 'MultiThreaded') {
114+
throw "single MSVC runtime library was not preserved as an array"
115+
}
116+
43117
$missing = 'missing-runtime-174.dll'
44118
$rejected = $false
45119
try {

‎.github/scripts/verify-windows-staging.ps1‎

Lines changed: 148 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ $header = Join-Path $prefixPath 'include\lance\lance.h'
4545
$headerCpp = Join-Path $prefixPath 'include\lance\lance.hpp'
4646
$readme = Join-Path $prefixPath 'share\doc\lance-c\README.md'
4747
$license = Join-Path $prefixPath 'share\licenses\lance-c\LICENSE'
48+
$packageConfig = Join-Path $prefixPath 'lib\cmake\LanceC\LanceCConfig.cmake'
4849

4950
foreach ($required in @(
5051
$dll,
@@ -53,7 +54,8 @@ foreach ($required in @(
5354
$header,
5455
$headerCpp,
5556
$readme,
56-
$license
57+
$license,
58+
$packageConfig
5759
)) {
5860
if (-not (Test-Path -LiteralPath $required -PathType Leaf)) {
5961
throw "staged package is missing $required"
@@ -63,6 +65,11 @@ foreach ($required in @(
6365
}
6466
}
6567

68+
$packageConfigText = Get-Content -LiteralPath $packageConfig -Raw
69+
if ($packageConfigText -notmatch '(?m)^set\(LanceC_STATIC_CRT ON\)\s*$') {
70+
throw 'staged package does not declare LanceC_STATIC_CRT=ON'
71+
}
72+
6673
$msvcComponent = if ($Architecture -eq 'ARM64') {
6774
'Microsoft.VisualStudio.Component.VC.Tools.ARM64'
6875
} else {
@@ -168,37 +175,77 @@ if ($importExports.Count -ne $expectedExports.Count) {
168175
Write-Host "==> Verified $($importExports.Count) public lance_* imports"
169176

170177
$dependentsText = (Invoke-Dumpbin @('/dependents', $dll)) -join "`n"
171-
$dependencySection = ($dependentsText -split 'Image has the following dependencies:')[-1]
172-
$dependencies = [regex]::Matches(
173-
$dependencySection, '(?m)^\s+([A-Za-z0-9_.-]+\.dll)\s*$') |
174-
ForEach-Object { $_.Groups[1].Value } |
175-
Sort-Object -Unique
176-
if ($dependencies.Count -eq 0) {
177-
throw "staged DLL reports no runtime dependencies:`n$dependentsText"
178+
$dependencies = Get-PeDependencies -DependentsText $dependentsText
179+
if ($dependencies.Direct.Count -eq 0) {
180+
throw "staged DLL reports no direct runtime dependencies:`n$dependentsText"
178181
}
182+
Assert-NoRedistributableRuntimeDependencies `
183+
-Dependencies $dependencies.Direct `
184+
-Description 'staged DLL direct imports'
185+
Assert-NoRedistributableRuntimeDependencies `
186+
-Dependencies $dependencies.Delay `
187+
-Description 'staged DLL delay-load imports'
179188

180189
$system32 = Join-Path $env:SystemRoot 'System32'
181-
foreach ($dependency in $dependencies) {
190+
foreach ($dependency in $dependencies.Direct) {
182191
$dependencySource = Resolve-RuntimeDependency `
183192
-Dependency $dependency `
184193
-PrefixPath $prefixPath `
185194
-System32 $system32
186195
switch ($dependencySource) {
187196
'api-set' {
188-
Write-Host " $dependency -> API-set contract; native loader check follows"
197+
Write-Host " direct $dependency -> API-set contract; native loader check follows"
189198
}
190199
'system32' {
191-
Write-Host " $dependency -> System32"
200+
Write-Host " direct $dependency -> System32"
192201
}
193202
'staged' {
194-
Write-Host " $dependency -> staged lib"
203+
Write-Host " direct $dependency -> staged lib"
195204
}
196205
default {
197206
throw "unknown dependency classification for ${dependency}: $dependencySource"
198207
}
199208
}
200209
}
201-
Write-Host "==> Inspected $($dependencies.Count) runtime DLL dependencies"
210+
foreach ($dependency in $dependencies.Delay) {
211+
$dependencySource = Resolve-RuntimeDependency `
212+
-Dependency $dependency `
213+
-PrefixPath $prefixPath `
214+
-System32 $system32
215+
switch ($dependencySource) {
216+
'api-set' {
217+
Write-Host " delay $dependency -> API-set contract; native loader check follows"
218+
}
219+
'system32' {
220+
Write-Host " delay $dependency -> System32"
221+
}
222+
'staged' {
223+
Write-Host " delay $dependency -> staged lib"
224+
}
225+
default {
226+
throw "unknown dependency classification for ${dependency}: $dependencySource"
227+
}
228+
}
229+
}
230+
Write-Host ("==> Inspected $($dependencies.Direct.Count) direct and " +
231+
"$($dependencies.Delay.Count) delay-load DLL dependencies")
232+
233+
$staticDirectives = @(
234+
& $script:Dumpbin /directives $staticLibrary 2>&1 |
235+
Select-String -Pattern '/DEFAULTLIB:'
236+
)
237+
if ($LASTEXITCODE -ne 0) {
238+
throw "dumpbin /directives failed for the staged static library"
239+
}
240+
$staticDirectiveText = $staticDirectives -join "`n"
241+
if ($staticDirectiveText -notmatch '(?i)/DEFAULTLIB:(LIBCMT|libcmt)') {
242+
throw "staged static library does not carry a static CRT default library:`n$staticDirectiveText"
243+
}
244+
if ($staticDirectiveText -match
245+
'(?i)/DEFAULTLIB:(MSVCRT|MSVCRTD|VCRUNTIME|MSVCP)') {
246+
throw "staged static library carries an incompatible CRT default library:`n$staticDirectiveText"
247+
}
248+
Write-Host '==> Verified static archive CRT directives'
202249

203250
function Test-InstalledConsumer {
204251
param(
@@ -226,24 +273,75 @@ function Test-InstalledConsumer {
226273
$buildArguments = @(
227274
'--build', $buildDir, '--config', 'Release', '--parallel', '4'
228275
)
229-
& cmake @buildArguments
276+
$buildOutput = & cmake @buildArguments 2>&1
277+
$buildOutput | ForEach-Object { Write-Host $_ }
230278
if ($LASTEXITCODE -ne 0) {
231279
throw "cmake build failed for $Linkage consumer with exit code $LASTEXITCODE"
232280
}
281+
$crtLinkDiagnostics = @(
282+
$buildOutput | Select-String -Pattern 'LNK4098|LNK2038'
283+
)
284+
if ($crtLinkDiagnostics.Count -ne 0) {
285+
throw ("$Linkage consumer produced an incompatible CRT link diagnostic:`n" +
286+
"$($crtLinkDiagnostics -join "`n")")
287+
}
233288

234289
$executable = Join-Path $buildDir 'Release\acceptance.exe'
235290
if (-not (Test-Path -LiteralPath $executable -PathType Leaf)) {
236291
throw "acceptance executable was not built: $executable"
237292
}
238293
Assert-PeImage -Path $executable -Description "$Linkage acceptance executable"
239294

295+
$consumerObject = Join-Path $buildDir 'acceptance.dir\Release\acceptance.obj'
296+
if (-not (Test-Path -LiteralPath $consumerObject -PathType Leaf)) {
297+
throw "$Linkage consumer object was not built: $consumerObject"
298+
}
299+
$objectDirectives = @(
300+
& $script:Dumpbin /directives $consumerObject 2>&1 |
301+
Select-String -Pattern '/DEFAULTLIB:'
302+
)
303+
if ($LASTEXITCODE -ne 0) {
304+
throw "$Linkage consumer object directive inspection failed"
305+
}
306+
$objectDirectiveText = $objectDirectives -join "`n"
307+
if ($objectDirectiveText -notmatch '(?i)/DEFAULTLIB:(LIBCMT|libcmt)') {
308+
throw "$Linkage consumer object does not use the static CRT:`n$objectDirectiveText"
309+
}
310+
if ($objectDirectiveText -match
311+
'(?i)/DEFAULTLIB:(MSVCRT|MSVCRTD|VCRUNTIME|MSVCP)') {
312+
throw "$Linkage consumer object uses an incompatible CRT:`n$objectDirectiveText"
313+
}
314+
Write-Host "==> Verified $Linkage consumer object CRT directives"
315+
316+
$vcxproj = Join-Path $buildDir 'acceptance.vcxproj'
317+
$runtimeLibraries = @(Get-MsvcRuntimeLibraries -ProjectPath $vcxproj)
318+
if ($runtimeLibraries.Count -eq 0) {
319+
throw "$Linkage consumer does not declare MSVC_RUNTIME_LIBRARY"
320+
}
321+
$unexpectedRuntimeLibraries = @(
322+
$runtimeLibraries | Where-Object { $_ -ne 'MultiThreaded' }
323+
)
324+
if ($unexpectedRuntimeLibraries.Count -ne 0) {
325+
throw ("$Linkage consumer does not use the /MT runtime: " +
326+
"$($unexpectedRuntimeLibraries -join ', ')")
327+
}
328+
Write-Host "==> Verified $Linkage consumer runtime library: MultiThreaded"
329+
240330
$executableDependents = (Invoke-Dumpbin @('/dependents', $executable)) -join "`n"
331+
$executableDependencies = Get-PeDependencies `
332+
-DependentsText $executableDependents
333+
Assert-NoRedistributableRuntimeDependencies `
334+
-Dependencies $executableDependencies.Direct `
335+
-Description "$Linkage acceptance direct imports"
336+
Assert-NoRedistributableRuntimeDependencies `
337+
-Dependencies $executableDependencies.Delay `
338+
-Description "$Linkage acceptance delay-load imports"
241339
if ($Linkage -eq 'shared') {
242340
Copy-Item -LiteralPath $dll -Destination (Split-Path -Parent $executable) -Force
243-
if ($executableDependents -notmatch '(?im)^\s*lance_c\.dll\s*$') {
341+
if ($executableDependencies.Direct -notcontains 'lance_c.dll') {
244342
throw "shared acceptance executable does not import lance_c.dll"
245343
}
246-
} elseif ($executableDependents -match '(?im)^\s*lance_c\.dll\s*$') {
344+
} elseif ($executableDependencies.Direct -contains 'lance_c.dll') {
247345
throw "static acceptance executable unexpectedly imports lance_c.dll"
248346
}
249347

@@ -254,15 +352,49 @@ function Test-InstalledConsumer {
254352

255353
Write-Host "==> Running installed $Linkage consumer with system-only PATH"
256354
$previousPath = $env:Path
355+
$previousModuleReport = $env:LANCE_C_MODULE_REPORT
356+
$moduleReport = Join-Path $workPath "loaded-modules-$Linkage.txt"
357+
Remove-Item -LiteralPath $moduleReport -Force -ErrorAction SilentlyContinue
257358
try {
258359
$env:Path = "$env:SystemRoot\System32;$env:SystemRoot"
360+
$env:LANCE_C_MODULE_REPORT = $moduleReport
259361
& $executable $uri
260362
if ($LASTEXITCODE -ne 0) {
261363
throw "$Linkage acceptance consumer failed with exit code $LASTEXITCODE"
262364
}
263365
} finally {
264366
$env:Path = $previousPath
367+
if ($null -eq $previousModuleReport) {
368+
Remove-Item Env:\LANCE_C_MODULE_REPORT `
369+
-ErrorAction SilentlyContinue
370+
} else {
371+
$env:LANCE_C_MODULE_REPORT = $previousModuleReport
372+
}
373+
}
374+
375+
if (-not (Test-Path -LiteralPath $moduleReport -PathType Leaf)) {
376+
throw "$Linkage acceptance consumer did not write its loaded-module report"
377+
}
378+
$loadedModules = @(
379+
Get-Content -LiteralPath $moduleReport |
380+
Where-Object { $_ -match '\.dll$' } |
381+
Sort-Object -Unique
382+
)
383+
if ($loadedModules.Count -eq 0) {
384+
throw "$Linkage loaded-module report is empty"
385+
}
386+
Assert-NoRedistributableRuntimeDependencies `
387+
-Dependencies $loadedModules `
388+
-Description "$Linkage loaded modules"
389+
$hasLanceDll = $loadedModules -contains 'lance_c.dll'
390+
if ($Linkage -eq 'shared' -and -not $hasLanceDll) {
391+
throw "shared acceptance executable did not load lance_c.dll"
392+
}
393+
if ($Linkage -eq 'static' -and $hasLanceDll) {
394+
throw "static acceptance executable unexpectedly loaded lance_c.dll"
265395
}
396+
Write-Host "==> Verified $($loadedModules.Count) loaded modules for $Linkage consumer"
397+
$loadedModules | ForEach-Object { Write-Host " $_" }
266398
}
267399

268400
Test-InstalledConsumer -Linkage static

0 commit comments

Comments
 (0)