Compare commits

..

6 Commits

Author SHA1 Message Date
Jerry Ma
7f8674f667 Merge branch 'v3' into v3c/library-fixes 2026-07-08 13:26:44 +08:00
Jerry Ma
63ab28097f Merge branch 'v3' into v3c/library-fixes 2026-06-16 13:59:12 +08:00
Jerry Ma
80ae7b093c Merge branch 'v3' into v3c/library-fixes 2026-06-04 16:08:37 +08:00
henderkes
daea8e10ad fix https://github.com/php/frankenphp/issues/1346 2026-05-28 12:22:14 +07:00
henderkes
727600a73a disable a whole lot of things we don't need to build 2026-05-26 21:10:00 +07:00
henderkes
29a8c9c196 libraries: honour SPC_DEFAULT_CFLAGS/CXXFLAGS/LDFLAGS and bug fixes
bzip2, fastlz, jbig, qdbm: thread SPC_DEFAULT_CFLAGS into the
hand-rolled Makefile patches and shell compile commands. Backward
compatible when the env var is empty.

icu: append SPC_DEFAULT_CXXFLAGS/LDFLAGS to runConfigureICU's CXXFLAGS
and LDFLAGS so user flags reach the bundled cxx invocation.

openssl: append user CFLAGS/LDFLAGS after the target name on Configure
so options like -flto and -fprofile-* reach the openssl build.

libheif: rewrite libheif 1.22+'s C-incompatible
`struct heif_bad_pixel { uint32_t row; uint32_t column; };` as a
typedef so C consumers compile.

ncurses: filter the clang/zig-cc "N warning(s) generated." stdout line
out of MKlib_gen.sh's preprocessor pipe before sed turns it into
invalid C in lib_gen.c.

libaom: detect target CPU from SystemTarget instead of hard-coding
generic, fall back to generic only when neither nasm nor yasm is
available, and turn off examples/tests/tools/docs.
2026-05-24 21:28:31 +07:00
64 changed files with 311 additions and 963 deletions

View File

@@ -2,14 +2,13 @@ name: "Extension Matrix Tests"
on: on:
workflow_dispatch: workflow_dispatch:
pull_request: push:
types: [opened, synchronize, labeled]
jobs: jobs:
test: test:
name: "${{ matrix.extension }} (PHP ${{ matrix.php-version }} on ${{ matrix.operating-system }})" name: "${{ matrix.extension }} (PHP ${{ matrix.php-version }} on ${{ matrix.operating-system }})"
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
if: contains(github.event.pull_request.labels.*.name, 'need-full-test') if: contains(github.event.head_commit.message, 'extension test') || contains(github.event.head_commit.message, 'test extensions')
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:

View File

@@ -227,7 +227,7 @@ jobs:
echo "matrix=$(echo "$FINAL" | jq -c '{"combo": .}')" >> "$GITHUB_OUTPUT" echo "matrix=$(echo "$FINAL" | jq -c '{"combo": .}')" >> "$GITHUB_OUTPUT"
ext-test: ext-test:
name: "Ext test: ${{ matrix.combo.extension }} [${{ matrix.combo.sapi }}] (PHP ${{ matrix.combo.php-version }} - ${{ matrix.combo.os }}-${{ matrix.combo.arch }})" name: "Ext test: ${{ matrix.combo.extension }} (PHP ${{ matrix.combo.php-version }} · ${{ matrix.combo.os }}-${{ matrix.combo.arch }})"
needs: gen-matrix needs: gen-matrix
runs-on: ${{ matrix.combo.runner }} runs-on: ${{ matrix.combo.runner }}
timeout-minutes: 120 timeout-minutes: 120
@@ -266,5 +266,5 @@ jobs:
if: always() && hashFiles('log/**') != '' if: always() && hashFiles('log/**') != ''
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: logs-${{ matrix.combo.os }}-${{ matrix.combo.arch }}-${{ matrix.combo.sapi }}-${{ matrix.combo.extension }}-php${{ matrix.combo.php-version }} name: logs-${{ matrix.combo.os }}-${{ matrix.combo.arch }}-${{ matrix.combo.extension }}-php${{ matrix.combo.php-version }}
path: log path: log

View File

@@ -20,7 +20,7 @@
] ]
}, },
{ {
"action": "php bin/spc dev:lint-config --check", "action": "bin/spc dev:lint-config --check",
"conditions": [ "conditions": [
{ {
"exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\InDirectory", "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\InDirectory",

View File

@@ -13,5 +13,4 @@ ext-imagick:
os: os:
- Linux - Linux
- Darwin - Darwin
- Windows
arg-type: custom arg-type: custom

View File

@@ -16,59 +16,13 @@ imagemagick:
- libtiff - libtiff
- libheif - libheif
- bzip2 - bzip2
depends@windows:
- zlib
suggests: suggests:
- zstd - zstd
- xz - xz
- libzip - libzip
- libxml2 - libxml2
headers@windows:
- imagemagick/MagickWand/MagickWand.h
lang: cpp lang: cpp
pkg-configs: pkg-configs:
- Magick++-7.Q16HDRI - Magick++-7.Q16HDRI
- MagickCore-7.Q16HDRI - MagickCore-7.Q16HDRI
- MagickWand-7.Q16HDRI - MagickWand-7.Q16HDRI
static-libs@windows:
- CORE_RL_MagickWand_.lib
- CORE_RL_MagickCore_.lib
- CORE_RL_coders_.lib
- CORE_RL_filters_.lib
- CORE_RL_aom_.lib
- CORE_RL_brotli_.lib
- CORE_RL_bzip2_.lib
- CORE_RL_cairo_.lib
- CORE_RL_croco_.lib
- CORE_RL_de265_.lib
- CORE_RL_exr_.lib
- CORE_RL_ffi_.lib
- CORE_RL_freetype_.lib
- CORE_RL_fribidi_.lib
- CORE_RL_gdk-pixbuf_.lib
- CORE_RL_glib_.lib
- CORE_RL_harfbuzz_.lib
- CORE_RL_heif_.lib
- CORE_RL_highway_.lib
- CORE_RL_imath_.lib
- CORE_RL_jpeg-turbo-12_.lib
- CORE_RL_jpeg-turbo-16_.lib
- CORE_RL_jpeg-turbo_.lib
- CORE_RL_jpeg-xl_.lib
- CORE_RL_lcms_.lib
- CORE_RL_lqr_.lib
- CORE_RL_lzma_.lib
- CORE_RL_openh264_.lib
- CORE_RL_openjpeg_.lib
- CORE_RL_openjph_.lib
- CORE_RL_pango_.lib
- CORE_RL_pixman_.lib
- CORE_RL_png_.lib
- CORE_RL_raqm_.lib
- CORE_RL_raw_.lib
- CORE_RL_rsvg_.lib
- CORE_RL_tiff_.lib
- CORE_RL_webp_.lib
- CORE_RL_xml_.lib
- CORE_RL_zip_.lib
- CORE_RL_zlib_.lib

View File

@@ -9,4 +9,5 @@ libiconv-win:
license-files: [source/COPYING] license-files: [source/COPYING]
license: GPL-3.0-or-later license: GPL-3.0-or-later
static-libs@windows: static-libs@windows:
- libiconv.lib
- libiconv_a.lib - libiconv_a.lib

View File

@@ -11,10 +11,6 @@ libzip:
license: BSD-3-Clause license: BSD-3-Clause
depends: depends:
- zlib - zlib
depends@windows:
- zlib
- bzip2
- xz
suggests: suggests:
- bzip2 - bzip2
- xz - xz

View File

@@ -27,5 +27,4 @@ openssl:
- libcrypto.lib - libcrypto.lib
tools@windows: tools@windows:
- jom - jom
- nasm
- strawberry-perl - strawberry-perl

View File

@@ -5,6 +5,8 @@ postgresql:
type: ghtagtar type: ghtagtar
repo: postgres/postgres repo: postgres/postgres
match: REL_18_\d+ match: REL_18_\d+
binary:
windows-x86_64: { type: url, url: 'https://get.enterprisedb.com/postgresql/postgresql-16.8-1-windows-x64-binaries.zip', extract: { lib/libpq.lib: '{build_root_path}/lib/libpq.lib', lib/libpgport.lib: '{build_root_path}/lib/libpgport.lib', lib/libpgcommon.lib: '{build_root_path}/lib/libpgcommon.lib', include/libpq-fe.h: '{build_root_path}/include/libpq-fe.h', include/postgres_ext.h: '{build_root_path}/include/postgres_ext.h', include/pg_config_ext.h: '{build_root_path}/include/pg_config_ext.h', include/libpq/libpq-fs.h: '{build_root_path}/include/libpq/libpq-fs.h' } }
metadata: metadata:
license-files: ['@/postgresql.txt'] license-files: ['@/postgresql.txt']
license: PostgreSQL license: PostgreSQL
@@ -14,9 +16,6 @@ postgresql:
- openssl - openssl
- zlib - zlib
- libedit - libedit
depends@windows:
- openssl
- zlib
suggests@unix: suggests@unix:
- icu - icu
- libxslt - libxslt
@@ -28,9 +27,3 @@ postgresql:
- libpq.lib - libpq.lib
- libpgport.lib - libpgport.lib
- libpgcommon.lib - libpgcommon.lib
tools@windows:
- python-win
- meson
- ninja
- winflexbison
- strawberry-perl

View File

@@ -5,7 +5,7 @@ go-win:
env: env:
GOROOT: '{pkg_root_path}/go-win' GOROOT: '{pkg_root_path}/go-win'
GOBIN: '{pkg_root_path}/go-win/bin' GOBIN: '{pkg_root_path}/go-win/bin'
GOPATH: '{pkg_root_path}/go-win/gopath' GOPATH: '{pkg_root_path}/go-win/go'
path@windows: path@windows:
- '{pkg_root_path}/go-win/bin' - '{pkg_root_path}/go-win/bin'
tool: tool:

View File

@@ -1,11 +0,0 @@
meson:
type: tool
artifact:
binary:
windows-x86_64: { type: url, url: 'https://github.com/mesonbuild/meson/releases/download/1.11.1/meson-1.11.1-py3-none-any.whl', extract: '{pkg_root_path}/meson/meson-1.11.1-py3-none-any.whl' }
path@windows:
- '{pkg_root_path}\meson'
tool:
provides:
- meson.bat
binary-subdir: meson

View File

@@ -1,9 +0,0 @@
ninja:
type: tool
artifact:
binary:
windows-x86_64: { type: url, url: 'https://github.com/ninja-build/ninja/releases/download/v1.13.2/ninja-win.zip', extract: { ninja.exe: '{pkg_root_path}/bin/ninja.exe' } }
tool:
provides:
- ninja.exe
binary-subdir: bin

View File

@@ -1,8 +0,0 @@
python-win:
type: tool
artifact:
binary: custom
tool:
provides:
- python.exe
binary-subdir: python-win/tools

View File

@@ -1,12 +0,0 @@
winflexbison:
type: tool
artifact:
binary:
windows-x86_64: { type: url, url: 'https://github.com/lexxmark/winflexbison/releases/download/v2.5.25/win_flex_bison-2.5.25.zip', extract: '{pkg_root_path}/winflexbison' }
path@windows:
- '{pkg_root_path}\winflexbison'
tool:
provides:
- win_flex.exe
- win_bison.exe
binary-subdir: winflexbison

View File

@@ -1,48 +0,0 @@
<?php
declare(strict_types=1);
namespace Package\Artifact;
use StaticPHP\Attribute\Artifact\AfterBinaryExtract;
use StaticPHP\Exception\EnvironmentException;
use StaticPHP\Util\FileSystem;
class meson_win
{
/**
* Meson 1.11 dropped the Windows MSI, so the artifact is the wheel, installed offline
* into a private venv. The venv is not just packaging hygiene: pip generates a real
* meson.exe launcher there, and PostgreSQL needs one because its build re-invokes meson
* through find_program(), which rejects non-executables like the meson.pyz zipapp.
*/
#[AfterBinaryExtract('meson', ['windows-x86_64'])]
public function afterExtract(string $target_path): void
{
$dir = dirname($target_path);
$venv = "{$dir}\\venv";
// Prefer the python-win tool package (installed alongside via tools@windows),
// fall back to whatever Python the machine already has.
$candidates = ['"' . PKG_ROOT_PATH . '\python-win\tools\python.exe"', 'python', 'py -3'];
$python = null;
foreach ($candidates as $candidate) {
[$code] = cmd()->execWithResult("{$candidate} --version", false);
if ($code === 0) {
$python = $candidate;
break;
}
}
if ($python === null) {
throw new EnvironmentException('meson needs Python 3; the python-win tool package did not install and no system Python was found.');
}
if (is_dir($venv)) {
FileSystem::removeDir($venv);
}
cmd()->exec("{$python} -m venv \"{$venv}\"")
->exec("\"{$venv}\\Scripts\\python.exe\" -m pip install --no-index --no-deps \"{$target_path}\"");
FileSystem::writeFile("{$dir}\\meson.bat", "@echo off\r\n\"%~dp0venv\\Scripts\\meson.exe\" %*\r\n");
}
}

View File

@@ -1,66 +0,0 @@
<?php
declare(strict_types=1);
namespace Package\Artifact;
use StaticPHP\Artifact\ArtifactDownloader;
use StaticPHP\Artifact\Downloader\DownloadResult;
use StaticPHP\Artifact\Downloader\Type\CheckUpdateResult;
use StaticPHP\Attribute\Artifact\AfterBinaryExtract;
use StaticPHP\Attribute\Artifact\CustomBinary;
use StaticPHP\Attribute\Artifact\CustomBinaryCheckUpdate;
use StaticPHP\Exception\DownloaderException;
/**
* Full CPython for Windows from the official python.org nuget package. It is a plain zip
* (python.exe plus stdlib under tools/, venv and ensurepip included), so it installs into
* the pkgroot without touching the system. Used by the meson tool package.
*/
class python_win
{
#[CustomBinary('python-win', [
'windows-x86_64',
])]
public function downBinary(ArtifactDownloader $downloader): DownloadResult
{
$version = $this->getLatestVersion($downloader->getRetry());
$url = "https://api.nuget.org/v3-flatcontainer/python/{$version}/python.{$version}.nupkg";
// .nupkg is a zip; name the cache file .zip so the extractor treats it as one
$path = DOWNLOAD_PATH . DIRECTORY_SEPARATOR . "python-win-{$version}.zip";
default_shell()->executeCurlDownload($url, $path, retries: $downloader->getRetry());
return DownloadResult::archive(basename($path), ['url' => $url, 'version' => $version], extract: '{pkg_root_path}/python-win', version: $version);
}
#[CustomBinaryCheckUpdate('python-win', ['windows-x86_64'])]
public function checkUpdateBinary(?string $old_version): CheckUpdateResult
{
$version = $this->getLatestVersion();
return new CheckUpdateResult(
old: $old_version,
new: $version,
needUpdate: $old_version === null || $version !== $old_version,
);
}
#[AfterBinaryExtract('python-win', ['windows-x86_64'])]
public function afterExtract(string $target_path): void
{
if (!file_exists("{$target_path}\\tools\\python.exe")) {
throw new DownloaderException("Python installation appears incomplete: python.exe not found at {$target_path}\\tools\\python.exe");
}
}
private function getLatestVersion(int $retries = 0): string
{
$index = default_shell()->executeCurl('https://api.nuget.org/v3-flatcontainer/python/index.json', retries: $retries);
$versions = $index ? (json_decode($index, true)['versions'] ?? []) : [];
$stable = array_filter($versions, fn ($v) => preg_match('/^\d+\.\d+\.\d+$/', $v));
if ($stable === []) {
throw new DownloaderException('Failed to get Python versions from the nuget index');
}
return end($stable);
}
}

View File

@@ -4,17 +4,12 @@ declare(strict_types=1);
namespace Package\Extension; namespace Package\Extension;
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\CustomPhpConfigureArg; use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
use StaticPHP\Attribute\Package\Extension; use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\PackageBuilder; use StaticPHP\Package\PackageBuilder;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;
#[Extension('imagick')] #[Extension('imagick')]
class imagick extends PhpExtensionPackage class imagick
{ {
#[CustomPhpConfigureArg('Darwin')] #[CustomPhpConfigureArg('Darwin')]
#[CustomPhpConfigureArg('Linux')] #[CustomPhpConfigureArg('Linux')]
@@ -23,35 +18,4 @@ class imagick extends PhpExtensionPackage
$disable_omp = ' ac_cv_func_omp_pause_resource_all=no'; $disable_omp = ' ac_cv_func_omp_pause_resource_all=no';
return '--with-imagick=' . ($shared ? 'shared,' : '') . $builder->getBuildRootPath() . $disable_omp; return '--with-imagick=' . ($shared ? 'shared,' : '') . $builder->getBuildRootPath() . $disable_omp;
} }
#[CustomPhpConfigureArg('Windows')]
public function getWindowsConfigureArg(bool $shared): string
{
// config.w32 uses PHP_IMAGICK as an extra search path for CORE_RL_*.lib; the static
// ImageMagick libs are installed flat in buildroot/lib (headers in buildroot/include/imagemagick).
return '--with-imagick=' . BUILD_LIB_PATH;
}
#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-imagick')]
#[PatchDescription('Add the Win32 system libraries the static ImageMagick stack needs')]
public function patchConfigW32ForWindows(): void
{
$config = $this->getSourceDir() . '/config.w32';
// Idempotency guard (the source dir may be patched in place and reused across builds).
if (str_contains(FileSystem::readFile($config), 'LIBS_IMAGICK')) {
return;
}
// The static ImageMagick stack needs several Win32 system libraries (GDI/GDI+, WIC, urlmon, ...)
// that aren't already pulled in by the other extensions. (imagick itself builds as plain C:
// ImageMagick is built with a 32-bit channel mask, see imagemagick.php buildWin, so the
// MagickCore headers don't require a C++ translation unit.)
FileSystem::replaceFileStr(
$config,
"AC_DEFINE('HAVE_IMAGICK', 1);",
'ADD_FLAG("LIBS_IMAGICK", "gdi32.lib gdiplus.lib urlmon.lib msimg32.lib oleaut32.lib windowscodecs.lib iphlpapi.lib");' . "\n\t\t" .
"AC_DEFINE('HAVE_IMAGICK', 1);"
);
}
} }

View File

@@ -5,15 +5,11 @@ declare(strict_types=1);
namespace Package\Extension; namespace Package\Extension;
use Package\Target\php; use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\CustomPhpConfigureArg; use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
use StaticPHP\Attribute\Package\Extension; use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\PackageBuilder; use StaticPHP\Package\PackageBuilder;
use StaticPHP\Package\PackageInstaller; use StaticPHP\Package\PackageInstaller;
use StaticPHP\Package\PhpExtensionPackage; use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Package\TargetPackage;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\SPCConfigUtil; use StaticPHP\Util\SPCConfigUtil;
#[Extension('pgsql')] #[Extension('pgsql')]
@@ -43,27 +39,6 @@ class pgsql extends PhpExtensionPackage
return "--with-pgsql={$builder->getBuildRootPath()}"; return "--with-pgsql={$builder->getBuildRootPath()}";
} }
#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-pgsql')]
#[PatchDescription('Link the Win32 system libraries the static libpq needs')]
public function patchConfigW32ForWindows(TargetPackage $package): void
{
$config = "{$package->getSourceDir()}\\ext\\pgsql\\config.w32";
if (str_contains(FileSystem::readFile($config), 'LIBS_PGSQL')) {
return;
}
// libpq uses SSPI for Windows auth (secur32) and the static libcrypto behind it
// reads the system cert store (crypt32). Nothing else puts these on the link line
// when the openssl extension itself is not part of the build.
FileSystem::replaceFileStr(
$config,
'EXTENSION("pgsql", "pgsql.c", PHP_PGSQL_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");',
'EXTENSION("pgsql", "pgsql.c", PHP_PGSQL_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");' . "\n\t\t" .
'ADD_FLAG("LIBS_PGSQL", "secur32.lib crypt32.lib");'
);
}
public function getSharedExtensionEnv(): array public function getSharedExtensionEnv(): array
{ {
$parent = parent::getSharedExtensionEnv(); $parent = parent::getSharedExtensionEnv();

View File

@@ -11,7 +11,6 @@ use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\PatchDescription; use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\PackageInstaller; use StaticPHP\Package\PackageInstaller;
use StaticPHP\Package\PhpExtensionPackage; use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\SourcePatcher; use StaticPHP\Util\SourcePatcher;
#[Extension('xlswriter')] #[Extension('xlswriter')]
@@ -29,17 +28,6 @@ class xlswriter extends PhpExtensionPackage
return $arg; return $arg;
} }
#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-xlswriter')]
#[PatchDescription('Define XML_STATIC so bundled Expat uses plain symbols instead of __declspec(dllimport) in static builds')]
public function patchConfigForStaticExpat(): void
{
FileSystem::replaceFileStr(
"{$this->getSourceDir()}/config.w32",
"' /D USE_SYSTEM_MINIZIP",
"' /D XML_STATIC /D USE_SYSTEM_MINIZIP"
);
}
#[BeforeStage('php', [php::class, 'makeForWindows'], 'ext-xlswriter')] #[BeforeStage('php', [php::class, 'makeForWindows'], 'ext-xlswriter')]
#[PatchDescription('Fix Windows build: apply win32 patch and add UTF-8 BOM to theme.c')] #[PatchDescription('Fix Windows build: apply win32 patch and add UTF-8 BOM to theme.c')]
public function patchBeforeMakeForWindows(): void public function patchBeforeMakeForWindows(): void

