Merge remote-tracking branch 'origin/v3' into feat/pgo-v3

This commit is contained in:
henderkes
2026-05-11 21:05:54 +07:00
54 changed files with 1171 additions and 263 deletions

View File

@@ -23,13 +23,13 @@ class go_win
$pkgroot = PKG_ROOT_PATH;
// get version
[$version] = explode("\n", default_shell()->executeCurl('https://go.dev/VERSION?m=text') ?: '');
[$version] = explode("\n", default_shell()->executeCurl('https://go.dev/VERSION?m=text', retries: $downloader->getRetry()) ?: '');
if ($version === '') {
throw new DownloaderException('Failed to get latest Go version from https://go.dev/VERSION?m=text');
}
// find SHA256 hash from download page
$page = default_shell()->executeCurl('https://go.dev/dl/');
$page = default_shell()->executeCurl('https://go.dev/dl/', retries: $downloader->getRetry());
if ($page === '' || $page === false) {
throw new DownloaderException('Failed to get Go download page from https://go.dev/dl/');
}

View File

@@ -39,11 +39,11 @@ class go_xcaddy
};
// get version and hash
[$version] = explode("\n", default_shell()->executeCurl('https://go.dev/VERSION?m=text') ?: '');
[$version] = explode("\n", default_shell()->executeCurl('https://go.dev/VERSION?m=text', retries: $downloader->getRetry()) ?: '');
if ($version === '') {
throw new DownloaderException('Failed to get latest Go version from https://go.dev/VERSION?m=text');
}
$page = default_shell()->executeCurl('https://go.dev/dl/');
$page = default_shell()->executeCurl('https://go.dev/dl/', retries: $downloader->getRetry());
if ($page === '' || $page === false) {
throw new DownloaderException('Failed to get Go download page from https://go.dev/dl/');
}

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace Package\Extension;
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;
#[Extension('clickhouse')]
class clickhouse extends PhpExtensionPackage
{
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-clickhouse')]
#[PatchDescription('Replace THIS_DIR=`dirname $0` with PHP_EXT_SRCDIR() in config.m4 so include paths resolve to the ext source dir during PHP main configure (dirname $0 returns "." when run from php-src root).')]
public function patchBeforeBuildconfUnix(): void
{
FileSystem::replaceFileRegex(
"{$this->getSourceDir()}/config.m4",
'/^(\s*)THIS_DIR=.*/m',
'$1THIS_DIR=PHP_EXT_SRCDIR()',
);
}
#[CustomPhpConfigureArg('Darwin')]
#[CustomPhpConfigureArg('Linux')]
public function getUnixConfigureArg(bool $shared, PackageInstaller $installer): string
{
$arg = '--enable-clickhouse' . ($shared ? '=shared' : '');
if ($installer->getLibraryPackage('openssl')) {
$arg .= ' --enable-clickhouse-openssl';
}
return $arg;
}
}

View File

@@ -9,6 +9,7 @@ use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\Package\Validate;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Exception\WrongUsageException;
use StaticPHP\Package\PackageBuilder;
use StaticPHP\Package\PackageInstaller;
@@ -26,6 +27,19 @@ class imap extends PhpExtensionPackage
}
}
#[BeforeStage('php', [php::class, 'makeCliForUnix'], 'ext-imap')]
#[PatchDescription('Fix imap zend_zval_value_name() call for PHP 8.2 compatibility')]
public function patchBeforeMake(): void
{
// zend_zval_value_name() was introduced in PHP 8.3; PHP 8.2 imap backported the call but not the declaration
// replace with the equivalent PHP 8.2-compatible function
FileSystem::replaceFileStr(
"{$this->getSourceDir()}/php_imap.c",
'zend_zval_value_name(data)',
'zend_zval_type_name(data)'
);
}
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-imap')]
public function patchBeforeBuildconf(PackageInstaller $installer): void
{

View File

@@ -16,7 +16,7 @@ use StaticPHP\Util\FileSystem;
class intl extends PhpExtensionPackage
{
#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-intl')]
#[PatchDescription('Fix intl config.w32: replace hardcoded true with PHP_INTL_SHARED for static build support')]
#[PatchDescription('Fix intl config.w32: replace hardcoded true with PHP_INTL_SHARED for static build support; add /std:c++17 required by ICU 73+')]
public function patchBeforeBuildconfForWindows(PackageInstaller $installer): void
{
$php_src = $installer->getTargetPackage('php')->getSourceDir();
@@ -25,5 +25,11 @@ class intl extends PhpExtensionPackage
'EXTENSION("intl", "php_intl.c intl_convert.c intl_convertcpp.cpp intl_error.c ", true,',
'EXTENSION("intl", "php_intl.c intl_convert.c intl_convertcpp.cpp intl_error.c ", PHP_INTL_SHARED,'
);
// ICU 73+ headers (char16ptr.h etc.) unconditionally include <string_view> which requires C++17.
FileSystem::replaceFileStr(
"{$php_src}/ext/intl/config.w32",
'ADD_FLAG("CFLAGS_INTL", "/EHsc',
'ADD_FLAG("CFLAGS_INTL", "/std:c++17 /EHsc'
);
}
}

