change extension to custom

This commit is contained in:
crazywhalecc 2023-04-15 18:45:11 +08:00
parent 6de0d81ea3
commit f95b3bcd4b
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
18 changed files with 409 additions and 178 deletions

View File

@ -4,7 +4,7 @@
}, },
"bz2": { "bz2": {
"type": "builtin", "type": "builtin",
"arg-type": "custom", "arg-type": "with-prefix",
"lib-depends": [ "lib-depends": [
"bzip2" "bzip2"
] ]
@ -17,7 +17,7 @@
}, },
"curl": { "curl": {
"type": "builtin", "type": "builtin",
"arg-type": "with", "arg-type": "custom",
"lib-depends": [ "lib-depends": [
"curl" "curl"
] ]
@ -28,6 +28,7 @@
}, },
"dom": { "dom": {
"type": "builtin", "type": "builtin",
"arg-type": "custom",
"arg-type-windows": "with", "arg-type-windows": "with",
"lib-depends": [ "lib-depends": [
"libxml2", "libxml2",
@ -38,7 +39,7 @@
"type": "builtin" "type": "builtin"
}, },
"ffi": { "ffi": {
"arg-type": "with", "arg-type": "custom",
"type": "builtin", "type": "builtin",
"lib-depends": [ "lib-depends": [
"libffi" "libffi"
@ -58,6 +59,7 @@
}, },
"gd": { "gd": {
"type": "builtin", "type": "builtin",
"arg-type": "custom",
"arg-type-windows": "with", "arg-type-windows": "with",
"lib-depends": [ "lib-depends": [
"zlib", "zlib",
@ -97,14 +99,14 @@
}, },
"gmp": { "gmp": {
"type": "builtin", "type": "builtin",
"arg-type": "none", "arg-type": "with-prefix",
"lib-depends": [ "lib-depends": [
"gmp" "gmp"
] ]
}, },
"iconv": { "iconv": {
"type": "builtin", "type": "builtin",
"arg-type": "custom", "arg-type": "with-prefix",
"lib-depends-windows": [ "lib-depends-windows": [
"libiconv" "libiconv"
] ]
@ -140,6 +142,7 @@
}, },
"mbstring": { "mbstring": {
"type": "builtin", "type": "builtin",
"arg-type": "custom",
"lib-depends": [ "lib-depends": [
"onig" "onig"
] ]
@ -164,7 +167,7 @@
}, },
"openssl": { "openssl": {
"type": "builtin", "type": "builtin",
"arg-type": "with", "arg-type": "custom",
"lib-depends": [ "lib-depends": [
"openssl" "openssl"
] ]
@ -207,7 +210,7 @@
}, },
"phar": { "phar": {
"type": "builtin", "type": "builtin",
"lib-suggests": [ "ext-depends": [
"zlib" "zlib"
] ]
}, },
@ -239,7 +242,8 @@
}, },
"redis": { "redis": {
"type": "external", "type": "external",
"source": "redis" "source": "redis",
"arg-type": "custom"
}, },
"session": { "session": {
"type": "builtin" "type": "builtin"
@ -249,6 +253,7 @@
}, },
"simplexml": { "simplexml": {
"type": "builtin", "type": "builtin",
"arg-type": "custom",
"arg-type-windows": "with", "arg-type-windows": "with",
"lib-depends": [ "lib-depends": [
"libxml2" "libxml2"
@ -263,6 +268,7 @@
}, },
"soap": { "soap": {
"type": "builtin", "type": "builtin",
"arg-type": "custom",
"lib-depends": [ "lib-depends": [
"libxml2" "libxml2"
] ]
@ -279,7 +285,7 @@
}, },
"sqlite3": { "sqlite3": {
"type": "builtin", "type": "builtin",
"arg-type": "with", "arg-type": "custom",
"lib-depends": [ "lib-depends": [
"sqlite" "sqlite"
] ]
@ -287,6 +293,7 @@
"swoole": { "swoole": {
"type": "external", "type": "external",
"source": "swoole", "source": "swoole",
"arg-type": "custom",
"lib-depends": [ "lib-depends": [
"openssl" "openssl"
], ],
@ -305,6 +312,7 @@
"swow": { "swow": {
"type": "external", "type": "external",
"source": "swow", "source": "swow",
"arg-type": "custom",
"lib-suggests": [ "lib-suggests": [
"openssl", "openssl",
"curl" "curl"
@ -338,6 +346,7 @@
}, },
"xml": { "xml": {
"type": "builtin", "type": "builtin",
"arg-type": "custom",
"arg-type-windows": "with", "arg-type-windows": "with",
"lib-depends": [ "lib-depends": [
"libxml2" "libxml2"
@ -345,12 +354,14 @@
}, },
"xmlreader": { "xmlreader": {
"type": "builtin", "type": "builtin",
"arg-type": "custom",
"lib-depends": [ "lib-depends": [
"libxml2" "libxml2"
] ]
}, },
"xmlwriter": { "xmlwriter": {
"type": "builtin", "type": "builtin",
"arg-type": "custom",
"lib-depends": [ "lib-depends": [
"libxml2" "libxml2"
] ]
@ -365,14 +376,14 @@
"yaml": { "yaml": {
"type": "external", "type": "external",
"source": "yaml", "source": "yaml",
"arg-type": "with", "arg-type": "with-prefix",
"lib-depends": [ "lib-depends": [
"libyaml" "libyaml"
] ]
}, },
"zip": { "zip": {
"type": "builtin", "type": "builtin",
"arg-type": "with", "arg-type": "custom",
"arg-type-windows": "enable", "arg-type-windows": "enable",
"lib-depends": [ "lib-depends": [
"libzip" "libzip"
@ -389,6 +400,7 @@
"zstd": { "zstd": {
"type": "external", "type": "external",
"source": "ext-zstd", "source": "ext-zstd",
"arg-type": "custom",
"lib-depends": [ "lib-depends": [
"zstd" "zstd"
] ]

View File

@ -14,8 +14,9 @@ class Extension
protected array $dependencies = []; protected array $dependencies = [];
/** /**
* @throws RuntimeException
* @throws FileSystemException * @throws FileSystemException
* @throws RuntimeException
* @throws WrongUsageException
*/ */
public function __construct(protected string $name, protected BuilderBase $builder) public function __construct(protected string $name, protected BuilderBase $builder)
{ {
@ -34,13 +35,14 @@ class Extension
* 获取开启该扩展的 PHP 编译添加的参数 * 获取开启该扩展的 PHP 编译添加的参数
* *
* @throws FileSystemException|RuntimeException * @throws FileSystemException|RuntimeException
* @throws WrongUsageException
*/ */
public function getConfigureArg(): string public function getConfigureArg(): string
{ {
$arg = $this->getEnableArg(); $arg = $this->getEnableArg();
switch (PHP_OS_FAMILY) { switch (PHP_OS_FAMILY) {
case 'Windows': case 'Windows':
$arg .= $this->getWindowsConfigureArg(); $arg = $this->getWindowsConfigureArg();
break; break;
case 'Darwin': case 'Darwin':
case 'Linux': case 'Linux':
@ -55,15 +57,17 @@ class Extension
* *
* @throws FileSystemException * @throws FileSystemException
* @throws RuntimeException * @throws RuntimeException
* @throws WrongUsageException
*/ */
public function getEnableArg(): string public function getEnableArg(): string
{ {
$_name = str_replace('_', '-', $this->name); $_name = str_replace('_', '-', $this->name);
return match ($arg_type = Config::getExt($this->name, 'arg-type', 'enable')) { return match ($arg_type = Config::getExt($this->name, 'arg-type', 'enable')) {
'enable' => '--enable-' . $_name, 'enable' => '--enable-' . $_name . ' ',
'with' => '--with-' . $_name, 'with' => '--with-' . $_name . ' ',
'with-prefix' => '--with-' . $_name . '="' . BUILD_ROOT_PATH . '" ',
'none', 'custom' => '', 'none', 'custom' => '',
default => throw new WrongUsageException("argType does not accept {$arg_type}, use [enable/with] ."), default => throw new WrongUsageException("argType does not accept {$arg_type}, use [enable/with/with-prefix] ."),
}; };
} }
@ -84,6 +88,7 @@ class Extension
* *
* @throws RuntimeException * @throws RuntimeException
* @throws FileSystemException * @throws FileSystemException
* @throws WrongUsageException
*/ */
public function checkDependency(): static public function checkDependency(): static
{ {
@ -117,10 +122,18 @@ class Extension
*/ */
public function getDistName(): string public function getDistName(): string
{ {
return match ($this->name) { return $this->name;
'mbregex' => 'mbstring', }
default => $this->name,
}; public function getWindowsConfigureArg(): string
{
return '';
// Windows is not supported yet
}
public function getUnixConfigureArg(): string
{
return '';
} }
/** /**
@ -155,164 +168,6 @@ class Extension
} }
} }
private function getWindowsConfigureArg(): string
{
$arg = '';
switch ($this->name) {
case 'redis':
// $arg = '--enable-redis';
// if ($this->builder->getLib('zstd')) {
// $arg .= ' --enable-redis-zstd --with-libzstd ';
// }
break;
case 'xml':
case 'soap':
case 'xmlreader':
case 'xmlwriter':
case 'dom':
$arg .= ' --with-libxml ';
break;
case 'swow':
if ($this->builder->getLib('openssl')) {
$arg .= ' --enable-swow-ssl';
}
if ($this->builder->getLib('curl')) {
$arg .= ' --enable-swow-curl';
}
break;
}
return $arg;
}
private function getUnixConfigureArg(): string
{
$arg = '';
switch ($this->name) {
/*case 'event':
$arg = ' --with-event-core --with-event-libevent-dir="' . BUILD_ROOT_PATH . '"';
if ($this->builder->getLib('openssl')) {
$arg .= ' --with-event-openssl --with-openssl-dir="' . BUILD_ROOT_PATH . '"';
}
break;*/
case 'enchant':
$glibs = [
'/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libgio-2.0.a',
'/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libglib-2.0.a',
'/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libgmodule-2.0.a',
'/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libgobject-2.0.a',
'/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libgthread-2.0.a',
'/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libintl.a',
];
$arg = ' --with-enchant="' . BUILD_ROOT_PATH . '"';
$arg .= ' ENCHANT2_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '/enchant-2"';
$arg .= ' ENCHANT2_LIBS="' . $this->getLibFilesString() . '"';
$arg .= ' GLIB_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '"';
$arg .= ' GLIB_LIBS="' . implode(' ', $glibs) . '"';
break;
case 'iconv':
$arg = ' --with-iconv="' . BUILD_ROOT_PATH . '"';
break;
case 'mbstring':
$arg = ' --disable-mbregex ONIG_CFLAGS=-I"' . BUILD_ROOT_PATH . '" ' .
'ONIG_LIBS="' . $this->getLibFilesString() . '" ';
break;
case 'gmp':
$arg = ' --with-gmp="' . BUILD_ROOT_PATH . '" ';
break;
case 'sqlite3':
$arg = ' --with-sqlite3="' . BUILD_ROOT_PATH . '" ' .
'SQLITE_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'SQLITE_LIBS="' . $this->getLibFilesString() . '" ';
break;
case 'redis':
$arg = ' --enable-redis --disable-redis-session';
if ($this->builder->getLib('zstd')) {
$arg .= ' --enable-redis-zstd --with-libzstd="' . BUILD_ROOT_PATH . '" ';
}
break;
case 'yaml':
$arg .= ' --with-yaml="' . BUILD_ROOT_PATH . '" ';
break;
case 'zstd':
$arg .= ' --with-libzstd';
break;
case 'bz2':
$arg = ' --with-bz2="' . BUILD_ROOT_PATH . '" ';
break;
case 'openssl':
$arg .= ' ' .
'OPENSSL_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'OPENSSL_LIBS="' . $this->getLibFilesString() . '" ';
break;
case 'curl':
$arg .= ' ' .
'CURL_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'CURL_LIBS="' . $this->getLibFilesString() . '" ';
break;
case 'gd':
if ($this->builder->getLib('freetype')) {
$arg .= ' --with-freetype ' .
'FREETYPE2_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '/freetype2" ' .
'FREETYPE2_LIBS="' . $this->getLibFilesString() . '" ';
}
$arg .= ' ' .
'PNG_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'PNG_LIBS="' . $this->getLibFilesString() . '" ';
break;
// TODO: other libraries
case 'phar':
case 'zlib':
$arg .= ' ' .
'ZLIB_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'ZLIB_LIBS="' . $this->getLibFilesString() . '" ';
break;
case 'xml': // xml may use expat
if ($this->getLibraryDependencies()['expat'] ?? null) {
$arg .= ' --with-expat="' . BUILD_ROOT_PATH . '" ' .
'EXPAT_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'EXPAT_LIBS="' . $this->getLibFilesString() . '" ';
break;
}
// no break
case 'soap':
case 'xmlreader':
case 'xmlwriter':
case 'dom':
$arg .= ' --with-libxml="' . BUILD_ROOT_PATH . '" ' .
'LIBXML_CFLAGS=-I"' . realpath('include/libxml2') . '" ' .
'LIBXML_LIBS="' . $this->getLibFilesString() . '" ';
break;
case 'ffi':
$arg .= ' ' .
'FFI_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'FFI_LIBS="' . $this->getLibFilesString() . '" ';
break;
case 'zip':
$arg .= ' ' .
'LIBZIP_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'LIBZIP_LIBS="' . $this->getLibFilesString() . '" ';
break;
case 'mbregex':
$arg .= ' ' .
'ONIG_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'ONIG_LIBS="' . $this->getLibFilesString() . '" ';
break;
case 'swow':
$arg .= $this->builder->getLib('openssl') ? ' --enable-swow-ssl' : ' --disable-swow-ssl';
$arg .= $this->builder->getLib('curl') ? ' --enable-swow-curl' : ' --disable-swow-curl';
break;
case 'swoole':
if ($this->builder->getLib('openssl')) {
$arg .= ' --enable-openssl';
} else {
$arg .= ' --disable-openssl --without-openssl';
}
// curl hook is buggy for static php
$arg .= ' --disable-swoole-curl';
}
return $arg;
}
private function getLibraryDependencies(bool $recursive = false): array private function getLibraryDependencies(bool $recursive = false): array
{ {
$ret = array_filter($this->dependencies, fn ($x) => $x instanceof LibraryBase); $ret = array_filter($this->dependencies, fn ($x) => $x instanceof LibraryBase);

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('curl')]
class curl extends Extension
{
public function getUnixConfigureArg(): string
{
return '--with-curl CURL_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'CURL_LIBS="' . $this->getLibFilesString() . '"';
}
}

View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('enchant')]
class enchant extends Extension
{
public function getUnixConfigureArg(): string
{
$glibs = [
'/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libgio-2.0.a',
'/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libglib-2.0.a',
'/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libgmodule-2.0.a',
'/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libgobject-2.0.a',
'/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libgthread-2.0.a',
'/Users/jerry/project/git-project/static-php-cli/buildroot/lib/libintl.a',
];
$arg = '--with-enchant="' . BUILD_ROOT_PATH . '"';
$arg .= ' ENCHANT2_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '/enchant-2"';
$arg .= ' ENCHANT2_LIBS="' . $this->getLibFilesString() . '"';
$arg .= ' GLIB_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '"';
$arg .= ' GLIB_LIBS="' . implode(' ', $glibs) . '"';
return $arg;
}
}

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('ffi')]
class ffi extends Extension
{
public function getUnixConfigureArg(): string
{
return '--with-ffi FFI_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'FFI_LIBS="' . $this->getLibFilesString() . '"';
}
}

View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('gd')]
class gd extends Extension
{
public function getUnixConfigureArg(): string
{
$arg = '--enable-gd';
if ($this->builder->getLib('freetype')) {
$arg .= ' --with-freetype ' .
'FREETYPE2_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '/freetype2" ' .
'FREETYPE2_LIBS="' . $this->getLibFilesString() . '"';
}
$arg .= ' PNG_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'PNG_LIBS="' . $this->getLibFilesString() . '"';
return $arg;
}
}

View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('mbregex')]
class mbregex extends Extension
{
public function getDistName(): string
{
return 'mbstring';
}
}

View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('mbstring')]
class mbstring extends Extension
{
public function getUnixConfigureArg(): string
{
$arg = '--enable-mbstring';
if ($this->builder->getExt('mbregex') === null) {
$arg .= ' --disable-mbregex';
}
return $arg . ' ONIG_CFLAGS=-I"' . BUILD_ROOT_PATH . '" ONIG_LIBS="' . $this->getLibFilesString() . '"';
}
}

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('openssl')]
class openssl extends Extension
{
public function getUnixConfigureArg(): string
{
return '--with-openssl OPENSSL_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'OPENSSL_LIBS="' . $this->getLibFilesString() . '" ';
}
}

View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('redis')]
class redis extends Extension
{
public function getUnixConfigureArg(): string
{
$arg = '--enable-redis --disable-redis-session';
if ($this->builder->getLib('zstd')) {
$arg .= ' --enable-redis-zstd --with-libzstd="' . BUILD_ROOT_PATH . '"';
}
return $arg;
}
}

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('sqlite3')]
class sqlite3 extends Extension
{
public function getUnixConfigureArg(): string
{
return '--with-sqlite3="' . BUILD_ROOT_PATH . '" ' .
'SQLITE_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'SQLITE_LIBS="' . $this->getLibFilesString() . '"';
}
}

View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('swoole')]
class swoole extends Extension
{
public function getUnixConfigureArg(): string
{
$arg = '--enable-swoole';
if ($this->builder->getLib('openssl')) {
$arg .= ' --enable-openssl';
} else {
$arg .= ' --disable-openssl --without-openssl';
}
// curl hook is buggy for static php
$arg .= ' --disable-swoole-curl';
return $arg;
}
}

View File

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('swow')]
class swow extends Extension
{
public function getUnixConfigureArg(): string
{
$arg = '--enable-swow';
$arg .= $this->builder->getLib('openssl') ? ' --enable-swow-ssl' : ' --disable-swow-ssl';
$arg .= $this->builder->getLib('curl') ? ' --enable-swow-curl' : ' --disable-swow-curl';
return $arg;
}
}

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\exception\RuntimeException;
use SPC\util\CustomExt;
#[CustomExt('xml')]
#[CustomExt('soap')]
#[CustomExt('xmlreader')]
#[CustomExt('xmlwriter')]
#[CustomExt('dom')]
#[CustomExt('simplexml')]
class xml extends Extension
{
/**
* @throws RuntimeException
*/
public function getUnixConfigureArg(): string
{
$arg = match ($this->name) {
'xml' => '--enable-xml',
'soap' => '--enable-soap',
'xmlreader' => '--enable-xmlreader',
'xmlwriter' => '--enable-xmlwriter',
'dom' => '--enable-dom',
'simplexml' => '--enable-simplexml',
default => throw new RuntimeException('Not accept non-xml extension'),
};
$arg .= ' --with-libxml="' . BUILD_ROOT_PATH . '" ' .
'LIBXML_CFLAGS=-I"' . realpath('include/libxml2') . '" ' .
'LIBXML_LIBS="' . $this->getLibFilesString() . '" ';
return $arg;
}
}

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('zip')]
class zip extends Extension
{
public function getUnixConfigureArg(): string
{
return '--with-zip LIBZIP_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'LIBZIP_LIBS="' . $this->getLibFilesString() . '"';
}
}

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('zlib')]
class zlib extends Extension
{
public function getUnixConfigureArg(): string
{
return '--with-zlib ZLIB_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' .
'ZLIB_LIBS="' . $this->getLibFilesString() . '"';
}
}

View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('zstd')]
class zstd extends Extension
{
public function getUnixConfigureArg(): string
{
return '--with-libzstd';
}
}

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace SPC\util;
use SPC\builder\Extension;
use SPC\exception\FileSystemException;
use SPC\store\FileSystem;
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS)]
class CustomExt
{
private static array $custom_ext_class = [];
public function __construct(protected string $ext_name)
{
}
/**
* Load all custom extension classes
*
* @throws \ReflectionException
* @throws FileSystemException
*/
public static function loadCustomExt(): void
{
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/builder/extension', 'SPC\\builder\\extension');
foreach ($classes as $class) {
$reflection = new \ReflectionClass($class);
foreach ($reflection->getAttributes(CustomExt::class) as $attribute) {
self::$custom_ext_class[$attribute->getArguments()[0]] = $class;
}
}
}
public static function getExtClass(string $ext_name): string
{
return self::$custom_ext_class[$ext_name] ?? Extension::class;
}
}