View File

@@ -27,7 +27,10 @@ class brotli
{ {
UnixCMakeExecutor::create($lib) UnixCMakeExecutor::create($lib)
->setBuildDir($lib->getSourceDir() . '/build-dir') ->setBuildDir($lib->getSourceDir() . '/build-dir')
->addConfigureArgs("-DSHARE_INSTALL_PREFIX={$lib->getBuildRootPath()}") ->addConfigureArgs(
"-DSHARE_INSTALL_PREFIX={$lib->getBuildRootPath()}",
'-DBROTLI_DISABLE_TESTS=ON',
)
->build(); ->build();
// Patch pkg-config files // Patch pkg-config files

View File

@@ -17,7 +17,9 @@ class bzip2
#[PatchBeforeBuild] #[PatchBeforeBuild]
public function patchBeforeBuild(LibraryPackage $lib): void public function patchBeforeBuild(LibraryPackage $lib): void
{ {
FileSystem::replaceFileStr($lib->getSourceDir() . '/Makefile', 'CFLAGS=-Wall', 'CFLAGS=-fPIC -Wall'); // Makefile pins -O2 -fPIC; inject SPC_DEFAULT_CFLAGS
$extra = deduplicate_flags(trim((string) getenv('SPC_DEFAULT_CFLAGS')) . ' -fPIC -Wall');
FileSystem::replaceFileStr($lib->getSourceDir() . '/Makefile', 'CFLAGS=-Wall', "CFLAGS={$extra}");
} }
#[BuildFor('Windows')] #[BuildFor('Windows')]

View File

@@ -18,9 +18,11 @@ class fastlz
{ {
$cc = getenv('CC') ?: 'cc'; $cc = getenv('CC') ?: 'cc';
$ar = getenv('AR') ?: 'ar'; $ar = getenv('AR') ?: 'ar';
$extra = trim((string) getenv('SPC_DEFAULT_CFLAGS'));
$extra = $extra !== '' ? $extra . ' -fPIC' : '-O3 -fPIC';
shell()->cd($lib->getSourceDir())->initializeEnv($lib) shell()->cd($lib->getSourceDir())->initializeEnv($lib)
->exec("{$cc} -c -O3 -fPIC fastlz.c -o fastlz.o") ->exec("{$cc} -c {$extra} fastlz.c -o fastlz.o")
->exec("{$ar} rcs libfastlz.a fastlz.o"); ->exec("{$ar} rcs libfastlz.a fastlz.o");
// Copy header file // Copy header file

View File

@@ -8,6 +8,7 @@ use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library; use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage; use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor; use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Runtime\SystemTarget;
#[Library('gmp')] #[Library('gmp')]
class gmp class gmp
@@ -16,10 +17,12 @@ class gmp
#[BuildFor('Darwin')] #[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void public function build(LibraryPackage $lib): void
{ {
UnixAutoconfExecutor::create($lib) $make = UnixAutoconfExecutor::create($lib)->appendEnv(['CFLAGS' => '-std=c17']);
->appendEnv(['CFLAGS' => '-std=c17']) if (SystemTarget::getTargetArch() === 'x86_64' && SystemTarget::getTargetOS() === 'Linux') {
->configure('--enable-fat') $libc = SystemTarget::getLibc() === 'glibc' ? 'gnu' : 'musl';
->make(); $make->addConfigureArgs(["--host=x86_64-pc-linux-{$libc}"]);
}
$make->configure('--enable-fat')->make();
$lib->patchPkgconfPrefix(['gmp.pc']); $lib->patchPkgconfPrefix(['gmp.pc']);
} }
} }

View File

@@ -24,9 +24,12 @@ class icu
#[BuildFor('Linux')] #[BuildFor('Linux')]
public function buildLinux(LibraryPackage $lib, ToolchainInterface $toolchain, PackageBuilder $builder): void public function buildLinux(LibraryPackage $lib, ToolchainInterface $toolchain, PackageBuilder $builder): void
{ {
// runConfigureICU bakes CXXFLAGS/LDFLAGS, apply user flags too
$userCxxFlags = trim((string) getenv('SPC_DEFAULT_CXXFLAGS'));
$userLdFlags = trim((string) getenv('SPC_DEFAULT_LDFLAGS'));
$cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1 -DPIC -fPIC"'; $cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1 -DPIC -fPIC"';
$cxxflags = 'CXXFLAGS="-std=c++17 -DPIC -fPIC -fno-ident"'; $cxxflags = "CXXFLAGS=\"-std=c++17 -DPIC -fPIC -fno-ident {$userCxxFlags}\"";
$ldflags = $toolchain->isStatic() ? 'LDFLAGS="-static"' : ''; $ldflags = $toolchain->isStatic() ? "LDFLAGS=\"-static {$userLdFlags}\"" : "LDFLAGS=\"{$userLdFlags}\"";
shell()->cd($lib->getSourceDir() . '/source')->initializeEnv($lib) shell()->cd($lib->getSourceDir() . '/source')->initializeEnv($lib)
->exec( ->exec(
"{$cppflags} {$cxxflags} {$ldflags} " . "{$cppflags} {$cxxflags} {$ldflags} " .

View File

@@ -6,86 +6,15 @@ namespace Package\Library;
use StaticPHP\Attribute\Package\BuildFor; use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library; use StaticPHP\Attribute\Package\Library;
use StaticPHP\Exception\EnvironmentException;
use StaticPHP\Package\LibraryPackage; use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor; use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Runtime\SystemTarget; use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Toolchain\Interface\ToolchainInterface; use StaticPHP\Toolchain\Interface\ToolchainInterface;
use StaticPHP\Util\FileSystem; use StaticPHP\Util\FileSystem;
use StaticPHP\Util\System\WindowsUtil;
#[Library('imagemagick')] #[Library('imagemagick')]
class imagemagick class imagemagick
{ {
/**
* Build a fully static, self-contained ImageMagick 7 (Q16-HDRI, /MT) on Windows using the
* official VisualMagick build (the ImageMagick/Windows + Configure + Dependencies repos), which
* bundles every delegate. ImageMagick has no autoconf/CMake build on Windows, so this clones the
* VisualMagick tree, generates a static x64 solution via the Configure tool, and builds it with
* msbuild. The resulting CORE_RL_*.lib static libraries + MagickWand/MagickCore headers are
* installed into the build root for ext-imagick to link.
*
* The VisualMagick tree lives under source/ so bin/spc reset cleans it up like everything
* else; override the location with SPC_IMAGEMAGICK_BUILD_DIR.
*/
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
$work = getenv('SPC_IMAGEMAGICK_BUILD_DIR') ?: SOURCE_PATH . '\imagemagick-win';
$configure_release = '2026.05.30.2033';
$configure_url = "https://github.com/ImageMagick/Configure/releases/download/{$configure_release}/Configure.Release.x64.exe";
FileSystem::createDir($work);
// Clone the VisualMagick repos (ImageMagick source + Configure + Dependencies + all delegates).
if (!is_dir("{$work}\\ImageMagick")) {
cmd()->cd($work)->exec(SPC_GIT_EXEC . ' clone --depth 1 https://github.com/ImageMagick/Windows.git .');
cmd()->cd($work)->exec('bash clone-repositories.sh --imagemagick7');
}
// Use the prebuilt Configure tool (building it from source needs the MFC components).
default_shell()->executeCurlDownload($configure_url, "{$work}\\Configure\\Configure.Release.x64.exe", retries: 2);
// Generate a static, /MT (linkRuntime), x64, Q16-HDRI solution with the configs embedded
// (zeroConfigurationSupport) and OpenMP off (no vcomp runtime dependency).
$ver = WindowsUtil::findVisualStudio();
$vs_major = is_array($ver) ? $ver['major_version'] : 'unknown';
$vs_arg = match ($vs_major) {
'18',
'17' => '/VS2022',
'16' => '/VS2019',
default => throw new EnvironmentException("Current VS version {$vs_major} is not supported yet!"),
};
cmd()->cd("{$work}\\Configure")
->exec("Configure.Release.x64.exe /noWizard {$vs_arg} /x64 /static /linkRuntime /noOpenMP /zeroConfigurationSupport");
// x64 IM7 defaults to a 64-bit channel mask, whose magick-baseconfig.h #errors unless the
// consuming translation unit is C++. ext-imagick is plain C, so force a 32-bit channel mask
// (ample: 32 channels >> RGBA/CMYK) before building, keeping libs and the installed header in sync.
FileSystem::replaceFileStr(
"{$work}\\ImageMagick\\MagickCore\\magick-baseconfig.h",
'#define MAGICKCORE_CHANNEL_MASK_DEPTH 64',
'#define MAGICKCORE_CHANNEL_MASK_DEPTH 32'
);
cmd()->cd($work)
->exec('msbuild IM7.Static.x64.sln /m /t:Rebuild /nologo /p:Configuration=Release /p:Platform=x64');
$artifacts = "{$work}\\Artifacts\\lib";
if (!is_dir($artifacts)) {
throw new EnvironmentException('ImageMagick VisualMagick build produced no Artifacts/lib; build failed.');
}
// Install the static libs (flat, onto the build-root lib path) and the public headers.
FileSystem::createDir($lib->getLibDir());
foreach (glob("{$artifacts}\\CORE_RL_*.lib") as $f) {
FileSystem::copy($f, $lib->getLibDir() . '\\' . basename($f));
}
foreach (['MagickWand', 'MagickCore'] as $dir) {
FileSystem::createDir($lib->getIncludeDir() . "\\imagemagick\\{$dir}");
foreach (glob("{$work}\\ImageMagick\\{$dir}\\*.h") as $h) {
FileSystem::copy($h, $lib->getIncludeDir() . "\\imagemagick\\{$dir}\\" . basename($h));
}
}
}
#[BuildFor('Darwin')] #[BuildFor('Darwin')]
#[BuildFor('Linux')] #[BuildFor('Linux')]
public function buildUnix(LibraryPackage $lib, ToolchainInterface $toolchain): void public function buildUnix(LibraryPackage $lib, ToolchainInterface $toolchain): void
@@ -116,6 +45,9 @@ class imagemagick
// implicit --with-gcc-arch // implicit --with-gcc-arch
// bleeds host cpu features into built binaries // bleeds host cpu features into built binaries
'--without-gcc-arch', '--without-gcc-arch',
'--disable-docs',
'--without-utilities',
'--disable-dpc',
); );
// special: linux-static target needs `-static` // special: linux-static target needs `-static`

View File

@@ -17,7 +17,9 @@ class jbig
#[PatchBeforeBuild] #[PatchBeforeBuild]
public function patchBeforeBuild(LibraryPackage $lib): void public function patchBeforeBuild(LibraryPackage $lib): void
{ {
FileSystem::replaceFileStr($lib->getSourceDir() . '/Makefile', 'CFLAGS = -O2 -W -Wno-unused-result', 'CFLAGS = -O2 -W -Wno-unused-result -fPIC'); $extra = trim((string) getenv('SPC_DEFAULT_CFLAGS'));
$cflags = ($extra !== '' ? $extra : '-O2') . ' -W -Wno-unused-result -fPIC';
FileSystem::replaceFileStr($lib->getSourceDir() . '/Makefile', 'CFLAGS = -O2 -W -Wno-unused-result', "CFLAGS = {$cflags}");
} }
#[BuildFor('Darwin')] #[BuildFor('Darwin')]

View File

@@ -35,6 +35,7 @@ class ldap
->optionalPackage('libsodium', '--with-argon2=libsodium', '--enable-argon2=no') ->optionalPackage('libsodium', '--with-argon2=libsodium', '--enable-argon2=no')
->addConfigureArgs( ->addConfigureArgs(
'--disable-slapd', '--disable-slapd',
'--disable-debug',
'--without-systemd', '--without-systemd',
'--without-cyrus-sasl', '--without-cyrus-sasl',
'ac_cv_func_pthread_kill_other_threads_np=no' 'ac_cv_func_pthread_kill_other_threads_np=no'

View File

@@ -9,8 +9,10 @@ use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage; use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor; use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor; use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Toolchain\Interface\ToolchainInterface; use StaticPHP\Toolchain\Interface\ToolchainInterface;
use StaticPHP\Toolchain\ZigToolchain; use StaticPHP\Toolchain\ZigToolchain;
use StaticPHP\Util\System\UnixUtil;
#[Library('libaom')] #[Library('libaom')]
class libaom extends LibraryPackage class libaom extends LibraryPackage
@@ -39,9 +41,23 @@ class libaom extends LibraryPackage
$new = trim($extra . ' -D_GNU_SOURCE'); $new = trim($extra . ' -D_GNU_SOURCE');
f_putenv("SPC_COMPILER_EXTRA={$new}"); f_putenv("SPC_COMPILER_EXTRA={$new}");
} }
$targetCpu = SystemTarget::getTargetArch();
if (str_starts_with($targetCpu, 'aarch')) {
$targetCpu = str_replace('aarch', 'arm', $targetCpu);
}
if (!UnixUtil::findCommand('nasm') && !UnixUtil::findCommand('yasm')) {
$targetCpu = 'generic';
}
UnixCMakeExecutor::create($this) UnixCMakeExecutor::create($this)
->setBuildDir("{$this->getSourceDir()}/builddir") ->setBuildDir("{$this->getSourceDir()}/builddir")
->addConfigureArgs('-DAOM_TARGET_CPU=generic') ->addConfigureArgs(
"-DAOM_TARGET_CPU={$targetCpu}",
'-DCONFIG_RUNTIME_CPU_DETECT=1',
'-DENABLE_EXAMPLES=OFF',
'-DENABLE_TESTS=OFF',
'-DENABLE_TOOLS=OFF',
'-DENABLE_DOCS=OFF',
)
->build(); ->build();
f_putenv("SPC_COMPILER_EXTRA={$extra}"); f_putenv("SPC_COMPILER_EXTRA={$extra}");
$this->patchPkgconfPrefix(['aom.pc']); $this->patchPkgconfPrefix(['aom.pc']);

View File

@@ -35,7 +35,12 @@ class libavif
->optionalPackage('libjpeg', '-DAVIF_JPEG=SYSTEM', '-DAVIF_JPEG=OFF') ->optionalPackage('libjpeg', '-DAVIF_JPEG=SYSTEM', '-DAVIF_JPEG=OFF')
->optionalPackage('libxml2', '-DAVIF_LIBXML2=SYSTEM', '-DAVIF_LIBXML2=OFF') ->optionalPackage('libxml2', '-DAVIF_LIBXML2=SYSTEM', '-DAVIF_LIBXML2=OFF')
->optionalPackage('libpng', '-DAVIF_LIBPNG=SYSTEM', '-DAVIF_LIBPNG=OFF') ->optionalPackage('libpng', '-DAVIF_LIBPNG=SYSTEM', '-DAVIF_LIBPNG=OFF')
->addConfigureArgs('-DAVIF_LIBYUV=OFF') ->addConfigureArgs(
'-DAVIF_LIBYUV=OFF',
'-DAVIF_BUILD_APPS=OFF',
'-DAVIF_BUILD_TESTS=OFF',
'-DAVIF_GTEST=OFF',
)
->build(); ->build();
// patch pkgconfig // patch pkgconfig
$lib->patchPkgconfPrefix(['libavif.pc']); $lib->patchPkgconfPrefix(['libavif.pc']);
@@ -49,7 +54,7 @@ class libavif
'-DAVIF_BUILD_APPS=OFF', '-DAVIF_BUILD_APPS=OFF',
'-DAVIF_BUILD_TESTS=OFF', '-DAVIF_BUILD_TESTS=OFF',
'-DAVIF_LIBYUV=OFF', '-DAVIF_LIBYUV=OFF',
'-DAVIF_ENABLE_GTEST=OFF', '-DAVIF_GTEST=OFF',
) )
->build(); ->build();
} }

View File

@@ -16,7 +16,7 @@ class libffi extends LibraryPackage
public function buildLinux(): void public function buildLinux(): void
{ {
UnixAutoconfExecutor::create($this) UnixAutoconfExecutor::create($this)
->configure()->make(); ->configure('--disable-docs')->make();
if (is_file("{$this->getBuildRootPath()}/lib64/libffi.a")) { if (is_file("{$this->getBuildRootPath()}/lib64/libffi.a")) {
copy("{$this->getBuildRootPath()}/lib64/libffi.a", "{$this->getBuildRootPath()}/lib/libffi.a"); copy("{$this->getBuildRootPath()}/lib64/libffi.a", "{$this->getBuildRootPath()}/lib/libffi.a");
@@ -33,6 +33,7 @@ class libffi extends LibraryPackage
->configure( ->configure(
"--host={$arch}-apple-darwin", "--host={$arch}-apple-darwin",
"--target={$arch}-apple-darwin", "--target={$arch}-apple-darwin",
'--disable-docs',
) )
->make(); ->make();
$this->patchPkgconfPrefix(['libffi.pc']); $this->patchPkgconfPrefix(['libffi.pc']);

View File

@@ -24,6 +24,17 @@ class libheif
'list(APPEND REQUIRES_PRIVATE "libbrotlidec")' . "\n" . ' list(APPEND REQUIRES_PRIVATE "libbrotlienc")' 'list(APPEND REQUIRES_PRIVATE "libbrotlidec")' . "\n" . ' list(APPEND REQUIRES_PRIVATE "libbrotlienc")'
); );
} }
// libheif 1.22+ ships a C-incompatible header: `struct heif_bad_pixel`
$heif_properties = $lib->getSourceDir() . '/libheif/api/libheif/heif_properties.h';
if (file_exists($heif_properties)
&& str_contains(file_get_contents($heif_properties), 'struct heif_bad_pixel { uint32_t row; uint32_t column; };')
) {
FileSystem::replaceFileStr(
$heif_properties,
'struct heif_bad_pixel { uint32_t row; uint32_t column; };',
'typedef struct heif_bad_pixel { uint32_t row; uint32_t column; } heif_bad_pixel;'
);
}
} }
#[BuildFor('Darwin')] #[BuildFor('Darwin')]
@@ -36,6 +47,7 @@ class libheif
'-DWITH_EXAMPLES=OFF', '-DWITH_EXAMPLES=OFF',
'-DWITH_GDK_PIXBUF=OFF', '-DWITH_GDK_PIXBUF=OFF',
'-DBUILD_TESTING=OFF', '-DBUILD_TESTING=OFF',
'-DBUILD_DOCUMENTATION=OFF',
'-DWITH_LIBSHARPYUV=ON', // optional: libwebp '-DWITH_LIBSHARPYUV=ON', // optional: libwebp
'-DENABLE_PLUGIN_LOADING=OFF', '-DENABLE_PLUGIN_LOADING=OFF',
) )

