Merge remote-tracking branch 'origin/v3-refactor/new-extensions' into v3-refactor/new-extensions

# Conflicts:
#	config/pkg/ext/builtin-extensions.yml
This commit is contained in:
crazywhalecc 2026-03-11 09:41:17 +08:00
commit 0719c45a29
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
14 changed files with 231 additions and 14 deletions

View File

@ -76,6 +76,35 @@ ext-gmp:
- gmp
php-extension:
arg-type: with-path
ext-iconv:
type: php-extension
depends@unix:
- libiconv
php-extension:
arg-type@unix: with-path
arg-type@windows: with
ext-intl:
type: php-extension
depends@unix:
- icu
ext-ldap:
type: php-extension
depends:
- ldap
suggests:
- gmp
- libsodium
- ext-openssl
php-extension:
arg-type: with-path
ext-libxml:
type: php-extension
depends:
- ext-xml
php-extension:
build-with-php: true
build-shared: false
arg-type: none
ext-mbregex:
type: php-extension
depends:
@ -115,6 +144,8 @@ ext-readline:
arg-type: '--with-libedit --without-readline'
build-shared: false
build-static: true
ext-session:
type: php-extension
ext-sockets:
type: php-extension
ext-xml:

View File

@ -0,0 +1,14 @@
ext-grpc:
type: php-extension
artifact:
source:
type: pecl
name: grpc
metadata:
license-files: [LICENSE]
license: Apache-2.0
depends:
- grpc
lang: cpp
php-extension:
arg-type@unix: enable-path

View File

@ -0,0 +1,12 @@
ext-igbinary:
type: php-extension
artifact:
source:
type: pecl
name: igbinary
metadata:
license-files: [COPYING]
license: BSD-3-Clause
suggests:
- ext-session
- ext-apcu

View File

@ -0,0 +1,13 @@
ext-imagick:
type: php-extension
artifact:
source:
type: pecl
name: imagick
metadata:
license-files: [LICENSE]
license: PHP-3.01
depends:
- imagemagick
php-extension:
arg-type: custom

View File

@ -0,0 +1,15 @@
ext-lz4:
type: php-extension
artifact:
source:
type: ghtagtar
repo: kjdev/php-ext-lz4
extract: php-src/ext/lz4
metadata:
license-files: [LICENSE]
license: MIT
depends:
- liblz4
php-extension:
arg-type@unix: '--enable-lz4=@shared_suffix@ --with-lz4-includedir=@build_root_path@'
arg-type@windows: '--enable-lz4'

View File

@ -0,0 +1,13 @@
ext-maxminddb:
type: php-extension
artifact:
source:
type: pecl
name: maxminddb
metadata:
license-files: [LICENSE]
license: Apache-2.0
depends:
- libmaxminddb
php-extension:
arg-type: with

View File

@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace Package\Extension;
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Exception\EnvironmentException;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\FileSystem;
#[Extension('grpc')]
class grpc extends PhpExtensionPackage
{
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-grpc')]
public function patchBeforeBuildconf(): void
{
if (SystemTarget::getTargetOS() === 'Windows') {
throw new EnvironmentException('grpc extension does not support windows yet');
}
// Fix deprecated PHP API usage in call.c
FileSystem::replaceFileStr(
"{$this->getSourceDir()}/src/php/ext/grpc/call.c",
'zend_exception_get_default(TSRMLS_C),',
'zend_ce_exception,',
);
// custom config.m4 content for grpc extension, to prevent building libgrpc.a again
$config_m4 = <<<'M4'
PHP_ARG_ENABLE(grpc, [whether to enable grpc support], [AS_HELP_STRING([--enable-grpc], [Enable grpc support])])
if test "$PHP_GRPC" != "no"; then
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/include)
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/src/php/ext/grpc)
GRPC_LIBDIR=@@build_lib_path@@
PHP_ADD_LIBPATH($GRPC_LIBDIR)
PHP_ADD_LIBRARY(grpc,,GRPC_SHARED_LIBADD)
LIBS="-lpthread $LIBS"
PHP_ADD_LIBRARY(pthread)
case $host in
*darwin*)
PHP_ADD_LIBRARY(c++,1,GRPC_SHARED_LIBADD)
;;
*)
PHP_ADD_LIBRARY(stdc++,1,GRPC_SHARED_LIBADD)
PHP_ADD_LIBRARY(rt,,GRPC_SHARED_LIBADD)
PHP_ADD_LIBRARY(rt)
;;
esac
PHP_NEW_EXTENSION(grpc, @grpc_c_files@, $ext_shared, , -DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1)
PHP_SUBST(GRPC_SHARED_LIBADD)
PHP_INSTALL_HEADERS([ext/grpc], [php_grpc.h])
fi
M4;
$replace = get_pack_replace();
// load grpc c files from src/php/ext/grpc
$c_files = glob("{$this->getSourceDir()}/src/php/ext/grpc/*.c");
$replace['@grpc_c_files@'] = implode(" \\\n ", array_map(fn ($f) => 'src/php/ext/grpc/' . basename($f), $c_files));
$config_m4 = str_replace(array_keys($replace), array_values($replace), $config_m4);
file_put_contents("{$this->getSourceDir()}/config.m4", $config_m4);
copy("{$this->getSourceDir()}/src/php/ext/grpc/php_grpc.h", "{$this->getSourceDir()}/php_grpc.h");
}
}

