mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-10 10:25:36 +08:00
Compare commits
4 Commits
98a618f1cd
...
1ee8bc7d34
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ee8bc7d34 | ||
|
|
a24fae7a55 | ||
|
|
b5b917ce32 | ||
|
|
b1a59dad79 |
72
config/pkg/ext/ext-swoole.yml
Normal file
72
config/pkg/ext/ext-swoole.yml
Normal file
@@ -0,0 +1,72 @@
|
||||
ext-swoole:
|
||||
type: php-extension
|
||||
artifact:
|
||||
source:
|
||||
type: ghtar
|
||||
repo: swoole/swoole-src
|
||||
extract: php-src/ext/swoole
|
||||
match: v6\.+
|
||||
prefer-stable: true
|
||||
metadata:
|
||||
license-files: [LICENSE]
|
||||
license: Apache-2.0
|
||||
depends:
|
||||
- libcares
|
||||
- brotli
|
||||
- nghttp2
|
||||
- zlib
|
||||
- ext-openssl
|
||||
- ext-curl
|
||||
suggests:
|
||||
- zstd
|
||||
- ext-sockets
|
||||
- ext-swoole-hook-pgsql
|
||||
- ext-swoole-hook-mysql
|
||||
- ext-swoole-hook-sqlite
|
||||
- ext-swoole-hook-odbc
|
||||
suggests@linux:
|
||||
- zstd
|
||||
- liburing
|
||||
- ext-sockets
|
||||
- ext-swoole-hook-pgsql
|
||||
- ext-swoole-hook-mysql
|
||||
- ext-swoole-hook-sqlite
|
||||
- ext-swoole-hook-odbc
|
||||
lang: cpp
|
||||
php-extension:
|
||||
arg-type: custom
|
||||
ext-swoole-hook-mysql:
|
||||
type: php-extension
|
||||
depends:
|
||||
- ext-mysqlnd
|
||||
- ext-pdo
|
||||
- ext-pdo_mysql
|
||||
suggests:
|
||||
- ext-mysqli
|
||||
php-extension:
|
||||
arg-type: none
|
||||
display-name: swoole
|
||||
ext-swoole-hook-odbc:
|
||||
type: php-extension
|
||||
depends:
|
||||
- ext-pdo
|
||||
- unixodbc
|
||||
php-extension:
|
||||
arg-type: none
|
||||
display-name: swoole
|
||||
ext-swoole-hook-pgsql:
|
||||
type: php-extension
|
||||
depends:
|
||||
- ext-pgsql
|
||||
- ext-pdo
|
||||
php-extension:
|
||||
arg-type: none
|
||||
display-name: swoole
|
||||
ext-swoole-hook-sqlite:
|
||||
type: php-extension
|
||||
depends:
|
||||
- ext-sqlite3
|
||||
- ext-pdo
|
||||
php-extension:
|
||||
arg-type: none
|
||||
display-name: swoole
|
||||
18
config/pkg/ext/ext-swow.yml
Normal file
18
config/pkg/ext/ext-swow.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
ext-swow:
|
||||
type: php-extension
|
||||
artifact:
|
||||
source:
|
||||
extract: php-src/ext/swow-src
|
||||
type: ghtar
|
||||
repo: swow/swow
|
||||
prefer-stable: true
|
||||
metadata:
|
||||
license: Apache-2.0
|
||||
license-files: [LICENSE]
|
||||
suggests:
|
||||
- openssl
|
||||
- curl
|
||||
- ext-openssl
|
||||
- ext-curl
|
||||
php-extension:
|
||||
arg-type: custom
|
||||
150
src/Package/Extension/swoole.php
Normal file
150
src/Package/Extension/swoole.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Package\Extension;
|
||||
|
||||
use Package\Target\php;
|
||||
use StaticPHP\Attribute\Package\AfterStage;
|
||||
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\ValidationException;
|
||||
use StaticPHP\Exception\WrongUsageException;
|
||||
use StaticPHP\Package\PackageBuilder;
|
||||
use StaticPHP\Package\PackageInstaller;
|
||||
use StaticPHP\Package\PhpExtensionPackage;
|
||||
use StaticPHP\Runtime\SystemTarget;
|
||||
use StaticPHP\Util\FileSystem;
|
||||
use StaticPHP\Util\SPCConfigUtil;
|
||||
|
||||
#[Extension('swoole')]
|
||||
class swoole extends PhpExtensionPackage
|
||||
{
|
||||
#[Validate]
|
||||
public function validate(PackageInstaller $installer): void
|
||||
{
|
||||
// swoole-hook-odbc conflicts with pdo_odbc
|
||||
if ($installer->getPhpExtensionPackage('swoole-hook-odbc') && $installer->getPhpExtensionPackage('pdo_odbc')?->isBuildStatic()) {
|
||||
throw new WrongUsageException('swoole-hook-odbc provides pdo_odbc, if you enable odbc hook for swoole, you must remove pdo_odbc extension.');
|
||||
}
|
||||
// swoole-hook-pgsql conflicts with pdo_pgsql
|
||||
if ($installer->getPhpExtensionPackage('swoole-hook-pgsql') && $installer->getPhpExtensionPackage('pdo_pgsql')?->isBuildStatic()) {
|
||||
throw new WrongUsageException('swoole-hook-pgsql provides pdo_pgsql, if you enable pgsql hook for swoole, you must remove pdo_pgsql extension.');
|
||||
}
|
||||
// swoole-hook-sqlite conflicts with pdo_sqlite
|
||||
if ($installer->getPhpExtensionPackage('swoole-hook-sqlite') && $installer->getPhpExtensionPackage('pdo_sqlite')?->isBuildStatic()) {
|
||||
throw new WrongUsageException('swoole-hook-sqlite provides pdo_sqlite, if you enable sqlite hook for swoole, you must remove pdo_sqlite extension.');
|
||||
}
|
||||
}
|
||||
|
||||
#[BeforeStage('php', [php::class, 'makeForUnix'], 'ext-swoole')]
|
||||
#[PatchDescription('Fix maximum version check for Swoole 6.2')]
|
||||
public function patchBeforeMake(): void
|
||||
{
|
||||
FileSystem::replaceFileStr($this->getSourceDir() . '/ext-src/php_swoole_private.h', 'PHP_VERSION_ID > 80500', 'PHP_VERSION_ID >= 80600');
|
||||
}
|
||||
|
||||
#[BeforeStage('php', [php::class, 'makeForUnix'], 'ext-swoole')]
|
||||
#[PatchDescription('Fix swoole with event extension <util.h> conflict bug on macOS')]
|
||||
public function patchBeforeMake2(): void
|
||||
{
|
||||
if (SystemTarget::getTargetOS() === 'Darwin') {
|
||||
// Fix swoole with event extension <util.h> conflict bug
|
||||
$util_path = shell()->execWithResult('xcrun --show-sdk-path', false)[1][0] . '/usr/include/util.h';
|
||||
FileSystem::replaceFileStr(
|
||||
"{$this->getSourceDir()}/thirdparty/php/standard/proc_open.cc",
|
||||
'include <util.h>',
|
||||
"include \"{$util_path}\"",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[CustomPhpConfigureArg('Darwin')]
|
||||
#[CustomPhpConfigureArg('Linux')]
|
||||
public function getUnixConfigureArg(bool $shared, PackageBuilder $builder, PackageInstaller $installer): string
|
||||
{
|
||||
// enable swoole
|
||||
$arg = '--enable-swoole' . ($shared ? '=shared' : '');
|
||||
|
||||
// commonly used feature: coroutine-time
|
||||
$arg .= ' --enable-swoole-coro-time --with-pic';
|
||||
|
||||
$arg .= $builder->getOption('enable-zts') ? ' --enable-swoole-thread --disable-thread-context' : ' --disable-swoole-thread --enable-thread-context';
|
||||
|
||||
// required features: curl, openssl (but curl hook is buggy for php 8.0)
|
||||
$arg .= php::getPHPVersionID() >= 80100 ? ' --enable-swoole-curl' : ' --disable-swoole-curl';
|
||||
$arg .= ' --enable-openssl';
|
||||
|
||||
// additional features that only require libraries
|
||||
$arg .= $installer->getLibraryPackage('libcares') ? ' --enable-cares' : '';
|
||||
$arg .= $installer->getLibraryPackage('brotli') ? (' --enable-brotli --with-brotli-dir=' . BUILD_ROOT_PATH) : '';
|
||||
$arg .= $installer->getLibraryPackage('nghttp2') ? (' --with-nghttp2-dir=' . BUILD_ROOT_PATH) : '';
|
||||
$arg .= $installer->getLibraryPackage('zstd') ? ' --enable-zstd' : '';
|
||||
$arg .= $installer->getLibraryPackage('liburing') ? ' --enable-iouring' : '';
|
||||
$arg .= $installer->getPhpExtensionPackage('sockets') ? ' --enable-sockets' : '';
|
||||
|
||||
// enable additional features that require the pdo extension, but conflict with pdo_* extensions
|
||||
// to make sure everything works as it should, this is done in fake addon extensions
|
||||
$arg .= $installer->getPhpExtensionPackage('swoole-hook-pgsql') ? ' --enable-swoole-pgsql' : ' --disable-swoole-pgsql';
|
||||
$arg .= $installer->getPhpExtensionPackage('swoole-hook-mysql') ? ' --enable-mysqlnd' : ' --disable-mysqlnd';
|
||||
$arg .= $installer->getPhpExtensionPackage('swoole-hook-sqlite') ? ' --enable-swoole-sqlite' : ' --disable-swoole-sqlite';
|
||||
if ($installer->getPhpExtensionPackage('swoole-hook-odbc')) {
|
||||
$config = new SPCConfigUtil()->getLibraryConfig($installer->getLibraryPackage('unixodbc'));
|
||||
$arg .= " --with-swoole-odbc=unixODBC,{$builder->getBuildRootPath()} SWOOLE_ODBC_LIBS=\"{$config['libs']}\"";
|
||||
}
|
||||
|
||||
// Get version from source directory
|
||||
$ver = null;
|
||||
$file = SOURCE_PATH . '/php-src/ext/swoole/include/swoole_version.h';
|
||||
// Match #define SWOOLE_VERSION "5.1.3"
|
||||
$pattern = '/#define SWOOLE_VERSION "(.+)"/';
|
||||
if (preg_match($pattern, file_get_contents($file), $matches)) {
|
||||
$ver = $matches[1];
|
||||
}
|
||||
|
||||
if ($ver && $ver >= '6.1.0') {
|
||||
$arg .= ' --enable-swoole-stdext';
|
||||
}
|
||||
|
||||
if (SystemTarget::getTargetOS() === 'Darwin') {
|
||||
$arg .= ' ac_cv_lib_pthread_pthread_barrier_init=no';
|
||||
}
|
||||
|
||||
return $arg;
|
||||
}
|
||||
|
||||
#[AfterStage('php', [php::class, 'smokeTestCliForUnix'], 'ext-swoole-hook-mysql')]
|
||||
public function mysqlTest(PackageInstaller $installer): void
|
||||
{
|
||||
[$ret, $out] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -n' . $this->getSharedExtensionLoadString() . ' --ri "swoole"', false);
|
||||
$out = implode('', $out);
|
||||
if ($ret !== 0) {
|
||||
throw new ValidationException("extension {$this->getName()} failed compile check: php-cli returned {$ret}", validation_module: 'extension swoole_hook_mysql sanity check');
|
||||
}
|
||||
// mysqlnd
|
||||
if ($installer->getPhpExtensionPackage('swoole-hook-mysql') && !str_contains($out, 'mysqlnd')) {
|
||||
throw new ValidationException('swoole mysql hook is not enabled correctly.', validation_module: 'Extension swoole mysql hook availability check');
|
||||
}
|
||||
// coroutine_odbc
|
||||
if ($installer->getPhpExtensionPackage('swoole-hook-odbc') && !str_contains($out, 'coroutine_odbc')) {
|
||||
throw new ValidationException('swoole odbc hook is not enabled correctly.', validation_module: 'Extension swoole odbc hook availability check');
|
||||
}
|
||||
// coroutine_pgsql
|
||||
if ($installer->getPhpExtensionPackage('swoole-hook-pgsql') && !str_contains($out, 'coroutine_pgsql')) {
|
||||
throw new ValidationException(
|
||||
'swoole pgsql hook is not enabled correctly.',
|
||||
validation_module: 'Extension swoole pgsql hook availability check'
|
||||
);
|
||||
}
|
||||
// coroutine_sqlite
|
||||
if ($installer->getPhpExtensionPackage('swoole-hook-sqlite') && !str_contains($out, 'coroutine_sqlite')) {
|
||||
throw new ValidationException(
|
||||
'swoole sqlite hook is not enabled correctly.',
|
||||
validation_module: 'Extension swoole sqlite hook availability check'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
44
src/Package/Extension/swow.php
Normal file
44
src/Package/Extension/swow.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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\Package\PackageInstaller;
|
||||
use StaticPHP\Package\PhpExtensionPackage;
|
||||
use StaticPHP\Util\FileSystem;
|
||||
|
||||
#[Extension('swow')]
|
||||
class swow extends PhpExtensionPackage
|
||||
{
|
||||
#[CustomPhpConfigureArg('Darwin')]
|
||||
#[CustomPhpConfigureArg('Linux')]
|
||||
public function configureArg(PackageInstaller $installer): string
|
||||
{
|
||||
$arg = '--enable-swow';
|
||||
$arg .= $installer->getLibraryPackage('openssl') ? ' --enable-swow-ssl' : ' --disable-swow-ssl';
|
||||
$arg .= $installer->getLibraryPackage('curl') ? ' --enable-swow-curl' : ' --disable-swow-curl';
|
||||
return $arg;
|
||||
}
|
||||
|
||||
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-swow')]
|
||||
#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-swow')]
|
||||
public function patchBeforeBuildconf(PackageInstaller $installer): bool
|
||||
{
|
||||
$php_src = $installer->getTargetPackage('php')->getSourceDir();
|
||||
if (php::getPHPVersionID() >= 80000 && !is_link("{$php_src}/ext/swow")) {
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
f_passthru("cd {$php_src}/ext && mklink /D swow swow-src\\ext");
|
||||
} else {
|
||||
f_passthru("cd {$php_src}/ext && ln -s swow-src/ext swow");
|
||||
}
|
||||
}
|
||||
// replace AC_DEFUN([SWOW_PKG_CHECK_MODULES] to AC_DEFUN([SWOW_PKG_CHECK_MODULES_STATIC]
|
||||
FileSystem::replaceFileStr($this->getSourceDir() . '/ext/config.m4', 'AC_DEFUN([SWOW_PKG_CHECK_MODULES]', 'AC_DEFUN([SWOW_PKG_CHECK_MODULES_STATIC]');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -327,6 +327,34 @@ class PhpExtensionPackage extends Package
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the `-d extension_dir=... -d extension=...` string for all resolved shared extensions.
|
||||
* Used in CLI smoke test to load shared extension dependencies at runtime.
|
||||
*/
|
||||
public function getSharedExtensionLoadString(): string
|
||||
{
|
||||
$sharedExts = array_filter(
|
||||
$this->getInstaller()->getResolvedPackages(PhpExtensionPackage::class),
|
||||
fn (PhpExtensionPackage $ext) => $ext->isBuildShared() && !$ext->isBuildWithPhp()
|
||||
);
|
||||
|
||||
if (empty($sharedExts)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$ret = ' -d "extension_dir=' . BUILD_MODULES_PATH . '"';
|
||||
foreach ($sharedExts as $ext) {
|
||||
$extConfig = PackageConfig::get($ext->getName(), 'php-extension', []);
|
||||
if ($extConfig['zend-extension'] ?? false) {
|
||||
$ret .= ' -d "zend_extension=' . $ext->getExtensionName() . '"';
|
||||
} else {
|
||||
$ret .= ' -d "extension=' . $ext->getExtensionName() . '"';
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a given string of library flags into static and shared libraries.
|
||||
*
|
||||
@@ -354,34 +382,6 @@ class PhpExtensionPackage extends Package
|
||||
return [trim($staticLibString), trim($sharedLibString)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the `-d extension_dir=... -d extension=...` string for all resolved shared extensions.
|
||||
* Used in CLI smoke test to load shared extension dependencies at runtime.
|
||||
*/
|
||||
private function getSharedExtensionLoadString(): string
|
||||
{
|
||||
$sharedExts = array_filter(
|
||||
$this->getInstaller()->getResolvedPackages(PhpExtensionPackage::class),
|
||||
fn (PhpExtensionPackage $ext) => $ext->isBuildShared() && !$ext->isBuildWithPhp()
|
||||
);
|
||||
|
||||
if (empty($sharedExts)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$ret = ' -d "extension_dir=' . BUILD_MODULES_PATH . '"';
|
||||
foreach ($sharedExts as $ext) {
|
||||
$extConfig = PackageConfig::get($ext->getName(), 'php-extension', []);
|
||||
if ($extConfig['zend-extension'] ?? false) {
|
||||
$ret .= ' -d "zend_extension=' . $ext->getExtensionName() . '"';
|
||||
} else {
|
||||
$ret .= ' -d "extension=' . $ext->getExtensionName() . '"';
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape PHP test file content for inline `-r` usage.
|
||||
* Strips <?php / declare, replaces newlines and special shell characters.
|
||||
|
||||
@@ -67,6 +67,9 @@ class ZigToolchain implements UnixToolchainInterface
|
||||
$extra_vars = getenv('SPC_EXTRA_PHP_VARS') ?: '';
|
||||
GlobalEnvManager::putenv("SPC_EXTRA_PHP_VARS=php_cv_have_avx512=no php_cv_have_avx512vbmi=no {$extra_vars}");
|
||||
}
|
||||
// zig-cc/clang treats strlcpy/strlcat as compiler builtins, so configure link tests pass (HAVE_STRLCPY=1)
|
||||
$extra_vars = getenv('SPC_EXTRA_PHP_VARS') ?: '';
|
||||
GlobalEnvManager::putenv("SPC_EXTRA_PHP_VARS=ac_cv_func_strlcpy=no ac_cv_func_strlcat=no {$extra_vars}");
|
||||
}
|
||||
|
||||
public function getCompilerInfo(): ?string
|
||||
|
||||
Reference in New Issue
Block a user