View File

@@ -25,6 +25,7 @@ class libjxl extends LibraryPackage
'-DJPEGXL_ENABLE_MANPAGES=OFF', '-DJPEGXL_ENABLE_MANPAGES=OFF',
'-DJPEGXL_ENABLE_BENCHMARK=OFF', '-DJPEGXL_ENABLE_BENCHMARK=OFF',
'-DJPEGXL_ENABLE_PLUGINS=OFF', '-DJPEGXL_ENABLE_PLUGINS=OFF',
'-DJPEGXL_ENABLE_DOXYGEN=OFF',
'-DJPEGXL_ENABLE_SJPEG=ON', '-DJPEGXL_ENABLE_SJPEG=ON',
'-DJPEGXL_ENABLE_JNI=OFF', '-DJPEGXL_ENABLE_JNI=OFF',
'-DJPEGXL_ENABLE_TRANSCODE_JPEG=ON', '-DJPEGXL_ENABLE_TRANSCODE_JPEG=ON',

View File

@@ -12,17 +12,25 @@ use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
#[Library('libmemcached')] #[Library('libmemcached')]
class libmemcached extends LibraryPackage class libmemcached extends LibraryPackage
{ {
private const array DISABLE_ARGS = [
'-DBUILD_TESTING=OFF',
'-DBUILD_DOCS=OFF',
'-DENABLE_MEMASLAP=OFF',
];
#[BuildFor('Linux')] #[BuildFor('Linux')]
public function buildLinux(): void public function buildLinux(): void
{ {
UnixCMakeExecutor::create($this) UnixCMakeExecutor::create($this)
->addConfigureArgs('-DCMAKE_INSTALL_RPATH=""') ->addConfigureArgs('-DCMAKE_INSTALL_RPATH=""', ...self::DISABLE_ARGS)
->build(); ->build();
} }
#[BuildFor('Darwin')] #[BuildFor('Darwin')]
public function buildDarwin(): void public function buildDarwin(): void
{ {
UnixCMakeExecutor::create($this)->build(); UnixCMakeExecutor::create($this)
->addConfigureArgs(...self::DISABLE_ARGS)
->build();
} }
} }

View File

@@ -20,6 +20,8 @@ class libpng
{ {
$args = [ $args = [
'--enable-hardware-optimizations', '--enable-hardware-optimizations',
'--disable-tests',
'--disable-tools',
"--with-zlib-prefix={$lib->getBuildRootPath()}", "--with-zlib-prefix={$lib->getBuildRootPath()}",
]; ];

View File

@@ -13,17 +13,29 @@ use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
#[Library('librabbitmq')] #[Library('librabbitmq')]
class librabbitmq extends LibraryPackage class librabbitmq extends LibraryPackage
{ {
private const array DISABLE_ARGS = [
'-DBUILD_EXAMPLES=OFF',
'-DBUILD_TESTING=OFF',
'-DBUILD_TOOLS=OFF',
'-DBUILD_TOOLS_DOCS=OFF',
'-DBUILD_API_DOCS=OFF',
];
#[BuildFor('Darwin')] #[BuildFor('Darwin')]
#[BuildFor('Linux')] #[BuildFor('Linux')]
public function buildUnix(): void public function buildUnix(): void
{ {
UnixCMakeExecutor::create($this)->addConfigureArgs('-DBUILD_STATIC_LIBS=ON')->build(); UnixCMakeExecutor::create($this)
->addConfigureArgs('-DBUILD_STATIC_LIBS=ON', ...self::DISABLE_ARGS)
->build();
} }
#[BuildFor('Windows')] #[BuildFor('Windows')]
public function buildWin(): void public function buildWin(): void
{ {
WindowsCMakeExecutor::create($this)->build(); WindowsCMakeExecutor::create($this)
->addConfigureArgs(...self::DISABLE_ARGS)
->build();
rename("{$this->getLibDir()}\\librabbitmq.4.lib", "{$this->getLibDir()}\\rabbitmq.4.lib"); rename("{$this->getLibDir()}\\librabbitmq.4.lib", "{$this->getLibDir()}\\rabbitmq.4.lib");
} }
} }

View File

@@ -41,6 +41,9 @@ class libtiff
'--disable-libdeflate', '--disable-libdeflate',
'--disable-tools', '--disable-tools',
'--disable-contrib', '--disable-contrib',
'--disable-tests',
'--disable-docs',
'--disable-sphinx',
'--disable-cxx', '--disable-cxx',
'--without-x', '--without-x',
) )

View File

