From 4aff7c2d315634f5ea90a83051a0a940573d9c2f Mon Sep 17 00:00:00 2001 From: Luther Monson Date: Sat, 10 Oct 2026 16:31:39 -0700 Subject: [PATCH 1/2] ci(windows-shared): shared-engine Windows SDK + Windows Xdebug catalog The default Windows SDK is a static spc --build-embed, and a binary that links PHP statically has no php8ts.dll for extension DLLs to import the engine from, so php_xdebug.dll (or any php_*.dll) cannot load into it. Add a separate lane, windows-shared.yml + tools/windows-shared/package.ps1, that repackages the official windows.php.net ZTS x64 build of a release instead of compiling PHP: php-sdk--windows-x86_64-shared.tar.gz (attached to v) lib/php8embed.lib + lib/php8ts.lib + include/php + bin/php8ts.dll, the dependency DLLs, the official bin/ext/php_*.dll, and ephpm-sdk.json whose `preload` list restores the static SDK's extension set (mbstring, openssl, intl, pdo_mysql, ...; opcache as a zend_extension on 8.3/8.4). ephpm-ext--windows-x86_64.tar.gz (attached to ext-) php_xdebug.dll (the official xdebug.org ZTS DLL for the minor) + manifest.json in the Linux catalog's schema, libc "msvc". Every download is sha256-verified (checksums.txt pins, or the live windows.php.net list for current releases; the Xdebug pins match xdebug.org's published hashes). Packaging is refused unless the official php.exe, run from a directory holding only the packaged bin/ payload, loads all 37 extensions of the static set plus Xdebug as a Zend extension. Nothing is compiled, so it runs on GitHub-hosted windows-latest, not the ephemerd fleet. Publishing (main + workflow_dispatch only) uses `gh release upload --clobber`, which adds assets and never rewrites an existing release's body. A PR touching the lane builds and smoke-tests 8.3.33 / 8.4.23 / 8.5.7 without publishing. build.yml and extensions.yml are untouched. --- .github/workflows/windows-shared.yml | 135 +++++++++ README.md | 59 +++- tools/windows-shared/checksums.txt | 31 ++ tools/windows-shared/package.ps1 | 404 +++++++++++++++++++++++++++ 4 files changed, 627 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/windows-shared.yml create mode 100644 tools/windows-shared/checksums.txt create mode 100644 tools/windows-shared/package.ps1 diff --git a/.github/workflows/windows-shared.yml b/.github/workflows/windows-shared.yml new file mode 100644 index 0000000..243145a --- /dev/null +++ b/.github/workflows/windows-shared.yml @@ -0,0 +1,135 @@ +name: Windows shared SDK + extension catalog +run-name: "Windows shared SDK for PHP ${{ inputs.php_version || 'pinned set (PR check)' }}" + +# Packages the Windows *shared* PHP SDK (php8ts.dll + php8ts.lib + +# php8embed.lib + headers + the official extension DLLs) and the Windows Xdebug +# catalog entry for one PHP release. See tools/windows-shared/package.ps1 for +# the full rationale; the short version: +# +# The default Windows SDK (build.yml, platform windows-x86_64) is a static spc +# --build-embed, and a binary that links PHP statically has no php8ts.dll for +# extension DLLs to import the engine from, so it cannot load php_xdebug.dll +# or any other PHP extension. This lane repackages the official +# windows.php.net ZTS build of the same release instead of compiling PHP, so +# the official extension DLLs and xdebug.org's Xdebug DLLs are ABI-matched to +# the engine by construction. +# +# Separate workflow on purpose: build.yml's Windows legs and extensions.yml's +# Linux catalog stay untouched. Nothing here is compiled, so it runs on +# GitHub-hosted windows-latest rather than the self-hosted ephemerd fleet. +# +# Publishing (workflow_dispatch from main only) ADDS assets to existing +# releases with `gh release upload --clobber`, which never edits a release's +# title or body: +# v php-sdk--windows-x86_64-shared.tar.gz +# ext- ephpm-ext--windows-x86_64.tar.gz +# A missing release is created as a plain release with a short note. +# +# A pull request touching this lane builds and smoke-tests the pinned set +# below without publishing anything. + +on: + workflow_dispatch: + inputs: + php_version: + description: "PHP version (GA x.y.z, e.g. 8.5.7). Must be a windows.php.net release." + required: true + type: string + xdebug_version: + description: "Xdebug release (xdebug.org Windows DLL; its sha256 must be in tools/windows-shared/checksums.txt)" + required: false + type: string + default: "3.5.3" + pull_request: + paths: + - ".github/workflows/windows-shared.yml" + - "tools/windows-shared/**" + +permissions: + contents: read + +jobs: + setup: + name: Setup + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.m.outputs.matrix }} + steps: + - id: m + env: + PHP_VERSION: ${{ inputs.php_version }} + XDEBUG_VERSION: ${{ inputs.xdebug_version }} + run: | + if [ -n "$PHP_VERSION" ]; then + echo "matrix=[{\"php\":\"$PHP_VERSION\",\"xdebug\":\"${XDEBUG_VERSION:-3.5.3}\"}]" >> "$GITHUB_OUTPUT" + else + # PR check: the versions ephpm's xtask pins today (pinned + # checksums path) - keep in step with checksums.txt. + echo 'matrix=[{"php":"8.3.33","xdebug":"3.5.3"},{"php":"8.4.23","xdebug":"3.5.3"},{"php":"8.5.7","xdebug":"3.5.3"}]' >> "$GITHUB_OUTPUT" + fi + + package: + name: Package (PHP ${{ matrix.php }}) + needs: setup + runs-on: windows-latest + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + include: ${{ fromJSON(needs.setup.outputs.matrix) }} + steps: + - uses: actions/checkout@v4 + + - name: Package shared SDK + Xdebug catalog + shell: pwsh + run: | + ./tools/windows-shared/package.ps1 ` + -PhpVersion '${{ matrix.php }}' ` + -XdebugVersion '${{ matrix.xdebug }}' ` + -OutDir "$env:RUNNER_TEMP/out" ` + -WorkDir "$env:RUNNER_TEMP/work" + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: windows-shared-${{ matrix.php }} + path: ${{ runner.temp }}/out/*.tar.gz + if-no-files-found: error + + publish: + name: Publish + needs: package + if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/download-artifact@v4 + with: + path: artifacts + merge-multiple: true + + - name: Attach to v and ext- + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + PHP_VERSION: ${{ inputs.php_version }} + run: | + set -eu + ls -lh artifacts/ + sdk="artifacts/php-sdk-${PHP_VERSION}-windows-x86_64-shared.tar.gz" + ext="artifacts/ephpm-ext-${PHP_VERSION}-windows-x86_64.tar.gz" + test -f "$sdk" && test -f "$ext" + + ensure_release() { + if ! gh release view "$1" > /dev/null 2>&1; then + gh release create "$1" --title "$2" --notes "$3" + fi + } + ensure_release "v${PHP_VERSION}" "PHP ${PHP_VERSION}" \ + "PHP ${PHP_VERSION} SDK. Windows shared-engine SDK attached by windows-shared.yml." + ensure_release "ext-${PHP_VERSION}" "PHP ${PHP_VERSION} ZTS extensions" \ + "PHP ${PHP_VERSION} ZTS extensions. Windows Xdebug attached by windows-shared.yml." + + gh release upload "v${PHP_VERSION}" "$sdk" --clobber + gh release upload "ext-${PHP_VERSION}" "$ext" --clobber diff --git a/README.md b/README.md index bbaa57f..c0458a4 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Built with [static-php-cli](https://github.com/crazywhalecc/static-php-cli) — | Linux x86_64 (glibc, **NTS**, shared embed) | `-linux-x86_64-gnu-nts-shared` | `lib/libphp.so` (dependencies linked in) + headers, non-thread-safe | | Linux aarch64 (glibc, **NTS**, shared embed) | `-linux-aarch64-gnu-nts-shared` | `lib/libphp.so` (dependencies linked in) + headers, non-thread-safe | | Windows x86_64 (**experimental**, clang-cl + TAILCALL VM) | `-windows-x86_64-clang` | `lib/php8embed.lib` + dep `.lib`s + headers, ZTS | +| Windows x86_64 (**shared engine**, official build) | `-windows-x86_64-shared` | `bin/php8ts.dll` + `lib/php8ts.lib` + `lib/php8embed.lib` + headers + official `bin/ext/php_*.dll`, ZTS | The glibc floor is 2.28 (built on AlmaLinux 8 with `gcc-toolset-13`), so a consumer binary linked against these runs on RHEL/Alma 8, Ubuntu 20.04+, Debian 10+, Amazon Linux 2023 and Fedora 40+. @@ -95,6 +96,58 @@ change PHP upstream does not test on macOS. Until then: **use macOS PHP 8.5 for CPU-bound workloads.** The build logs the selected VM kind (macOS "Record Zend VM kind" step) and warns when a pre-8.5 macOS SDK lands on CALL. +### Windows shared-engine SDK (`-windows-x86_64-shared`) + +The default Windows SDK links PHP statically, and a static PHP cannot load +extension DLLs: `php_xdebug.dll` and every other PHP extension import the +engine from `php8ts.dll`, which a static build does not have. The `-shared` +tarball is the alternative for consumers that need to load extensions (Xdebug +first of all). + +It is **not compiled here**. `.github/workflows/windows-shared.yml` runs +`tools/windows-shared/package.ps1`, which repackages the official +windows.php.net ZTS x64 build of the same release (the zip already contains a +small static `php8embed.lib` whose objects import the engine through +`php8ts.lib`; the matching devel pack carries `php8ts.lib` and the headers). +Using the official engine means the official extension DLLs and xdebug.org's +Xdebug DLLs are ABI-matched to it by construction. Every download is +sha256-verified against `tools/windows-shared/checksums.txt` or the live +windows.php.net checksum list, and the lane refuses to package unless a smoke +test — the official `php.exe` run from a directory holding only the packaged +`bin/` payload — loads every extension of the static SDK's set plus Xdebug. + +``` +include/php/ headers (devel pack) +lib/php8embed.lib embed SAPI, static, imports the engine +lib/php8ts.lib import library for php8ts.dll +bin/php8ts.dll the engine: ship it next to the consuming .exe +bin/*.dll engine + extension dependency DLLs (OpenSSL, ICU, ...) +bin/ext/php_*.dll official shared extensions +ephpm-sdk.json php_version, php_api_no, zts, crt, and `preload` +LICENSE-PHP.txt, readme-redist-bins.txt, sbom/ +``` + +Extensions the static SDK compiles in but the official build ships as DLLs +(`mbstring`, `openssl`, `curl`, `intl`, `pdo_mysql`, ... and `opcache` on 8.3 +and 8.4) are listed, in a dependency-safe load order, under `preload` in +`ephpm-sdk.json`; a consumer loads them at startup to get the same extension +set as the static SDK. The VS toolset is the one windows.php.net uses for the +minor (`vs16` for 8.3, `vs17` for 8.4+), recorded as `crt`. + +The same run publishes `ephpm-ext--windows-x86_64.tar.gz` to the +`ext-` release: `php_xdebug.dll` plus a `manifest.json` in the Linux +catalog's schema (with `"libc": "msvc"`, `"os": "windows"`). + +```bash +gh workflow run windows-shared.yml -f php_version=8.5.7 +``` + +Older releases move to windows.php.net's `archives/`, which publishes no +checksum list — pin their hashes in `checksums.txt` (the script prints the +hash to pin when one is missing). A new Xdebug version needs its three +`php_xdebug---ts--x86_64.dll` hashes from xdebug.org added +there too. + ## Tarball layout ``` @@ -112,7 +165,7 @@ THIRD-PARTY-NOTICES.txt Assets are named: ``` -php-sdk-{php_version}-{os}-{arch}[-gnu][-nts[-shared]][-clang].tar.gz +php-sdk-{php_version}-{os}-{arch}[-gnu][-nts[-shared]][-clang|-shared].tar.gz ``` ### `bin/php-config` @@ -148,7 +201,7 @@ Windows drops the Unix-only entries (`pcntl`, `posix`, `sysv*`), plus `gmp`, `pg `ffi` is not in the shared extension set on purpose. static-php-cli's `ext-ffi` passes `--enable-zend-signals`, and extension arguments land after the target arguments on the configure line, so it would override the `--disable-zend-signals` that spc emits for ZTS builds — silently changing signal behavior in the SDK ePHPm links. NTS builds emit no `--disable-zend-signals`, so `ffi` rides along there. -Loadable **shared** ZTS extensions (`igbinary`, `msgpack`, `apcu`, `redis`, `mongodb`) are a separate artifact built by `.github/workflows/extensions.yml` and published under `ext-` tags. That catalog is ZTS-only by design: Debian and Sury publish no ZTS builds, which is the gap it fills. There is no NTS catalog. +Loadable **shared** ZTS extensions (`igbinary`, `msgpack`, `apcu`, `redis`, `mongodb`) are a separate artifact built by `.github/workflows/extensions.yml` and published under `ext-` tags. That catalog is ZTS-only by design: Debian and Sury publish no ZTS builds, which is the gap it fills. There is no NTS catalog. Windows has a catalog entry for Xdebug only (`ephpm-ext--windows-x86_64.tar.gz`, from `windows-shared.yml`); it loads only into a binary linked against the `-windows-x86_64-shared` SDK. ## Building @@ -242,3 +295,5 @@ then builds with `PHP_SDK_PATH=php-sdk cargo build --release`. The MIT license in this repository covers the workflows and scripts here. It does **not** cover the contents of the published tarballs: those are an aggregate of PHP (PHP License 3.01 / Zend Engine License 2.00) and roughly twenty upstream libraries, each under its own terms — including a bundled `libstdc++.a` carrying the GCC Runtime Library Exception. Every tarball ships a `THIRD-PARTY-NOTICES.txt` listing the components, their SPDX identifiers, and where to get the full license texts. Read it before redistributing anything built from this SDK. + +The `-windows-x86_64-shared` tarball is the exception: it is the official windows.php.net binary distribution repackaged unmodified, so it carries that distribution's own notices instead — `LICENSE-PHP.txt` (PHP's `license.txt`), `readme-redist-bins.txt` (the bundled third-party DLLs and their licenses) and the upstream SBOM under `sbom/`. Xdebug (`ephpm-ext--windows-x86_64.tar.gz`) is under the Xdebug License. diff --git a/tools/windows-shared/checksums.txt b/tools/windows-shared/checksums.txt new file mode 100644 index 0000000..3fd8d29 --- /dev/null +++ b/tools/windows-shared/checksums.txt @@ -0,0 +1,31 @@ +# Trusted sha256 pins for tools/windows-shared/package.ps1, in sha256sum +# format (" *"). Consulted before the live +# windows.php.net/downloads/releases/sha256sum.txt, which only lists the +# CURRENT patch release of each minor: older releases move to +# releases/archives/, which publishes no checksum list, so building an older +# pinned release needs its hashes here. +# +# Provenance: +# - php_xdebug-*.dll: copied from the SHA256 values published on +# https://xdebug.org/download (cross-checked against the downloaded files). +# - php-*-Win32-*.zip / php-devel-pack-*: hashed from the windows.php.net +# archives on 2026-10-10 (no upstream list exists for archived releases). +# A release that is still current is covered by the live list and needs +# no entry here; pin it before it is archived if it must stay buildable. + +# Xdebug 3.5.3 (ZTS, x64) +c178f05068a6f0cef4a37eaca6003a56120004bf4ac20db6ff20f6f1ce0b439e *php_xdebug-3.5.3-8.3-ts-vs16-x86_64.dll +b9c79caec87f2b289df4b7bfa64b64f01c97956c9ac7ddb936302b79aec65cda *php_xdebug-3.5.3-8.4-ts-vs17-x86_64.dll +c75623ba050ddef734ba28a957e92df9ce5b8dfdb1a0569e5071bd6b68a12292 *php_xdebug-3.5.3-8.5-ts-vs17-x86_64.dll + +# PHP 8.3.33 (vs16) +b089e370ff99eb7038b0d22617dec2f3a1d0e93ca26b11fd218f2f5b60422271 *php-8.3.33-Win32-vs16-x64.zip +d58cedfa76b74b49f88ee54d25426700a27dad76dbad4732440cf28ca8267a7c *php-devel-pack-8.3.33-Win32-vs16-x64.zip + +# PHP 8.4.23 (vs17) +6cb93c23c5e87237881f2b3d8b93fdd70ff04a4a32bc16c9cf846aeb17f518dc *php-8.4.23-Win32-vs17-x64.zip +f2774e1534586769b90ad5550d4c1658f522bcca8d711a231d5d19abeaa7d25b *php-devel-pack-8.4.23-Win32-vs17-x64.zip + +# PHP 8.5.7 (vs17) +0e8a7a368de950408e1df5d34a5a9deb3817e434007f28f310e6674354ed8d06 *php-8.5.7-Win32-vs17-x64.zip +e59d547f68d42b08051f597d63df27781dc39b92163439b1267f5a7d753f64e4 *php-devel-pack-8.5.7-Win32-vs17-x64.zip diff --git a/tools/windows-shared/package.ps1 b/tools/windows-shared/package.ps1 new file mode 100644 index 0000000..b3ee9b4 --- /dev/null +++ b/tools/windows-shared/package.ps1 @@ -0,0 +1,404 @@ +<# +.SYNOPSIS + Package the Windows *shared* PHP SDK (php8ts.dll + import lib + headers) + and the Windows Xdebug catalog for one PHP release. + +.DESCRIPTION + The default Windows SDK (build.yml, platform windows-x86_64) is a static + spc --build-embed: one fat php8embed.lib. A binary linked against it has no + php8ts.dll, so it cannot load extension DLLs at all: php_xdebug.dll and + every other PHP extension import their engine symbols from php8ts.dll. + + This script produces the shared alternative from the official + windows.php.net build of the same PHP release (ZTS, x64, the VS toolset PHP + ships that minor with). Nothing is compiled: the official release zip + already contains a small static php8embed.lib (the embed SAPI, whose + objects import the engine from php8ts.dll via php8ts.lib), and the matching + devel pack carries php8ts.lib and the headers. Because the engine is the + official one, the official extension DLLs (ext\php_*.dll) and the official + Xdebug DLLs from xdebug.org are ABI-matched to it by construction. + + Outputs (in -OutDir): + php-sdk--windows-x86_64-shared.tar.gz + include/php/... headers (devel pack include/) + lib/php8embed.lib embed SAPI (static, imports php8ts.dll) + lib/php8ts.lib import library for php8ts.dll + bin/php8ts.dll the engine; ship next to the consuming .exe + bin/*.dll the engine's and extensions' dependency DLLs + bin/ext/php_*.dll the official shared extensions + ephpm-sdk.json manifest: ABI identity + the extension preload + list that restores the static SDK's set + LICENSE-PHP.txt, readme-redist-bins.txt, sbom/ + ephpm-ext--windows-x86_64.tar.gz + php_xdebug.dll + manifest.json, same manifest schema as the Linux + catalog (extensions.yml) plus "os"/"crt"; libc is "msvc". + + Every download is sha256-verified before use, against + tools/windows-shared/checksums.txt first and the live + windows.php.net/downloads/releases/sha256sum.txt second. A file found in + neither is refused (the error prints the hash to pin). + + Before packaging, a smoke test runs the official php.exe from a directory + that holds ONLY the packaged bin/ payload, loads the whole preload list + plus Xdebug, and fails unless every extension of the static SDK's set is + present and Xdebug registered as a Zend extension. + +.PARAMETER PhpVersion + Full PHP version, e.g. 8.5.7. Pre-releases are not published as Windows + builds on windows.php.net and are refused. + +.PARAMETER XdebugVersion + Xdebug release to package (an official xdebug.org Windows DLL). + +.PARAMETER OutDir + Where the two tarballs are written. + +.PARAMETER WorkDir + Scratch directory (downloads + staging). Deleted and recreated. +#> +[CmdletBinding()] +param( + [Parameter(Mandatory = $true)][string]$PhpVersion, + [string]$XdebugVersion = '3.5.3', + [string]$OutDir = (Join-Path (Get-Location) 'out'), + [string]$WorkDir = (Join-Path (Get-Location) 'work-windows-shared') +) + +$ErrorActionPreference = 'Stop' +# Native exit codes are checked explicitly ($LASTEXITCODE): the first URL a +# file is tried at is expected to 404 for archived releases. PowerShell 7.4+ +# would otherwise turn that non-zero exit into a terminating error. +$PSNativeCommandUseErrorActionPreference = $false +Set-StrictMode -Version 3 + +# The static SDK's extension set (build.yml WIN_PHP_EXTENSIONS), in a load +# order that satisfies inter-extension dependencies (mbstring before exif, +# pdo/mysqlnd before pdo_mysql/mysqli, dom/xml before xsl). mbregex is part of +# mbstring. An entry that is compiled into php8ts.dll has no ext\php_.dll +# and is simply skipped; the smoke test then proves it is present anyway. +$WantedExtensions = @( + 'bcmath', 'bz2', 'calendar', 'ctype', 'curl', 'dom', 'mbstring', 'exif', + 'fileinfo', 'filter', 'ftp', 'gd', 'gettext', 'hash', 'iconv', 'intl', + 'mysqlnd', 'mysqli', 'opcache', 'openssl', 'pcre', 'pdo', 'pdo_mysql', + 'pdo_sqlite', 'phar', 'session', 'simplexml', 'soap', 'sodium', 'sqlite3', + 'tokenizer', 'xml', 'xmlreader', 'xmlwriter', 'xsl', 'zip', 'zlib' +) +# Loaded with zend_extension= rather than extension= when shipped as a DLL +# (PHP 8.3/8.4; 8.5 compiles OPcache into php8ts.dll). +$ZendExtensions = @('opcache') +# Extension DLLs that are test fixtures, not features: never shipped. +$NeverShip = @('php_dl_test.dll', 'php_zend_test.dll') +# SAPI DLLs for other servers: not needed by an embedder. +$OtherSapis = @('php8apache2_4.dll', 'php8phpdbg.dll') + +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$ChecksumFile = Join-Path $ScriptDir 'checksums.txt' +$Curl = Join-Path $env:SystemRoot 'System32\curl.exe' +$Tar = Join-Path $env:SystemRoot 'System32\tar.exe' + +function Fail([string]$msg) { + Write-Host "::error::$msg" + throw $msg +} + +if ($PhpVersion -notmatch '^(\d+)\.(\d+)\.(\d+)$') { + Fail "php version '$PhpVersion' must be a GA x.y.z version (windows.php.net publishes no pre-release builds)" +} +$Minor = "$($Matches[1]).$($Matches[2])" +# The VS toolset windows.php.net builds each minor with. An extension DLL must +# be built with the same one (the CRT/ABI is part of the module build id). +$Vs = switch ($Minor) { + '8.3' { 'vs16' } + default { 'vs17' } +} +$ZipName = "php-$PhpVersion-Win32-$Vs-x64.zip" +$DevelName = "php-devel-pack-$PhpVersion-Win32-$Vs-x64.zip" +$XdebugName = "php_xdebug-$XdebugVersion-$Minor-ts-$Vs-x86_64.dll" + +if (Test-Path $WorkDir) { Remove-Item -Recurse -Force $WorkDir } +New-Item -ItemType Directory -Force -Path $WorkDir, $OutDir | Out-Null +$Dl = Join-Path $WorkDir 'dl' +New-Item -ItemType Directory -Force -Path $Dl | Out-Null + +# --------------------------------------------------------------------------- +# Checksums +# --------------------------------------------------------------------------- +function Read-Checksums([string]$path) { + $map = @{} + if (-not (Test-Path $path)) { return $map } + foreach ($line in Get-Content $path) { + $line = $line.Trim() + if ($line -eq '' -or $line.StartsWith('#')) { continue } + if ($line -match '^([0-9a-fA-F]{64})\s+\*?(\S+)$') { + $map[$Matches[2]] = $Matches[1].ToLowerInvariant() + } + } + return $map +} + +$Pinned = Read-Checksums $ChecksumFile +$LiveSums = Join-Path $Dl 'live-sha256sum.txt' +& $Curl -fsSL --retry 3 --retry-delay 5 --max-time 120 -o $LiveSums 'https://windows.php.net/downloads/releases/sha256sum.txt' +if ($LASTEXITCODE -ne 0) { + Write-Host "::warning::could not fetch the live windows.php.net sha256sum.txt (curl exit $LASTEXITCODE); only pinned checksums are usable" + $Live = @{} +} else { + $Live = Read-Checksums $LiveSums +} + +function Get-Verified([string]$name, [string[]]$urls) { + $dest = Join-Path $Dl $name + $ok = $false + foreach ($url in $urls) { + & $Curl -fsL --retry 3 --retry-delay 5 --max-time 900 -o $dest $url + if ($LASTEXITCODE -eq 0) { $ok = $true; Write-Host "==> fetched $url"; break } + Write-Host " $url -> curl exit $LASTEXITCODE" + } + if (-not $ok) { Fail "could not download $name from any of: $($urls -join ', ')" } + $actual = (Get-FileHash -Algorithm SHA256 $dest).Hash.ToLowerInvariant() + $expected = $null + $source = $null + if ($Pinned.ContainsKey($name)) { $expected = $Pinned[$name]; $source = 'checksums.txt' } + elseif ($Live.ContainsKey($name)) { $expected = $Live[$name]; $source = 'windows.php.net sha256sum.txt' } + if (-not $expected) { + Fail "no trusted sha256 for $name (not in tools/windows-shared/checksums.txt nor the live windows.php.net list). Downloaded hash: $actual - verify it out of band and pin it as: $actual *$name" + } + if ($actual -ne $expected) { + Fail "sha256 mismatch for $name (expected $expected from $source, got $actual)" + } + Write-Host "==> sha256 OK for $name ($source)" + return @{ Path = $dest; Sha256 = $actual } +} + +$base = 'https://windows.php.net/downloads/releases' +$zip = Get-Verified $ZipName @("$base/$ZipName", "$base/archives/$ZipName") +$devel = Get-Verified $DevelName @("$base/$DevelName", "$base/archives/$DevelName") +$xdebug = Get-Verified $XdebugName @("https://xdebug.org/files/$XdebugName") + +# --------------------------------------------------------------------------- +# Extract +# --------------------------------------------------------------------------- +$PhpDir = Join-Path $WorkDir 'php' +$DevelDir = Join-Path $WorkDir 'devel' +New-Item -ItemType Directory -Force -Path $PhpDir, $DevelDir | Out-Null +& $Tar -xf $zip.Path -C $PhpDir +if ($LASTEXITCODE -ne 0) { Fail "failed to extract $ZipName" } +& $Tar -xf $devel.Path -C $DevelDir +if ($LASTEXITCODE -ne 0) { Fail "failed to extract $DevelName" } +# The devel pack nests everything under php--devel--x64/. +$DevelRoot = Get-ChildItem -Directory $DevelDir | Select-Object -First 1 +if (-not $DevelRoot -or -not (Test-Path (Join-Path $DevelRoot.FullName 'include\main\php.h'))) { + Fail "unexpected devel pack layout: include\main\php.h not found under $DevelDir" +} +$DevelRoot = $DevelRoot.FullName + +foreach ($required in @('php8ts.dll', 'php8embed.lib', 'php.exe', 'ext')) { + if (-not (Test-Path (Join-Path $PhpDir $required))) { Fail "official zip has no $required" } +} +$ImportLib = Join-Path $DevelRoot 'lib\php8ts.lib' +if (-not (Test-Path $ImportLib)) { $ImportLib = Join-Path $PhpDir 'dev\php8ts.lib' } +if (-not (Test-Path $ImportLib)) { Fail 'php8ts.lib found in neither the devel pack nor the zip dev\ dir' } + +# --------------------------------------------------------------------------- +# Identity guards +# --------------------------------------------------------------------------- +$VersionH = Join-Path $DevelRoot 'include\main\php_version.h' +$m = Select-String -Path $VersionH -Pattern '#define PHP_VERSION "([^"]+)"' +if (-not $m) { Fail "cannot read PHP_VERSION from $VersionH" } +$staged = $m.Matches[0].Groups[1].Value +if ($staged -ne $PhpVersion) { Fail "devel pack headers are PHP $staged, asked for $PhpVersion" } + +$ModulesH = Join-Path $DevelRoot 'include\Zend\zend_modules.h' +$m = Select-String -Path $ModulesH -Pattern '#define ZEND_MODULE_API_NO (\d+)' +if (-not $m) { Fail "cannot read ZEND_MODULE_API_NO from $ModulesH" } +$ApiNo = $m.Matches[0].Groups[1].Value + +# Windows passes ZTS as a compiler flag (/D ZTS=1), not via config.w32.h; the +# devel pack records the build's thread-safety mode for phpize here. The +# smoke test below re-checks it at runtime from `php -v`. +$PhpizeJs = Join-Path $DevelRoot 'script\phpize.js' +if (-not (Select-String -Path $PhpizeJs -Pattern '^var PHP_ZTS="Yes"' -Quiet)) { + Fail "devel pack $PhpizeJs does not declare PHP_ZTS=Yes - not a thread-safe build" +} +Write-Host "==> PHP $staged, ZEND_MODULE_API_NO=$ApiNo, ZTS, $Vs" + +# --------------------------------------------------------------------------- +# Stage the SDK +# --------------------------------------------------------------------------- +$Sdk = Join-Path $WorkDir 'sdk' +$SdkBin = Join-Path $Sdk 'bin' +$SdkExt = Join-Path $SdkBin 'ext' +New-Item -ItemType Directory -Force -Path (Join-Path $Sdk 'include'), (Join-Path $Sdk 'lib'), $SdkExt | Out-Null + +Copy-Item -Recurse (Join-Path $DevelRoot 'include') (Join-Path $Sdk 'include\php') +Copy-Item (Join-Path $PhpDir 'php8embed.lib') (Join-Path $Sdk 'lib\') +Copy-Item $ImportLib (Join-Path $Sdk 'lib\') + +# Runtime payload: every DLL at the zip root except other servers' SAPIs. +# These are php8ts.dll plus the third-party DLLs the engine and the shared +# extensions import (libcrypto, libssl, ICU, libsqlite3, nghttp2, ...); the +# Windows loader resolves them from the directory of the .exe. +Get-ChildItem -File (Join-Path $PhpDir '*.dll') | + Where-Object { $OtherSapis -notcontains $_.Name } | + ForEach-Object { Copy-Item $_.FullName $SdkBin } +Get-ChildItem -File (Join-Path $PhpDir 'ext\*.dll') | + Where-Object { $NeverShip -notcontains $_.Name } | + ForEach-Object { Copy-Item $_.FullName $SdkExt } +# php_enchant.dll loads its providers from lib\enchant\ next to the .exe. +if (Test-Path (Join-Path $PhpDir 'lib')) { + Copy-Item -Recurse (Join-Path $PhpDir 'lib') (Join-Path $SdkBin 'lib') +} +Copy-Item (Join-Path $PhpDir 'license.txt') (Join-Path $Sdk 'LICENSE-PHP.txt') +foreach ($f in @('readme-redist-bins.txt', 'news.txt')) { + if (Test-Path (Join-Path $PhpDir $f)) { Copy-Item (Join-Path $PhpDir $f) $Sdk } +} +if (Test-Path (Join-Path $PhpDir 'extras\sbom')) { + Copy-Item -Recurse (Join-Path $PhpDir 'extras\sbom') (Join-Path $Sdk 'sbom') +} + +# Preload list: the static SDK's set, minus what php8ts.dll compiles in. +$Preload = @() +foreach ($name in $WantedExtensions) { + $file = "php_$name.dll" + if (Test-Path (Join-Path $SdkExt $file)) { + $Preload += [ordered]@{ + name = $name + file = $file + zend_extension = ($ZendExtensions -contains $name) + } + } +} +Write-Host "==> preload: $(($Preload | ForEach-Object { $_.name }) -join ', ')" + +# --------------------------------------------------------------------------- +# Smoke test: official php.exe + ONLY the staged bin/ payload +# --------------------------------------------------------------------------- +$Smoke = Join-Path $WorkDir 'smoke' +Copy-Item -Recurse $SdkBin $Smoke +Copy-Item (Join-Path $PhpDir 'php.exe') $Smoke +Copy-Item $xdebug.Path (Join-Path $Smoke 'ext\php_xdebug.dll') +$SmokeExt = Join-Path $Smoke 'ext' + +$phpArgs = @('-n', '-d', "extension_dir=$SmokeExt") +foreach ($p in $Preload) { + $directive = if ($p.zend_extension) { 'zend_extension' } else { 'extension' } + $phpArgs += @('-d', "$directive=$(Join-Path $SmokeExt $p.file)") +} +$phpArgs += @('-d', "zend_extension=$(Join-Path $SmokeExt 'php_xdebug.dll')") + +$SmokeExe = Join-Path $Smoke 'php.exe' + +# Run php.exe capturing stdout+stderr without PowerShell's native-stderr +# handling (Windows PowerShell 5.1 turns redirected stderr into terminating +# errors under ErrorActionPreference=Stop). +function Invoke-Php([string[]]$argv) { + $psi = New-Object System.Diagnostics.ProcessStartInfo + $psi.FileName = $SmokeExe + $psi.Arguments = ($argv | ForEach-Object { '"' + ($_ -replace '"', '\"') + '"' }) -join ' ' + $psi.UseShellExecute = $false + $psi.RedirectStandardOutput = $true + $psi.RedirectStandardError = $true + $psi.WorkingDirectory = $Smoke + $proc = [System.Diagnostics.Process]::Start($psi) + $stdout = $proc.StandardOutput.ReadToEndAsync() + $stderr = $proc.StandardError.ReadToEnd() + $proc.WaitForExit() + return @{ Code = $proc.ExitCode; Output = ($stdout.Result + $stderr) } +} + +# Any startup warning (an extension that failed to load) is displayed with +# display_startup_errors=1; capture everything and fail on it. +$r = Invoke-Php ($phpArgs + @('-d', 'display_startup_errors=1', '-m')) +$modules = $r.Output +if ($r.Code -ne 0) { Fail "php -m failed (exit $($r.Code)):`n$modules" } +if ($modules -match '(?i)(warning|unable to load|failed loading)') { + Fail "an extension failed to load in the smoke test:`n$modules" +} +$loaded = @{} +foreach ($line in ($modules -split "`r?`n")) { + $l = $line.Trim() + if ($l -ne '' -and -not $l.StartsWith('[')) { $loaded[$l.ToLowerInvariant()] = $true } +} +$missing = @() +foreach ($name in $WantedExtensions) { + $key = if ($name -eq 'opcache') { 'zend opcache' } else { $name } + if (-not $loaded.ContainsKey($key)) { $missing += $name } +} +if ($missing.Count -gt 0) { + Fail "the shared SDK cannot provide the static SDK's extension set; missing: $($missing -join ', ')`n$modules" +} +Write-Host "==> smoke: all $($WantedExtensions.Count) extensions of the static set present" + +$r = Invoke-Php ($phpArgs + @('-v')) +$banner = $r.Output +if ($r.Code -ne 0) { Fail "php -v failed (exit $($r.Code)):`n$banner" } +if ($banner -notmatch [regex]::Escape("with Xdebug v$XdebugVersion")) { + Fail "Xdebug $XdebugVersion did not register as a Zend extension:`n$banner" +} +if ($banner -notmatch '\(ZTS ') { Fail "php -v does not report a ZTS build:`n$banner" } +Write-Host "==> smoke: $(($banner -split "`r?`n")[0])" +Write-Host "==> smoke: Xdebug $XdebugVersion loads as a Zend extension" + +# --------------------------------------------------------------------------- +# Manifests +# --------------------------------------------------------------------------- +$SdkManifest = [ordered]@{ + php_version = $PhpVersion + php_api_no = $ApiNo + zts = 1 + os = 'windows' + arch = 'x86_64' + crt = $Vs + linkage = 'shared' + runtime_dir = 'bin' + source = [ordered]@{ + zip = [ordered]@{ file = $ZipName; sha256 = $zip.Sha256 } + devel = [ordered]@{ file = $DevelName; sha256 = $devel.Sha256 } + } + preload = @($Preload) +} +$SdkManifest | ConvertTo-Json -Depth 6 | Set-Content -Encoding ascii (Join-Path $Sdk 'ephpm-sdk.json') + +$ExtOut = Join-Path $WorkDir 'ext-out' +New-Item -ItemType Directory -Force -Path $ExtOut | Out-Null +Copy-Item $xdebug.Path (Join-Path $ExtOut 'php_xdebug.dll') +# Redistributing the DLL means shipping its license text with it. +& $Curl -fsSL --retry 3 --retry-delay 5 --max-time 120 -o (Join-Path $ExtOut 'LICENSE-xdebug.txt') ` + "https://raw.githubusercontent.com/xdebug/xdebug/$XdebugVersion/LICENSE" +if ($LASTEXITCODE -ne 0) { Fail "could not fetch the Xdebug $XdebugVersion LICENSE (curl exit $LASTEXITCODE)" } +$ExtManifest = [ordered]@{ + php_version = $PhpVersion + php_api_no = $ApiNo + zts = 1 + libc = 'msvc' + os = 'windows' + arch = 'x86_64' + crt = $Vs + extensions = @( + [ordered]@{ + name = 'xdebug' + file = 'php_xdebug.dll' + version = $XdebugVersion + php_api_no = $ApiNo + zts = 1 + zend_extension = $true + sha256 = $xdebug.Sha256 + source = "https://xdebug.org/files/$XdebugName" + } + ) +} +$ExtManifest | ConvertTo-Json -Depth 6 | Set-Content -Encoding ascii (Join-Path $ExtOut 'manifest.json') + +# --------------------------------------------------------------------------- +# Package +# --------------------------------------------------------------------------- +$SdkTar = Join-Path $OutDir "php-sdk-$PhpVersion-windows-x86_64-shared.tar.gz" +$ExtTar = Join-Path $OutDir "ephpm-ext-$PhpVersion-windows-x86_64.tar.gz" +& $Tar -czf $SdkTar -C $Sdk . +if ($LASTEXITCODE -ne 0) { Fail "failed to write $SdkTar" } +& $Tar -czf $ExtTar -C $ExtOut . +if ($LASTEXITCODE -ne 0) { Fail "failed to write $ExtTar" } +foreach ($t in @($SdkTar, $ExtTar)) { + $h = (Get-FileHash -Algorithm SHA256 $t).Hash.ToLowerInvariant() + Write-Host ("==> {0} ({1:N1} MB) sha256 {2}" -f (Split-Path -Leaf $t), ((Get-Item $t).Length / 1MB), $h) +} From 8087c74dba0be632949686c0d23e12ae309c6761 Mon Sep 17 00:00:00 2001 From: Luther Monson Date: Sun, 11 Oct 2026 08:18:02 -0700 Subject: [PATCH 2/2] ci(windows-shared): validate dispatch inputs before they reach the matrix php_version and xdebug_version are written into the matrix JSON and then expanded into the pwsh packaging step; accept only plain version strings. --- .github/workflows/windows-shared.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/windows-shared.yml b/.github/workflows/windows-shared.yml index 243145a..f699132 100644 --- a/.github/workflows/windows-shared.yml +++ b/.github/workflows/windows-shared.yml @@ -61,7 +61,16 @@ jobs: XDEBUG_VERSION: ${{ inputs.xdebug_version }} run: | if [ -n "$PHP_VERSION" ]; then - echo "matrix=[{\"php\":\"$PHP_VERSION\",\"xdebug\":\"${XDEBUG_VERSION:-3.5.3}\"}]" >> "$GITHUB_OUTPUT" + # Both values end up in the matrix JSON and are expanded into + # the pwsh step below, so only accept plain version strings. + XDEBUG_VERSION="${XDEBUG_VERSION:-3.5.3}" + if ! [[ "$PHP_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "::error::php_version '$PHP_VERSION' must be a GA x.y.z version"; exit 1 + fi + if ! [[ "$XDEBUG_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([a-zA-Z0-9]+)?$ ]]; then + echo "::error::xdebug_version '$XDEBUG_VERSION' is not an Xdebug release version"; exit 1 + fi + echo "matrix=[{\"php\":\"$PHP_VERSION\",\"xdebug\":\"$XDEBUG_VERSION\"}]" >> "$GITHUB_OUTPUT" else # PR check: the versions ephpm's xtask pins today (pinned # checksums path) - keep in step with checksums.txt.