View File

@@ -17,6 +17,20 @@ class memcache extends PhpExtensionPackage
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-memcache')]
public function patchBeforeBuildconf(): bool
{
// PHP 8.5 moved php_smart_string*.h from ext/standard/ to Zend/
foreach (['src/memcache_pool.h', 'src/memcache_pool.c', 'src/memcache_session.c', 'src/memcache_ascii_protocol.c', 'src/memcache_binary_protocol.c'] as $file) {
FileSystem::replaceFileStr(
"{$this->getSourceDir()}/{$file}",
'#include "ext/standard/php_smart_string_public.h"',
'#include "Zend/zend_smart_string_public.h"',
);
FileSystem::replaceFileStr(
"{$this->getSourceDir()}/{$file}",
'#include "ext/standard/php_smart_string.h"',
'#include "Zend/zend_smart_string.h"',
);
}
if (!$this->isBuildStatic()) {
return false;
}

View File

@@ -7,15 +7,21 @@ namespace Package\Extension;
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Toolchain\Interface\ToolchainInterface;
use StaticPHP\Toolchain\ZigToolchain;
use StaticPHP\Util\GlobalEnvManager;
#[Extension('opentelemetry')]
class opentelemetry
{
#[BeforeStage('php', [php::class, 'makeForUnix'], 'ext-opentelemetry')]
public function patchBeforeMake(): void
public function patchBeforeMake(ToolchainInterface $toolchain): void
{
// add -Wno-strict-prototypes
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -Wno-strict-prototypes');
$extra_cflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') ?: '';
$extra_cflags .= ' -Wno-strict-prototypes';
if ($toolchain instanceof ZigToolchain) {
$extra_cflags .= ' -Wno-unknown-warning-option';
}
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . trim($extra_cflags));
}
}

View File

@@ -20,7 +20,7 @@ class swow extends PhpExtensionPackage
#[CustomPhpConfigureArg('Windows')]
public function configureArg(PackageInstaller $installer): string
{
$arg = '--enable-swow';
$arg = '--enable-swow --disable-swow-pdo-pgsql';
$arg .= $installer->getLibraryPackage('openssl') ? ' --enable-swow-ssl' : ' --disable-swow-ssl';
$arg .= $installer->getLibraryPackage('curl') ? ' --enable-swow-curl' : ' --disable-swow-curl';
return $arg;

View File

@@ -8,15 +8,16 @@ use Package\Target\php;
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Package\PackageBuilder;
use StaticPHP\Package\PackageInstaller;
#[Extension('zlib')]
class zlib
{
#[CustomPhpConfigureArg('Darwin')]
#[CustomPhpConfigureArg('Linux')]
public function unixConfigureArg(PackageBuilder $builder): string
public function unixConfigureArg(PackageBuilder $builder, PackageInstaller $installer): string
{
$zlib_dir = php::getPHPVersionID() >= 80400 ? '' : ' --with-zlib-dir=' . $builder->getBuildRootPath();
return '--with-zlib' . $zlib_dir;
$zlib_dir = (php::getPHPVersionID() >= 80400 && !$installer->getPhpExtensionPackage('spx')) ? '' : " --with-zlib-dir={$builder->getBuildRootPath()}";
return "--with-zlib{$zlib_dir}";
}
}

View File

@@ -33,7 +33,7 @@ class mpir
{
$vs_ver_dir = ApplicationContext::get('mpir_vs_ver_dir');
cmd()->cd("{$lib->getSourceDir()}{$vs_ver_dir}\\lib_mpir_gc")
->exec('msbuild lib_mpir_gc.vcxproj /t:Rebuild /p:Configuration=Release /p:Platform=x64');
->exec('msbuild lib_mpir_gc.vcxproj /t:Rebuild /p:Configuration=Release /p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0');
FileSystem::createDir($lib->getLibDir());
FileSystem::createDir($lib->getIncludeDir());
FileSystem::copy("{$lib->getSourceDir()}{$vs_ver_dir}\\lib_mpir_gc\\x64\\Release\\mpir_a.lib", "{$lib->getLibDir()}\\mpir_a.lib");

View File

@@ -26,6 +26,7 @@ class zstd
)
->build();
FileSystem::copy($package->getLibDir() . '\zstd_static.lib', $package->getLibDir() . '/zstd.lib');
FileSystem::copy($package->getLibDir() . '\zstd_static.lib', $package->getLibDir() . '/libzstd.lib');
}
#[BuildFor('Linux')]

View File