@@ -13,12 +13,18 @@ use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
#[Library('libuv')] #[Library('libuv')]
class libuv class libuv
{ {
private const array DISABLE_ARGS = [
'-DLIBUV_BUILD_SHARED=OFF',
'-DLIBUV_BUILD_TESTS=OFF',
'-DLIBUV_BUILD_BENCH=OFF',
];
#[BuildFor('Darwin')] #[BuildFor('Darwin')]
#[BuildFor('Linux')] #[BuildFor('Linux')]
public function buildUnix(LibraryPackage $lib): void public function buildUnix(LibraryPackage $lib): void
{ {
UnixCMakeExecutor::create($lib) UnixCMakeExecutor::create($lib)
->addConfigureArgs('-DLIBUV_BUILD_SHARED=OFF') ->addConfigureArgs(...self::DISABLE_ARGS)
->build(); ->build();
// patch pkgconfig // patch pkgconfig
$lib->patchPkgconfPrefix(['libuv-static.pc']); $lib->patchPkgconfPrefix(['libuv-static.pc']);
@@ -28,7 +34,7 @@ class libuv
public function buildWindows(LibraryPackage $lib): void public function buildWindows(LibraryPackage $lib): void
{ {
WindowsCMakeExecutor::create($lib) WindowsCMakeExecutor::create($lib)
->addConfigureArgs('-DLIBUV_BUILD_SHARED=OFF') ->addConfigureArgs(...self::DISABLE_ARGS)
->build(); ->build();
} }
} }

View File

@@ -34,6 +34,7 @@ class libxslt
'--without-crypto', '--without-crypto',
'--without-debug', '--without-debug',
'--without-debugger', '--without-debugger',
'--without-profiler',
"--with-libxml-prefix={$lib->getBuildRootPath()}", "--with-libxml-prefix={$lib->getBuildRootPath()}",
); );
if (getenv('SPC_LD_LIBRARY_PATH') && getenv('SPC_LIBRARY_PATH')) { if (getenv('SPC_LD_LIBRARY_PATH') && getenv('SPC_LIBRARY_PATH')) {

View File

@@ -21,6 +21,7 @@ class mimalloc
->addConfigureArgs( ->addConfigureArgs(
'-DMI_BUILD_SHARED=OFF', '-DMI_BUILD_SHARED=OFF',
'-DMI_BUILD_OBJECT=OFF', '-DMI_BUILD_OBJECT=OFF',
'-DMI_BUILD_TESTS=OFF',
'-DMI_INSTALL_TOPLEVEL=ON', '-DMI_INSTALL_TOPLEVEL=ON',
); );
if (SystemTarget::getLibc() === 'musl') { if (SystemTarget::getLibc() === 'musl') {

View File

@@ -6,6 +6,8 @@ namespace Package\Library;
use StaticPHP\Attribute\Package\BuildFor; use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library; use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\PatchBeforeBuild;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\LibraryPackage; use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor; use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Toolchain\Interface\ToolchainInterface; use StaticPHP\Toolchain\Interface\ToolchainInterface;
@@ -16,6 +18,24 @@ use StaticPHP\Util\FileSystem;
#[Library('ncursesw')] #[Library('ncursesw')]
class ncurses class ncurses
{ {
#[PatchBeforeBuild]
#[PatchDescription('Filter clang/zig "N warning(s) generated." line out of MKlib_gen.sh preprocessor pipe')]
public function patchBeforeBuild(LibraryPackage $lib): void
{
// MKlib_gen.sh feeds the C preprocessor's stdout through a sed/awk
// pipeline into lib_gen.c. zig-cc/clang emits "N warning(s) generated."
// on stdout (not stderr), and that line ends up as invalid C in the
// generated source. Filter it out of the pipe before sed sees it.
$mklibGen = $lib->getSourceDir() . '/ncurses/base/MKlib_gen.sh';
if (is_file($mklibGen) && !str_contains((string) file_get_contents($mklibGen), "| grep -v ' generated")) {
FileSystem::replaceFileStr(
$mklibGen,
'$preprocessor $TMP 2>/dev/null \\',
"\$preprocessor \$TMP 2>/dev/null \\\n| grep -v ' generated\\.\$' \\",
);
}
}
#[BuildFor('Darwin')] #[BuildFor('Darwin')]
#[BuildFor('Linux')] #[BuildFor('Linux')]
public function build(LibraryPackage $package, ToolchainInterface $toolchain): void public function build(LibraryPackage $package, ToolchainInterface $toolchain): void

View File

@@ -24,6 +24,7 @@ class nghttp3
'-DBUILD_SHARED_LIBS=OFF', '-DBUILD_SHARED_LIBS=OFF',
'-DENABLE_STATIC_CRT=ON', '-DENABLE_STATIC_CRT=ON',
'-DENABLE_LIB_ONLY=ON', '-DENABLE_LIB_ONLY=ON',
'-DBUILD_TESTING=OFF',
) )
->build(); ->build();
} }

View File

@@ -25,6 +25,7 @@ class ngtcp2
'-DENABLE_STATIC_CRT=ON', '-DENABLE_STATIC_CRT=ON',
'-DENABLE_LIB_ONLY=ON', '-DENABLE_LIB_ONLY=ON',
'-DENABLE_OPENSSL=OFF', '-DENABLE_OPENSSL=OFF',
'-DBUILD_TESTING=OFF',
) )
->build(); ->build();
} }

View File

