Skip to content

Commit

Permalink
add event support
Browse files Browse the repository at this point in the history
  • Loading branch information
crazywhalecc committed Apr 30, 2023
1 parent 893fa5b commit cac3ffc
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 8 deletions.
14 changes: 14 additions & 0 deletions config/ext.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@
"zlib"
]
},
"event": {
"type": "external",
"source": "ext-event",
"arg-type": "custom",
"lib-depends": [
"libevent"
],
"ext-depends": [
"openssl"
],
"ext-suggests": [
"sockets"
]
},
"exif": {
"type": "builtin"
},
Expand Down
12 changes: 12 additions & 0 deletions config/lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@
"libavif.a"
]
},
"libevent": {
"source": "libevent",
"static-libs-unix": [
"libevent.a",
"libevent_core.a",
"libevent_extra.a",
"libevent_openssl.a"
],
"lib-depends": [
"openssl"
]
},
"libffi": {
"source": "libffi",
"static-libs-unix": [
Expand Down
26 changes: 18 additions & 8 deletions config/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
"path": "COPYING"
}
},
"ext-event": {
"type": "url",
"url": "https://bitbucket.org/osmanov/pecl-event/get/3.0.8.tar.gz",
"path": "php-src/ext/event",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"ext-zstd": {
"type": "git",
"path": "php-src/ext/zstd",
Expand Down Expand Up @@ -78,6 +87,15 @@
"path": "LICENSE"
}
},
"libevent": {
"type": "ghrel",
"repo": "libevent/libevent",
"match": "libevent.+\\.tar\\.gz",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"libffi": {
"type": "ghrel",
"repo": "libffi/libffi",
Expand Down Expand Up @@ -139,14 +157,6 @@
"path": "COPYING"
}
},
"libuv": {
"type": "ghtar",
"repo": "libuv/libuv",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"libwebp": {
"type": "ghtagtar",
"repo": "webmproject/libwebp",
Expand Down
26 changes: 26 additions & 0 deletions src/SPC/builder/extension/event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace SPC\builder\extension;

use SPC\builder\Extension;
use SPC\util\CustomExt;

#[CustomExt('event')]
class event extends Extension
{
public function getUnixConfigureArg(): 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;
}
}
12 changes: 12 additions & 0 deletions src/SPC/builder/linux/library/libevent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace SPC\builder\linux\library;

class libevent extends LinuxLibraryBase
{
use \SPC\builder\unix\library\libevent;

public const NAME = 'libevent';
}
12 changes: 12 additions & 0 deletions src/SPC/builder/macos/library/libevent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace SPC\builder\macos\library;

class libevent extends MacOSLibraryBase
{
use \SPC\builder\unix\library\libevent;

public const NAME = 'libevent';
}
33 changes: 33 additions & 0 deletions src/SPC/builder/unix/library/libevent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace SPC\builder\unix\library;

use SPC\store\FileSystem;

trait libevent
{
protected function build()
{
// CMake needs a clean build directory
FileSystem::resetDir($this->source_dir . '/build');
// Start build
shell()->cd($this->source_dir . '/build')
->exec(
"{$this->builder->configure_env} cmake " .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DEVENT__LIBRARY_TYPE=STATIC ' .
'-DEVENT__DISABLE_BENCHMARK=ON ' .
'-DEVENT__DISABLE_THREAD_SUPPORT=ON ' .
'-DEVENT__DISABLE_TESTS=ON ' .
'-DEVENT__DISABLE_SAMPLES=ON ' .
'..'
)
->exec("cmake --build . -j {$this->builder->concurrency}")
->exec('make install');
// patch pkgconfig
}
}
4 changes: 4 additions & 0 deletions src/SPC/store/SourcePatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public static function patchPHPConfigure(BuilderBase $builder): void
if ($pdo_sqlite = $builder->getExt('pdo_sqlite')) {
$patch[] = ['pdo_sqlite linking', '/sqlite3_column_table_name=yes/', 'sqlite3_column_table_name=no'];
}
if ($event = $builder->getExt('event')) {
$patch[] = ['event check', '/-levent_openssl/', $event->getLibFilesString()];
}
$patch[] = ['disable capstone', '/have_capstone="yes"/', 'have_capstone="no"'];
foreach ($patch as $item) {
logger()->info('Patching configure: ' . $item[0]);
Expand Down Expand Up @@ -208,5 +211,6 @@ public static function patchPHPAfterConfigure(BuilderBase $param)
FileSystem::replaceFile(SOURCE_PATH . '/php-src/main/php_config.h', REPLACE_FILE_PREG, '/^#define HAVE_STRLCPY 1$/m', '');
FileSystem::replaceFile(SOURCE_PATH . '/php-src/main/php_config.h', REPLACE_FILE_PREG, '/^#define HAVE_STRLCAT 1$/m', '');
}
FileSystem::replaceFile(SOURCE_PATH . '/php-src/main/php_config.h', REPLACE_FILE_PREG, '/^#define HAVE_OPENPTY 1$/m', '');
}
}

0 comments on commit cac3ffc

Please sign in to comment.