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

View File

@@ -2,33 +2,29 @@
Chicken (6) 4 Windows 10+.
Upstream does not ship a Windows binary. This repo keeps the MinGW patches and builds a UCRT64 prefix, then publishes that prefix as a Gitea release. CHICKEN sources are not stored here.
This repo keeps the MinGW pathes, builds a MinGW-w64 prefix with w64devkit and publishes
that prefix as a Gitea release.
## Kit
A clean Windows install is not a development machine. Start with [scoop](https://scoop.sh), then:
The build uses [w64devkit](https://github.com/skeeto/w64devkit), a portable folder with MinGW-w64 GCC, GNU make, and a POSIX shell.
```powershell
scoop install git msys2
.\ck.ps1 bootstrap
```
In the UCRT64 shell (`C:\Users\<you>\scoop\apps\msys2\current\ucrt64.exe`, or `bash` after `MSYSTEM=UCRT64`):
That downloads one pinned kit archive into `work/w64devkit`. To use a kit you already unpacked:
```sh
pacman -S --needed --noconfirm base-devel mingw-w64-ucrt-x86_64-gcc
```powershell
$env:W64DEVKIT_ROOT = 'C:\w64devkit'
```
Put `%USERPROFILE%\scoop\apps\msys2\current\ucrt64\bin` on `PATH` so `gcc` is the UCRT64 one.
Publishing reads `GITEA_TOKEN` from a gitignored `.env` in this directory:
```
GITEA_TOKEN=...
```
Nothing is added to the machine `PATH`; `ck.ps1` puts the kit on `PATH` for each command.
## Commands
```powershell
.\ck.ps1 bootstrap
.\ck.ps1 fetch-sources
.\ck.ps1 patch
.\ck.ps1 build
@@ -37,10 +33,31 @@ GITEA_TOKEN=...
.\ck.ps1 clean
```
Versions live in `chicken.json`. The script loads and saves it with `ConvertFrom-Json` and `ConvertTo-Json`. Change `upstream.version` and clear `upstream.sha256`; `fetch-sources` downloads that release and writes the hash back. `.\ck.ps1 fetch-sources -Latest` (and `publish -Latest`) instead takes whatever `https://code.call-cc.org/releases/current/` is serving and overwrites `upstream.version` and `upstream.sha256`. `revision` is the local serial in the same file. The tag is `<version>-win<revision>`.
Versions live in `chicken.json`, the script loads and saves it.
Change `upstream.version` and clear `upstream.sha256`; `fetch-sources` downloads that release and writes the hash back.
`.\ck.ps1 fetch-sources -Latest` (and `publish -Latest`) instead takes whatever
`https://code.call-cc.org/releases/current/` is serving and overwrites `upstream.version` and `upstream.sha256`.
`revision` is the local serial in the same file. The tag is `<version>-win<revision>`.
`publish` runs fetch, patch, build, and test, then uploads `work/dist/chicken-<version>-ucrt64-x86_64.zip`. If that tag already exists, publish stops. Bump `revision` to ship another build of the same upstream tarball.
`publish` runs fetch, patch, build, and test, then uploads `work/dist/chicken-<version>-mingw-x86_64.zip`.
If that tag already exists, publish stops. Bump `revision` to ship another build of the same upstream tarball.
`clean` deletes `work/` only.
`clean` deletes the sources, prefix, and dist; it keeps the toolchain in `work/w64devkit`.
`csc` in the zip still has `work/prefix` compiled into it. Consumers pass `-libdir` at wherever they unpacked the zip. Sex does that.
Publishing reads `GITEA_TOKEN` from a gitignored `.env` in this directory:
```
GITEA_TOKEN=...
```
## The zip
The release zip is relocatable: unpack it anywhere and run `bin\csc.exe`.
When the prefix it was configured with is gone, `csc`, `csi`, and the `chicken-*` tools locate
the include, library, and share directories from the running executable.
Compiling with `csc` still needs a C compiler on `PATH`: the w64devkit `bin` directory (it provides `cc` and `gcc`).
`csc -static` links a standalone executable; the default links `libchicken.dll`, which must sit next to the executable or on `PATH`.
The two MinGW patches keep MinGW's SEH `setjmp` off CHICKEN's alloca frames and make the standard
handles inheritable for `process`. The third makes the installed prefix relocatable.

View File

@@ -1,13 +1,16 @@
#!/usr/bin/env bash
# Configure, build, and install into work/prefix. Run from a UCRT64 shell.
# Configure, build, and install into work/prefix.
# Run from a w64devkit shell (or let ck.ps1 provide one).
set -eu
root=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
src="$root/work/src"
prefix=$(cygpath -m "$root/work/prefix")
prefix="${CHICKEN_PREFIX:-$root/work/prefix}"
prefix=${prefix//\\//}
if [ "${1:-}" = check ]; then
export PATH="$(cygpath -u "$prefix")/bin:${PATH}"
PATH="$prefix/bin;$PATH"
export PATH
make -C "$src" check
exit 0
fi
@@ -17,19 +20,11 @@ if [ ! -f "$src/configure" ]; then
exit 1
fi
case "${MSYSTEM:-}" in
UCRT64|MINGW64|CLANG64) ;;
*)
echo "build.sh needs an MSYS2 MinGW shell (UCRT64)." >&2
exit 1
;;
esac
machine=$(gcc -dumpmachine)
case "$machine" in
*mingw*) ;;
*)
echo "gcc targets ${machine}. Install the UCRT64 toolchain." >&2
echo "gcc targets ${machine}. Run this from w64devkit (or .\\ck.ps1 build)." >&2
exit 1
;;
esac
@@ -41,13 +36,25 @@ if [ -f "$src/posixwin.c" ]; then
fi
jobs=$(nproc 2>/dev/null || echo 1)
# Bootstrap rebuilds run "chicken" from the source directory; sh does
# not look in the current directory, so put it on PATH.
PATH="$src;$PATH"
export PATH
(
cd "$src"
./configure --prefix "$prefix" --platform mingw
# The tarball ships generated C that is newer than the Scheme sources
# it came from, and the portable-prefix patch changes two of those
# sources. Regenerating them needs the compiler those C files build,
# so build it from the shipped C first, then let it regenerate.
touch library.c csc.c chicken-install.c chicken-status.c chicken-uninstall.c
make -j"$jobs" chicken.exe
touch library.scm egg-environment.scm
make -j"$jobs"
make install
)
export PATH="$(cygpath -u "$prefix")/bin:${PATH}"
PATH="$prefix/bin;$PATH"
export PATH
echo "installed $prefix"
csc -version