@@ -6,24 +6,43 @@ namespace Package\Library;
use StaticPHP\Attribute\Package\BuildFor; use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library; use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\Validate;
use StaticPHP\DI\ApplicationContext;
use StaticPHP\Exception\EnvironmentException; use StaticPHP\Exception\EnvironmentException;
use StaticPHP\Package\LibraryPackage; use StaticPHP\Package\LibraryPackage;
use StaticPHP\Package\PackageBuilder; use StaticPHP\Package\PackageBuilder;
use StaticPHP\Package\ToolPackage; use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Registry\PackageLoader;
use StaticPHP\Util\FileSystem; use StaticPHP\Util\FileSystem;
use StaticPHP\Util\System\LinuxUtil; use StaticPHP\Util\System\LinuxUtil;
use StaticPHP\Util\System\WindowsUtil;
#[Library('openssl')] #[Library('openssl')]
class openssl class openssl
{ {
#[Validate]
public function validate(): void
{
if (SystemTarget::getTargetOS() === 'Windows') {
global $argv;
$perl_path_native = PKG_ROOT_PATH . '\strawberry-perl\perl\bin\perl.exe';
$perl = file_exists($perl_path_native) ? ($perl_path_native) : WindowsUtil::findCommand('perl.exe');
if ($perl === null) {
throw new EnvironmentException(
'You need to install perl first!',
"Please run \"{$argv[0]} doctor\" to fix the environment.",
);
}
ApplicationContext::set('perl', $perl);
}
}
#[BuildFor('Windows')] #[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib, PackageBuilder $builder): void public function buildWin(LibraryPackage $lib, PackageBuilder $builder): void
{ {
$perl = $this->resolveWindowsPerl(); $perl = ApplicationContext::get('perl');
$cmd = cmd()->cd($lib->getSourceDir()) $cmd = cmd()->cd($lib->getSourceDir())
->exec( ->exec(
escapeshellarg($perl) . ' Configure zlib VC-WIN64A ' . "{$perl} Configure zlib VC-WIN64A " .
'no-shared ' . 'no-shared ' .
'--prefix=' . quote($lib->getBuildRootPath()) . ' ' . '--prefix=' . quote($lib->getBuildRootPath()) . ' ' .
'--with-zlib-lib=' . quote($lib->getLibDir()) . ' ' . '--with-zlib-lib=' . quote($lib->getLibDir()) . ' ' .
@@ -92,6 +111,12 @@ class openssl
$openssl_dir ??= LinuxUtil::getOSRelease()['dist'] === 'redhat' ? '/etc/pki/tls' : '/etc/ssl'; $openssl_dir ??= LinuxUtil::getOSRelease()['dist'] === 'redhat' ? '/etc/pki/tls' : '/etc/ssl';
$ex_lib = trim($ex_lib); $ex_lib = trim($ex_lib);
// anything we want included (PGO -fprofile-*, LTO, custom hardening)
// has to be appended on the command line *after* the target name.
$userCFlags = trim((string) getenv('SPC_DEFAULT_CFLAGS'));
$userLdFlags = trim((string) getenv('SPC_DEFAULT_LDFLAGS'));
$userExtra = trim($userCFlags . ' ' . $userLdFlags);
shell()->cd($lib->getSourceDir())->initializeEnv($lib) shell()->cd($lib->getSourceDir())->initializeEnv($lib)
->exec( ->exec(
"{$env} ./Configure no-shared zlib " . "{$env} ./Configure no-shared zlib " .
@@ -102,7 +127,8 @@ class openssl
'enable-pie ' . 'enable-pie ' .
'no-legacy ' . 'no-legacy ' .
'no-tests ' . 'no-tests ' .
"linux-{$arch}" "linux-{$arch} " .
$userExtra
) )
->exec('make clean') ->exec('make clean')
->exec("make -j{$lib->getBuilder()->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") ->exec("make -j{$lib->getBuilder()->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")
@@ -126,22 +152,4 @@ class openssl
FileSystem::replaceFileRegex("{$pkg->getLibDir()}/pkgconfig/libcrypto.pc", '/Libs.private:.*/m', 'Requires.private: zlib'); FileSystem::replaceFileRegex("{$pkg->getLibDir()}/pkgconfig/libcrypto.pc", '/Libs.private:.*/m', 'Requires.private: zlib');
FileSystem::replaceFileRegex("{$pkg->getLibDir()}/cmake/OpenSSL/OpenSSLConfig.cmake", '/set\(OPENSSL_LIBCRYPTO_DEPENDENCIES .*\)/m', 'set(OPENSSL_LIBCRYPTO_DEPENDENCIES "${OPENSSL_LIBRARY_DIR}/libz.a")'); FileSystem::replaceFileRegex("{$pkg->getLibDir()}/cmake/OpenSSL/OpenSSLConfig.cmake", '/set\(OPENSSL_LIBCRYPTO_DEPENDENCIES .*\)/m', 'set(OPENSSL_LIBCRYPTO_DEPENDENCIES "${OPENSSL_LIBRARY_DIR}/libz.a")');
} }
private function resolveWindowsPerl(): string
{
global $argv;
$tool = PackageLoader::getPackage('strawberry-perl');
if ($tool instanceof ToolPackage) {
$perl = $tool->getBinary('perl.exe');
if (file_exists($perl)) {
return $perl;
}
}
throw new EnvironmentException(
'OpenSSL requires strawberry-perl, but it is not installed.',
"Please run \"{$argv[0]} install-pkg strawberry-perl\" or retry the build with downloads enabled.",
);
}
} }

View File

@@ -37,10 +37,6 @@ class postgresql extends LibraryPackage
#[PatchDescription('Various patches before building PostgreSQL')] #[PatchDescription('Various patches before building PostgreSQL')]
public function patchBeforeBuild(): bool public function patchBeforeBuild(): bool
{ {
// These patches target the autoconf/Make build; the Windows build uses Meson (see buildWin).
if (SystemTarget::getTargetOS() === 'Windows') {
return true;
}
// skip the test on platforms where libpq infrastructure may be provided by statically-linked libraries // skip the test on platforms where libpq infrastructure may be provided by statically-linked libraries
FileSystem::replaceFileStr("{$this->getSourceDir()}/src/interfaces/libpq/Makefile", 'invokes exit\'; exit 1;', 'invokes exit\';'); FileSystem::replaceFileStr("{$this->getSourceDir()}/src/interfaces/libpq/Makefile", 'invokes exit\'; exit 1;', 'invokes exit\';');
// disable shared libs build // disable shared libs build
@@ -57,73 +53,6 @@ class postgresql extends LibraryPackage
return true; return true;
} }
#[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void
{
$src = $lib->getSourceDir();
$build_root = $lib->getBuildRootPath();
$lib_dir = $lib->getLibDir();
$inc_dir = $lib->getIncludeDir();
$build = "{$src}\\build";
// Export the public pg_char_to_encoding()/pg_encoding_to_char() from libpgcommon.a so a
// statically-linked libpq.a resolves them (PHP's ext/pgsql relies on them too). This mirrors
// the Unix build's -UUSE_PRIVATE_ENCODING_FUNCS patch, but for the Meson build.
FileSystem::replaceFileStr(
"{$src}\\src\\common\\meson.build",
"'c_args': ['-DUSE_PRIVATE_ENCODING_FUNCS'],",
"'c_args': [],"
);
// Fresh Meson build dir (Meson refuses to reuse a dir configured differently).
if (is_dir($build)) {
FileSystem::removeDir($build);
}
// Meson's OpenSSL detection link-tests CRYPTO_new_ex_data; our static libcrypto needs its
// Win32 deps (and zlib, since OpenSSL was built with zlib) on the link line to succeed.
$ld = 'ws2_32.lib gdi32.lib advapi32.lib crypt32.lib user32.lib secur32.lib zlibstatic.lib';
$configure = 'meson setup build'
. ' --prefix=' . escapeshellarg($build_root)
. ' -Ddefault_library=static' // static libpq.a / libpgcommon.a / libpgport.a
. ' -Db_vscrt=mt' // /MT static CRT, matching the rest of the build
. ' -Dssl=openssl'
// Everything libpq doesn't need: keeps deps minimal and avoids server-only detection.
. ' -Dzlib=disabled -Dnls=disabled -Dreadline=disabled -Dicu=disabled'
. ' -Dlz4=disabled -Dzstd=disabled -Dtap_tests=disabled'
. ' -Dplperl=disabled -Dplpython=disabled -Dpltcl=disabled'
. ' -Dgssapi=disabled -Dldap=disabled -Dlibxml=disabled -Dlibxslt=disabled'
. ' -Dextra_include_dirs=' . escapeshellarg("{$build_root}\\include")
. ' -Dextra_lib_dirs=' . escapeshellarg($lib_dir);
// Build only the three frontend static libs (not the server) — keeps it fast and avoids
// needing every backend dependency. meson/ninja/win_bison/win_flex/perl come from the
// tool packages declared in the package config (tools@windows).
$targets = 'src/interfaces/libpq/libpq.a src/common/libpgcommon.a src/port/libpgport.a';
cmd()->cd($src)
->setEnv([
'LIB' => $lib_dir . ';' . (getenv('LIB') ?: ''),
'LDFLAGS' => $ld,
])
->exec($configure)
->exec("ninja -C build {$targets}");
// Install the static libs under the names PHP's ext/pgsql + frankenphp expect (.lib).
FileSystem::createDir($lib_dir);
FileSystem::createDir($inc_dir);
FileSystem::copy("{$build}\\src\\interfaces\\libpq\\libpq.a", "{$lib_dir}\\libpq.lib");
FileSystem::copy("{$build}\\src\\common\\libpgcommon.a", "{$lib_dir}\\libpgcommon.lib");
FileSystem::copy("{$build}\\src\\port\\libpgport.a", "{$lib_dir}\\libpgport.lib");
// Install the public libpq headers (PG18 no longer ships pg_config_ext.h).
FileSystem::copy("{$src}\\src\\interfaces\\libpq\\libpq-fe.h", "{$inc_dir}\\libpq-fe.h");
FileSystem::copy("{$src}\\src\\include\\postgres_ext.h", "{$inc_dir}\\postgres_ext.h");
FileSystem::createDir("{$inc_dir}\\libpq");
FileSystem::copy("{$src}\\src\\include\\libpq\\libpq-fs.h", "{$inc_dir}\\libpq\\libpq-fs.h");
}
#[BuildFor('Darwin')] #[BuildFor('Darwin')]
#[BuildFor('Linux')] #[BuildFor('Linux')]
public function buildUnix(PackageInstaller $installer, PackageBuilder $builder): void public function buildUnix(PackageInstaller $installer, PackageBuilder $builder): void

View File

@@ -20,6 +20,11 @@ class qdbm
{ {
$ac = UnixAutoconfExecutor::create($lib)->configure(); $ac = UnixAutoconfExecutor::create($lib)->configure();
FileSystem::replaceFileRegex($lib->getSourceDir() . '/Makefile', '/MYLIBS = libqdbm.a.*/m', 'MYLIBS = libqdbm.a'); FileSystem::replaceFileRegex($lib->getSourceDir() . '/Makefile', '/MYLIBS = libqdbm.a.*/m', 'MYLIBS = libqdbm.a');
// Makefile pins -O3, replace with SPC_DEFAULT_CFLAGS
$extra = trim((string) getenv('SPC_DEFAULT_CFLAGS'));
if ($extra !== '') {
FileSystem::replaceFileRegex($lib->getSourceDir() . '/Makefile', '/^CFLAGS = .*$/m', "CFLAGS = -Wall {$extra}");
}
$ac->make(SystemTarget::getTargetOS() === 'Darwin' ? 'mac' : ''); $ac->make(SystemTarget::getTargetOS() === 'Darwin' ? 'mac' : '');
$lib->patchPkgconfPrefix(['qdbm.pc']); $lib->patchPkgconfPrefix(['qdbm.pc']);
} }

View File

@@ -20,6 +20,7 @@ class readline
->configure( ->configure(
'--with-curses', '--with-curses',
'--enable-multibyte=yes', '--enable-multibyte=yes',
'--disable-install-examples',
) )
->make(); ->make();
$lib->patchPkgconfPrefix(['readline.pc']); $lib->patchPkgconfPrefix(['readline.pc']);

View File

@@ -22,7 +22,8 @@ class tidy
->setBuildDir("{$lib->getSourceDir()}/build-dir") ->setBuildDir("{$lib->getSourceDir()}/build-dir")
->addConfigureArgs( ->addConfigureArgs(
'-DSUPPORT_CONSOLE_APP=OFF', '-DSUPPORT_CONSOLE_APP=OFF',
'-DBUILD_SHARED_LIB=OFF' '-DBUILD_SHARED_LIB=OFF',
'-DSUPPORT_LOCALIZATIONS=OFF',
); );
if (version_compare(get_cmake_version(), '4.0.0', '>=')) { if (version_compare(get_cmake_version(), '4.0.0', '>=')) {
$cmake->addConfigureArgs('-DCMAKE_POLICY_VERSION_MINIMUM=3.5'); $cmake->addConfigureArgs('-DCMAKE_POLICY_VERSION_MINIMUM=3.5');
@@ -38,7 +39,8 @@ class tidy
->setBuildDir("{$lib->getSourceDir()}/build-dir") ->setBuildDir("{$lib->getSourceDir()}/build-dir")
->addConfigureArgs( ->addConfigureArgs(
'-DSUPPORT_CONSOLE_APP=OFF', '-DSUPPORT_CONSOLE_APP=OFF',
'-DBUILD_SHARED_LIB=OFF' '-DBUILD_SHARED_LIB=OFF',
'-DSUPPORT_LOCALIZATIONS=OFF',
)->build(); )->build();
// rename tidy_static.lib to tidy_a.lib // rename tidy_static.lib to tidy_a.lib

View File

@@ -35,6 +35,7 @@ class unixodbc extends LibraryPackage
'--with-included-ltdl', '--with-included-ltdl',
"--sysconfdir={$sysconf_selector}", "--sysconfdir={$sysconf_selector}",
'--enable-gui=no', '--enable-gui=no',
'--enable-readline=no',
) )
->make(); ->make();
$this->patchPkgconfPrefix(['odbc.pc', 'odbccr.pc', 'odbcinst.pc']); $this->patchPkgconfPrefix(['odbc.pc', 'odbccr.pc', 'odbcinst.pc']);

View File

@@ -22,6 +22,11 @@ class xz
->configure( ->configure(
'--disable-scripts', '--disable-scripts',
'--disable-doc', '--disable-doc',
'--disable-xz',
'--disable-xzdec',
'--disable-lzmadec',
'--disable-lzmainfo',
'--disable-lzma-links',
'--with-libiconv', '--with-libiconv',
'--bindir=/tmp/xz', // xz binary will corrupt `tar` command, that's really strange. '--bindir=/tmp/xz', // xz binary will corrupt `tar` command, that's really strange.
) )

View File

@@ -14,16 +14,20 @@ use StaticPHP\Util\FileSystem;
#[Library('zstd')] #[Library('zstd')]
class zstd class zstd
{ {
private const array DISABLE_ARGS = [
'-DZSTD_BUILD_STATIC=ON',
'-DZSTD_BUILD_SHARED=OFF',
'-DZSTD_BUILD_PROGRAMS=OFF',
'-DZSTD_BUILD_TESTS=OFF',
];
#[BuildFor('Windows')] #[BuildFor('Windows')]
public function buildWin(LibraryPackage $package): void public function buildWin(LibraryPackage $package): void
{ {
WindowsCMakeExecutor::create($package) WindowsCMakeExecutor::create($package)
->setWorkingDir("{$package->getSourceDir()}/build/cmake") ->setWorkingDir("{$package->getSourceDir()}/build/cmake")
->setBuildDir("{$package->getSourceDir()}/build/cmake/build") ->setBuildDir("{$package->getSourceDir()}/build/cmake/build")
->addConfigureArgs( ->addConfigureArgs(...self::DISABLE_ARGS)
'-DZSTD_BUILD_STATIC=ON',
'-DZSTD_BUILD_SHARED=OFF',
)
->build(); ->build();
FileSystem::copy($package->getLibDir() . '\zstd_static.lib', $package->getLibDir() . '/zstd.lib'); FileSystem::copy($package->getLibDir() . '\zstd_static.lib', $package->getLibDir() . '/zstd.lib');
FileSystem::copy($package->getLibDir() . '\zstd_static.lib', $package->getLibDir() . '/libzstd.lib'); FileSystem::copy($package->getLibDir() . '\zstd_static.lib', $package->getLibDir() . '/libzstd.lib');
@@ -35,10 +39,7 @@ class zstd
{ {
UnixCMakeExecutor::create($lib) UnixCMakeExecutor::create($lib)
->setBuildDir("{$lib->getSourceDir()}/build/cmake/build") ->setBuildDir("{$lib->getSourceDir()}/build/cmake/build")
->addConfigureArgs( ->addConfigureArgs(...self::DISABLE_ARGS)
'-DZSTD_BUILD_STATIC=ON',
'-DZSTD_BUILD_SHARED=OFF',
)
->build(); ->build();
$lib->patchPkgconfPrefix(['libzstd.pc'], PKGCONF_PATCH_PREFIX); $lib->patchPkgconfPrefix(['libzstd.pc'], PKGCONF_PATCH_PREFIX);

View File

@@ -35,18 +35,16 @@ class curl
#[BuildFor('Windows')] #[BuildFor('Windows')]
public function buildWin(LibraryPackage $lib): void public function buildWin(LibraryPackage $lib): void
{ {
$lib_dir = str_replace('\\', '/', $lib->getLibDir());
$zstd_lib = "{$lib_dir}/zstd_static.lib";
$extra_libs = "{$lib_dir}/libcrypto.lib {$lib_dir}/libssl.lib ws2_32.lib gdi32.lib advapi32.lib crypt32.lib user32.lib";
WindowsCMakeExecutor::create($lib) WindowsCMakeExecutor::create($lib)
->optionalPackage('zstd', ...cmake_boolean_args('CURL_ZSTD')) ->optionalPackage('zstd', ...cmake_boolean_args('CURL_ZSTD'))
->optionalPackage('brotli', ...cmake_boolean_args('CURL_BROTLI')) ->optionalPackage('brotli', ...cmake_boolean_args('CURL_BROTLI'))
->addConfigureArgs( ->addConfigureArgs(
'-DBUILD_CURL_EXE=ON', '-DBUILD_CURL_EXE=ON',
'-DCMAKE_C_STANDARD_LIBRARIES=' . escapeshellarg($extra_libs), '-DZSTD_LIBRARY=' . BUILD_LIB_PATH . '/zstd_static.lib',
'-DZSTD_LIBRARY=' . escapeshellarg($zstd_lib),
'-DBUILD_TESTING=OFF', '-DBUILD_TESTING=OFF',
'-DBUILD_EXAMPLES=OFF', '-DBUILD_EXAMPLES=OFF',
'-DBUILD_LIBCURL_DOCS=OFF',
'-DENABLE_CURL_MANUAL=OFF',
'-DUSE_LIBIDN2=OFF', '-DUSE_LIBIDN2=OFF',
'-DCURL_USE_LIBPSL=OFF', '-DCURL_USE_LIBPSL=OFF',
'-DUSE_WINDOWS_SSPI=ON', '-DUSE_WINDOWS_SSPI=ON',
@@ -85,6 +83,9 @@ class curl
->addConfigureArgs( ->addConfigureArgs(
'-DBUILD_CURL_EXE=ON', '-DBUILD_CURL_EXE=ON',
'-DBUILD_LIBCURL_DOCS=OFF', '-DBUILD_LIBCURL_DOCS=OFF',
'-DBUILD_TESTING=OFF',
'-DBUILD_EXAMPLES=OFF',
'-DENABLE_CURL_MANUAL=OFF',
'-DOPENSSL_ROOT_DIR=' . BUILD_ROOT_PATH, '-DOPENSSL_ROOT_DIR=' . BUILD_ROOT_PATH,
) )
->build(); ->build();

View File

@@ -26,55 +26,6 @@ use ZM\Logger\ConsoleColor;
trait frankenphp trait frankenphp
{ {
/**
* Source of the -mthreads stripping shim, see windowsCgoCompilers(). The %s
* placeholder receives the wrapped compiler path as a C string literal.
*/
private const string MTHREADS_SHIM_C = <<<'C'
// Generated by static-php-cli. Drops the MinGW-only -mthreads flag Go passes to
// cgo (golang/go#80290) and forwards everything else to clang.
#include <windows.h>
#include <wchar.h>
#include <stdlib.h>
static const wchar_t compiler[] = L"%s";
int main(void)
{
const wchar_t *args = GetCommandLineW();
// skip our own (possibly quoted) argv[0]
if (*args == L'"') {
args++;
while (*args && *args != L'"') args++;
if (*args) args++;
} else {
while (*args && *args != L' ' && *args != L'\t') args++;
}
// "<compiler>" + args + trailing space so a flag at the very end still matches
size_t len = wcslen(compiler) + wcslen(args) + 8;
wchar_t *cmd = calloc(len, sizeof(wchar_t));
if (cmd == NULL) return 1;
swprintf(cmd, len, L"\"%%ls\"%%ls ", compiler, args);
// remove every space-delimited -mthreads token
wchar_t *p;
while ((p = wcsstr(cmd, L" -mthreads ")) != NULL) {
wmemmove(p, p + 10, wcslen(p + 10) + 1);
}
STARTUPINFOW si = {sizeof(si)};
PROCESS_INFORMATION pi;
if (!CreateProcessW(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) {
return 127;
}
WaitForSingleObject(pi.hProcess, INFINITE);
DWORD code = 1;
GetExitCodeProcess(pi.hProcess, &code);
return (int) code;
}
C;
#[Stage] #[Stage]
public function buildFrankenphpForUnix(TargetPackage $package, PackageInstaller $installer, ToolchainInterface $toolchain, PackageBuilder $builder): void public function buildFrankenphpForUnix(TargetPackage $package, PackageInstaller $installer, ToolchainInterface $toolchain, PackageBuilder $builder): void
{ {
@@ -282,21 +233,10 @@ trait frankenphp
$dep_libs = array_unique($dep_libs); $dep_libs = array_unique($dep_libs);
$lib_dir = str_replace('\\', '/', BUILD_LIB_PATH); $lib_dir = str_replace('\\', '/', BUILD_LIB_PATH);
$php_embed_lib = "-lphp{$major}embed"; $php_embed_lib = "-lphp{$major}embed";
// pathcch: PathCchCanonicalizeEx etc. used by frankenphp/caddy path handling. $win_sys_libs = '-lkernel32 -lole32 -luser32 -ladvapi32 -lshell32 -lws2_32 -ldnsapi -lpsapi -lbcrypt';
// secur32: InitSecurityInterfaceA (curl Schannel/SSPI). crypt32/gdi32: OpenSSL + Schannel.
$win_sys_libs = '-lkernel32 -lole32 -luser32 -ladvapi32 -lshell32 -lws2_32 -ldnsapi -lpsapi -lbcrypt -lpathcch -lsecur32 -lcrypt32 -lgdi32';
$cgo_ldflags = clean_spaces(implode(' ', array_filter([ $cgo_ldflags = clean_spaces(implode(' ', array_filter([
"-L{$lib_dir}", "-L{$lib_dir}",
$php_embed_lib, $php_embed_lib,
// FrankenPHP's cgo code references PHP/lexbor/zend symbols via __declspec(dllimport).
// Their definitions live in php{N}embed.lib but are only pulled in if the plain symbol
// is referenced, so the __imp_ refs go unresolved. Force-include one symbol from each
// defining object (zend_atomic.obj, lexbor url.obj, lexbor idna.obj) to pull them in;
// lld then auto-imports the __imp_ refs. (/WHOLEARCHIVE would also drag in libxml2.res,
// which collides with Go's own resource object: "more than one resource obj file".)
'-Wl,/INCLUDE:zend_atomic_bool_store',
'-Wl,/INCLUDE:lxb_url_parse',
'-Wl,/INCLUDE:lxb_unicode_idna_init',
implode(' ', $dep_libs), implode(' ', $dep_libs),
$win_sys_libs, $win_sys_libs,
'-llibcmt', '-llibcmt',
@@ -322,11 +262,10 @@ trait frankenphp
// Fix: prepend clang's directory to PATH and use plain executable names instead, // Fix: prepend clang's directory to PATH and use plain executable names instead,
// which matches FrankenPHP's official CI approach (CC=clang, CXX=clang++). // which matches FrankenPHP's official CI approach (CC=clang, CXX=clang++).
$clang_dir = dirname($clang_info['clang']); $clang_dir = dirname($clang_info['clang']);
[$cc, $cxx] = $this->windowsCgoCompilers($package, $clang_info['clang']);
$env = [ $env = [
'CGO_ENABLED' => '1', 'CGO_ENABLED' => '1',
'CC' => $cc, 'CC' => 'clang.exe',
'CXX' => $cxx, 'CXX' => 'clang++.exe',
'PATH' => $clang_dir . ';' . getenv('PATH'), 'PATH' => $clang_dir . ';' . getenv('PATH'),
'CGO_CFLAGS' => clean_spaces($cgo_cflags), 'CGO_CFLAGS' => clean_spaces($cgo_cflags),
'CGO_LDFLAGS' => $cgo_ldflags, 'CGO_LDFLAGS' => $cgo_ldflags,
@@ -427,48 +366,6 @@ trait frankenphp
} }
} }
/**
* Return the [CC, CXX] cgo should use to build FrankenPHP on Windows.
*
* Go passes the MinGW-only `-mthreads` flag to the C compiler for cgo builds;
* Clang >= 20 rejects it for the MSVC target. When it does, wrap Clang with a
* small compiled shim that strips the flag before forwarding. An executable and
* not a .bat on purpose: batch files run through cmd.exe, which caps the command
* line at 8191 characters, and cgo link steps with big extension stacks (imagick)
* blow past that. A real process gets the full ~32K limit, and beyond that Go
* switches to a response file by itself.
*
* Workaround for https://github.com/golang/go/issues/80290, remove once Go
* stops passing the flag.
*
* @return array{0: string, 1: string}
*/
protected function windowsCgoCompilers(TargetPackage $package, string $clang): array
{
$probe = $package->getSourceDir() . '\mthreads-probe.c';
file_put_contents($probe, "int main(void){return 0;}\n");
[$ret] = cmd()->execWithResult('"' . $clang . '" -mthreads -c ' . escapeshellarg($probe) . ' -o ' . escapeshellarg($probe . '.o'), false);
FileSystem::removeFileIfExists($probe);
FileSystem::removeFileIfExists($probe . '.o');
if ($ret === 0) {
return ['clang.exe', 'clang++.exe'];
}
logger()->info('Clang rejects -mthreads; wrapping it to strip the flag (golang/go#80290)');
$dir = dirname($clang);
$wrappers = [];
foreach (['cc-nothreads' => 'clang.exe', 'cxx-nothreads' => 'clang++.exe'] as $name => $compiler) {
$src = $package->getSourceDir() . "\\{$name}.c";
$exe = $package->getSourceDir() . "\\{$name}.exe";
file_put_contents($src, sprintf(self::MTHREADS_SHIM_C, str_replace('\\', '\\\\', "{$dir}\\{$compiler}")));
cmd()->cd($package->getSourceDir())
->exec('"' . $clang . '" -O2 ' . escapeshellarg($src) . ' -o ' . escapeshellarg($exe));
$wrappers[] = $exe;
}
return $wrappers;
}
protected function getFrankenPHPVersion(TargetPackage $package): string protected function getFrankenPHPVersion(TargetPackage $package): string
{ {
if ($version = getenv('FRANKENPHP_VERSION')) { if ($version = getenv('FRANKENPHP_VERSION')) {

View File

@@ -59,7 +59,7 @@ trait unix
} }
if (self::getPHPVersionID() >= 80300 && self::getPHPVersionID() < 80400) { if (self::getPHPVersionID() >= 80300 && self::getPHPVersionID() < 80400) {
SourcePatcher::patchFile('spc_fix_avx512_cache_before_80400.patch', $package->getSourceDir()); SourcePatcher::patchFile('spc_fix_avx512_cache_before_80400.patch', $this->getSourceDir());
} }
} }
@@ -289,7 +289,16 @@ trait unix
$builder->deployBinary($package->getSourceDir() . '/sapi/micro/micro.sfx', $dst); $builder->deployBinary($package->getSourceDir() . '/sapi/micro/micro.sfx', $dst);
// patch after UPX-ed micro.sfx (Linux only) // patch after UPX-ed micro.sfx (Linux only)
if (SystemTarget::getTargetOS() === 'Linux' && $builder->getOption('with-upx-pack')) { if (SystemTarget::getTargetOS() === 'Linux' && $builder->getOption('with-upx-pack')) {
self::patchMicroUpxPackedBinary($dst); // cut binary with readelf to remove UPX extra segment
[$ret, $out] = shell()->execWithResult("readelf -l {$dst} | awk '/LOAD|GNU_STACK/ {getline; print \\$1, \\$2, \\$3, \\$4, \\$6, \\$7}'");
$out[1] = explode(' ', $out[1]);
$offset = $out[1][0];
if ($ret !== 0 || !str_starts_with($offset, '0x')) {
throw new PatchException('phpmicro UPX patcher', 'Cannot find offset in readelf output');
}
$offset = hexdec($offset);
// remove upx extra wastes
file_put_contents($dst, substr(file_get_contents($dst), 0, $offset));
} }
$package->setOutput('Binary path for micro SAPI', $dst); $package->setOutput('Binary path for micro SAPI', $dst);
} }
@@ -671,43 +680,6 @@ trait unix
return $php; return $php;
} }
/**
* Remove the extra segment appended by UPX when packing phpmicro.
*/
private static function patchMicroUpxPackedBinary(string $binaryPath): void
{
[$ret, $out] = shell()->execWithResult('readelf -W -l ' . escapeshellarg($binaryPath));
if ($ret !== 0) {
throw new PatchException('phpmicro UPX patcher', 'Cannot find offset in readelf output');
}
$fileSizes = [];
foreach ($out as $index => $line) {
$line = trim($line);
if (!preg_match('/^(LOAD|GNU_STACK)\s+/', $line)) {
continue;
}
$columns = preg_split('/\s+/', $line);
if (isset($columns[4]) && preg_match('/^0x[[:xdigit:]]+$/', $columns[4]) === 1) {
$fileSizes[] = $columns[4];
continue;
}
$next = $out[$index + 1] ?? '';
if (preg_match('/^\s*(0x[[:xdigit:]]+)\s+0x[[:xdigit:]]+/', $next, $matches)) {
$fileSizes[] = $matches[1];
}
}
$offset = $fileSizes[1] ?? null;
if ($offset === null) {
throw new PatchException('phpmicro UPX patcher', 'Cannot find offset in readelf output');
}
file_put_contents($binaryPath, substr(file_get_contents($binaryPath), 0, intval(hexdec($offset))));
}
/** /**
* Rename libphp.so to libphp-<release>.so if -release is set in LDFLAGS. * Rename libphp.so to libphp-<release>.so if -release is set in LDFLAGS.
*/ */

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Package\Target\php; namespace Package\Target\php;
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage; use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\BuildFor; use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Stage; use StaticPHP\Attribute\Package\Stage;
@@ -127,10 +126,7 @@ trait windows
throw new PatchException('Windows Makefile patching for php.exe target', 'Cannot patch windows CLI Makefile, Makefile does not contain "$(BUILD_DIR)\php.exe:" line'); throw new PatchException('Windows Makefile patching for php.exe target', 'Cannot patch windows CLI Makefile, Makefile does not contain "$(BUILD_DIR)\php.exe:" line');
} }
$lines[$line_num] = '$(BUILD_DIR)\php.exe: generated_files $(DEPS_CLI) $(PHP_GLOBAL_OBJS) $(CLI_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(ASM_OBJS) $(BUILD_DIR)\php.exe.res $(BUILD_DIR)\php.exe.manifest'; $lines[$line_num] = '$(BUILD_DIR)\php.exe: generated_files $(DEPS_CLI) $(PHP_GLOBAL_OBJS) $(CLI_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(ASM_OBJS) $(BUILD_DIR)\php.exe.res $(BUILD_DIR)\php.exe.manifest';
// /FORCE:MULTIPLE: extensions may bundle their own static copies of common libraries (e.g. $lines[$line_num + 1] = "\t" . '"$(LINK)" /nologo $(PHP_GLOBAL_OBJS_RESP) $(CLI_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(ASM_OBJS) $(LIBS) $(LIBS_CLI) $(BUILD_DIR)\php.exe.res /out:$(BUILD_DIR)\php.exe $(LDFLAGS) $(LDFLAGS_CLI) /ltcg /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /ignore:4286';
// imagick's ImageMagick ships its own zlib/png/jpeg, duplicating gd's); let the first
// definition win instead of failing with LNK2005. /ignore:4006 silences the resulting noise.
$lines[$line_num + 1] = "\t" . '"$(LINK)" /nologo $(PHP_GLOBAL_OBJS_RESP) $(CLI_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(ASM_OBJS) $(LIBS) $(LIBS_CLI) $(BUILD_DIR)\php.exe.res /out:$(BUILD_DIR)\php.exe $(LDFLAGS) $(LDFLAGS_CLI) /ltcg /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /ignore:4286 /FORCE:MULTIPLE /ignore:4006';
FileSystem::writeFile("{$package->getSourceDir()}\\Makefile", implode("\r\n", $lines)); FileSystem::writeFile("{$package->getSourceDir()}\\Makefile", implode("\r\n", $lines));
} }
@@ -175,9 +171,8 @@ trait windows
} }
} }
$libs_cli = $this->makeLibsResponseFile($package, 'cli', "ws2_32.lib shell32.lib {$extra_libs}");
cmd()->cd($package->getSourceDir()) cmd()->cd($package->getSourceDir())
->exec("nmake /nologo {$debug_overrides}LIBS_CLI=\"{$libs_cli}\" EXTRA_LD_FLAGS_PROGRAM= php.exe"); ->exec("nmake /nologo {$debug_overrides}LIBS_CLI=\"ws2_32.lib shell32.lib {$extra_libs}\" EXTRA_LD_FLAGS_PROGRAM= php.exe");
$this->deployWindowsBinary($builder, $package, 'php-cli'); $this->deployWindowsBinary($builder, $package, 'php-cli');
} }
@@ -202,10 +197,7 @@ trait windows
throw new PatchException('Windows Makefile patching for php-cgi.exe target', 'Cannot patch windows CGI Makefile, Makefile does not contain "$(BUILD_DIR)\php-cgi.exe:" line'); throw new PatchException('Windows Makefile patching for php-cgi.exe target', 'Cannot patch windows CGI Makefile, Makefile does not contain "$(BUILD_DIR)\php-cgi.exe:" line');
} }
$lines[$line_num] = '$(BUILD_DIR)\php-cgi.exe: $(DEPS_CGI) $(CGI_GLOBAL_OBJS) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(ASM_OBJS) $(BUILD_DIR)\php-cgi.exe.res $(BUILD_DIR)\php-cgi.exe.manifest'; $lines[$line_num] = '$(BUILD_DIR)\php-cgi.exe: $(DEPS_CGI) $(CGI_GLOBAL_OBJS) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(ASM_OBJS) $(BUILD_DIR)\php-cgi.exe.res $(BUILD_DIR)\php-cgi.exe.manifest';
// /FORCE:MULTIPLE /ignore:4006: same reason as the php.exe target above. Without it the $lines[$line_num + 1] = "\t" . '@"$(LINK)" /nologo $(PHP_GLOBAL_OBJS_RESP) $(CGI_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(ASM_OBJS) $(LIBS) $(LIBS_CGI) $(BUILD_DIR)\php-cgi.exe.res /out:$(BUILD_DIR)\php-cgi.exe $(LDFLAGS) $(LDFLAGS_CGI) /ltcg /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /ignore:4286';
// CGI link fails with LNK2005 (e.g. imagick's MagickCore defines gettimeofday, which
// php's time.obj also defines).
$lines[$line_num + 1] = "\t" . '@"$(LINK)" /nologo $(PHP_GLOBAL_OBJS_RESP) $(CGI_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(ASM_OBJS) $(LIBS) $(LIBS_CGI) $(BUILD_DIR)\php-cgi.exe.res /out:$(BUILD_DIR)\php-cgi.exe $(LDFLAGS) $(LDFLAGS_CGI) /ltcg /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /ignore:4286 /FORCE:MULTIPLE /ignore:4006';
FileSystem::writeFile("{$package->getSourceDir()}\\Makefile", implode("\r\n", $lines)); FileSystem::writeFile("{$package->getSourceDir()}\\Makefile", implode("\r\n", $lines));
// Patch cgi-static, comment ZEND_TSRMLS_CACHE_DEFINE() // Patch cgi-static, comment ZEND_TSRMLS_CACHE_DEFINE()
@@ -246,9 +238,8 @@ trait windows
} }
} }
$libs_cgi = $this->makeLibsResponseFile($package, 'cgi', "ws2_32.lib kernel32.lib advapi32.lib {$extra_libs}");
cmd()->cd($package->getSourceDir()) cmd()->cd($package->getSourceDir())
->exec("nmake /nologo {$debug_overrides}LIBS_CGI=\"{$libs_cgi}\" EXTRA_LD_FLAGS_PROGRAM= php-cgi.exe"); ->exec("nmake /nologo {$debug_overrides}LIBS_CGI=\"ws2_32.lib kernel32.lib advapi32.lib {$extra_libs}\" EXTRA_LD_FLAGS_PROGRAM= php-cgi.exe");
$this->deployWindowsBinary($builder, $package, 'php-cgi'); $this->deployWindowsBinary($builder, $package, 'php-cgi');
} }
@@ -273,19 +264,6 @@ trait windows
} }
} }
#[BeforeStage('php', [self::class, 'makeMicroForWindows'])]
#[PatchDescription('Add /FORCE:MULTIPLE to the micro.sfx link, matching the CLI and CGI targets')]
public function patchMicroTarget(TargetPackage $package): void
{
$makefile = "{$package->getSourceDir()}\\Makefile";
if (str_contains(FileSystem::readFile($makefile), 'LDFLAGS_MICRO=/FORCE:MULTIPLE')) {
return;
}
// Same reason as the php.exe and php-cgi.exe targets: extension-bundled libs duplicate
// symbols from php's own objects and the link fails with LNK2005.
FileSystem::replaceFileStr($makefile, "\r\nLDFLAGS_MICRO=", "\r\nLDFLAGS_MICRO=/FORCE:MULTIPLE /ignore:4006 ");
}
#[Stage] #[Stage]
public function makeMicroForWindows(TargetPackage $package, PackageBuilder $builder, PackageInstaller $installer): void public function makeMicroForWindows(TargetPackage $package, PackageBuilder $builder, PackageInstaller $installer): void
{ {
@@ -333,9 +311,8 @@ trait windows
$fake_cli = $package->getBuildOption('with-micro-fake-cli', false) ? ' /DPHP_MICRO_FAKE_CLI' : ''; $fake_cli = $package->getBuildOption('with-micro-fake-cli', false) ? ' /DPHP_MICRO_FAKE_CLI' : '';
$libs_micro = $this->makeLibsResponseFile($package, 'micro', "ws2_32.lib shell32.lib {$extra_libs}");
cmd()->cd($package->getSourceDir()) cmd()->cd($package->getSourceDir())
->exec("nmake /nologo {$debug_overrides}LIBS_MICRO=\"{$libs_micro}\" CFLAGS_MICRO=\"/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1{$fake_cli}\" EXTRA_LD_FLAGS_PROGRAM= micro"); ->exec("nmake /nologo {$debug_overrides}LIBS_MICRO=\"ws2_32.lib shell32.lib {$extra_libs}\" CFLAGS_MICRO=\"/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1{$fake_cli}\" EXTRA_LD_FLAGS_PROGRAM= micro");
$this->deployWindowsBinary($builder, $package, 'php-micro'); $this->deployWindowsBinary($builder, $package, 'php-micro');
} }
@@ -737,18 +714,12 @@ C_CODE;
// MSVC cl.exe format: compiler flags must come before /link, linker flags after // MSVC cl.exe format: compiler flags must come before /link, linker flags after
// ldflags contains /LIBPATH which must be after /link // ldflags contains /LIBPATH which must be after /link
// /FORCE:MULTIPLE: in ZTS mode both zend.obj and php_embed.obj (both packed into the fat php8embed.lib) define _tsrm_ls_cache as a __declspec(thread) variable. // /FORCE:MULTIPLE: in ZTS mode both zend.obj and php_embed.obj (both packed into the fat php8embed.lib) define _tsrm_ls_cache as a __declspec(thread) variable.
// /INCLUDE: php8embed.lib's ext/uri (uri_parser_whatwg.obj) references lexbor lxb_url_*/
// lxb_unicode_idna_* via __declspec(dllimport); their definitions live in url.obj/idna.obj
// but are only pulled in if the plain symbol is referenced. Force-include one symbol from
// each so the objects are linked and the __imp_ refs auto-import. (FrankenPHP needs the same.)
// System libs add pathcch (PathCchCanonicalizeEx), secur32 (curl Schannel InitSecurityInterface),
// crypt32/gdi32 (OpenSSL + Schannel) on top of the Makefile LIBS set.
$compile_cmd = sprintf( $compile_cmd = sprintf(
'cl.exe /nologo /O2 /MT /Z7 %s embed.c /Fe:embed.exe /link /FORCE:MULTIPLE /INCLUDE:lxb_url_parse /INCLUDE:lxb_unicode_idna_init /LIBPATH:"%s\lib" %s %s', 'cl.exe /nologo /O2 /MT /Z7 %s embed.c /Fe:embed.exe /link /FORCE:MULTIPLE /LIBPATH:"%s\lib" %s %s',
$include_flags, $include_flags,
BUILD_ROOT_PATH, BUILD_ROOT_PATH,
$config['libs'], $config['libs'],
'kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib dnsapi.lib psapi.lib bcrypt.lib pathcch.lib secur32.lib crypt32.lib gdi32.lib' // Windows system libs (match Makefile LIBS) + curl/openssl deps 'kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib dnsapi.lib psapi.lib bcrypt.lib' // Windows system libs (match Makefile LIBS)
); );
// Log command explicitly (workaround for cmd() not logging complex commands properly) // Log command explicitly (workaround for cmd() not logging complex commands properly)
@@ -762,11 +733,9 @@ C_CODE;
); );
} }
// Run the embed test. Use a ".\" prefix: cmd.exe does not resolve a bare "embed.exe" from // Run the embed test
// the current directory, while the cwd must remain $test_dir so the script's relative
// "embed.php" is found.
InteractiveTerm::setMessage('Running php-embed run smoke test'); InteractiveTerm::setMessage('Running php-embed run smoke test');
[$ret, $output] = cmd()->cd($test_dir)->execWithResult('.\embed.exe'); [$ret, $output] = cmd()->cd($test_dir)->execWithResult('embed.exe');
$raw_output = implode('', $output); $raw_output = implode('', $output);
if ($ret !== 0 || trim($raw_output) !== 'hello') { if ($ret !== 0 || trim($raw_output) !== 'hello') {
throw new ValidationException( throw new ValidationException(
@@ -887,17 +856,4 @@ C_CODE;
$package->setOutput('PHP headers path for embed SAPI', $php_include_dir); $package->setOutput('PHP headers path for embed SAPI', $php_include_dir);
} }
/**
* Write the collected lib list into a linker response file and return the @file
* token for the nmake command line. With big extension stacks (imagick alone pulls
* in ~60 static libs) the inline list can push the whole command past cmd.exe's
* 8191 character limit; link.exe reads @file without any length limit.
*/
private function makeLibsResponseFile(TargetPackage $package, string $sapi, string $libs): string
{
$file = "{$package->getSourceDir()}\\spc-libs-{$sapi}.rsp";
FileSystem::writeFile($file, $libs);
return "@{$file}";
}
} }