@@ -20,8 +20,10 @@ use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Package\TargetPackage;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Toolchain\Interface\ToolchainInterface;
use StaticPHP\Toolchain\ZigToolchain;
use StaticPHP\Util\DirDiff;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\GlobalEnvManager;
use StaticPHP\Util\InteractiveTerm;
use StaticPHP\Util\SourcePatcher;
use StaticPHP\Util\SPCConfigUtil;
@@ -93,7 +95,8 @@ trait unix
// disable undefined behavior sanitizer when opcache JIT is enabled (Linux only)
if (SystemTarget::getTargetOS() === 'Linux' && !$package->getBuildOption('disable-opcache-jit', false)) {
if ($version_id >= 80500 || $installer->isPackageResolved('ext-opcache')) {
f_putenv('SPC_COMPILER_EXTRA=-fno-sanitize=undefined');
$compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: '';
GlobalEnvManager::putenv('SPC_COMPILER_EXTRA=' . trim($compiler_extra . ' -fno-sanitize=undefined'));
}
}
// PHP JSON extension is built-in since PHP 8.0
@@ -165,14 +168,20 @@ trait unix
#[BeforeStage('php', [self::class, 'makeForUnix'], 'php')]
#[PatchDescription('Patch Makefile to fix //lib path for Linux builds')]
public function tryPatchMakefileUnix(): void
#[PatchDescription('Patch BUILD_CC to use system cc instead of zig-cc (prevents minilua crash)')]
public function tryPatchMakefileUnix(TargetPackage $package, ToolchainInterface $toolchain): void
{
if (SystemTarget::getTargetOS() !== 'Linux') {
return;
}
// replace //lib with /lib in Makefile
shell()->cd(SOURCE_PATH . '/php-src')->exec('sed -i "s|//lib|/lib|g" Makefile');
shell()->cd($package->getSourceDir())->exec('sed -i "s|//lib|/lib|g" Makefile');
if ($toolchain instanceof ZigToolchain) {
$makefile = "{$package->getSourceDir()}/Makefile";
FileSystem::replaceFileRegex($makefile, '/^BUILD_CC\s*=\s*zig-cc\s*$/m', 'BUILD_CC = cc');
}
}
#[BeforeStage('php', [self::class, 'makeForUnix'], 'php')]
@@ -392,14 +401,13 @@ trait unix
// ------------- SPC_CMD_VAR_PHP_EMBED_TYPE=static -------------
// process libphp.a for static embed
if (!file_exists("{$package->getLibDir()}/libphp.a")) {
return;
// process libphp.a for static embed (only when present)
if (file_exists("{$package->getLibDir()}/libphp.a")) {
$ar = getenv('AR') ?: 'ar';
$libphp_a = "{$package->getLibDir()}/libphp.a";
shell()->exec("{$ar} -t {$libphp_a} | grep '\\.a$' | xargs -n1 {$ar} d {$libphp_a}");
UnixUtil::exportDynamicSymbols($libphp_a);
}
$ar = getenv('AR') ?: 'ar';
$libphp_a = "{$package->getLibDir()}/libphp.a";
shell()->exec("{$ar} -t {$libphp_a} | grep '\\.a$' | xargs -n1 {$ar} d {$libphp_a}");
UnixUtil::exportDynamicSymbols($libphp_a);
}
#[Stage]
@@ -552,7 +560,8 @@ trait unix
if (file_exists(BUILD_BIN_PATH . '/php-config')) {
logger()->debug('Patching php-config prefix and libs order');
$php_config_str = FileSystem::readFile(BUILD_BIN_PATH . '/php-config');
$php_config_str = str_replace('prefix=""', 'prefix="' . BUILD_ROOT_PATH . '"', $php_config_str);
// anchor to start-of-line so we don't also match `program_prefix=""`
$php_config_str = preg_replace('/^prefix=""/m', 'prefix="' . BUILD_ROOT_PATH . '"', $php_config_str);
// move mimalloc to the beginning of libs
$php_config_str = preg_replace('/(libs=")(.*?)\s*(' . preg_quote(BUILD_LIB_PATH, '/') . '\/mimalloc\.o)\s*(.*?)"/', '$1$3 $2 $4"', $php_config_str);
// move lstdc++ to the end of libs

View File

@@ -293,21 +293,8 @@ trait windows
$fake_cli = $package->getBuildOption('with-micro-fake-cli', false) ? ' /DPHP_MICRO_FAKE_CLI' : '';
// phar patch for micro
$phar_patched = false;
if ($installer->isPackageResolved('ext-phar')) {
$phar_patched = true;
SourcePatcher::patchMicroPhar(self::getPHPVersionID());
}
try {
cmd()->cd($package->getSourceDir())
->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");
} finally {
if ($phar_patched) {
SourcePatcher::unpatchMicroPhar();
}
}
cmd()->cd($package->getSourceDir())
->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');
}