Build 6.1.0 with w64devkit and make the prefix relocatable

Replace the MSYS2/UCRT64 toolchain with the portable w64devkit kit:
bootstrap a pinned kit, build with its sh/make/gcc, and keep the
compiler's temporary files inside work/.

Update upstream to 6.1.0 and add a portable-prefix patch: when the
configured prefix is gone, csc, csi, chicken, and the chicken-* tools
derive include, library, and repository paths from the running
executable.  A released zip now works wherever it is unpacked, which
it did not before.

Signed-off-by: Pavel Kulyov <kulyov.pavel@gmail.com>
This commit is contained in:
2026-11-18 00:09:31 +03:00
parent 8c25c16c79
commit 4865835943
5 changed files with 248 additions and 67 deletions

116
ck.ps1
View File

@@ -1,9 +1,9 @@
# Build and publish a UCRT64 CHICKEN 6 prefix.
# .\ck.ps1 fetch-sources | patch | build | test | publish | clean
# Build and publish a MinGW CHICKEN prefix.
# .\ck.ps1 bootstrap | fetch-sources | patch | build | test | publish | clean
# .\ck.ps1 publish -Latest
param(
[Parameter(Mandatory = $true, Position = 0)]
[ValidateSet('fetch-sources', 'patch', 'build', 'test', 'publish', 'clean')]
[ValidateSet('bootstrap', 'fetch-sources', 'patch', 'build', 'test', 'publish', 'clean')]
[string]$Command,
[switch]$Latest
@@ -17,6 +17,12 @@ $Prefix = Join-Path $Work 'prefix'
$Dist = Join-Path $Work 'dist'
$ConfigPath = Join-Path $Root 'chicken.json'
# The toolchain is a portable folder, not an installed package.
$KitVersion = '2.11.0'
$KitSha256 = '54c2bb9962e8a30c8270e34c5efc3d5fee579f53087fa7d435b95fbba2af7b2b'
$KitUrl = "https://github.com/skeeto/w64devkit/releases/download/v$KitVersion/w64devkit-x64-$KitVersion.7z.exe"
$Kit = Join-Path $Work 'w64devkit'
function Get-ProjectConfig {
Get-Content -Raw -LiteralPath $ConfigPath | ConvertFrom-Json
}
@@ -46,35 +52,32 @@ function Import-DotEnv {
}
}
function Find-Bash {
$roots = @()
if ($env:MSYS2_ROOT) { $roots += $env:MSYS2_ROOT }
$roots += (Join-Path $env:USERPROFILE 'scoop\apps\msys2\current')
$roots += 'C:\msys64'
foreach ($candidateRoot in $roots) {
if (-not $candidateRoot) { continue }
$candidate = Join-Path $candidateRoot 'usr\bin\bash.exe'
if (Test-Path -LiteralPath $candidate) { return $candidate }
function Get-KitRoot {
$candidates = @()
if ($env:W64DEVKIT_ROOT) { $candidates += $env:W64DEVKIT_ROOT }
$candidates += $Kit
foreach ($candidate in $candidates) {
if (-not $candidate) { continue }
if (Test-Path -LiteralPath (Join-Path $candidate 'bin\sh.exe')) {
return (Resolve-Path -LiteralPath $candidate).Path
}
}
Write-Error "MSYS2 bash.exe not found. Install MSYS2 (scoop install msys2) or set MSYS2_ROOT."
Write-Error "w64devkit not found. Run: .\ck.ps1 bootstrap (or set W64DEVKIT_ROOT)."
exit 1
}
function To-Msys([string]$Path) {
$full = (Resolve-Path -LiteralPath $Path).Path -replace '\\', '/'
if ($full -match '^([A-Za-z]):(.*)$') {
return '/' + $Matches[1].ToLower() + $Matches[2]
}
return $full
}
function Invoke-Ucrt([string]$Script) {
$bash = Find-Bash
$env:MSYSTEM = 'UCRT64'
$env:CHERE_INVOKING = '1'
$env:MSYS2_PATH_TYPE = 'strict'
$unix = To-Msys $Root
& $bash -lc "cd '$unix' && $Script"
function Invoke-Kit([string]$Script) {
$kit = Get-KitRoot
$env:PATH = (Join-Path $kit 'bin') + ';' + $env:PATH
# Keep the compiler's temporary files inside the tree: the build
# need not depend on the machine's %TEMP% being writable.
$tmp = Join-Path $Work '.tmp'
New-Item -ItemType Directory -Force -Path $tmp | Out-Null
$env:TEMP = $tmp
$env:TMP = $tmp
$env:TMPDIR = $tmp -replace '\\', '/'
$root = $Root -replace '\\', '/'
& (Join-Path $kit 'bin\sh.exe') -c "cd '$root' && $Script"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
@@ -101,6 +104,43 @@ function Get-FileSha256([string]$Path) {
(Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLower()
}
function Invoke-Bootstrap {
if (Test-Path -LiteralPath (Join-Path $Kit 'bin\sh.exe')) {
Write-Host "toolchain already in $Kit"
return
}
New-Item -ItemType Directory -Force -Path $Work | Out-Null
$sfx = Join-Path $Work "w64devkit-x64-$KitVersion.7z.exe"
if (-not (Test-Path -LiteralPath $sfx)) {
Write-Host "downloading w64devkit $KitVersion"
& curl.exe -fL --retry 2 -o $sfx $KitUrl
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
$actual = Get-FileSha256 $sfx
if ($actual -ne $KitSha256) {
Write-Error "w64devkit sha256 mismatch: got $actual, want $KitSha256"
exit 1
}
Write-Host "unpacking $Kit"
New-Item -ItemType Directory -Force -Path $Kit | Out-Null
$process = Start-Process -FilePath $sfx -ArgumentList @('-y', "-o$Kit") -Wait -PassThru -WindowStyle Hidden
if ($process.ExitCode -ne 0) {
Write-Error "w64devkit extractor failed with exit code $($process.ExitCode)"
exit 1
}
# The self-extractor puts everything under a w64devkit/ folder.
$nested = Join-Path $Kit 'w64devkit'
if (Test-Path -LiteralPath $nested) {
Get-ChildItem -LiteralPath $nested | Move-Item -Destination $Kit -Force
Remove-Item -LiteralPath $nested -Force
}
if (-not (Test-Path -LiteralPath (Join-Path $Kit 'bin\sh.exe'))) {
Write-Error "w64devkit archive has no bin\sh.exe"
exit 1
}
Write-Host "toolchain in $Kit"
}
function Invoke-FetchSources {
param([switch]$Latest)
@@ -157,6 +197,7 @@ function Invoke-Patch {
Push-Location $Root
try {
foreach ($patch in $patches) {
Write-Host "applying $($patch.Name)"
git apply --unsafe-paths --directory=work/src -p1 -- $patch.FullName
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
@@ -172,11 +213,11 @@ function Invoke-Patch {
}
function Invoke-Build {
Invoke-Ucrt './build.sh'
Invoke-Kit 'sh ./build.sh'
}
function Invoke-Test {
Invoke-Ucrt './build.sh check'
Invoke-Kit 'sh ./build.sh check'
}
function Get-Revision {
@@ -201,7 +242,7 @@ function Invoke-Publish {
exit 1
}
New-Item -ItemType Directory -Force -Path $Dist | Out-Null
$zipName = "chicken-$UpstreamVersion-ucrt64-x86_64.zip"
$zipName = "chicken-$UpstreamVersion-mingw-x86_64.zip"
$zip = Join-Path $Dist $zipName
if (Test-Path -LiteralPath $zip) { Remove-Item -LiteralPath $zip -Force }
& "$env:SystemRoot\System32\tar.exe" -a -cf $zip -C $Prefix .
@@ -222,7 +263,7 @@ function Invoke-Publish {
tag_name = $tag
target_commitish = 'main'
name = "CHICKEN $UpstreamVersion for Windows"
body = "UCRT64 x86_64 prefix. Unpack anywhere; csc needs ``-libdir <prefix>/lib``."
body = "MinGW-w64 x86_64 prefix. Unpack anywhere and run bin/csc.exe."
draft = $false
prerelease = $false
} | ConvertTo-Json
@@ -234,15 +275,20 @@ function Invoke-Publish {
}
switch ($Command) {
'bootstrap' { Invoke-Bootstrap }
'fetch-sources' { Invoke-FetchSources -Latest:$Latest }
'patch' { Invoke-Patch }
'build' { Invoke-Build }
'test' { Invoke-Test }
'publish' { Invoke-Publish -Latest:$Latest }
'clean' {
if (Test-Path -LiteralPath $Work) {
Remove-Item -LiteralPath $Work -Recurse -Force
foreach ($target in @($Src, $Prefix, $Dist)) {
if (Test-Path -LiteralPath $target) {
Remove-Item -LiteralPath $target -Recurse -Force
}
}
Write-Host "removed $Work"
Get-ChildItem -Path $Work -Filter 'chicken-*.tar.gz' -ErrorAction SilentlyContinue |
Remove-Item -Force
Write-Host "removed build outputs in $Work (kept $Kit)"
}
}