mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-16 21:35:36 +08:00
Apply event changes in feat/pgo-v3
This commit is contained in:
@@ -35,12 +35,37 @@ class event extends PhpExtensionPackage
|
||||
|
||||
#[BeforeStage('php', [php::class, 'makeForUnix'], 'ext-event')]
|
||||
#[PatchDescription('Prevent event extension compile error on macOS')]
|
||||
#[PatchDescription('Patch libevent http_connection.c to use a const peer address')]
|
||||
public function patchBeforeMake(PackageInstaller $installer): void
|
||||
{
|
||||
$php_src = $installer->getTargetPackage('php')->getSourceDir();
|
||||
// Prevent event extension compile error on macOS
|
||||
if (SystemTarget::getTargetOS() === 'Darwin') {
|
||||
$php_src = $installer->getTargetPackage('php')->getSourceDir();
|
||||
FileSystem::replaceFileRegex("{$php_src}/main/php_config.h", '/^#define HAVE_OPENPTY 1$/m', '');
|
||||
}
|
||||
$this->patchLibeventConstPeer("{$php_src}/ext/event");
|
||||
}
|
||||
|
||||
#[BeforeStage('ext-event', [PhpExtensionPackage::class, 'makeForUnix'])]
|
||||
#[PatchDescription('Patch libevent http_connection.c to use a const peer address')]
|
||||
public function patchBeforeSharedMake(PhpExtensionPackage $pkg): void
|
||||
{
|
||||
$this->patchLibeventConstPeer($pkg->getSourceDir());
|
||||
}
|
||||
|
||||
private function patchLibeventConstPeer(string $event_source_dir): bool
|
||||
{
|
||||
$file = "{$event_source_dir}/php8/classes/http_connection.c";
|
||||
if (!is_file($file)) {
|
||||
return false;
|
||||
}
|
||||
// libevent >= 2.2 changed evhttp_connection_get_peer()'s
|
||||
// address arg to `const char **`
|
||||
$header = $this->getBuilder()->getBuildRootPath() . '/include/event2/http.h';
|
||||
$isConst = is_file($header)
|
||||
&& preg_match('/evhttp_connection_get_peer\s*\([^;]*\bconst\s+char\s*\*\*\s*address/s', file_get_contents($header)) === 1;
|
||||
return (bool) ($isConst
|
||||
? FileSystem::replaceFileRegex($file, '/^\tchar \*address;$/m', "\tconst char *address;")
|
||||
: FileSystem::replaceFileRegex($file, '/^\tconst char \*address;$/m', "\tchar *address;"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user