View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace Package\Extension;
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Package\PackageBuilder;
#[Extension('imagick')]
class imagick
{
#[CustomPhpConfigureArg('Darwin')]
#[CustomPhpConfigureArg('Linux')]
public function getUnixConfigureArg(bool $shared, PackageBuilder $builder): string
{
$disable_omp = ' ac_cv_func_omp_pause_resource_all=no';
return '--with-imagick=' . ($shared ? 'shared,' : '') . $builder->getBuildRootPath() . $disable_omp;
}
}

View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Package\Extension;
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;
#[Extension('maxminddb')]
class maxminddb extends PhpExtensionPackage
{
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-maxminddb')]
#[PatchDescription('Patch maxminddb extension for buildconf to support new source structure')]
public function patchBeforeBuildconf(): void
{
if (file_exists("{$this->getSourceDir()}/config.m4")) {
return;
}
// move ext/maxminddb/ext/* to ext/maxminddb/
$files = FileSystem::scanDirFiles("{$this->getSourceDir()}/ext", false, true);
foreach ($files as $file) {
rename("{$this->getSourceDir()}/ext/{$file}", "{$this->getSourceDir()}/{$file}");
}
}
}

View File

@ -119,8 +119,7 @@ class postgresql extends LibraryPackage
// remove dynamic libs
shell()->cd($this->getSourceDir() . '/build')
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so.*")
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so")
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so*")
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.dylib");
FileSystem::replaceFileStr("{$this->getLibDir()}/pkgconfig/libpq.pc", '-lldap', '-lldap -llber');

View File

@ -91,6 +91,7 @@ trait frankenphp
'XCADDY_GO_BUILD_FLAGS' => '-buildmode=pie ' .
'-ldflags \"-linkmode=external ' . $extLdFlags . ' ' .
'-X \'github.com/caddyserver/caddy/v2/modules/caddyhttp.ServerHeader=FrankenPHP Caddy\' ' .
'-X \'github.com/caddyserver/caddy/v2.CustomBinaryName=frankenphp\' ' .
'-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' .
"v{$frankenphp_version} PHP {$libphp_version} Caddy'\\\" " .
"-tags={$muslTags}nobadger,nomysql,nopgx{$no_brotli}{$no_watcher}",

View File

@ -94,7 +94,7 @@ class PhpExtensionPackage extends Package
'enable-path' => $shared ? "--enable-{$name}=shared,{$escapedPath}" : "--enable-{$name}={$escapedPath}",
'with' => $shared ? "--with-{$name}=shared" : "--with-{$name}",
'with-path' => $shared ? "--with-{$name}=shared,{$escapedPath}" : "--with-{$name}={$escapedPath}",
'custom' => '',
'custom', 'none' => '',
default => $arg_type,
};
// customize argument from config string

View File

@ -20,8 +20,6 @@ class UnixAutoconfExecutor extends Executor
protected array $configure_args = [];
protected array $ignore_args = [];
protected PackageInstaller $installer;
public function __construct(protected LibraryPackage $package, ?PackageInstaller $installer = null)
@ -40,6 +38,8 @@ class UnixAutoconfExecutor extends Executor
if (!$this->package->hasStage('build')) {
throw new SPCInternalException("Package {$this->package->getName()} does not have a build stage defined.");
}
$this->configure_args = $this->getDefaultConfigureArgs();
}
/**
@ -48,18 +48,12 @@ class UnixAutoconfExecutor extends Executor
public function configure(...$args): static
{
// remove all the ignored args
$args = array_merge($args, $this->getDefaultConfigureArgs(), $this->configure_args);
$args = array_diff($args, $this->ignore_args);
$args = array_merge($args, $this->configure_args);
$configure_args = implode(' ', $args);
InteractiveTerm::setMessage('Building package: ' . ConsoleColor::yellow($this->package->getName()) . ' (./configure)');
return $this->seekLogFileOnException(fn () => $this->shell->exec("./configure {$configure_args}"));
}
public function getConfigureArgsString(): string
{
return implode(' ', array_merge($this->getDefaultConfigureArgs(), $this->configure_args));
}
/**
* Run make
*
@ -134,7 +128,7 @@ class UnixAutoconfExecutor extends Executor
*/
public function removeConfigureArgs(...$args): static
{
$this->ignore_args = [...$this->ignore_args, ...$args];
$this->configure_args = array_diff($this->configure_args, $args);
return $this;
}

View File

@ -74,7 +74,11 @@ abstract class UnixUtil
throw new SPCInternalException("The symbol file {$symbol_file} does not exist, please check if nm command is available.");
}
// https://github.com/ziglang/zig/issues/24662
if (SystemTarget::getTargetOS() !== 'Linux' || ApplicationContext::get(ToolchainInterface::class) instanceof ZigToolchain) {
$toolchain = ApplicationContext::get(ToolchainInterface::class);
if ($toolchain instanceof ZigToolchain) {
return '-Wl,--export-dynamic'; // needs release 0.16, can be removed then
}
if (SystemTarget::getTargetOS() !== 'Linux') {
return "-Wl,-exported_symbols_list,{$symbol_file}";
}
return "-Wl,--dynamic-list={$symbol_file}";