View File

@@ -228,27 +228,6 @@ class ArtifactExtractor
$mode = $extract_config['mode']; $mode = $extract_config['mode'];
if ($mode === 'selective') { if ($mode === 'selective') {
// Check if all destination files already exist before extracting
$all_files_exist = true;
foreach ($extract_config['files'] as $src_pattern => $dst_path) {
$resolved = $this->replacePathVariables($dst_path);
// For glob patterns, check if at least the parent directory exists
if (str_contains($src_pattern, '*')) {
$parent = dirname($resolved);
if (!is_dir($parent)) {
$all_files_exist = false;
break;
}
} elseif (!file_exists($resolved) && !is_dir($resolved)) {
$all_files_exist = false;
break;
}
}
if ($all_files_exist) {
logger()->debug("Binary [{$name}] already extracted (selective), skip.");
return SPC_STATUS_ALREADY_EXTRACTED;
}
$this->doSelectiveExtract($name, $cache_info, $extract_config['files']); $this->doSelectiveExtract($name, $cache_info, $extract_config['files']);
$artifact->emitAfterBinaryExtract($target_path, $platform); $artifact->emitAfterBinaryExtract($target_path, $platform);
logger()->debug("Emitted after-binary-extract hooks for [{$name}]"); logger()->debug("Emitted after-binary-extract hooks for [{$name}]");
@@ -272,14 +251,8 @@ class ArtifactExtractor
logger()->debug("Emitted after-binary-extract hooks for [{$name}]"); logger()->debug("Emitted after-binary-extract hooks for [{$name}]");
/* @phpstan-ignore-next-line */ /* @phpstan-ignore-next-line */
if ($hash !== null) { if ($hash !== null && $cache_info['cache_type'] !== 'file') {
// Directory targets: store hash inside the directory
if (is_dir($target_path)) {
FileSystem::writeFile("{$target_path}/.spc-hash", $hash); FileSystem::writeFile("{$target_path}/.spc-hash", $hash);
} elseif (is_file($target_path)) {
// File targets: store hash as a sidecar file (e.g., meson .whl)
FileSystem::writeFile("{$target_path}.spc-hash", $hash);
}
} }
return SPC_STATUS_EXTRACTED; return SPC_STATUS_EXTRACTED;
} }
@@ -359,24 +332,9 @@ class ArtifactExtractor
/** /**
* Check if artifact is already extracted with correct hash. * Check if artifact is already extracted with correct hash.
*
* Handles both directory targets (hash stored in $path/.spc-hash) and
* file targets (hash stored in $path.spc-hash sidecar).
*/ */
protected function isAlreadyExtracted(string $path, ?string $expected_hash): bool protected function isAlreadyExtracted(string $path, ?string $expected_hash): bool
{ {
// File targets: check sidecar hash file (e.g., meson .whl)
if (is_file($path)) {
if ($expected_hash === null) {
return false;
}
$hash_file = "{$path}.spc-hash";
if (!file_exists($hash_file)) {
return false;
}
return FileSystem::readFile($hash_file) === $expected_hash;
}
if (!is_dir($path)) { if (!is_dir($path)) {
return false; return false;
} }

View File

@@ -14,12 +14,6 @@ class GenExtTestMatrixCommand extends BaseCommand
{ {
private const string BUILD_TARGETS = '--build-cli --build-cgi --build-micro --with-suggests -vvv'; private const string BUILD_TARGETS = '--build-cli --build-cgi --build-micro --with-suggests -vvv';
private const string FRANKENPHP_BUILD_TARGETS = '--build-cli --build-frankenphp --enable-zts --with-suggests -vvv';
private const array SUPPORTED_SAPIS = [
'frankenphp',
];
private const array OS_RUNNERS = [ private const array OS_RUNNERS = [
'linux' => ['arch' => 'x86_64', 'runner' => 'ubuntu-latest', 'os_key' => 'Linux'], 'linux' => ['arch' => 'x86_64', 'runner' => 'ubuntu-latest', 'os_key' => 'Linux'],
'windows' => ['arch' => 'x86_64', 'runner' => 'windows-2025', 'os_key' => 'Windows'], 'windows' => ['arch' => 'x86_64', 'runner' => 'windows-2025', 'os_key' => 'Windows'],
@@ -90,7 +84,6 @@ class GenExtTestMatrixCommand extends BaseCommand
$this->addOption('for-extensions', null, InputOption::VALUE_OPTIONAL, 'Filter by extension display names, comma-separated', '') $this->addOption('for-extensions', null, InputOption::VALUE_OPTIONAL, 'Filter by extension display names, comma-separated', '')
->addOption('for-libs', null, InputOption::VALUE_OPTIONAL, 'Filter by lib names (depends+suggests), comma-separated', '') ->addOption('for-libs', null, InputOption::VALUE_OPTIONAL, 'Filter by lib names (depends+suggests), comma-separated', '')
->addOption('os', null, InputOption::VALUE_OPTIONAL, 'Filter by OS (Linux/Darwin/Windows), comma-separated', '') ->addOption('os', null, InputOption::VALUE_OPTIONAL, 'Filter by OS (Linux/Darwin/Windows), comma-separated', '')
->addOption('sapi', null, InputOption::VALUE_OPTIONAL, 'Add extra SAPI build tests, comma-separated (supported: frankenphp)', '')
->addOption('tier2', null, InputOption::VALUE_NONE, 'Use Tier 2 runners (Linux aarch64 + macOS x86_64, no Windows)'); ->addOption('tier2', null, InputOption::VALUE_NONE, 'Use Tier 2 runners (Linux aarch64 + macOS x86_64, no Windows)');
} }
@@ -105,15 +98,8 @@ class GenExtTestMatrixCommand extends BaseCommand
$filter_extensions = $parse_option('for-extensions'); $filter_extensions = $parse_option('for-extensions');
$filter_libs = $parse_option('for-libs'); $filter_libs = $parse_option('for-libs');
$filter_os_keys = $parse_option('os'); $filter_os_keys = $parse_option('os');
$filter_sapis = array_unique($parse_option('sapi'));
$tier2 = (bool) $this->input->getOption('tier2'); $tier2 = (bool) $this->input->getOption('tier2');
$unknown_sapis = array_values(array_diff($filter_sapis, self::SUPPORTED_SAPIS));
if (!empty($unknown_sapis)) {
$this->output->writeln('<error>Unsupported SAPI(s): ' . implode(', ', $unknown_sapis) . '</error>');
return static::USER_ERROR;
}
$base_runners = $tier2 ? self::OS_RUNNERS_TIER2 : self::OS_RUNNERS; $base_runners = $tier2 ? self::OS_RUNNERS_TIER2 : self::OS_RUNNERS;
$all = PackageConfig::getAll(); $all = PackageConfig::getAll();
@@ -140,67 +126,6 @@ class GenExtTestMatrixCommand extends BaseCommand
} }
} }
[$entries, $all_ext_lib_deps] = $this->buildEntriesForRunners(
$base_runners,
$filter_os_keys,
$all_regular,
$all_virtual,
$all_libraries,
self::BUILD_TARGETS,
'default',
);
if (in_array('frankenphp', $filter_sapis, true)) {
[$frankenphp_entries, $frankenphp_ext_lib_deps] = $this->buildEntriesForRunners(
self::OS_RUNNERS,
[],
$all_regular,
$all_virtual,
$all_libraries,
self::FRANKENPHP_BUILD_TARGETS,
'frankenphp',
);
$entries = array_merge($entries, $frankenphp_entries);
$all_ext_lib_deps = array_replace_recursive($all_ext_lib_deps, $frankenphp_ext_lib_deps);
}
if (!empty($filter_extensions) || !empty($filter_libs)) {
$entries = array_values(array_filter($entries, function (array $entry) use ($filter_extensions, $filter_libs, $all_ext_lib_deps): bool {
$names = explode(',', $entry['extension']);
if (!empty($filter_extensions) && count(array_intersect($names, $filter_extensions)) > 0) {
return true;
}
if (!empty($filter_libs)) {
$lib_deps = $all_ext_lib_deps[$entry['os']] ?? [];
foreach ($names as $name) {
if (count(array_intersect($lib_deps[$name] ?? [], $filter_libs)) > 0) {
return true;
}
}
}
return false;
}));
}
$this->output->write(json_encode($entries, JSON_UNESCAPED_SLASHES));
return static::SUCCESS;
}
/**
* @return array{array<int, array<string, string>>, array<string, array<string, string[]>>}
*/
private function buildEntriesForRunners(
array $base_runners,
array $filter_os_keys,
array $all_regular,
array $all_virtual,
array $all_libraries,
string $build_targets,
string $sapi,
): array {
$os_runners = empty($filter_os_keys) $os_runners = empty($filter_os_keys)
? $base_runners ? $base_runners
: array_filter($base_runners, fn ($info) => in_array($info['os_key'], $filter_os_keys, true)); : array_filter($base_runners, fn ($info) => in_array($info['os_key'], $filter_os_keys, true));
@@ -312,18 +237,40 @@ class GenExtTestMatrixCommand extends BaseCommand
sort($groups); sort($groups);
foreach ($groups as $group) { foreach ($groups as $group) {
$extra = $this->extraBuildFlags($group);
$entries[] = [ $entries[] = [
'runner' => $os_info['runner'], 'runner' => $os_info['runner'],
'os' => $os, 'os' => $os,
'arch' => $os_info['arch'], 'arch' => $os_info['arch'],
'sapi' => $sapi,
'extension' => $group, 'extension' => $group,
'build-args' => './bin/spc build "' . $group . '" ' . $this->buildTargetsWithExtraFlags($build_targets, $group), 'build-args' => './bin/spc build "' . $group . '" ' . self::BUILD_TARGETS . ($extra !== '' ? ' ' . $extra : ''),
]; ];
} }
} }
return [$entries, $all_ext_lib_deps]; if (!empty($filter_extensions) || !empty($filter_libs)) {
$entries = array_values(array_filter($entries, function (array $entry) use ($filter_extensions, $filter_libs, $all_ext_lib_deps): bool {
$names = explode(',', $entry['extension']);
if (!empty($filter_extensions) && count(array_intersect($names, $filter_extensions)) > 0) {
return true;
}
if (!empty($filter_libs)) {
$lib_deps = $all_ext_lib_deps[$entry['os']] ?? [];
foreach ($names as $name) {
if (count(array_intersect($lib_deps[$name] ?? [], $filter_libs)) > 0) {
return true;
}
}
}
return false;
}));
}
$this->output->write(json_encode($entries, JSON_UNESCAPED_SLASHES));
return static::SUCCESS;
} }
/** /**
@@ -450,18 +397,6 @@ class GenExtTestMatrixCommand extends BaseCommand
return implode(' ', $flags); return implode(' ', $flags);
} }
private function buildTargetsWithExtraFlags(string $build_targets, string $group): string
{
$flags = explode(' ', $build_targets);
foreach (explode(' ', $this->extraBuildFlags($group)) as $extra) {
if ($extra === '' || in_array($extra, $flags, true)) {
continue;
}
$flags[] = $extra;
}
return implode(' ', $flags);
}
/** /**
* Resolve the value of a platform-specific array field, applying the suffix fallback chain. * Resolve the value of a platform-specific array field, applying the suffix fallback chain.
* *

View File

@@ -25,10 +25,6 @@ class TestBotCommand extends BaseCommand
private const string TIER2_LABEL = 'test/tier2'; private const string TIER2_LABEL = 'test/tier2';
private const array SAPI_LABELS = [
'sapi/frankenphp' => 'frankenphp',
];
/** PHP version labels → version string (8.5 is always included as default) */ /** PHP version labels → version string (8.5 is always included as default) */
private const array PHP_VERSION_LABELS = [ private const array PHP_VERSION_LABELS = [
'test/php-83' => '8.3', 'test/php-83' => '8.3',
@@ -97,12 +93,6 @@ class TestBotCommand extends BaseCommand
} }
$tier2 = in_array(self::TIER2_LABEL, $label_names, true); $tier2 = in_array(self::TIER2_LABEL, $label_names, true);
$need_test = in_array('need-test', $label_names, true); $need_test = in_array('need-test', $label_names, true);
$sapis = [];
foreach (self::SAPI_LABELS as $label => $sapi) {
if (in_array($label, $label_names, true)) {
$sapis[] = $sapi;
}
}
// Resolve PHP versions (default always included) // Resolve PHP versions (default always included)
$php_versions = [self::DEFAULT_PHP_VERSION]; $php_versions = [self::DEFAULT_PHP_VERSION];
@@ -129,9 +119,6 @@ class TestBotCommand extends BaseCommand
if (!empty($os_keys)) { if (!empty($os_keys)) {
$flag_parts[] = '--os=' . implode(',', $os_keys); $flag_parts[] = '--os=' . implode(',', $os_keys);
} }
if (!empty($sapis)) {
$flag_parts[] = '--sapi=' . implode(',', $sapis);
}
$gen_matrix_args = implode(' ', $flag_parts); $gen_matrix_args = implode(' ', $flag_parts);
if ($tier2) { if ($tier2) {
@@ -141,7 +128,7 @@ class TestBotCommand extends BaseCommand
fn ($k) => $k !== 'Windows' fn ($k) => $k !== 'Windows'
)); ));
if (!empty($tier2_os)) { if (!empty($tier2_os)) {
$tier2_parts = array_values(array_filter($flag_parts, fn ($f) => !str_starts_with($f, '--os=') && !str_starts_with($f, '--sapi='))); $tier2_parts = array_values(array_filter($flag_parts, fn ($f) => !str_starts_with($f, '--os=')));
$tier2_parts[] = '--os=' . implode(',', $tier2_os); $tier2_parts[] = '--os=' . implode(',', $tier2_os);
$tier2_parts[] = '--tier2'; $tier2_parts[] = '--tier2';
$gen_matrix_args_tier2 = implode(' ', $tier2_parts); $gen_matrix_args_tier2 = implode(' ', $tier2_parts);
@@ -156,7 +143,6 @@ class TestBotCommand extends BaseCommand
$label_names, $label_names,
$os_keys, $os_keys,
$tier2, $tier2,
$sapis,
$php_versions, $php_versions,
$need_test, $need_test,
); );
@@ -170,7 +156,6 @@ class TestBotCommand extends BaseCommand
'gen_matrix_args_tier2' => $gen_matrix_args_tier2, 'gen_matrix_args_tier2' => $gen_matrix_args_tier2,
'php_versions' => $php_versions, 'php_versions' => $php_versions,
'tier2' => $tier2, 'tier2' => $tier2,
'sapis' => $sapis,
'comment_body' => $comment_body, 'comment_body' => $comment_body,
]; ];
@@ -254,7 +239,6 @@ class TestBotCommand extends BaseCommand
array $label_names, array $label_names,
array $os_keys, array $os_keys,
bool $tier2, bool $tier2,
array $sapis,
array $php_versions, array $php_versions,
bool $need_test, bool $need_test,
): string { ): string {
@@ -274,7 +258,6 @@ class TestBotCommand extends BaseCommand
'`test/linux` `test/windows` `test/macos` (platform)', '`test/linux` `test/windows` `test/macos` (platform)',
'`test/tier2` (extra arch)', '`test/tier2` (extra arch)',
'`test/php-83` `test/php-84` (PHP version)', '`test/php-83` `test/php-84` (PHP version)',
'`sapi/frankenphp` (extra FrankenPHP SAPI build)',
]); ]);
// Case 1: need-test absent → invite the author to add it // Case 1: need-test absent → invite the author to add it
@@ -320,8 +303,7 @@ class TestBotCommand extends BaseCommand
} }
$php_str = implode(', ', array_map(fn ($v) => "PHP {$v}", $php_versions)) . ' NTS'; $php_str = implode(', ', array_map(fn ($v) => "PHP {$v}", $php_versions)) . ' NTS';
$sapi_str = !empty($sapis) ? ' + SAPI: ' . implode(', ', $sapis) . ' (Tier1 Linux/macOS/Windows)' : ''; $active_test_labels = array_values(array_filter($label_names, fn ($l) => str_starts_with($l, 'test/')));
$active_test_labels = array_values(array_filter($label_names, fn ($l) => str_starts_with($l, 'test/') || str_starts_with($l, 'sapi/')));
$labels_str = !empty($active_test_labels) ? '`' . implode('`, `', $active_test_labels) . '`' : '_none_'; $labels_str = !empty($active_test_labels) ? '`' . implode('`, `', $active_test_labels) . '`' : '_none_';
return implode("\n", [ return implode("\n", [
@@ -331,7 +313,7 @@ class TestBotCommand extends BaseCommand
$detected, $detected,
'**Active labels**: ' . $labels_str, '**Active labels**: ' . $labels_str,
'**Available labels**: ' . $available_labels, '**Available labels**: ' . $available_labels,
'**Config**: ' . implode(' + ', $platform_parts) . ' | ' . $php_str . $sapi_str, '**Config**: ' . implode(' + ', $platform_parts) . ' | ' . $php_str,
]); ]);
} }
} }

