mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 12:54:52 +08:00
Merge remote-tracking branch 'origin/v3-refactor/new-extensions' into v3-refactor/new-extensions
This commit is contained in:
commit
e9023520de
@ -134,6 +134,19 @@ ext-mysqlnd:
|
|||||||
arg-type@unix: enable
|
arg-type@unix: enable
|
||||||
arg-type@windows: with
|
arg-type@windows: with
|
||||||
build-with-php: true
|
build-with-php: true
|
||||||
|
ext-odbc:
|
||||||
|
type: php-extension
|
||||||
|
depends@unix:
|
||||||
|
- unixodbc
|
||||||
|
php-extension:
|
||||||
|
arg-type@unix: '--with-unixODBC@shared_path_suffix@'
|
||||||
|
ext-opcache:
|
||||||
|
type: php-extension
|
||||||
|
php-extension:
|
||||||
|
arg-type@unix: custom
|
||||||
|
arg-type@windows: enable
|
||||||
|
zend-extension: true
|
||||||
|
display-name: 'Zend Opcache'
|
||||||
ext-openssl:
|
ext-openssl:
|
||||||
type: php-extension
|
type: php-extension
|
||||||
depends:
|
depends:
|
||||||
|
|||||||
21
config/pkg/ext/ext-mongodb.yml
Normal file
21
config/pkg/ext/ext-mongodb.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
ext-mongodb:
|
||||||
|
type: php-extension
|
||||||
|
artifact:
|
||||||
|
source:
|
||||||
|
type: ghrel
|
||||||
|
repo: mongodb/mongo-php-driver
|
||||||
|
match: mongodb.+\.tgz
|
||||||
|
extract: php-src/ext/mongodb
|
||||||
|
metadata:
|
||||||
|
license-files: [LICENSE]
|
||||||
|
license: PHP-3.01
|
||||||
|
suggests:
|
||||||
|
- icu
|
||||||
|
- openssl
|
||||||
|
- zstd
|
||||||
|
- zlib
|
||||||
|
frameworks:
|
||||||
|
- CoreFoundation
|
||||||
|
- Security
|
||||||
|
php-extension:
|
||||||
|
arg-type: custom
|
||||||
17
config/pkg/ext/ext-mysqlnd_parsec.yml
Normal file
17
config/pkg/ext/ext-mysqlnd_parsec.yml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
ext-mysqlnd_parsec:
|
||||||
|
type: php-extension
|
||||||
|
artifact:
|
||||||
|
source:
|
||||||
|
type: pie
|
||||||
|
repo: mariadb/mysqlnd_parsec
|
||||||
|
extract: php-src/ext/mysqlnd_parsec
|
||||||
|
metadata:
|
||||||
|
license-files: [LICENSE]
|
||||||
|
license: BSD-3-Clause
|
||||||
|
depends:
|
||||||
|
- ext-mysqlnd
|
||||||
|
- libsodium
|
||||||
|
- openssl
|
||||||
|
php-extension:
|
||||||
|
arg-type: '--enable-mysqlnd_parsec'
|
||||||
|
build-static: false
|
||||||
9
config/pkg/ext/ext-opentelemetry.yml
Normal file
9
config/pkg/ext/ext-opentelemetry.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
ext-opentelemetry:
|
||||||
|
type: php-extension
|
||||||
|
artifact:
|
||||||
|
source:
|
||||||
|
type: pecl
|
||||||
|
name: opentelemetry
|
||||||
|
metadata:
|
||||||
|
license-files: [LICENSE]
|
||||||
|
license: Apache-2.0
|
||||||
9
config/pkg/ext/ext-parallel.yml
Normal file
9
config/pkg/ext/ext-parallel.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
ext-parallel:
|
||||||
|
type: php-extension
|
||||||
|
artifact:
|
||||||
|
source:
|
||||||
|
type: pecl
|
||||||
|
name: parallel
|
||||||
|
metadata:
|
||||||
|
license-files: [LICENSE]
|
||||||
|
license: PHP-3.01
|
||||||
38
src/Package/Extension/mongodb.php
Normal file
38
src/Package/Extension/mongodb.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Package\Extension;
|
||||||
|
|
||||||
|
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
|
||||||
|
use StaticPHP\Attribute\Package\Extension;
|
||||||
|
use StaticPHP\Package\PackageInstaller;
|
||||||
|
use StaticPHP\Package\PhpExtensionPackage;
|
||||||
|
|
||||||
|
#[Extension('mongodb')]
|
||||||
|
class mongodb extends PhpExtensionPackage
|
||||||
|
{
|
||||||
|
#[CustomPhpConfigureArg('Darwin')]
|
||||||
|
#[CustomPhpConfigureArg('Linux')]
|
||||||
|
public function getUnixConfigureArg(bool $shared, PackageInstaller $installer): string
|
||||||
|
{
|
||||||
|
$arg = ' --enable-mongodb' . ($shared ? '=shared' : '') . ' ';
|
||||||
|
$arg .= ' --with-mongodb-system-libs=no --with-mongodb-client-side-encryption=no ';
|
||||||
|
$arg .= ' --with-mongodb-sasl=no ';
|
||||||
|
if ($installer->getLibraryPackage('openssl')) {
|
||||||
|
$arg .= '--with-mongodb-ssl=openssl';
|
||||||
|
}
|
||||||
|
$arg .= $installer->getLibraryPackage('icu') ? ' --with-mongodb-icu=yes ' : ' --with-mongodb-icu=no ';
|
||||||
|
$arg .= $installer->getLibraryPackage('zstd') ? ' --with-mongodb-zstd=yes ' : ' --with-mongodb-zstd=no ';
|
||||||
|
// $arg .= $installer->getLibraryPackage('snappy') ? ' --with-mongodb-snappy=yes ' : ' --with-mongodb-snappy=no ';
|
||||||
|
$arg .= $installer->getLibraryPackage('zlib') ? ' --with-mongodb-zlib=yes ' : ' --with-mongodb-zlib=bundled ';
|
||||||
|
return clean_spaces($arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSharedExtensionEnv(): array
|
||||||
|
{
|
||||||
|
$parent = parent::getSharedExtensionEnv();
|
||||||
|
$parent['CFLAGS'] .= ' -std=c17';
|
||||||
|
return $parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
76
src/Package/Extension/opcache.php
Normal file
76
src/Package/Extension/opcache.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?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\Package\Validate;
|
||||||
|
use StaticPHP\Attribute\PatchDescription;
|
||||||
|
use StaticPHP\Exception\WrongUsageException;
|
||||||
|
use StaticPHP\Package\PackageBuilder;
|
||||||
|
use StaticPHP\Package\PackageInstaller;
|
||||||
|
use StaticPHP\Package\PhpExtensionPackage;
|
||||||
|
use StaticPHP\Runtime\SystemTarget;
|
||||||
|
use StaticPHP\Util\SourcePatcher;
|
||||||
|
|
||||||
|
#[Extension('opcache')]
|
||||||
|
class opcache extends PhpExtensionPackage
|
||||||
|
{
|
||||||
|
#[Validate]
|
||||||
|
public function validate(): void
|
||||||
|
{
|
||||||
|
if (php::getPHPVersionID() < 80000 && getenv('SPC_SKIP_PHP_VERSION_CHECK') !== 'yes') {
|
||||||
|
throw new WrongUsageException('Statically compiled PHP with Zend Opcache only available for PHP >= 8.0 !');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-opcache')]
|
||||||
|
#[PatchDescription('Fix static opcache build for PHP 8.2.0 to 8.4.x')]
|
||||||
|
public function patchBeforeBuildconf(PackageInstaller $installer): bool
|
||||||
|
{
|
||||||
|
$version = php::getPHPVersion();
|
||||||
|
$php_src = $installer->getTargetPackage('php')->getSourceDir();
|
||||||
|
if (file_exists("{$php_src}/.opcache_patched")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// if 8.2.0 <= PHP_VERSION < 8.2.23, we need to patch from legacy patch file
|
||||||
|
if (version_compare($version, '8.2.0', '>=') && version_compare($version, '8.2.23', '<')) {
|
||||||
|
SourcePatcher::patchFile('spc_fix_static_opcache_before_80222.patch', $php_src);
|
||||||
|
}
|
||||||
|
// if 8.3.0 <= PHP_VERSION < 8.3.11, we need to patch from legacy patch file
|
||||||
|
elseif (version_compare($version, '8.3.0', '>=') && version_compare($version, '8.3.11', '<')) {
|
||||||
|
SourcePatcher::patchFile('spc_fix_static_opcache_before_80310.patch', $php_src);
|
||||||
|
}
|
||||||
|
// if 8.3.12 <= PHP_VERSION < 8.5.0-dev, we need to patch from legacy patch file
|
||||||
|
elseif (version_compare($version, '8.5.0-dev', '<')) {
|
||||||
|
SourcePatcher::patchPhpSrc(items: ['static_opcache']);
|
||||||
|
}
|
||||||
|
// PHP 8.5.0-dev and later supports static opcache without patching
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return file_put_contents($php_src . '/.opcache_patched', '1') !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[CustomPhpConfigureArg('Darwin')]
|
||||||
|
#[CustomPhpConfigureArg('Linux')]
|
||||||
|
public function getUnixConfigureArg(bool $shared, PackageBuilder $builder): string
|
||||||
|
{
|
||||||
|
$phpVersionID = php::getPHPVersionID();
|
||||||
|
$opcache_jit = ' --enable-opcache-jit';
|
||||||
|
if ((SystemTarget::getTargetOS() === 'Linux' &&
|
||||||
|
SystemTarget::getLibc() === 'musl' &&
|
||||||
|
$builder->getOption('enable-zts') &&
|
||||||
|
SystemTarget::getTargetArch() === 'x86_64' &&
|
||||||
|
$phpVersionID < 80500) ||
|
||||||
|
$builder->getOption('disable-opcache-jit')
|
||||||
|
) {
|
||||||
|
$opcache_jit = ' --disable-opcache-jit';
|
||||||
|
}
|
||||||
|
return '--enable-opcache' . ($shared ? '=shared' : '') . $opcache_jit;
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/Package/Extension/opentelemetry.php
Normal file
21
src/Package/Extension/opentelemetry.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Package\Extension;
|
||||||
|
|
||||||
|
use Package\Target\php;
|
||||||
|
use StaticPHP\Attribute\Package\BeforeStage;
|
||||||
|
use StaticPHP\Attribute\Package\Extension;
|
||||||
|
use StaticPHP\Util\GlobalEnvManager;
|
||||||
|
|
||||||
|
#[Extension('opentelemetry')]
|
||||||
|
class opentelemetry
|
||||||
|
{
|
||||||
|
#[BeforeStage('php', [php::class, 'makeForUnix'], 'ext-opentelemetry')]
|
||||||
|
public function patchBeforeMake(): void
|
||||||
|
{
|
||||||
|
// add -Wno-strict-prototypes
|
||||||
|
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -Wno-strict-prototypes');
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/Package/Extension/parallel.php
Normal file
35
src/Package/Extension/parallel.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Package\Extension;
|
||||||
|
|
||||||
|
use Package\Target\php;
|
||||||
|
use StaticPHP\Attribute\Package\BeforeStage;
|
||||||
|
use StaticPHP\Attribute\Package\Extension;
|
||||||
|
use StaticPHP\Attribute\Package\Validate;
|
||||||
|
use StaticPHP\Attribute\PatchDescription;
|
||||||
|
use StaticPHP\Exception\WrongUsageException;
|
||||||
|
use StaticPHP\Package\PackageBuilder;
|
||||||
|
use StaticPHP\Package\PhpExtensionPackage;
|
||||||
|
use StaticPHP\Util\FileSystem;
|
||||||
|
|
||||||
|
#[Extension('parallel')]
|
||||||
|
class parallel extends PhpExtensionPackage
|
||||||
|
{
|
||||||
|
#[Validate]
|
||||||
|
public function validate(PackageBuilder $builder): void
|
||||||
|
{
|
||||||
|
if (!$builder->getOption('enable-zts')) {
|
||||||
|
throw new WrongUsageException('ext-parallel must be built with ZTS builds. Use "--enable-zts" option!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-parallel')]
|
||||||
|
#[PatchDescription('Fix parallel m4 hardcoded PHP_VERSION check')]
|
||||||
|
public function patchBeforeBuildconf(): bool
|
||||||
|
{
|
||||||
|
FileSystem::replaceFileRegex("{$this->getSourceDir()}/config.m4", '/PHP_VERSION=.*/m', '');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -32,10 +32,14 @@ use ZM\Logger\ConsoleColor;
|
|||||||
trait unix
|
trait unix
|
||||||
{
|
{
|
||||||
#[BeforeStage('php', [self::class, 'buildconfForUnix'], 'php')]
|
#[BeforeStage('php', [self::class, 'buildconfForUnix'], 'php')]
|
||||||
|
#[PatchDescription('Patch SPC_MICRO_PATCHES defined patches (e.g. cli_checks, disable_huge_page)')]
|
||||||
#[PatchDescription('Patch configure.ac for musl and musl-toolchain')]
|
#[PatchDescription('Patch configure.ac for musl and musl-toolchain')]
|
||||||
#[PatchDescription('Let php m4 tools use static pkg-config')]
|
#[PatchDescription('Let php m4 tools use static pkg-config')]
|
||||||
public function patchBeforeBuildconf(TargetPackage $package): void
|
public function patchBeforeBuildconf(TargetPackage $package): void
|
||||||
{
|
{
|
||||||
|
// php-src patches from micro (reads SPC_MICRO_PATCHES env var)
|
||||||
|
SourcePatcher::patchPhpSrc();
|
||||||
|
|
||||||
// patch configure.ac for musl and musl-toolchain
|
// patch configure.ac for musl and musl-toolchain
|
||||||
$musl = SystemTarget::getTargetOS() === 'Linux' && SystemTarget::getLibc() === 'musl';
|
$musl = SystemTarget::getTargetOS() === 'Linux' && SystemTarget::getLibc() === 'musl';
|
||||||
FileSystem::backupFile(SOURCE_PATH . '/php-src/configure.ac');
|
FileSystem::backupFile(SOURCE_PATH . '/php-src/configure.ac');
|
||||||
@ -47,6 +51,7 @@ trait unix
|
|||||||
|
|
||||||
// let php m4 tools use static pkg-config
|
// let php m4 tools use static pkg-config
|
||||||
FileSystem::replaceFileStr("{$package->getSourceDir()}/build/php.m4", 'PKG_CHECK_MODULES(', 'PKG_CHECK_MODULES_STATIC(');
|
FileSystem::replaceFileStr("{$package->getSourceDir()}/build/php.m4", 'PKG_CHECK_MODULES(', 'PKG_CHECK_MODULES_STATIC(');
|
||||||
|
|
||||||
// also patch extension config.m4 files (they call PKG_CHECK_MODULES directly, not via php.m4)
|
// also patch extension config.m4 files (they call PKG_CHECK_MODULES directly, not via php.m4)
|
||||||
foreach (glob("{$package->getSourceDir()}/ext/*/*.m4") as $m4file) {
|
foreach (glob("{$package->getSourceDir()}/ext/*/*.m4") as $m4file) {
|
||||||
FileSystem::replaceFileStr($m4file, 'PKG_CHECK_MODULES(', 'PKG_CHECK_MODULES_STATIC(');
|
FileSystem::replaceFileStr($m4file, 'PKG_CHECK_MODULES(', 'PKG_CHECK_MODULES_STATIC(');
|
||||||
@ -156,6 +161,25 @@ trait unix
|
|||||||
shell()->cd(SOURCE_PATH . '/php-src')->exec('sed -i "s|//lib|/lib|g" Makefile');
|
shell()->cd(SOURCE_PATH . '/php-src')->exec('sed -i "s|//lib|/lib|g" Makefile');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[BeforeStage('php', [self::class, 'makeForUnix'], 'php')]
|
||||||
|
#[PatchDescription('Patch info.c to hide configure command in release builds')]
|
||||||
|
public function patchInfoCForRelease(): void
|
||||||
|
{
|
||||||
|
if (str_contains((string) getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'), '-release')) {
|
||||||
|
FileSystem::replaceFileLineContainsString(
|
||||||
|
SOURCE_PATH . '/php-src/ext/standard/info.c',
|
||||||
|
'#ifdef CONFIGURE_COMMAND',
|
||||||
|
'#ifdef NO_CONFIGURE_COMMAND',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
FileSystem::replaceFileLineContainsString(
|
||||||
|
SOURCE_PATH . '/php-src/ext/standard/info.c',
|
||||||
|
'#ifdef NO_CONFIGURE_COMMAND',
|
||||||
|
'#ifdef CONFIGURE_COMMAND',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[Stage]
|
#[Stage]
|
||||||
public function makeForUnix(TargetPackage $package, PackageInstaller $installer): void
|
public function makeForUnix(TargetPackage $package, PackageInstaller $installer): void
|
||||||
{
|
{
|
||||||
|
|||||||
@ -209,9 +209,6 @@ class SourcePatcher
|
|||||||
$patch_dir = $tmp_dir;
|
$patch_dir = $tmp_dir;
|
||||||
}
|
}
|
||||||
$php_package = PackageLoader::getTargetPackage('php');
|
$php_package = PackageLoader::getTargetPackage('php');
|
||||||
if (!file_exists("{$php_package->getSourceDir()}/sapi/micro/php_micro.c")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$ver_file = "{$php_package->getSourceDir()}/main/php_version.h";
|
$ver_file = "{$php_package->getSourceDir()}/main/php_version.h";
|
||||||
if (!file_exists($ver_file)) {
|
if (!file_exists($ver_file)) {
|
||||||
throw new PatchException('php-src patcher (original micro patches)', 'Patch failed, cannot find php source files');
|
throw new PatchException('php-src patcher (original micro patches)', 'Patch failed, cannot find php source files');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user