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-25 14:55:30 +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();
|
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-25 12:36:10 +07:00
|
|
|
// commonly-used feature: coroutine-time
|
|
|
|
|
$arg .= ' --enable-swoole-coro-time --with-pic';
|
|
|
|
|
|
2025-08-25 14:55:30 +07:00
|
|
|
$arg .= $this->builder->getOption('enable-zts') && SPCTarget::getTargetOS() !== 'Darwin' ? ' --enable-swoole-thread' : ' --disable-swoole-thread';
|
|
|
|
|
$arg .= $this->builder->getOption('enable-zts') || SPCTarget::getTargetOS() === 'Darwin' ? ' --disable-thread-context' : ' --enable-thread-context';
|
2024-01-03 10:31:21 +08:00
|
|
|
|
|
|
|
|
// required feature: curl, openssl (but curl hook is buggy for php 8.0)
|
|
|
|
|
$arg .= $this->builder->getPHPVersionID() >= 80100 ? ' --enable-swoole-curl' : ' --disable-swoole-curl';
|
2025-08-25 12:36:10 +07:00
|
|
|
$arg .= ' --enable-openssl'; // we depend on openssl so it's always enabled
|
2024-01-03 10:31:21 +08:00
|
|
|
|
|
|
|
|
// additional feature: c-ares, brotli, nghttp2 (can be disabled, but we enable it by default in config to support full network feature)
|
|
|
|
|
$arg .= $this->builder->getLib('libcares') ? ' --enable-cares' : '';
|
2025-03-27 11:12:19 +07:00
|
|
|
if (!$shared) {
|
|
|
|
|
$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' : '';
|
|
|
|
|
$arg .= $this->builder->getLib('iouring') ? ' --enable-iouring' : '';
|
|
|
|
|
$arg .= $this->builder->getExt('sockets') ? ' --enable-sockets' : '';
|
2024-01-03 10:31:21 +08:00
|
|
|
|
|
|
|
|
// additional feature: swoole-pgsql, it should depend on lib [postgresql], but it will lack of CFLAGS etc.
|
|
|
|
|
// so this is a tricky way (enable ext [pgsql,pdo] to add postgresql hook and pdo_pgsql support)
|
2025-08-25 12:08:53 +07:00
|
|
|
$arg .= $this->builder->getExt('swoole-hook-pgsql') ? ' --enable-swoole-pgsql' : ' --disable-swoole-pgsql';
|
2024-01-03 10:31:21 +08:00
|
|
|
|
2025-08-25 12:11:56 +07:00
|
|
|
// additional feature: swoole-mysql
|
2025-08-25 12:36:10 +07:00
|
|
|
$arg .= $this->builder->getExt('swoole-hook-mysql') ? ' --enable-mysqlnd' : ' --disable-mysqlnd';
|
2025-08-25 12:11:56 +07:00
|
|
|
|
2024-01-03 10:31:21 +08:00
|
|
|
// enable this feature , need remove pdo_sqlite
|
|
|
|
|
// more info : https://wenda.swoole.com/detail/109023
|
2025-08-25 12:08:53 +07:00
|
|
|
$arg .= $this->builder->getExt('swoole-hook-sqlite') ? ' --enable-swoole-sqlite' : ' --disable-swoole-sqlite';
|
2024-01-03 10:31:21 +08:00
|
|
|
|
|
|
|
|
// enable this feature , need stop pdo_*
|
2025-08-25 12:58:12 +07:00
|
|
|
$arg .= $this->builder->getLib('unixodbc') && !$this->builder->getExt('pdo')?->isBuildStatic() ? ' --with-swoole-odbc=unixODBC,' . BUILD_ROOT_PATH : '';
|
2023-04-15 18:45:11 +08:00
|
|
|
return $arg;
|
|
|
|
|
}
|
|
|
|
|
}
|