View File

@@ -12,6 +12,7 @@ use StaticPHP\Package\PackageInstaller;
use StaticPHP\Runtime\SystemTarget; use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Toolchain\ToolchainManager; use StaticPHP\Toolchain\ToolchainManager;
use StaticPHP\Util\FileSystem; use StaticPHP\Util\FileSystem;
use StaticPHP\Util\GlobalEnvManager;
use StaticPHP\Util\System\WindowsUtil; use StaticPHP\Util\System\WindowsUtil;
#[OptionalCheck([self::class, 'optional'])] #[OptionalCheck([self::class, 'optional'])]
@@ -73,6 +74,27 @@ class WindowsToolCheck
return CheckResult::ok($path); return CheckResult::ok($path);
} }
#[CheckItem('if nasm installed', level: 995)]
public function checkNasm(): ?CheckResult
{
if (($a = WindowsUtil::findCommand('nasm.exe')) === null) {
return CheckResult::fail('nasm.exe not found in path.', 'install-nasm');
}
return CheckResult::ok($a);
}
#[CheckItem('if perl(strawberry) installed', limit_os: 'Windows', level: 994)]
public function checkPerl(): ?CheckResult
{
if (($path = WindowsUtil::findCommand('perl.exe')) === null) {
return CheckResult::fail('perl not found in path.', 'install-perl');
}
if (!str_contains(implode('', cmd()->execWithResult(quote($path) . ' -v', false)[1]), 'MSWin32')) {
return CheckResult::fail($path . ' is not built for msvc.', 'install-perl');
}
return CheckResult::ok($path);
}
#[CheckItem('if environment is properly set up', level: 1)] #[CheckItem('if environment is properly set up', level: 1)]
public function checkenv(): ?CheckResult public function checkenv(): ?CheckResult
{ {
@@ -91,6 +113,16 @@ class WindowsToolCheck
return CheckResult::ok(); return CheckResult::ok();
} }
#[FixItem('install-perl')]
public function installPerl(): bool
{
$installer = new PackageInstaller();
$installer->addInstallPackage('strawberry-perl');
$installer->run(true);
GlobalEnvManager::addPathIfNotExists(PKG_ROOT_PATH . '\strawberry-perl');
return true;
}
#[FixItem('install-msys2-build-essentials')] #[FixItem('install-msys2-build-essentials')]
public function installMsys2(): bool public function installMsys2(): bool
{ {
@@ -109,6 +141,15 @@ class WindowsToolCheck
return true; return true;
} }
#[FixItem('install-nasm')]
public function installNasm(): bool
{
$installer = new PackageInstaller(interactive: false);
$installer->addInstallPackage('nasm');
$installer->run(true);
return true;
}
#[FixItem('install-vswhere')] #[FixItem('install-vswhere')]
public function installVSWhere(): bool public function installVSWhere(): bool
{ {

View File

@@ -111,7 +111,7 @@ class ExceptionHandler
private static function logError($message, int $indent_space = 0, bool $output_log = true, string $color = 'red'): void private static function logError($message, int $indent_space = 0, bool $output_log = true, string $color = 'red'): void
{ {
$spc_log = spc_log_stream(SPC_OUTPUT_LOG); $spc_log = fopen(SPC_OUTPUT_LOG, 'a');
$msg = explode("\n", (string) $message); $msg = explode("\n", (string) $message);
foreach ($msg as $v) { foreach ($msg as $v) {
$line = str_pad($v, strlen($v) + $indent_space, ' ', STR_PAD_LEFT); $line = str_pad($v, strlen($v) + $indent_space, ' ', STR_PAD_LEFT);

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace StaticPHP\Runtime\Shell; namespace StaticPHP\Runtime\Shell;
use StaticPHP\Exception\ExecutionException;
use StaticPHP\Exception\InterruptException; use StaticPHP\Exception\InterruptException;
use StaticPHP\Exception\SPCInternalException; use StaticPHP\Exception\SPCInternalException;
use StaticPHP\Runtime\SystemTarget; use StaticPHP\Runtime\SystemTarget;
@@ -154,7 +153,7 @@ class DefaultShell extends Shell
$this->logCommandInfo($cmd); $this->logCommandInfo($cmd);
logger()->debug("[TAR EXTRACT] {$cmd}"); logger()->debug("[TAR EXTRACT] {$cmd}");
$this->passthruTolerateSymlinks($cmd); $this->passthru($cmd, $this->console_putput);
return true; return true;
} }
@@ -201,7 +200,7 @@ class DefaultShell extends Shell
$run = function ($cmd) { $run = function ($cmd) {
$this->logCommandInfo($cmd); $this->logCommandInfo($cmd);
logger()->debug("[7Z EXTRACT] {$cmd}"); logger()->debug("[7Z EXTRACT] {$cmd}");
$this->passthruTolerateSymlinks($cmd); $this->passthru($cmd, $this->console_putput);
}; };
$extname = FileSystem::extname($archive_path); $extname = FileSystem::extname($archive_path);
@@ -215,67 +214,4 @@ class DefaultShell extends Shell
return true; return true;
} }
/**
* Run an extraction command, tolerating symbolic links that the host cannot create.
*
* Windows tar.exe (bsdtar) cannot create the symbolic links some archives ship (e.g. zstd's
* tests/cli-tests/bin/unzstd -> zstd), failing each with "Can't create '...': Invalid argument"
* and exiting non-zero. Those entries are never needed to build, so on Windows we swallow a
* failure whose only errors are such symlink creations and continue. Any other failure still throws.
*/
private function passthruTolerateSymlinks(string $cmd): void
{
// Symlink creation only fails on a Windows host; elsewhere extraction handles symlinks fine.
if (PHP_OS_FAMILY !== 'Windows') {
$this->passthru($cmd, $this->console_putput);
return;
}
$result = $this->passthru($cmd, $this->console_putput, capture_output: true, throw_on_error: false);
if ($result['code'] === 0) {
return;
}
if ($this->isSymlinkOnlyExtractFailure($result['output'])) {
logger()->warning('Some symbolic links could not be created during extraction and were skipped (not supported on this Windows host). This is harmless for building.');
return;
}
throw new ExecutionException(
cmd: $cmd,
message: "Command exited with non-zero code: {$result['code']}",
code: $result['code'],
cd: $this->cd,
env: $this->env,
);
}
/**
* Decide whether an extraction failure was caused solely by symbolic links that could not be
* created on Windows. Returns true only when at least one such error is present and no other
* error-looking output is found, so genuine extraction failures still propagate.
*/
private function isSymlinkOnlyExtractFailure(string $output): bool
{
$saw_symlink_error = false;
foreach (preg_split('/\r\n|\r|\n/', $output) ?: [] as $line) {
$line = trim($line);
if ($line === '') {
continue;
}
// bsdtar's trailing summary line; not an error on its own.
if (str_contains($line, 'Error exit delayed from previous errors')) {
continue;
}
// The symlink (or other unsupported special file) that Windows refused to create.
if (str_contains($line, "Can't create") && str_contains($line, 'Invalid argument')) {
$saw_symlink_error = true;
continue;
}
// Any other error-looking line means this was not a clean symlink-only failure.
if (preg_match('/\berror\b|cannot|can\'t|failed|denied|no space|not permitted/i', $line)) {
return false;
}
}
return $saw_symlink_error;
}
} }

