mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-10 02:15:36 +08:00
Compare commits
20 Commits
fe4803cfaf
...
v3c/llvm-t
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6df778f92f | ||
|
|
582a88ef60 | ||
|
|
153003b75c | ||
|
|
899555a964 | ||
|
|
891a222c39 | ||
|
|
39beb68024 | ||
|
|
0807e9e253 | ||
|
|
1a779be028 | ||
|
|
bdfd3eb269 | ||
|
|
7ae5d742c2 | ||
|
|
95be291a84 | ||
|
|
d89add106a | ||
|
|
a36129c6cd | ||
|
|
3f3edd62a1 | ||
|
|
82b77af317 | ||
|
|
df26b93e58 | ||
|
|
d1b4c05381 | ||
|
|
e1658bc0e6 | ||
|
|
5053620b61 | ||
|
|
9366cbacd9 |
@@ -5,7 +5,7 @@
|
|||||||
[](https://github.com/crazywhalecc/static-php-cli/releases)
|
[](https://github.com/crazywhalecc/static-php-cli/releases)
|
||||||
[](https://github.com/crazywhalecc/static-php-cli/actions/workflows/tests.yml)
|
[](https://github.com/crazywhalecc/static-php-cli/actions/workflows/tests.yml)
|
||||||
[](https://github.com/crazywhalecc/static-php-cli/blob/main/LICENSE)
|
[](https://github.com/crazywhalecc/static-php-cli/blob/main/LICENSE)
|
||||||
[](https://discord.gg/nrSRbpMJ)
|
[](https://discord.gg/xf6Rd4pEAk)
|
||||||
|
|
||||||
**StaticPHP** 是一个强大的工具,用于构建可移植的可执行文件,包括 PHP、扩展等。
|
**StaticPHP** 是一个强大的工具,用于构建可移植的可执行文件,包括 PHP、扩展等。
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
[](https://github.com/crazywhalecc/static-php-cli/releases)
|
[](https://github.com/crazywhalecc/static-php-cli/releases)
|
||||||
[](https://github.com/crazywhalecc/static-php-cli/actions/workflows/tests.yml)
|
[](https://github.com/crazywhalecc/static-php-cli/actions/workflows/tests.yml)
|
||||||
[](https://github.com/crazywhalecc/static-php-cli/blob/main/LICENSE)
|
[](https://github.com/crazywhalecc/static-php-cli/blob/main/LICENSE)
|
||||||
[](https://discord.gg/nrSRbpMJ)
|
[](https://discord.gg/xf6Rd4pEAk)
|
||||||
|
|
||||||
**StaticPHP** is a powerful tool designed for building portable executables including PHP, extensions, and more.
|
**StaticPHP** is a powerful tool designed for building portable executables including PHP, extensions, and more.
|
||||||
|
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ ext-password-argon2:
|
|||||||
type: php-extension
|
type: php-extension
|
||||||
depends:
|
depends:
|
||||||
- libargon2
|
- libargon2
|
||||||
|
suggests:
|
||||||
- ext-openssl
|
- ext-openssl
|
||||||
php-extension:
|
php-extension:
|
||||||
os:
|
os:
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ gettext-win:
|
|||||||
source:
|
source:
|
||||||
type: git
|
type: git
|
||||||
url: 'https://github.com/winlibs/gettext.git'
|
url: 'https://github.com/winlibs/gettext.git'
|
||||||
rev: master
|
rev: '0.18'
|
||||||
static-libs@windows:
|
static-libs@windows:
|
||||||
- libintl_a.lib
|
- libintl_a.lib
|
||||||
|
|||||||
6
config/pkg/target/llvm-tools.yml
Normal file
6
config/pkg/target/llvm-tools.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
llvm-tools:
|
||||||
|
type: target
|
||||||
|
artifact:
|
||||||
|
binary: custom
|
||||||
|
depends:
|
||||||
|
- zig
|
||||||
@@ -47,7 +47,7 @@ Build your CLI with [symfony/console](https://symfony.com/doc/current/components
|
|||||||
|
|
||||||
## Community
|
## Community
|
||||||
|
|
||||||
Join our [Discord server](https://discord.gg/nrSRbpMJ) to ask questions, share your builds, and connect with other StaticPHP users.
|
Join our [Discord server](https://discord.gg/xf6Rd4pEAk) to ask questions, share your builds, and connect with other StaticPHP users.
|
||||||
|
|
||||||
## Next steps
|
## Next steps
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ StaticPHP 支持将 FrankenPHP 连同所需扩展一起静态编译,
|
|||||||
|
|
||||||
## 社区
|
## 社区
|
||||||
|
|
||||||
加入我们的 [Discord 服务器](https://discord.gg/nrSRbpMJ),提问、分享构建成果,与其他 StaticPHP 用户交流。
|
加入我们的 [Discord 服务器](https://discord.gg/xf6Rd4pEAk),提问、分享构建成果,与其他 StaticPHP 用户交流。
|
||||||
|
|
||||||
## 接下来
|
## 接下来
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ class go_win
|
|||||||
])]
|
])]
|
||||||
public function downBinary(ArtifactDownloader $downloader): DownloadResult
|
public function downBinary(ArtifactDownloader $downloader): DownloadResult
|
||||||
{
|
{
|
||||||
$pkgroot = PKG_ROOT_PATH;
|
|
||||||
|
|
||||||
// get version
|
// get version
|
||||||
[$version] = explode("\n", default_shell()->executeCurl('https://go.dev/VERSION?m=text', retries: $downloader->getRetry()) ?: '');
|
[$version] = explode("\n", default_shell()->executeCurl('https://go.dev/VERSION?m=text', retries: $downloader->getRetry()) ?: '');
|
||||||
if ($version === '') {
|
if ($version === '') {
|
||||||
@@ -52,7 +50,7 @@ class go_win
|
|||||||
throw new DownloaderException("Hash mismatch for downloaded go-win binary. Expected {$hash}, got {$file_hash}");
|
throw new DownloaderException("Hash mismatch for downloaded go-win binary. Expected {$hash}, got {$file_hash}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return DownloadResult::archive(basename($path), ['url' => $url, 'version' => $version], extract: "{$pkgroot}/go-win", verified: true, version: $version);
|
return DownloadResult::archive(basename($path), ['url' => $url, 'version' => $version], extract: '{pkg_root_path}/go-win', verified: true, version: $version);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[CustomBinaryCheckUpdate('go-win', ['windows-x86_64'])]
|
#[CustomBinaryCheckUpdate('go-win', ['windows-x86_64'])]
|
||||||
|
|||||||
162
src/Package/Artifact/llvm_tools.php
Normal file
162
src/Package/Artifact/llvm_tools.php
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Package\Artifact;
|
||||||
|
|
||||||
|
use StaticPHP\Artifact\ArtifactDownloader;
|
||||||
|
use StaticPHP\Artifact\Downloader\DownloadResult;
|
||||||
|
use StaticPHP\Artifact\Downloader\Type\CheckUpdateResult;
|
||||||
|
use StaticPHP\Artifact\Downloader\Type\GitHubTokenSetupTrait;
|
||||||
|
use StaticPHP\Attribute\Artifact\AfterBinaryExtract;
|
||||||
|
use StaticPHP\Attribute\Artifact\CustomBinary;
|
||||||
|
use StaticPHP\Attribute\Artifact\CustomBinaryCheckUpdate;
|
||||||
|
use StaticPHP\DI\ApplicationContext;
|
||||||
|
use StaticPHP\Exception\BuildFailureException;
|
||||||
|
use StaticPHP\Exception\DownloaderException;
|
||||||
|
use StaticPHP\Package\PackageBuilder;
|
||||||
|
|
||||||
|
class llvm_tools
|
||||||
|
{
|
||||||
|
use GitHubTokenSetupTrait;
|
||||||
|
|
||||||
|
public const array TOOLS = ['llvm-objcopy', 'llvm-strip', 'llvm-profdata'];
|
||||||
|
|
||||||
|
/** Install prefix for the locally-built llvm-tools. */
|
||||||
|
public static function path(): string
|
||||||
|
{
|
||||||
|
return PKG_ROOT_PATH . '/llvm-tools';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Path to a binary under llvm-tools/bin (llvm-objcopy, llvm-strip, llvm-profdata, …). */
|
||||||
|
public static function binary(string $name = 'llvm-strip'): string
|
||||||
|
{
|
||||||
|
return self::path() . '/bin/' . $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** True when every required TOOLS binary is present and executable. */
|
||||||
|
public static function isInstalled(): bool
|
||||||
|
{
|
||||||
|
foreach (self::TOOLS as $t) {
|
||||||
|
$p = self::binary($t);
|
||||||
|
if (!is_file($p) || !is_executable($p)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[CustomBinary('llvm-tools', [
|
||||||
|
'linux-x86_64',
|
||||||
|
'linux-aarch64',
|
||||||
|
'macos-x86_64',
|
||||||
|
'macos-aarch64',
|
||||||
|
])]
|
||||||
|
public function downBinary(ArtifactDownloader $downloader): DownloadResult
|
||||||
|
{
|
||||||
|
$llvmVersion = $this->detectLlvmVersion()
|
||||||
|
?? throw new DownloaderException('Could not detect a clang version on host; install zig or clang first');
|
||||||
|
$tarball = "llvm-project-{$llvmVersion}.src.tar.xz";
|
||||||
|
$url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-{$llvmVersion}/{$tarball}";
|
||||||
|
$tarballPath = DOWNLOAD_PATH . '/' . $tarball;
|
||||||
|
default_shell()->executeCurlDownload($url, $tarballPath, headers: $this->getGitHubTokenHeaders(), retries: $downloader->getRetry());
|
||||||
|
return DownloadResult::archive($tarball, ['url' => $url, 'version' => $llvmVersion], extract: '{source_path}/llvm-tools', verified: false, version: $llvmVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[CustomBinaryCheckUpdate('llvm-tools', [
|
||||||
|
'linux-x86_64',
|
||||||
|
'linux-aarch64',
|
||||||
|
'macos-x86_64',
|
||||||
|
'macos-aarch64',
|
||||||
|
])]
|
||||||
|
public function checkUpdateBinary(?string $old_version, ArtifactDownloader $downloader): CheckUpdateResult
|
||||||
|
{
|
||||||
|
$llvmVersion = $this->detectLlvmVersion()
|
||||||
|
?? throw new DownloaderException('Could not detect a clang version on host; install zig or clang first');
|
||||||
|
return new CheckUpdateResult(
|
||||||
|
old: $old_version,
|
||||||
|
new: $llvmVersion,
|
||||||
|
needUpdate: $old_version === null || $llvmVersion !== $old_version,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[AfterBinaryExtract('llvm-tools', [
|
||||||
|
'linux-x86_64',
|
||||||
|
'linux-aarch64',
|
||||||
|
'macos-x86_64',
|
||||||
|
'macos-aarch64',
|
||||||
|
])]
|
||||||
|
public function postExtract(string $target_path): void
|
||||||
|
{
|
||||||
|
$this->buildForHost($target_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildForHost(?string $sourceRoot = null): void
|
||||||
|
{
|
||||||
|
$sourceRoot ??= SOURCE_PATH . '/llvm-tools';
|
||||||
|
if (self::isInstalled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$llvmDir = "{$sourceRoot}/llvm";
|
||||||
|
if (!is_dir($llvmDir)) {
|
||||||
|
throw new BuildFailureException("llvm-tools: missing source at {$llvmDir} (extraction layout changed?)");
|
||||||
|
}
|
||||||
|
$buildDir = "{$sourceRoot}/build";
|
||||||
|
$installDir = self::path();
|
||||||
|
$binDir = self::path() . '/bin';
|
||||||
|
f_mkdir($buildDir, recursive: true);
|
||||||
|
f_mkdir($binDir, recursive: true);
|
||||||
|
|
||||||
|
$cmakeArgs = implode(' ', array_map('escapeshellarg', [
|
||||||
|
'-S', $llvmDir,
|
||||||
|
'-B', $buildDir,
|
||||||
|
'-DCMAKE_BUILD_TYPE=Release',
|
||||||
|
'-DLLVM_ENABLE_PROJECTS=',
|
||||||
|
'-DLLVM_TARGETS_TO_BUILD=',
|
||||||
|
'-DLLVM_INCLUDE_BENCHMARKS=OFF',
|
||||||
|
'-DLLVM_INCLUDE_TESTS=OFF',
|
||||||
|
'-DLLVM_INCLUDE_EXAMPLES=OFF',
|
||||||
|
'-DLLVM_INCLUDE_DOCS=OFF',
|
||||||
|
'-DLLVM_ENABLE_ZLIB=OFF',
|
||||||
|
'-DLLVM_ENABLE_ZSTD=OFF',
|
||||||
|
'-DLLVM_ENABLE_LIBXML2=OFF',
|
||||||
|
'-DLLVM_ENABLE_TERMINFO=OFF',
|
||||||
|
'-DLLVM_ENABLE_LIBEDIT=OFF',
|
||||||
|
'-DLLVM_ENABLE_LIBPFM=OFF',
|
||||||
|
'-DLLVM_BUILD_LLVM_DYLIB=OFF',
|
||||||
|
'-DLLVM_LINK_LLVM_DYLIB=OFF',
|
||||||
|
'-DBUILD_SHARED_LIBS=OFF',
|
||||||
|
'-DCMAKE_C_COMPILER=' . zig::binary('zig-cc'),
|
||||||
|
'-DCMAKE_CXX_COMPILER=' . zig::binary('zig-c++'),
|
||||||
|
'-DCMAKE_INSTALL_PREFIX=' . $installDir,
|
||||||
|
]));
|
||||||
|
$jobs = ApplicationContext::get(PackageBuilder::class)->concurrency;
|
||||||
|
$targetArgs = implode(' ', array_map(fn ($t) => '--target ' . escapeshellarg($t), self::TOOLS));
|
||||||
|
|
||||||
|
shell()
|
||||||
|
->setEnv(['SPC_TARGET' => GNU_ARCH . '-linux-musl'])
|
||||||
|
->exec('cmake ' . $cmakeArgs)
|
||||||
|
->exec('cmake --build ' . escapeshellarg($buildDir) . ' ' . $targetArgs . " -j {$jobs}");
|
||||||
|
|
||||||
|
foreach (self::TOOLS as $t) {
|
||||||
|
$built = "{$buildDir}/bin/{$t}";
|
||||||
|
if (!is_file($built)) {
|
||||||
|
throw new BuildFailureException("llvm-tools: missing build output {$built}");
|
||||||
|
}
|
||||||
|
copy($built, self::binary($t));
|
||||||
|
chmod(self::binary($t), 0755);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function detectLlvmVersion(): ?string
|
||||||
|
{
|
||||||
|
if (!zig::isInstalled()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
[$rc, $out] = shell()->execWithResult(escapeshellarg(zig::binary()) . ' cc --version', false);
|
||||||
|
if ($rc !== 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return preg_match('/clang version (\d+\.\d+\.\d+)/', implode("\n", $out), $m) ? $m[1] : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,7 +46,7 @@ class rust
|
|||||||
$download_url = "https://static.rust-lang.org/dist/rust-{$latest_version}-{$arch}-unknown-linux-{$distro}.tar.xz";
|
$download_url = "https://static.rust-lang.org/dist/rust-{$latest_version}-{$arch}-unknown-linux-{$distro}.tar.xz";
|
||||||
$path = DOWNLOAD_PATH . DIRECTORY_SEPARATOR . basename($download_url);
|
$path = DOWNLOAD_PATH . DIRECTORY_SEPARATOR . basename($download_url);
|
||||||
default_shell()->executeCurlDownload($download_url, $path, retries: $downloader->getRetry());
|
default_shell()->executeCurlDownload($download_url, $path, retries: $downloader->getRetry());
|
||||||
return DownloadResult::archive(basename($path), ['url' => $download_url, 'version' => $latest_version], extract: PKG_ROOT_PATH . '/rust-install', verified: false, version: $latest_version);
|
return DownloadResult::archive(basename($path), ['url' => $download_url, 'version' => $latest_version], extract: '{pkg_root_path}/rust-install', verified: false, version: $latest_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[CustomBinaryCheckUpdate('rust', [
|
#[CustomBinaryCheckUpdate('rust', [
|
||||||
|
|||||||
@@ -15,6 +15,23 @@ use StaticPHP\Runtime\SystemTarget;
|
|||||||
|
|
||||||
class zig
|
class zig
|
||||||
{
|
{
|
||||||
|
/** Directory zig extracts into. */
|
||||||
|
public static function path(): string
|
||||||
|
{
|
||||||
|
return PKG_ROOT_PATH . '/zig';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Path to a binary inside the zig install dir (zig, zig-cc, zig-c++, zig-ar, …). */
|
||||||
|
public static function binary(string $name = 'zig'): string
|
||||||
|
{
|
||||||
|
return self::path() . '/' . $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isInstalled(): bool
|
||||||
|
{
|
||||||
|
return is_file(self::binary());
|
||||||
|
}
|
||||||
|
|
||||||
#[CustomBinary('zig', [
|
#[CustomBinary('zig', [
|
||||||
'linux-x86_64',
|
'linux-x86_64',
|
||||||
'linux-aarch64',
|
'linux-aarch64',
|
||||||
|
|||||||
@@ -4,29 +4,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Package\Extension;
|
namespace Package\Extension;
|
||||||
|
|
||||||
use Package\Target\php;
|
|
||||||
use StaticPHP\Attribute\Package\BeforeStage;
|
|
||||||
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
|
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
|
||||||
use StaticPHP\Attribute\Package\Extension;
|
use StaticPHP\Attribute\Package\Extension;
|
||||||
use StaticPHP\Attribute\PatchDescription;
|
|
||||||
use StaticPHP\Package\PackageInstaller;
|
use StaticPHP\Package\PackageInstaller;
|
||||||
use StaticPHP\Package\PhpExtensionPackage;
|
use StaticPHP\Package\PhpExtensionPackage;
|
||||||
use StaticPHP\Util\FileSystem;
|
|
||||||
|
|
||||||
#[Extension('clickhouse')]
|
#[Extension('clickhouse')]
|
||||||
class clickhouse extends PhpExtensionPackage
|
class clickhouse extends PhpExtensionPackage
|
||||||
{
|
{
|
||||||
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-clickhouse')]
|
|
||||||
#[PatchDescription('Replace THIS_DIR=`dirname $0` with PHP_EXT_SRCDIR() in config.m4 so include paths resolve to the ext source dir during PHP main configure (dirname $0 returns "." when run from php-src root).')]
|
|
||||||
public function patchBeforeBuildconfUnix(): void
|
|
||||||
{
|
|
||||||
FileSystem::replaceFileRegex(
|
|
||||||
"{$this->getSourceDir()}/config.m4",
|
|
||||||
'/^(\s*)THIS_DIR=.*/m',
|
|
||||||
'$1THIS_DIR=PHP_EXT_SRCDIR()',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[CustomPhpConfigureArg('Darwin')]
|
#[CustomPhpConfigureArg('Darwin')]
|
||||||
#[CustomPhpConfigureArg('Linux')]
|
#[CustomPhpConfigureArg('Linux')]
|
||||||
public function getUnixConfigureArg(bool $shared, PackageInstaller $installer): string
|
public function getUnixConfigureArg(bool $shared, PackageInstaller $installer): string
|
||||||
|
|||||||
@@ -16,6 +16,14 @@ use StaticPHP\Util\FileSystem;
|
|||||||
#[Extension('mongodb')]
|
#[Extension('mongodb')]
|
||||||
class mongodb extends PhpExtensionPackage
|
class mongodb extends PhpExtensionPackage
|
||||||
{
|
{
|
||||||
|
#[BeforeStage('php', [php::class, 'configureForUnix'], 'ext-mongodb')]
|
||||||
|
#[PatchDescription('Export PHP_VERSION_ID so mongo-php-driver >= 2.3.3 skips its php-config lookup (in-tree builds have no php-config).')]
|
||||||
|
public function exportPhpVersionIdForUnix(): void
|
||||||
|
{
|
||||||
|
$id = php::getPHPVersionID();
|
||||||
|
f_putenv("PHP_VERSION_ID={$id}");
|
||||||
|
}
|
||||||
|
|
||||||
#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-mongodb')]
|
#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-mongodb')]
|
||||||
#[PatchDescription('Add /utf-8 flag to CFLAGS_MONGODB for Windows build to fix compilation error on non-English Windows.')]
|
#[PatchDescription('Add /utf-8 flag to CFLAGS_MONGODB for Windows build to fix compilation error on non-English Windows.')]
|
||||||
public function patchBeforeBuild(): void
|
public function patchBeforeBuild(): void
|
||||||
|
|||||||
@@ -72,6 +72,10 @@ class opcache extends PhpExtensionPackage
|
|||||||
) {
|
) {
|
||||||
$opcache_jit = ' --disable-opcache-jit';
|
$opcache_jit = ' --disable-opcache-jit';
|
||||||
}
|
}
|
||||||
return '--enable-opcache' . ($shared ? '=shared' : '') . $opcache_jit;
|
// PHP 8.5+ has opcache built-in
|
||||||
|
if ($phpVersionID < 80500) {
|
||||||
|
return '--enable-opcache' . ($shared ? '=shared' : '') . $opcache_jit;
|
||||||
|
}
|
||||||
|
return trim($opcache_jit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class password_argon2 extends PhpExtensionPackage
|
|||||||
#[CustomPhpConfigureArg('Darwin')]
|
#[CustomPhpConfigureArg('Darwin')]
|
||||||
public function getConfigureArg(PackageInstaller $installer, PackageBuilder $builder): string
|
public function getConfigureArg(PackageInstaller $installer, PackageBuilder $builder): string
|
||||||
{
|
{
|
||||||
if ($installer->getLibraryPackage('openssl') !== null) {
|
if ($installer->getPhpExtensionPackage('openssl')?->isBuildStatic()) {
|
||||||
if (php::getPHPVersionID() >= 80500 || (php::getPHPVersionID() >= 80400 && !$builder->getOption('enable-zts'))) {
|
if (php::getPHPVersionID() >= 80500 || (php::getPHPVersionID() >= 80400 && !$builder->getOption('enable-zts'))) {
|
||||||
return '--without-password-argon2'; // use --with-openssl-argon2 in openssl extension instead
|
return '--without-password-argon2'; // use --with-openssl-argon2 in openssl extension instead
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class pgsql extends PhpExtensionPackage
|
|||||||
public function getUnixConfigureArg(bool $shared, PackageBuilder $builder, PackageInstaller $installer): string
|
public function getUnixConfigureArg(bool $shared, PackageBuilder $builder, PackageInstaller $installer): string
|
||||||
{
|
{
|
||||||
if (php::getPHPVersionID() >= 80400) {
|
if (php::getPHPVersionID() >= 80400) {
|
||||||
$libfiles = new SPCConfigUtil(['libs_only_deps' => true, 'absolute_libs' => true])->getPackageDepsConfig('postgresql', array_keys($installer->getResolvedPackages()), $builder->getOption('with-suggests'))['libs'];
|
$libfiles = new SPCConfigUtil(['libs_only_deps' => true, 'absolute_libs' => true])->getPackageDepsConfig('postgresql', array_keys($installer->getResolvedPackages()))['libs'];
|
||||||
$libfiles = str_replace("{$builder->getLibDir()}/lib", '-l', $libfiles);
|
$libfiles = str_replace("{$builder->getLibDir()}/lib", '-l', $libfiles);
|
||||||
$libfiles = str_replace('.a', '', $libfiles);
|
$libfiles = str_replace('.a', '', $libfiles);
|
||||||
return '--with-pgsql' . ($shared ? '=shared' : '') .
|
return '--with-pgsql' . ($shared ? '=shared' : '') .
|
||||||
|
|||||||
@@ -6,14 +6,27 @@ namespace Package\Extension;
|
|||||||
|
|
||||||
use Package\Target\php;
|
use Package\Target\php;
|
||||||
use StaticPHP\Attribute\Package\BeforeStage;
|
use StaticPHP\Attribute\Package\BeforeStage;
|
||||||
|
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
|
||||||
use StaticPHP\Attribute\Package\Extension;
|
use StaticPHP\Attribute\Package\Extension;
|
||||||
use StaticPHP\Attribute\PatchDescription;
|
use StaticPHP\Attribute\PatchDescription;
|
||||||
|
use StaticPHP\Package\PackageInstaller;
|
||||||
use StaticPHP\Package\PhpExtensionPackage;
|
use StaticPHP\Package\PhpExtensionPackage;
|
||||||
use StaticPHP\Util\FileSystem;
|
use StaticPHP\Util\FileSystem;
|
||||||
|
|
||||||
#[Extension('spx')]
|
#[Extension('spx')]
|
||||||
class spx extends PhpExtensionPackage
|
class spx extends PhpExtensionPackage
|
||||||
{
|
{
|
||||||
|
#[CustomPhpConfigureArg('Linux')]
|
||||||
|
#[CustomPhpConfigureArg('Darwin')]
|
||||||
|
public function getUnixConfigureArg(bool $shared, PackageInstaller $installer): string
|
||||||
|
{
|
||||||
|
$arg = '--enable-SPX' . ($shared ? '=shared' : '');
|
||||||
|
if ($installer->getLibraryPackage('zlib') !== null) {
|
||||||
|
$arg .= ' --with-zlib-dir=' . BUILD_ROOT_PATH;
|
||||||
|
}
|
||||||
|
return $arg;
|
||||||
|
}
|
||||||
|
|
||||||
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-spx')]
|
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-spx')]
|
||||||
#[PatchDescription('Fix spx extension compile error when building as static')]
|
#[PatchDescription('Fix spx extension compile error when building as static')]
|
||||||
public function patchBeforeBuildconf(): bool
|
public function patchBeforeBuildconf(): bool
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ use StaticPHP\Attribute\Package\Extension;
|
|||||||
use StaticPHP\Attribute\PatchDescription;
|
use StaticPHP\Attribute\PatchDescription;
|
||||||
use StaticPHP\Package\PackageInstaller;
|
use StaticPHP\Package\PackageInstaller;
|
||||||
use StaticPHP\Package\PhpExtensionPackage;
|
use StaticPHP\Package\PhpExtensionPackage;
|
||||||
use StaticPHP\Util\GlobalEnvManager;
|
|
||||||
use StaticPHP\Util\SourcePatcher;
|
use StaticPHP\Util\SourcePatcher;
|
||||||
|
|
||||||
#[Extension('xlswriter')]
|
#[Extension('xlswriter')]
|
||||||
@@ -21,20 +20,14 @@ class xlswriter extends PhpExtensionPackage
|
|||||||
#[CustomPhpConfigureArg('Linux')]
|
#[CustomPhpConfigureArg('Linux')]
|
||||||
public function getUnixConfigureArg(bool $shared, PackageInstaller $installer): string
|
public function getUnixConfigureArg(bool $shared, PackageInstaller $installer): string
|
||||||
{
|
{
|
||||||
$arg = '--with-xlswriter --enable-reader';
|
$shared = $shared ? '=shared' : '';
|
||||||
|
$arg = "--with-xlswriter{$shared} --enable-reader";
|
||||||
if ($installer->getLibraryPackage('openssl')) {
|
if ($installer->getLibraryPackage('openssl')) {
|
||||||
$arg .= ' --with-openssl=' . $installer->getLibraryPackage('openssl')->getBuildRootPath();
|
$arg .= ' --with-openssl=' . $installer->getLibraryPackage('openssl')->getBuildRootPath();
|
||||||
}
|
}
|
||||||
return $arg;
|
return $arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[BeforeStage('php', [php::class, 'makeForUnix'], 'ext-xlswriter')]
|
|
||||||
#[PatchDescription('Fix Unix build: add -std=gnu17 to CFLAGS to fix build errors on older GCC versions')]
|
|
||||||
public function patchBeforeUnixMake(): void
|
|
||||||
{
|
|
||||||
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -std=gnu17');
|
|
||||||
}
|
|
||||||
|
|
||||||
#[BeforeStage('php', [php::class, 'makeForWindows'], 'ext-xlswriter')]
|
#[BeforeStage('php', [php::class, 'makeForWindows'], 'ext-xlswriter')]
|
||||||
#[PatchDescription('Fix Windows build: apply win32 patch and add UTF-8 BOM to theme.c')]
|
#[PatchDescription('Fix Windows build: apply win32 patch and add UTF-8 BOM to theme.c')]
|
||||||
public function patchBeforeMakeForWindows(): void
|
public function patchBeforeMakeForWindows(): void
|
||||||
@@ -47,11 +40,4 @@ class xlswriter extends PhpExtensionPackage
|
|||||||
file_put_contents($this->getSourceDir() . '/library/libxlsxwriter/src/theme.c', $bom . $content);
|
file_put_contents($this->getSourceDir() . '/library/libxlsxwriter/src/theme.c', $bom . $content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSharedExtensionEnv(): array
|
|
||||||
{
|
|
||||||
$parent = parent::getSharedExtensionEnv();
|
|
||||||
$parent['CFLAGS'] .= ' -std=gnu17';
|
|
||||||
return $parent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ class imagemagick
|
|||||||
->addConfigureArgs(
|
->addConfigureArgs(
|
||||||
'--disable-openmp',
|
'--disable-openmp',
|
||||||
'--without-x',
|
'--without-x',
|
||||||
|
// implicit --with-gcc-arch
|
||||||
|
// bleeds host cpu features into built binaries
|
||||||
|
'--without-gcc-arch',
|
||||||
);
|
);
|
||||||
|
|
||||||
// special: linux-static target needs `-static`
|
// special: linux-static target needs `-static`
|
||||||
|
|||||||
@@ -20,9 +20,8 @@ class watcher extends LibraryPackage
|
|||||||
if (stripos($cflags, '-fpic') === false) {
|
if (stripos($cflags, '-fpic') === false) {
|
||||||
$cflags .= ' -fPIC';
|
$cflags .= ' -fPIC';
|
||||||
}
|
}
|
||||||
$ldflags = $this->getLibExtraLdFlags() ? ' ' . $this->getLibExtraLdFlags() : '';
|
|
||||||
shell()->cd("{$this->getSourceDir()}/watcher-c")
|
shell()->cd("{$this->getSourceDir()}/watcher-c")
|
||||||
->exec(getenv('CXX') . " -c -o libwatcher-c.o ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -Wall -Wextra {$cflags}{$ldflags}")
|
->exec(getenv('CXX') . " -c -o libwatcher-c.o ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -Wall -Wextra {$cflags}")
|
||||||
->exec(getenv('AR') . ' rcs libwatcher-c.a libwatcher-c.o');
|
->exec(getenv('AR') . ' rcs libwatcher-c.a libwatcher-c.o');
|
||||||
|
|
||||||
copy("{$this->getSourceDir()}/watcher-c/libwatcher-c.a", "{$this->getLibDir()}/libwatcher-c.a");
|
copy("{$this->getSourceDir()}/watcher-c/libwatcher-c.a", "{$this->getLibDir()}/libwatcher-c.a");
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class curl
|
|||||||
->optionalPackage('zstd', ...cmake_boolean_args('CURL_ZSTD'))
|
->optionalPackage('zstd', ...cmake_boolean_args('CURL_ZSTD'))
|
||||||
->optionalPackage('brotli', ...cmake_boolean_args('CURL_BROTLI'))
|
->optionalPackage('brotli', ...cmake_boolean_args('CURL_BROTLI'))
|
||||||
->addConfigureArgs(
|
->addConfigureArgs(
|
||||||
'-DBUILD_CURL_EXE=OFF',
|
'-DBUILD_CURL_EXE=ON',
|
||||||
'-DZSTD_LIBRARY=zstd_static.lib',
|
'-DZSTD_LIBRARY=zstd_static.lib',
|
||||||
'-DBUILD_TESTING=OFF',
|
'-DBUILD_TESTING=OFF',
|
||||||
'-DBUILD_EXAMPLES=OFF',
|
'-DBUILD_EXAMPLES=OFF',
|
||||||
@@ -81,6 +81,7 @@ class curl
|
|||||||
->addConfigureArgs(
|
->addConfigureArgs(
|
||||||
'-DBUILD_CURL_EXE=ON',
|
'-DBUILD_CURL_EXE=ON',
|
||||||
'-DBUILD_LIBCURL_DOCS=OFF',
|
'-DBUILD_LIBCURL_DOCS=OFF',
|
||||||
|
'-DOPENSSL_ROOT_DIR=' . BUILD_ROOT_PATH,
|
||||||
)
|
)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
@@ -92,6 +93,9 @@ class curl
|
|||||||
if (str_contains(FileSystem::readFile($pc_path), '-lgssapi_krb5')) {
|
if (str_contains(FileSystem::readFile($pc_path), '-lgssapi_krb5')) {
|
||||||
FileSystem::replaceFileRegex($pc_path, '/-lcom_err$/m', '-lcom_err -lkrb5support');
|
FileSystem::replaceFileRegex($pc_path, '/-lcom_err$/m', '-lcom_err -lkrb5support');
|
||||||
}
|
}
|
||||||
|
// FindThreads can put '-lpthread' into INTERFACE_LINK_LIBRARIES; curl's pc generator
|
||||||
|
// prepends '-l' to each entry, producing '-l-lpthread'. Strip the extra '-l'.
|
||||||
|
FileSystem::replaceFileRegex($pc_path, '/-l(-l\S+)/', '$1');
|
||||||
shell()->cd("{$lib->getLibDir()}/cmake/CURL/")
|
shell()->cd("{$lib->getLibDir()}/cmake/CURL/")
|
||||||
->exec("sed -ie 's|\"/lib/libcurl.a\"|\"{$lib->getLibDir()}/libcurl.a\"|g' CURLTargets-release.cmake");
|
->exec("sed -ie 's|\"/lib/libcurl.a\"|\"{$lib->getLibDir()}/libcurl.a\"|g' CURLTargets-release.cmake");
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,25 @@ class ApplicationContext
|
|||||||
return self::getContainer()->has($id);
|
return self::getContainer()->has($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve $id, returning null if it can't be constructed.
|
||||||
|
* PHP-DI's has() returns true for any autowirable class even when get()
|
||||||
|
* would throw on missing scalar args — for "is this resolvable right now"
|
||||||
|
* semantics use this.
|
||||||
|
*
|
||||||
|
* @template T
|
||||||
|
* @param class-string<T> $id
|
||||||
|
* @return null|T
|
||||||
|
*/
|
||||||
|
public static function tryGet(string $id): mixed
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return self::getContainer()->get($id);
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a service in the container.
|
* Set a service in the container.
|
||||||
* Use sparingly - prefer configuration-based definitions.
|
* Use sparingly - prefer configuration-based definitions.
|
||||||
|
|||||||
44
src/StaticPHP/Doctor/Item/LlvmToolsCheck.php
Normal file
44
src/StaticPHP/Doctor/Item/LlvmToolsCheck.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace StaticPHP\Doctor\Item;
|
||||||
|
|
||||||
|
use Package\Artifact\llvm_tools;
|
||||||
|
use StaticPHP\Attribute\Doctor\CheckItem;
|
||||||
|
use StaticPHP\Attribute\Doctor\FixItem;
|
||||||
|
use StaticPHP\Attribute\Doctor\OptionalCheck;
|
||||||
|
use StaticPHP\DI\ApplicationContext;
|
||||||
|
use StaticPHP\Doctor\CheckResult;
|
||||||
|
use StaticPHP\Package\PackageInstaller;
|
||||||
|
use StaticPHP\Toolchain\Interface\ToolchainInterface;
|
||||||
|
use StaticPHP\Toolchain\ZigToolchain;
|
||||||
|
|
||||||
|
#[OptionalCheck([self::class, 'optionalCheck'])]
|
||||||
|
class LlvmToolsCheck
|
||||||
|
{
|
||||||
|
public static function optionalCheck(): bool
|
||||||
|
{
|
||||||
|
return ApplicationContext::get(ToolchainInterface::class) instanceof ZigToolchain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @noinspection PhpUnused */
|
||||||
|
#[CheckItem('if llvm-tools (objcopy/strip/profdata) are built', level: 798)]
|
||||||
|
public function checkLlvmTools(): CheckResult
|
||||||
|
{
|
||||||
|
if (llvm_tools::isInstalled()) {
|
||||||
|
return CheckResult::ok(llvm_tools::path() . '/bin');
|
||||||
|
}
|
||||||
|
return CheckResult::fail('llvm-tools are not built', 'build-llvm-tools');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[FixItem('build-llvm-tools')]
|
||||||
|
public function fixLlvmTools(): bool
|
||||||
|
{
|
||||||
|
$installer = new PackageInstaller(interactive: false);
|
||||||
|
$installer->addInstallPackage('llvm-tools');
|
||||||
|
$installer->run(true);
|
||||||
|
new llvm_tools()->buildForHost();
|
||||||
|
return llvm_tools::isInstalled();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace StaticPHP\Package;
|
namespace StaticPHP\Package;
|
||||||
|
|
||||||
|
use Package\Artifact\llvm_tools;
|
||||||
use StaticPHP\Config\PackageConfig;
|
use StaticPHP\Config\PackageConfig;
|
||||||
use StaticPHP\DI\ApplicationContext;
|
use StaticPHP\DI\ApplicationContext;
|
||||||
use StaticPHP\Exception\SPCException;
|
use StaticPHP\Exception\SPCException;
|
||||||
@@ -11,6 +12,8 @@ use StaticPHP\Exception\SPCInternalException;
|
|||||||
use StaticPHP\Exception\WrongUsageException;
|
use StaticPHP\Exception\WrongUsageException;
|
||||||
use StaticPHP\Runtime\Shell\Shell;
|
use StaticPHP\Runtime\Shell\Shell;
|
||||||
use StaticPHP\Runtime\SystemTarget;
|
use StaticPHP\Runtime\SystemTarget;
|
||||||
|
use StaticPHP\Toolchain\Interface\ToolchainInterface;
|
||||||
|
use StaticPHP\Toolchain\ZigToolchain;
|
||||||
use StaticPHP\Util\FileSystem;
|
use StaticPHP\Util\FileSystem;
|
||||||
use StaticPHP\Util\GlobalPathTrait;
|
use StaticPHP\Util\GlobalPathTrait;
|
||||||
use StaticPHP\Util\InteractiveTerm;
|
use StaticPHP\Util\InteractiveTerm;
|
||||||
@@ -178,14 +181,18 @@ class PackageBuilder
|
|||||||
if (SystemTarget::getTargetOS() === 'Darwin') {
|
if (SystemTarget::getTargetOS() === 'Darwin') {
|
||||||
shell()->exec("dsymutil -f {$binary_path} -o {$debug_file}");
|
shell()->exec("dsymutil -f {$binary_path} -o {$debug_file}");
|
||||||
} elseif (SystemTarget::getTargetOS() === 'Linux') {
|
} elseif (SystemTarget::getTargetOS() === 'Linux') {
|
||||||
|
$objcopy = getenv('OBJCOPY')
|
||||||
|
?: (ApplicationContext::tryGet(ToolchainInterface::class) instanceof ZigToolchain
|
||||||
|
? llvm_tools::binary('llvm-objcopy')
|
||||||
|
: 'objcopy');
|
||||||
if ($eu_strip = LinuxUtil::findCommand('eu-strip')) {
|
if ($eu_strip = LinuxUtil::findCommand('eu-strip')) {
|
||||||
shell()
|
shell()
|
||||||
->exec("{$eu_strip} -f {$debug_file} {$binary_path}")
|
->exec("{$eu_strip} -f {$debug_file} {$binary_path}")
|
||||||
->exec("objcopy --add-gnu-debuglink={$debug_file} {$binary_path}");
|
->exec("{$objcopy} --add-gnu-debuglink={$debug_file} {$binary_path}");
|
||||||
} else {
|
} else {
|
||||||
shell()
|
shell()
|
||||||
->exec("objcopy --only-keep-debug {$binary_path} {$debug_file}")
|
->exec("{$objcopy} --only-keep-debug {$binary_path} {$debug_file}")
|
||||||
->exec("objcopy --add-gnu-debuglink={$debug_file} {$binary_path}");
|
->exec("{$objcopy} --add-gnu-debuglink={$debug_file} {$binary_path}");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger()->debug('extractDebugInfo is only supported on Linux and macOS');
|
logger()->debug('extractDebugInfo is only supported on Linux and macOS');
|
||||||
@@ -199,9 +206,12 @@ class PackageBuilder
|
|||||||
*/
|
*/
|
||||||
public function stripBinary(string $binary_path): void
|
public function stripBinary(string $binary_path): void
|
||||||
{
|
{
|
||||||
|
$strip = ApplicationContext::tryGet(ToolchainInterface::class) instanceof ZigToolchain
|
||||||
|
? llvm_tools::binary('llvm-strip')
|
||||||
|
: 'strip';
|
||||||
shell()->exec(match (SystemTarget::getTargetOS()) {
|
shell()->exec(match (SystemTarget::getTargetOS()) {
|
||||||
'Darwin' => "strip -S {$binary_path}",
|
'Darwin' => "{$strip} -S {$binary_path}",
|
||||||
'Linux' => "strip --strip-unneeded {$binary_path}",
|
'Linux' => "{$strip} --strip-unneeded {$binary_path}",
|
||||||
'Windows' => 'echo "Skip strip on Windows"', // Windows strip is not available for now
|
'Windows' => 'echo "Skip strip on Windows"', // Windows strip is not available for now
|
||||||
default => throw new SPCInternalException('stripBinary is only supported on Linux and macOS'),
|
default => throw new SPCInternalException('stripBinary is only supported on Linux and macOS'),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -244,6 +244,7 @@ class FileSystem
|
|||||||
*/
|
*/
|
||||||
public static function getClassesPsr4(string $dir, string $base_namespace, mixed $rule = null, bool|string $return_path_value = false, bool $auto_require = false): array
|
public static function getClassesPsr4(string $dir, string $base_namespace, mixed $rule = null, bool|string $return_path_value = false, bool $auto_require = false): array
|
||||||
{
|
{
|
||||||
|
$base_namespace = rtrim($base_namespace, '\\');
|
||||||
$classes = [];
|
$classes = [];
|
||||||
$files = FileSystem::scanDirFiles($dir, true, true);
|
$files = FileSystem::scanDirFiles($dir, true, true);
|
||||||
if ($files === false) {
|
if ($files === false) {
|
||||||
|
|||||||
@@ -77,5 +77,9 @@ if (filter_var(getenv('SPC_ENABLE_LOG_FILE'), FILTER_VALIDATE_BOOLEAN)) {
|
|||||||
|
|
||||||
// load core registry
|
// load core registry
|
||||||
Registry::loadRegistry(ROOT_DIR . '/spc.registry.yml');
|
Registry::loadRegistry(ROOT_DIR . '/spc.registry.yml');
|
||||||
|
// in vendor mode, auto-load the local working directory registry if it exists
|
||||||
|
if (spc_mode(SPC_MODE_VENDOR) && file_exists(WORKING_DIR . '/spc.registry.yml')) {
|
||||||
|
Registry::loadRegistry(WORKING_DIR . '/spc.registry.yml');
|
||||||
|
}
|
||||||
// load registries from environment variable SPC_REGISTRIES
|
// load registries from environment variable SPC_REGISTRIES
|
||||||
Registry::loadFromEnvOrOption();
|
Registry::loadFromEnvOrOption();
|
||||||
|
|||||||
Reference in New Issue
Block a user