2023-04-15 18:45:11 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder\extension;
|
|
|
|
|
|
|
|
|
|
use SPC\builder\Extension;
|
2024-07-09 19:31:00 +08:00
|
|
|
use SPC\builder\macos\MacOSBuilder;
|
|
|
|
|
use SPC\store\FileSystem;
|
2023-04-15 18:45:11 +08:00
|
|
|
use SPC\util\CustomExt;
|
2025-08-26 00:24:40 +07:00
|
|
|
use SPC\util\SPCConfigUtil;
|
2025-08-26 19:35:10 +07:00
|
|
|
use SPC\util\SPCTarget;
|
2023-04-15 18:45:11 +08:00
|
|
|
|
|
|
|
|
#[CustomExt('swoole')]
|
|
|
|
|
class swoole extends Extension
|
|
|
|
|
{
|
2024-07-09 19:31:00 +08:00
|
|
|
public function patchBeforeMake(): bool
|
|
|
|
|
{
|
2025-07-19 15:10:42 +07:00
|
|
|
$patched = parent::patchBeforeMake();
|
2025-12-18 20:12:01 +01:00
|
|
|
FileSystem::replaceFileStr($this->source_dir . '/ext-src/php_swoole_private.h', 'PHP_VERSION_ID > 80500', 'PHP_VERSION_ID >= 80600');
|
2024-07-09 19:31:00 +08:00
|
|
|
if ($this->builder instanceof MacOSBuilder) {
|
|
|
|
|
// Fix swoole with event extension <util.h> conflict bug
|
|
|
|
|
$util_path = shell()->execWithResult('xcrun --show-sdk-path', false)[1][0] . '/usr/include/util.h';
|
2025-07-03 11:21:24 +07:00
|
|
|
FileSystem::replaceFileStr(
|
|
|
|
|
"{$this->source_dir}/thirdparty/php/standard/proc_open.cc",
|
|
|
|
|
'include <util.h>',
|
|
|
|
|
'include "' . $util_path . '"',
|
|
|
|
|
);
|
2025-07-03 11:11:21 +07:00
|
|
|
return true;
|
2024-07-09 19:31:00 +08:00
|
|
|
}
|
2025-07-19 15:10:42 +07:00
|
|
|
return $patched;
|
2024-07-09 19:31:00 +08:00
|
|
|
}
|
|
|
|
|
|
2024-06-30 22:37:01 +08:00
|
|
|
public function getExtVersion(): ?string
|
|
|
|
|
{
|
|
|
|
|
// Get version from source directory
|
|
|
|
|
$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)) {
|
|
|
|
|
return $matches[1];
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-27 11:12:19 +07:00
|
|
|
public function getUnixConfigureArg(bool $shared = false): string
|
2023-04-15 18:45:11 +08:00
|
|
|
{
|
2024-01-03 10:31:21 +08:00
|
|
|
// enable swoole
|
2025-08-25 12:36:10 +07:00
|
|
|
$arg = '--enable-swoole' . ($shared ? '=shared' : '');
|
2024-01-03 10:31:21 +08:00
|
|
|
|
2025-08-26 00:38:35 +07:00
|
|
|
// commonly used feature: coroutine-time
|
2025-08-25 12:36:10 +07:00
|
|
|
$arg .= ' --enable-swoole-coro-time --with-pic';
|
|
|
|
|
|
2025-08-25 15:28:53 +07:00
|
|
|
$arg .= $this->builder->getOption('enable-zts') ? ' --enable-swoole-thread --disable-thread-context' : ' --disable-swoole-thread --enable-thread-context';
|
2024-01-03 10:31:21 +08:00
|
|
|
|
2025-08-26 00:38:35 +07:00
|
|
|
// required features: curl, openssl (but curl hook is buggy for php 8.0)
|
2024-01-03 10:31:21 +08:00
|
|
|
$arg .= $this->builder->getPHPVersionID() >= 80100 ? ' --enable-swoole-curl' : ' --disable-swoole-curl';
|
2025-08-25 19:29:10 +07:00
|
|
|
$arg .= ' --enable-openssl';
|
2024-01-03 10:31:21 +08:00
|
|
|
|
2025-08-26 00:38:35 +07:00
|
|
|
// additional features that only require libraries
|
2024-01-03 10:31:21 +08:00
|
|
|
$arg .= $this->builder->getLib('libcares') ? ' --enable-cares' : '';
|
2025-08-26 00:38:35 +07:00
|
|
|
$arg .= $this->builder->getLib('brotli') ? (' --enable-brotli --with-brotli-dir=' . BUILD_ROOT_PATH) : '';
|
2024-01-03 10:31:21 +08:00
|
|
|
$arg .= $this->builder->getLib('nghttp2') ? (' --with-nghttp2-dir=' . BUILD_ROOT_PATH) : '';
|
2025-08-25 12:36:10 +07:00
|
|
|
$arg .= $this->builder->getLib('zstd') ? ' --enable-zstd' : '';
|
2025-08-25 22:57:04 +07:00
|
|
|
$arg .= $this->builder->getLib('liburing') ? ' --enable-iouring' : '';
|
2025-08-25 12:36:10 +07:00
|
|
|
$arg .= $this->builder->getExt('sockets') ? ' --enable-sockets' : '';
|
2024-01-03 10:31:21 +08:00
|
|
|
|
2025-08-26 00:38:35 +07:00
|
|
|
// 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
|
2025-08-25 12:08:53 +07:00
|
|
|
$arg .= $this->builder->getExt('swoole-hook-pgsql') ? ' --enable-swoole-pgsql' : ' --disable-swoole-pgsql';
|
2025-08-25 12:36:10 +07:00
|
|
|
$arg .= $this->builder->getExt('swoole-hook-mysql') ? ' --enable-mysqlnd' : ' --disable-mysqlnd';
|
2025-08-25 12:08:53 +07:00
|
|
|
$arg .= $this->builder->getExt('swoole-hook-sqlite') ? ' --enable-swoole-sqlite' : ' --disable-swoole-sqlite';
|
2025-08-26 14:07:49 +07:00
|
|
|
if ($this->builder->getExt('swoole-hook-odbc')) {
|
2025-11-04 13:36:29 +08:00
|
|
|
$config = (new SPCConfigUtil($this->builder))->getLibraryConfig($this->builder->getLib('unixodbc'));
|
2025-08-26 14:07:49 +07:00
|
|
|
$arg .= ' --with-swoole-odbc=unixODBC,' . BUILD_ROOT_PATH . ' SWOOLE_ODBC_LIBS="' . $config['libs'] . '"';
|
|
|
|
|
}
|
2025-08-26 19:35:10 +07:00
|
|
|
|
2025-10-23 20:08:52 +02:00
|
|
|
if ($this->getExtVersion() >= '6.1.0') {
|
|
|
|
|
$arg .= ' --enable-swoole-stdext';
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-26 19:35:10 +07:00
|
|
|
if (SPCTarget::getTargetOS() === 'Darwin') {
|
|
|
|
|
$arg .= ' ac_cv_lib_pthread_pthread_barrier_init=no';
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 18:45:11 +08:00
|
|
|
return $arg;
|
|
|
|
|
}
|
|
|
|
|
}
|