View File

@@ -1,7 +1,7 @@
{
"upstream": {
"version": "6.0.0",
"sha256": "92835552b1b687ad26737e429b5aba36510bf429f8816ec0f6d336c8cb41f443"
"version": "6.1.0",
"sha256": "c6aee9a5374102ba318e0cfae62ded5e1825346577137952d7fb15b3094d49d8"
},
"gitea": {
"host": "https://git.kotobank.ch",

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)"
}
}

View File

@@ -0,0 +1,111 @@
--- a/library.scm
+++ b/library.scm
@@ -7896,8 +7896,41 @@
;;; Installation locations
(define-foreign-variable binary-version int "C_BINARY_VERSION")
-(define-foreign-variable installation-home c-string "C_INSTALL_SHARE_HOME")
-(define-foreign-variable install-egg-home c-string "C_INSTALL_EGG_HOME")
+
+;; A prefix that has been unpacked somewhere else no longer has the
+;; directories naming it was configured with. When they are gone, use
+;; the tree the running executable lives in.
+(define (##sys#executable-prefix)
+ (let ((dir (foreign-value "C_executable_dirname()" c-string)))
+ (and dir
+ (let loop ((i (fx- (string-length dir) 1)))
+ (cond ((fx< i 0) #f)
+ ((or (char=? (string-ref dir i) #\/)
+ (char=? (string-ref dir i) #\\))
+ (and (fx> i 0) (substring dir 0 i)))
+ (else (loop (fx- i 1))))))))
+
+(define (##sys#existing-directory dir)
+ (and dir (##sys#file-exists? dir #f #t 'installation-home) dir))
+
+(define installation-home
+ (let ((configured (foreign-value "C_INSTALL_SHARE_HOME" c-string)))
+ (or (##sys#existing-directory configured)
+ (let ((prefix (##sys#executable-prefix)))
+ (and prefix
+ (##sys#existing-directory
+ (string-append prefix "/share/chicken"))))
+ configured)))
+
+(define install-egg-home
+ (let ((configured (foreign-value "C_INSTALL_EGG_HOME" c-string)))
+ (or (##sys#existing-directory configured)
+ (let ((prefix (##sys#executable-prefix)))
+ (and prefix
+ (##sys#existing-directory
+ (string-append prefix "/lib/chicken/"
+ (number->string binary-version)))))
+ configured)))
(define (include-path #!optional new)
(when new
--- a/egg-environment.scm
+++ b/egg-environment.scm
@@ -65,9 +65,36 @@
(foreign-value "C_WINDOWS_SHELL" bool)
'unix))
-(define default-prefix (foreign-value "C_INSTALL_PREFIX" c-string))
-(define default-bindir (foreign-value "C_INSTALL_BIN_HOME" c-string))
+;; A prefix unpacked somewhere else no longer has the directories it was
+;; configured with. When they are gone, use the tree the running
+;; executable lives in.
+(define (existing-directory path)
+ (and path (directory-exists? path) path))
+(define (executable-bindir)
+ (foreign-value "C_executable_dirname()" c-string))
+
+(define (executable-prefix)
+ (let ((bindir (executable-bindir)))
+ (and bindir (pathname-directory bindir))))
+
+(define (install-path configured relative)
+ (or (existing-directory configured)
+ (let ((prefix (executable-prefix)))
+ (and prefix
+ (existing-directory (string-append prefix relative))))
+ configured))
+
+(define default-prefix
+ (or (existing-directory (foreign-value "C_INSTALL_PREFIX" c-string))
+ (executable-prefix)
+ (foreign-value "C_INSTALL_PREFIX" c-string)))
+
+(define default-bindir
+ (or (existing-directory (foreign-value "C_INSTALL_BIN_HOME" c-string))
+ (executable-bindir)
+ (foreign-value "C_INSTALL_BIN_HOME" c-string)))
+
(define default-csc
(string-append default-bindir "/" (foreign-value "C_CSC_PROGRAM" c-string)))
@@ -80,12 +107,17 @@
(define target-librarian (foreign-value "C_TARGET_LIBRARIAN" c-string))
(define target-librarian-options (foreign-value "C_TARGET_LIBRARIAN_FLAGS" c-string))
-(define host-prefix (foreign-value "C_INSTALL_PREFIX" c-string))
-(define host-repo (foreign-value "C_INSTALL_EGG_HOME" c-string))
-(define host-libdir (foreign-value "C_INSTALL_LIB_HOME" c-string))
-(define host-bindir (foreign-value "C_INSTALL_BIN_HOME" c-string))
-(define host-incdir (foreign-value "C_INSTALL_INCLUDE_HOME" c-string))
-(define host-sharedir (foreign-value "C_INSTALL_SHARE_HOME" c-string))
+(define host-prefix default-prefix)
+(define host-repo
+ (install-path (foreign-value "C_INSTALL_EGG_HOME" c-string)
+ (string-append "/lib/chicken/" (number->string binary-version))))
+(define host-libdir
+ (install-path (foreign-value "C_INSTALL_LIB_HOME" c-string) "/lib"))
+(define host-bindir default-bindir)
+(define host-incdir
+ (install-path (foreign-value "C_INSTALL_INCLUDE_HOME" c-string) "/include/chicken"))
+(define host-sharedir
+ (install-path (foreign-value "C_INSTALL_SHARE_HOME" c-string) "/share/chicken"))
(define host-libs (foreign-value "C_INSTALL_MORE_LIBS" c-string))
(define host-cflags (foreign-value "C_INSTALL_CFLAGS" c-string))
(define host-ldflags (foreign-value "C_INSTALL_LDFLAGS" c-string))