mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 12:54:52 +08:00
Support define php extension arg-type in config
This commit is contained in:
parent
478b85879f
commit
5c7ab48718
20
src/Package/Artifact/gmssl.php
Normal file
20
src/Package/Artifact/gmssl.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Package\Artifact;
|
||||||
|
|
||||||
|
use StaticPHP\Attribute\Artifact\AfterSourceExtract;
|
||||||
|
use StaticPHP\Attribute\PatchDescription;
|
||||||
|
use StaticPHP\Util\FileSystem;
|
||||||
|
|
||||||
|
class gmssl
|
||||||
|
{
|
||||||
|
#[AfterSourceExtract('gmssl')]
|
||||||
|
#[PatchDescription('Patch gmssl hex.c to rename OPENSSL functions to GMSSL')]
|
||||||
|
public function patch(string $target_path): void
|
||||||
|
{
|
||||||
|
FileSystem::replaceFileStr($target_path . '/src/hex.c', 'unsigned char *OPENSSL_hexstr2buf(const char *str, size_t *len)', 'unsigned char *GMSSL_hexstr2buf(const char *str, size_t *len)');
|
||||||
|
FileSystem::replaceFileStr($target_path . '/src/hex.c', 'OPENSSL_hexchar2int', 'GMSSL_hexchar2int');
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/Package/Artifact/libaom.php
Normal file
22
src/Package/Artifact/libaom.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Package\Artifact;
|
||||||
|
|
||||||
|
use StaticPHP\Attribute\Artifact\AfterSourceExtract;
|
||||||
|
use StaticPHP\Attribute\PatchDescription;
|
||||||
|
use StaticPHP\Runtime\SystemTarget;
|
||||||
|
use StaticPHP\Util\SourcePatcher;
|
||||||
|
use StaticPHP\Util\System\LinuxUtil;
|
||||||
|
|
||||||
|
class libaom
|
||||||
|
{
|
||||||
|
#[AfterSourceExtract('libaom')]
|
||||||
|
#[PatchDescription('Patch libaom for Linux Musl distributions - posix implicit declaration')]
|
||||||
|
public function patch(string $target_path): void
|
||||||
|
{
|
||||||
|
spc_skip_if(SystemTarget::getTargetOS() !== 'Linux' || !LinuxUtil::isMuslDist(), 'Only for Linux Musl distros');
|
||||||
|
SourcePatcher::patchFile('libaom_posix_implict.patch', $target_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/Package/Artifact/pkg_config.php
Normal file
19
src/Package/Artifact/pkg_config.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Package\Artifact;
|
||||||
|
|
||||||
|
use StaticPHP\Attribute\Artifact\AfterSourceExtract;
|
||||||
|
use StaticPHP\Attribute\PatchDescription;
|
||||||
|
use StaticPHP\Util\SourcePatcher;
|
||||||
|
|
||||||
|
class pkg_config
|
||||||
|
{
|
||||||
|
#[AfterSourceExtract('pkg-config')]
|
||||||
|
#[PatchDescription('Patch pkg-config for GCC 15 compatibility - __builtin_available issue')]
|
||||||
|
public function patch(string $target_path): void
|
||||||
|
{
|
||||||
|
SourcePatcher::patchFile('pkg-config_gcc15.patch', $target_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
50
src/Package/Extension/openssl.php
Normal file
50
src/Package/Extension/openssl.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Package\Extension;
|
||||||
|
|
||||||
|
use Package\Target\php;
|
||||||
|
use StaticPHP\Attribute\Package\BeforeStage;
|
||||||
|
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
|
||||||
|
use StaticPHP\Attribute\Package\Extension;
|
||||||
|
use StaticPHP\Attribute\PatchDescription;
|
||||||
|
use StaticPHP\Package\PackageBuilder;
|
||||||
|
|
||||||
|
#[Extension('openssl')]
|
||||||
|
class openssl
|
||||||
|
{
|
||||||
|
#[BeforeStage('php', [php::class, 'makeForUnix'], 'ext-openssl')]
|
||||||
|
#[PatchDescription('Patch OpenSSL extension for PHP 8.0 compatibility with OpenSSL 3')]
|
||||||
|
public function patchBeforeMake(): void
|
||||||
|
{
|
||||||
|
// patch openssl3 with php8.0 bug
|
||||||
|
if (php::getPHPVersionID() < 80100) {
|
||||||
|
$openssl_c = file_get_contents(SOURCE_PATH . '/php-src/ext/openssl/openssl.c');
|
||||||
|
$openssl_c = preg_replace('/REGISTER_LONG_CONSTANT\s*\(\s*"OPENSSL_SSLV23_PADDING"\s*.+;/', '', $openssl_c);
|
||||||
|
file_put_contents(SOURCE_PATH . '/php-src/ext/openssl/openssl.c', $openssl_c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[CustomPhpConfigureArg('Darwin')]
|
||||||
|
#[CustomPhpConfigureArg('Linux')]
|
||||||
|
public function getUnixConfigureArg(PackageBuilder $builder, bool $shared = false): string
|
||||||
|
{
|
||||||
|
$openssl_dir = php::getPHPVersionID() >= 80400 ? '' : ' --with-openssl-dir=' . BUILD_ROOT_PATH;
|
||||||
|
$args = '--with-openssl=' . ($shared ? 'shared,' : '') . BUILD_ROOT_PATH . $openssl_dir;
|
||||||
|
if (php::getPHPVersionID() >= 80500 || (php::getPHPVersionID() >= 80400 && !$builder->getOption('enable-zts'))) {
|
||||||
|
$args .= ' --with-openssl-argon2 OPENSSL_LIBS="-lz"';
|
||||||
|
}
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[CustomPhpConfigureArg('Windows')]
|
||||||
|
public function getWindowsConfigureArg(PackageBuilder $builder): string
|
||||||
|
{
|
||||||
|
$args = '--with-openssl';
|
||||||
|
if (php::getPHPVersionID() >= 80500 || (php::getPHPVersionID() >= 80400 && !$builder->getOption('enable-zts'))) {
|
||||||
|
$args .= ' --with-openssl-argon2';
|
||||||
|
}
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -79,7 +79,7 @@ class PhpExtensionPackage extends Package
|
|||||||
return ApplicationContext::invoke($callback, ['shared' => $shared, static::class => $this, Package::class => $this]);
|
return ApplicationContext::invoke($callback, ['shared' => $shared, static::class => $this, Package::class => $this]);
|
||||||
}
|
}
|
||||||
$escapedPath = str_replace("'", '', escapeshellarg(BUILD_ROOT_PATH)) !== BUILD_ROOT_PATH || str_contains(BUILD_ROOT_PATH, ' ') ? escapeshellarg(BUILD_ROOT_PATH) : BUILD_ROOT_PATH;
|
$escapedPath = str_replace("'", '', escapeshellarg(BUILD_ROOT_PATH)) !== BUILD_ROOT_PATH || str_contains(BUILD_ROOT_PATH, ' ') ? escapeshellarg(BUILD_ROOT_PATH) : BUILD_ROOT_PATH;
|
||||||
$name = str_replace('_', '-', $this->getExtensionName());
|
$name = str_replace('_', '-', $this->getName());
|
||||||
$ext_config = PackageConfig::get($name, 'php-extension', []);
|
$ext_config = PackageConfig::get($name, 'php-extension', []);
|
||||||
|
|
||||||
$arg_type = match (SystemTarget::getTargetOS()) {
|
$arg_type = match (SystemTarget::getTargetOS()) {
|
||||||
@ -89,13 +89,22 @@ class PhpExtensionPackage extends Package
|
|||||||
default => $ext_config['arg-type'] ?? 'enable',
|
default => $ext_config['arg-type'] ?? 'enable',
|
||||||
};
|
};
|
||||||
|
|
||||||
return match ($arg_type) {
|
$arg = match ($arg_type) {
|
||||||
'enable' => $shared ? "--enable-{$name}=shared" : "--enable-{$name}",
|
'enable' => $shared ? "--enable-{$name}=shared" : "--enable-{$name}",
|
||||||
'enable-path' => $shared ? "--enable-{$name}=shared,{$escapedPath}" : "--enable-{$name}={$escapedPath}",
|
'enable-path' => $shared ? "--enable-{$name}=shared,{$escapedPath}" : "--enable-{$name}={$escapedPath}",
|
||||||
'with' => $shared ? "--with-{$name}=shared" : "--with-{$name}",
|
'with' => $shared ? "--with-{$name}=shared" : "--with-{$name}",
|
||||||
'with-path' => $shared ? "--with-{$name}=shared,{$escapedPath}" : "--with-{$name}={$escapedPath}",
|
'with-path' => $shared ? "--with-{$name}=shared,{$escapedPath}" : "--with-{$name}={$escapedPath}",
|
||||||
default => throw new WrongUsageException("Unknown argument type '{$arg_type}' for PHP extension '{$name}'"),
|
'custom' => '',
|
||||||
|
default => $arg_type,
|
||||||
};
|
};
|
||||||
|
// customize argument from config string
|
||||||
|
$replace = get_pack_replace();
|
||||||
|
$arg = str_replace(array_values($replace), array_keys($replace), $arg);
|
||||||
|
$replace = [
|
||||||
|
'@shared_suffix@' => $shared ? '=shared' : '',
|
||||||
|
'@shared_path_suffix@' => $shared ? "=shared,{$escapedPath}" : "={$escapedPath}",
|
||||||
|
];
|
||||||
|
return str_replace(array_keys($replace), array_values($replace), $arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBuildShared(bool $build_shared = true): void
|
public function setBuildShared(bool $build_shared = true): void
|
||||||
@ -233,7 +242,7 @@ class PhpExtensionPackage extends Package
|
|||||||
{
|
{
|
||||||
// Add build stages for shared build on Unix-like systems
|
// Add build stages for shared build on Unix-like systems
|
||||||
// TODO: Windows shared build support
|
// TODO: Windows shared build support
|
||||||
if ($this->build_shared && in_array(SystemTarget::getTargetOS(), ['Linux', 'Darwin'])) {
|
if ((PackageConfig::get($this->getName(), 'php-extension')['build-shared'] ?? true) && in_array(SystemTarget::getTargetOS(), ['Linux', 'Darwin'])) {
|
||||||
if (!$this->hasStage('build')) {
|
if (!$this->hasStage('build')) {
|
||||||
$this->addBuildFunction(SystemTarget::getTargetOS(), [$this, 'buildSharedForUnix']);
|
$this->addBuildFunction(SystemTarget::getTargetOS(), [$this, 'buildSharedForUnix']);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user