Skip to content

Commit 016df80

Browse files
Ignore a mismatched system Zig during native restore
Resolve-ZigPath returned any zig on PATH without checking its version, so a newer system Zig (e.g. 0.17) broke dotnet build: Zig's build API changes between minor releases and the pinned Ghostty sources only build with 0.16. A zig on PATH is now used only when it matches the pinned major.minor (patch and dev builds included); otherwise it is skipped and the pinned Zig is used from, or downloaded into, artifacts/tools. An explicit -ZigPath is still honored but warns on a version mismatch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b1620d6 commit 016df80

3 files changed

Lines changed: 62 additions & 3 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ Do not point that tool at this repository.
7373
- Windows Explorer/toast helpers: `native/windows-shell` (MSVC, gitignored `bin/`)
7474

7575
`dotnet build` restores Ghostty and `dt-pty-host` for the host RID (Zig is
76-
downloaded into `artifacts/tools` on first use). See
76+
downloaded into `artifacts/tools` on first use; a system `zig` of a different
77+
minor version than the pinned one is ignored, so it does not break the build). See
7778
[`native/ghostty/README.md`](native/ghostty/README.md). Pass
7879
`-p:SkipNativeRestore=true` to skip.
7980

‎native/Zig.ps1‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,50 @@ function Install-Zig {
111111
return $found.FullName
112112
}
113113

114+
function Get-ZigVersion {
115+
param(
116+
[Parameter(Mandatory)]
117+
[string] $ZigPath
118+
)
119+
120+
try {
121+
$output = & $ZigPath version 2>$null
122+
if ($LASTEXITCODE -ne 0) {
123+
return $null
124+
}
125+
126+
return ([string]$output).Trim()
127+
}
128+
catch {
129+
return $null
130+
}
131+
}
132+
133+
# Zig's build API changes between minor releases, so only the pinned major.minor can build the
134+
# pinned sources; patch releases (and dev builds of that minor) are accepted.
135+
function Test-ZigVersionCompatible {
136+
param(
137+
[string] $Actual,
138+
[Parameter(Mandatory)]
139+
[string] $Required
140+
)
141+
142+
if ([string]::IsNullOrWhiteSpace($Actual)) {
143+
return $false
144+
}
145+
146+
$actualCore = ($Actual -split '[-+]', 2)[0]
147+
$requiredCore = ($Required -split '[-+]', 2)[0]
148+
$actualVersion = $null
149+
$requiredVersion = $null
150+
if (-not [version]::TryParse($actualCore, [ref]$actualVersion) -or
151+
-not [version]::TryParse($requiredCore, [ref]$requiredVersion)) {
152+
return $false
153+
}
154+
155+
return $actualVersion.Major -eq $requiredVersion.Major -and $actualVersion.Minor -eq $requiredVersion.Minor
156+
}
157+
114158
function Resolve-ZigPath {
115159
param(
116160
[string] $ZigPath,
@@ -122,12 +166,24 @@ function Resolve-ZigPath {
122166
)
123167

124168
if (-not [string]::IsNullOrWhiteSpace($ZigPath) -and (Test-Path -LiteralPath $ZigPath)) {
169+
$explicitVersion = Get-ZigVersion -ZigPath $ZigPath
170+
if (-not (Test-ZigVersionCompatible -Actual $explicitVersion -Required $Version)) {
171+
Write-Warning "Using explicit Zig '$ZigPath' ($explicitVersion); the pinned sources expect Zig $Version."
172+
}
173+
125174
return $ZigPath
126175
}
127176

177+
# A different system Zig (for example a newer release on PATH) is ignored rather than failing
178+
# the build: the pinned version is used from, or downloaded into, artifacts/tools instead.
128179
$command = Get-Command zig -ErrorAction SilentlyContinue | Select-Object -First 1
129180
if ($null -ne $command) {
130-
return $command.Source
181+
$pathVersion = Get-ZigVersion -ZigPath $command.Source
182+
if (Test-ZigVersionCompatible -Actual $pathVersion -Required $Version) {
183+
return $command.Source
184+
}
185+
186+
Write-Host "Ignoring Zig $pathVersion at '$($command.Source)'; native libraries require Zig $Version."
131187
}
132188

133189
$zigName = if (Test-HostWindows) { "zig.exe" } else { "zig" }

‎native/ghostty/README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ The optional Ghostty terminal engine uses `libghostty-vt` built from
1212
Binaries are **not** committed. `dotnet build` / `dotnet test` restore the host
1313
RID via [`../Restore-NativeLibraries.ps1`](../Restore-NativeLibraries.ps1),
1414
which downloads Zig 0.16.0 if needed and compiles `libghostty-vt` into
15-
`native/ghostty/<rid>/` (gitignored). ABI checks use the type manifest, not a
15+
`native/ghostty/<rid>/` (gitignored). A `zig` on `PATH` is used only when it is
16+
Zig 0.16.x; any other version (for example a newer system install) is ignored
17+
and the pinned Zig is downloaded into `artifacts/tools` instead. ABI checks use the type manifest, not a
1618
file hash.
1719

1820
Linux: glibc **2.31+**. macOS: **13.0+** (`aarch64-macos.13.0` /

0 commit comments

Comments
 (0)