View File

@@ -114,8 +114,8 @@ abstract class Shell
if (!$this->enable_log_file) { if (!$this->enable_log_file) {
return; return;
} }
// write executed command to log file using spc_write_log (shared handle, see spc_log_stream) // write executed command to log file using spc_write_log
$log_file = spc_log_stream(SPC_SHELL_LOG); $log_file = fopen(SPC_SHELL_LOG, 'a');
spc_write_log($log_file, "\n>>>>>>>>>>>>>>>>>>>>>>>>>> [" . date('Y-m-d H:i:s') . "]\n"); spc_write_log($log_file, "\n>>>>>>>>>>>>>>>>>>>>>>>>>> [" . date('Y-m-d H:i:s') . "]\n");
spc_write_log($log_file, "> Executing command: {$cmd}\n"); spc_write_log($log_file, "> Executing command: {$cmd}\n");
// get the backtrace to find the file and line number // get the backtrace to find the file and line number
@@ -154,8 +154,8 @@ abstract class Shell
): array { ): array {
$file_res = null; $file_res = null;
if ($this->enable_log_file) { if ($this->enable_log_file) {
// write executed command to the log file using spc_write_log (shared handle, see spc_log_stream) // write executed command to the log file using spc_write_log
$file_res = spc_log_stream(SPC_SHELL_LOG); $file_res = fopen(SPC_SHELL_LOG, 'a');
} }
if ($console_output) { if ($console_output) {
$console_res = STDOUT; $console_res = STDOUT;
@@ -263,7 +263,9 @@ abstract class Shell
} }
fclose($pipes[1]); fclose($pipes[1]);
fclose($pipes[2]); fclose($pipes[2]);
// $file_res is a shared, process-wide handle (see spc_log_stream); do not close it here. if ($file_res !== null) {
fclose($file_res);
}
proc_close($process); proc_close($process);
} }
} }

View File

@@ -322,16 +322,7 @@ class FileSystem
} }
$sub_file = self::convertPath($dir . '/' . $v); $sub_file = self::convertPath($dir . '/' . $v);
if (is_link($sub_file) || is_file($sub_file)) { if (is_link($sub_file) || is_file($sub_file)) {
if (!@unlink($sub_file)) { if (!unlink($sub_file)) {
$last_error = error_get_last();
logger()->debug("unlink failed for '{$sub_file}': " . ($last_error['message'] ?? 'unknown error') . ', attempting chmod + unlink');
// Go module cache files are often read-only; make writable and retry
if (@chmod($sub_file, 0666) && @unlink($sub_file)) {
continue;
}
// Shell fallback: del /f /q forces deletion of read-only files on Windows
$cmd = PHP_OS_FAMILY === 'Windows' ? 'del /f /q' : 'rm -f'; $cmd = PHP_OS_FAMILY === 'Windows' ? 'del /f /q' : 'rm -f';
f_exec("{$cmd} " . escapeshellarg($sub_file), $out, $ret); f_exec("{$cmd} " . escapeshellarg($sub_file), $out, $ret);
if ($ret !== 0) { if ($ret !== 0) {

View File

@@ -66,10 +66,11 @@ if (filter_var(getenv('SPC_ENABLE_LOG_FILE'), FILTER_VALIDATE_BOOLEAN)) {
} }
} }
// Use a single shared handle (see spc_log_stream) so the file is opened exactly once; $log_file_fd = fopen(SPC_OUTPUT_LOG, 'a');
// on Windows a second concurrent open fails while child processes hold an inherited handle. $ob_logger->addLogCallback(function ($level, $output) use ($log_file_fd) {
$ob_logger->addLogCallback(function ($level, $output) { if ($log_file_fd) {
spc_write_log(spc_log_stream(SPC_OUTPUT_LOG), strip_ansi_colors($output) . "\n"); spc_write_log($log_file_fd, strip_ansi_colors($output) . "\n");
}
return true; return true;
}); });
} }

View File

@@ -137,11 +137,6 @@ function spc_add_log_filter(array|string $filter): void
function spc_write_log(mixed $stream, string $data): false|int function spc_write_log(mixed $stream, string $data): false|int
{ {
// Defensive: a log stream may be false/null when its file could not be opened
// (e.g. transient sharing violations on Windows). Never let logging crash the run.
if (!is_resource($stream)) {
return false;
}
// get filter // get filter
global $spc_log_filters; global $spc_log_filters;
if (is_array($spc_log_filters)) { if (is_array($spc_log_filters)) {
@@ -150,29 +145,6 @@ function spc_write_log(mixed $stream, string $data): false|int
return fwrite($stream, $data); return fwrite($stream, $data);
} }
/**
* Return a single, process-wide shared append handle for the given log file.
*
* The handle is opened lazily once and reused for the lifetime of the process. This is
* important on Windows: every time a log file is opened with fopen() its handle is inherited
* by child processes spawned via proc_open() (curl, git, tar, ...). While such a child is
* alive it keeps the file open, and any *additional* open of the same file fails with a
* sharing violation ("The process cannot access the file because it is being used by another
* process."). During parallel downloads many children run at once, so opening a fresh handle
* per log line crashes. Keeping exactly one handle per file means there is never a second open
* to violate. Returns null when the file cannot be opened.
*
* @internal
*/
function spc_log_stream(string $file): mixed
{
static $streams = [];
if (!isset($streams[$file]) || !is_resource($streams[$file])) {
$streams[$file] = @fopen($file, 'a') ?: null;
}
return $streams[$file];
}
// ------- function f_* part ------- // ------- function f_* part -------
// f_ means standard function wrapper // f_ means standard function wrapper