Files
static-php-cli/src/SPC/builder/extension/event.php
2026-07-09 10:17:23 +07:00

62 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\builder\macos\MacOSBuilder;
use SPC\store\FileSystem;
use SPC\util\CustomExt;
#[CustomExt('event')]
class event extends Extension
{
public function getUnixConfigureArg(bool $shared = false): string
{
$arg = '--with-event-core --with-event-extra --with-event-libevent-dir=' . BUILD_ROOT_PATH;
if ($this->builder->getLib('openssl')) {
$arg .= ' --with-event-openssl=' . BUILD_ROOT_PATH;
}
if ($this->builder->getExt('sockets')) {
$arg .= ' --enable-event-sockets';
} else {
$arg .= ' --disable-event-sockets';
}
return $arg;
}
public function patchBeforeConfigure(): bool
{
FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/configure', '/-levent_openssl/', $this->getLibFilesString());
return true;
}
public function patchBeforeMake(): bool
{
$patched = parent::patchBeforeMake();
// Prevent event extension compile error on macOS
if ($this->builder instanceof MacOSBuilder) {
FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/main/php_config.h', '/^#define HAVE_OPENPTY 1$/m', '');
$patched = true;
}
return $this->patchLibeventConstPeer() || $patched;
}
public function patchBeforeSharedMake(): bool
{
$patched = parent::patchBeforeSharedMake();
return $this->patchLibeventConstPeer() || $patched;
}
private function patchLibeventConstPeer(): bool
{
$patched = false;
$file = SOURCE_PATH . '/php-src/ext/event/php8/classes/http_connection.c';
if (is_file($file) && FileSystem::replaceFileRegex($file, '/^\tchar \*address;$/m', "\tconst char *address;")) {
$patched = true;
}
return $patched;
}
}