This commit is contained in:
crazywhalecc 2026-02-06 16:34:51 +08:00
parent cf5a946de1
commit 478b85879f
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
11 changed files with 97 additions and 70 deletions

View File

@ -10,3 +10,5 @@ librabbitmq:
license: MIT
depends:
- openssl
static-libs@unix:
- librabbitmq.a

View File

@ -15,10 +15,6 @@ class bzip2
#[PatchDescription('Patch bzip2 Makefile to add -fPIC flag for position-independent code')]
public function patchBzip2Makefile(Artifact $artifact): void
{
FileSystem::replaceFileStr(
$artifact->getSourceDir() . '/Makefile',
'CFLAGS=-Wall',
'CFLAGS=-fPIC -Wall'
);
FileSystem::replaceFileStr("{$artifact->getSourceDir()}/Makefile", 'CFLAGS=-Wall', 'CFLAGS=-fPIC -Wall');
}
}

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Package\Artifact;
use Package\Target\php;
use StaticPHP\Attribute\Artifact\AfterSourceExtract;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Runtime\SystemTarget;
@ -16,9 +17,8 @@ class php_src
#[PatchDescription('Patch PHP source for libxml2 2.12 compatibility on Alpine Linux')]
public function patchPhpLibxml212(): void
{
$file = file_get_contents(SOURCE_PATH . '/php-src/main/php_version.h');
if (preg_match('/PHP_VERSION_ID (\d+)/', $file, $match) !== 0) {
$ver_id = intval($match[1]);
$ver_id = php::getPHPVersionID(return_null_if_failed: true);
if ($ver_id) {
if ($ver_id < 80000) {
SourcePatcher::patchFile('spc_fix_alpine_build_php80.patch', SOURCE_PATH . '/php-src');
return;
@ -39,9 +39,8 @@ class php_src
#[PatchDescription('Patch GD extension for Windows builds')]
public function patchGDWin32(): void
{
$file = file_get_contents(SOURCE_PATH . '/php-src/main/php_version.h');
if (preg_match('/PHP_VERSION_ID (\d+)/', $file, $match) !== 0) {
$ver_id = intval($match[1]);
$ver_id = php::getPHPVersionID(return_null_if_failed: true);
if ($ver_id) {
if ($ver_id < 80200) {
// see: https://github.com/php/php-src/commit/243966177e39eb71822935042c3f13fa6c5b9eed
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/gd/libgd/gdft.c', '#ifndef MSWIN32', '#ifndef _WIN32');
@ -58,9 +57,8 @@ class php_src
public function patchFfiCentos7FixO3strncmp(): void
{
spc_skip_if(!($ver = SystemTarget::getLibcVersion()) || version_compare($ver, '2.17', '>'));
spc_skip_if(!file_exists(SOURCE_PATH . '/php-src/main/php_version.h'));
$file = file_get_contents(SOURCE_PATH . '/php-src/main/php_version.h');
spc_skip_if(preg_match('/PHP_VERSION_ID (\d+)/', $file, $match) !== 0 && intval($match[1]) < 80316);
$ver_id = php::getPHPVersionID(return_null_if_failed: true);
spc_skip_if($ver_id === null || $ver_id < 80316);
SourcePatcher::patchFile('ffi_centos7_fix_O3_strncmp.patch', SOURCE_PATH . '/php-src');
}

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Package\Command;
use Package\Target\php;
use StaticPHP\Artifact\ArtifactCache;
use StaticPHP\Artifact\ArtifactDownloader;
use StaticPHP\Artifact\DownloaderOptions;
@ -25,7 +26,7 @@ class SwitchPhpVersionCommand extends BaseCommand
$this->addArgument(
'php-version',
InputArgument::REQUIRED,
'PHP version (e.g., 8.4, 8.3, 8.2, 8.1, 8.0, 7.4, or specific like 8.4.5)',
'PHP version (e.g., ' . implode(', ', php::SUPPORTED_MAJOR_VERSIONS) . ' or specific like 8.4.5)',
);
// Downloader options
@ -42,7 +43,7 @@ class SwitchPhpVersionCommand extends BaseCommand
// Validate version format
if (!$this->isValidPhpVersion($php_ver)) {
$this->output->writeln("<error>Invalid PHP version '{$php_ver}'!</error>");
$this->output->writeln('<comment>Supported formats: 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, or specific version like 8.4.5</comment>');
$this->output->writeln('<comment>Supported formats: ' . implode(', ', php::SUPPORTED_MAJOR_VERSIONS) . ', or specific version like 8.4.5</comment>');
return static::FAILURE;
}
@ -101,13 +102,13 @@ class SwitchPhpVersionCommand extends BaseCommand
* Validate PHP version format.
*
* Accepts:
* - Major.Minor format: 7.4, 8.0, 8.1, 8.2, 8.3, 8.4
* - Full version format: 8.4.5, 8.3.12, etc.
* - Major.Minor format, e.g. 7.4
* - Full version format, e.g. 8.4.5, 8.3.12, etc.
*/
private function isValidPhpVersion(string $version): bool
{
// Check major.minor format (e.g., 8.4)
if (in_array($version, ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'], true)) {
if (in_array($version, php::SUPPORTED_MAJOR_VERSIONS, true)) {
return true;
}

View File

@ -43,18 +43,34 @@ class php extends TargetPackage
use unix;
use windows;
public static function getPHPVersionID(): int
/** @var string[] Supported major PHP versions */
public const array SUPPORTED_MAJOR_VERSIONS = ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'];
/**
* Get PHP version ID from php_version.h
*
* @param null|string $from_custom_source Where to read php_version.h from custom source
* @param bool $return_null_if_failed Whether to return null if failed to get version ID
* @return null|int PHP version ID (e.g., 80400 for PHP 8.4.0) or null if failed
*/
public static function getPHPVersionID(?string $from_custom_source = null, bool $return_null_if_failed = false): ?int
{
$artifact = ArtifactLoader::getArtifactInstance('php-src');
if (!file_exists("{$artifact->getSourceDir()}/main/php_version.h")) {
$source_dir = $from_custom_source ?? ArtifactLoader::getArtifactInstance('php-src')->getSourceDir();
if (!file_exists("{$source_dir}/main/php_version.h")) {
if ($return_null_if_failed) {
return null;
}
throw new WrongUsageException('PHP source files are not available, you need to download them first');
}
$file = file_get_contents("{$artifact->getSourceDir()}/main/php_version.h");
$file = file_get_contents("{$source_dir}/main/php_version.h");
if (preg_match('/PHP_VERSION_ID (\d+)/', $file, $match) !== 0) {
return intval($match[1]);
}
if ($return_null_if_failed) {
return null;
}
throw new WrongUsageException('PHP version file format is malformed, please remove "./source/php-src" dir and download/extract again');
}

View File

@ -262,7 +262,7 @@ trait unix
UnixUtil::exportDynamicSymbols($libphp_a);
// deploy embed php scripts
$package->runStage([$this, 'patchEmbedScripts']);
$package->runStage([$this, 'patchUnixEmbedScripts']);
}
#[Stage]

View File

@ -40,6 +40,6 @@ class pkgconfig
)
->make(with_install: 'install-exec');
shell()->exec('strip ' . BUILD_ROOT_PATH . '/bin/pkg-config');
shell()->exec("strip {$package->getBinDir()}/pkg-config");
}
}

View File

@ -18,22 +18,22 @@ class SourcePatcher
public static function init(): void
{
// FileSystem::addSourceExtractHook('swow', [__CLASS__, 'patchSwow']);
FileSystem::addSourceExtractHook('openssl', [__CLASS__, 'patchOpenssl11Darwin']);
FileSystem::addSourceExtractHook('openssl', [__CLASS__, 'patchOpenssl11Darwin']); // migrated
FileSystem::addSourceExtractHook('swoole', [__CLASS__, 'patchSwoole']);
FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchPhpLibxml212']);
FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchGDWin32']);
FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchFfiCentos7FixO3strncmp']);
FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchPhpLibxml212']); // migrated
FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchGDWin32']); // migrated
FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchFfiCentos7FixO3strncmp']); // migrated
FileSystem::addSourceExtractHook('sqlsrv', [__CLASS__, 'patchSQLSRVWin32']);
FileSystem::addSourceExtractHook('pdo_sqlsrv', [__CLASS__, 'patchSQLSRVWin32']);
FileSystem::addSourceExtractHook('pdo_sqlsrv', [__CLASS__, 'patchSQLSRVPhp85']);
FileSystem::addSourceExtractHook('yaml', [__CLASS__, 'patchYamlWin32']);
FileSystem::addSourceExtractHook('libyaml', [__CLASS__, 'patchLibYaml']);
FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchImapLicense']);
FileSystem::addSourceExtractHook('libyaml', [__CLASS__, 'patchLibYaml']); // removed
FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchImapLicense']); // migrated
FileSystem::addSourceExtractHook('ext-imagick', [__CLASS__, 'patchImagickWith84']);
FileSystem::addSourceExtractHook('libaom', [__CLASS__, 'patchLibaomForAlpine']);
FileSystem::addSourceExtractHook('pkg-config', [__CLASS__, 'patchPkgConfigForGcc15']);
FileSystem::addSourceExtractHook('attr', [__CLASS__, 'patchAttrForAlpine']);
FileSystem::addSourceExtractHook('gmssl', [__CLASS__, 'patchGMSSL']);
FileSystem::addSourceExtractHook('libaom', [__CLASS__, 'patchLibaomForAlpine']); // migrated
FileSystem::addSourceExtractHook('pkg-config', [__CLASS__, 'patchPkgConfigForGcc15']); // migrated
FileSystem::addSourceExtractHook('attr', [__CLASS__, 'patchAttrForAlpine']); // migrated
FileSystem::addSourceExtractHook('gmssl', [__CLASS__, 'patchGMSSL']); // migrated
}
public static function patchBeforeBuildconf(BuilderBase $builder): void

View File

@ -14,6 +14,7 @@ use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\DependencyResolver;
use StaticPHP\Util\DirDiff;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\GlobalPathTrait;
use StaticPHP\Util\SPCConfigUtil;
/**
@ -21,6 +22,8 @@ use StaticPHP\Util\SPCConfigUtil;
*/
class LibraryPackage extends Package
{
use GlobalPathTrait;
/**
* Custom postinstall actions for this package.
* @var array<array>
@ -369,41 +372,6 @@ class LibraryPackage extends Package
return getenv($this->getSnakeCaseName() . '_LIBS') ?: '';
}
/**
* Get the build root path for the package.
*
* TODO: Can be changed to support per-package build root path in the future.
*/
public function getBuildRootPath(): string
{
return BUILD_ROOT_PATH;
}
/**
* Get the include directory for the package.
*
* TODO: Can be changed to support per-package include directory in the future.
*/
public function getIncludeDir(): string
{
return BUILD_INCLUDE_PATH;
}
/**
* Get the library directory for the package.
*
* TODO: Can be changed to support per-package library directory in the future.
*/
public function getLibDir(): string
{
return BUILD_LIB_PATH;
}
public function getBinDir(): string
{
return BUILD_BIN_PATH;
}
/**
* Get tar compress options from suffix
*

View File

@ -11,11 +11,14 @@ use StaticPHP\Exception\WrongUsageException;
use StaticPHP\Runtime\Shell\Shell;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\GlobalPathTrait;
use StaticPHP\Util\InteractiveTerm;
use StaticPHP\Util\System\LinuxUtil;
class PackageBuilder
{
use GlobalPathTrait;
/** @var int make jobs count */
public readonly int $concurrency;

View File

@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Util;
trait GlobalPathTrait
{
/**
* Get the build root path for the package.
*
* TODO: Can be changed to support per-package build root path in the future.
*/
public function getBuildRootPath(): string
{
return BUILD_ROOT_PATH;
}
/**
* Get the include directory for the package.
*
* TODO: Can be changed to support per-package include directory in the future.
*/
public function getIncludeDir(): string
{
return BUILD_INCLUDE_PATH;
}
/**
* Get the library directory for the package.
*
* TODO: Can be changed to support per-package library directory in the future.
*/
public function getLibDir(): string
{
return BUILD_LIB_PATH;
}
public function getBinDir(): string
{
return BUILD_BIN_PATH;
}
}