mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-05 07:45:39 +08:00
Compare commits
19 Commits
v3c/llvm-t
...
bf6216e59f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf6216e59f | ||
|
|
411ad7cc0f | ||
|
|
0761267eb3 | ||
|
|
072a3b5505 | ||
|
|
0e5738b710 | ||
|
|
3ff9426e50 | ||
|
|
6057394641 | ||
|
|
2f4fb9d28f | ||
|
|
96ab2de4b1 | ||
|
|
c641c3b8db | ||
|
|
48d6e9ebc2 | ||
|
|
6cab47db67 | ||
|
|
ec3fd0f4b0 | ||
|
|
e72f9aa623 | ||
|
|
c666cd6cd0 | ||
|
|
b8dd508148 | ||
|
|
37d8b87c3b | ||
|
|
5172580294 | ||
|
|
99e05aa22b |
9
.github/workflows/release-build.yml
vendored
9
.github/workflows/release-build.yml
vendored
@@ -38,6 +38,9 @@ jobs:
|
||||
- name: "windows-x64"
|
||||
os: "ubuntu-latest"
|
||||
filename: "spc-windows-x64.exe"
|
||||
permissions:
|
||||
id-token: write
|
||||
attestations: write
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: "actions/checkout@v5"
|
||||
@@ -105,6 +108,12 @@ jobs:
|
||||
fi
|
||||
fi
|
||||
|
||||
- name: "Generate build provenance attestation"
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: actions/attest-build-provenance@v4
|
||||
with:
|
||||
subject-path: "${{ github.workspace }}/${{ matrix.operating-system.name == 'windows-x64' && 'spc.exe' || 'spc' }}"
|
||||
|
||||
- name: "Copy file"
|
||||
run: |
|
||||
if [ "${{ matrix.operating-system.name }}" != "windows-x64" ]; then
|
||||
|
||||
20
config/pkg/ext/ext-fastchart.yml
Normal file
20
config/pkg/ext/ext-fastchart.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
ext-fastchart:
|
||||
type: php-extension
|
||||
artifact:
|
||||
source:
|
||||
type: ghtar
|
||||
repo: iliaal/fastchart
|
||||
extract: php-src/ext/fastchart
|
||||
prefer-stable: true
|
||||
metadata:
|
||||
license-files: [LICENSE]
|
||||
depends:
|
||||
- freetype
|
||||
suggests:
|
||||
- libpng
|
||||
- libjpeg
|
||||
- libwebp
|
||||
php-extension:
|
||||
os:
|
||||
- Linux
|
||||
- Darwin
|
||||
14
config/pkg/ext/ext-fastjson.yml
Normal file
14
config/pkg/ext/ext-fastjson.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
ext-fastjson:
|
||||
type: php-extension
|
||||
artifact:
|
||||
source:
|
||||
type: ghtar
|
||||
repo: iliaal/fastjson
|
||||
extract: php-src/ext/fastjson
|
||||
prefer-stable: true
|
||||
metadata:
|
||||
license-files: [LICENSE]
|
||||
php-extension:
|
||||
os:
|
||||
- Linux
|
||||
- Darwin
|
||||
@@ -1,6 +0,0 @@
|
||||
llvm-tools:
|
||||
type: target
|
||||
artifact:
|
||||
binary: custom
|
||||
depends:
|
||||
- zig
|
||||
@@ -1,162 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -15,23 +15,6 @@ use StaticPHP\Runtime\SystemTarget;
|
||||
|
||||
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', [
|
||||
'linux-x86_64',
|
||||
'linux-aarch64',
|
||||
|
||||
@@ -20,8 +20,8 @@ class unixodbc extends LibraryPackage
|
||||
{
|
||||
$sysconf_selector = match ($os = SystemTarget::getTargetOS()) {
|
||||
'Darwin' => match (SystemTarget::getTargetArch()) {
|
||||
'x86_64' => '/usr/local/etc',
|
||||
'aarch64' => '/opt/homebrew/etc',
|
||||
'x86_64' => is_dir('/usr/local/etc') ? '/usr/local/etc' : '/opt/local/etc',
|
||||
'aarch64' => is_dir('/opt/homebrew/etc') ? '/opt/homebrew/etc' : '/opt/local/etc',
|
||||
default => throw new WrongUsageException('Unsupported architecture: ' . GNU_ARCH),
|
||||
},
|
||||
'Linux' => '/etc',
|
||||
|
||||
@@ -60,6 +60,7 @@ class GenExtTestMatrixCommand extends BaseCommand
|
||||
'glfw',
|
||||
'imagick',
|
||||
'intl',
|
||||
'mongodb',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -98,25 +98,6 @@ class ApplicationContext
|
||||
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.
|
||||
* Use sparingly - prefer configuration-based definitions.
|
||||
|
||||
@@ -73,13 +73,20 @@ class LinuxMuslCheck
|
||||
$prefix = 'sudo ';
|
||||
logger()->warning('Current user is not root, using sudo for running command');
|
||||
}
|
||||
$sysEnv = ['CC' => 'gcc', 'CXX' => 'g++', 'AR' => 'ar', 'LD' => 'ld', 'RANLIB' => 'ranlib'];
|
||||
$envFlags = '';
|
||||
foreach ($sysEnv as $k => $v) {
|
||||
$envFlags .= "{$k}={$v} ";
|
||||
}
|
||||
$envFlags = rtrim($envFlags);
|
||||
$shell = shell()->cd(SOURCE_PATH . '/musl-wrapper')
|
||||
->exec('CC=gcc CXX=g++ AR=ar LD=ld ./configure --disable-gcc-wrapper')
|
||||
->exec('CC=gcc CXX=g++ AR=ar LD=ld make -j');
|
||||
->setEnv($sysEnv)
|
||||
->exec('./configure --disable-gcc-wrapper')
|
||||
->exec('make -j');
|
||||
if ($prefix !== '') {
|
||||
f_passthru('cd ' . SOURCE_PATH . "/musl-wrapper && CC=gcc CXX=g++ AR=ar LD=ld {$prefix}make install");
|
||||
f_passthru('cd ' . SOURCE_PATH . "/musl-wrapper && {$envFlags} {$prefix}make install");
|
||||
} else {
|
||||
$shell->exec("CC=gcc CXX=g++ AR=ar LD=ld {$prefix}make install");
|
||||
$shell->exec("{$prefix}make install");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -33,15 +33,20 @@ class MacOSToolCheck
|
||||
'glibtoolize',
|
||||
];
|
||||
|
||||
#[CheckItem('if homebrew has installed', limit_os: 'Darwin', level: 998)]
|
||||
public function checkBrew(): ?CheckResult
|
||||
#[CheckItem('if homebrew or macports has installed', limit_os: 'Darwin', level: 998)]
|
||||
public function checkBrewOrPorts(): ?CheckResult
|
||||
{
|
||||
if (($path = MacOSUtil::findCommand('brew')) === null) {
|
||||
return CheckResult::fail('Homebrew is not installed', 'brew');
|
||||
}
|
||||
if ($path !== '/opt/homebrew/bin/brew' && getenv('GNU_ARCH') === 'aarch64') {
|
||||
$brewPath = MacOSUtil::findCommand('brew');
|
||||
$portPath = MacOSUtil::findCommand('port');
|
||||
|
||||
if ($brewPath && $brewPath !== '/opt/homebrew/bin/brew' && getenv('GNU_ARCH') === 'aarch64') {
|
||||
return CheckResult::fail('Current homebrew (/usr/local/bin/homebrew) is not installed for M1 Mac, please re-install homebrew in /opt/homebrew/ !');
|
||||
}
|
||||
|
||||
if ($brewPath === null && $portPath === null) {
|
||||
return CheckResult::fail('Homebrew is not installed', 'brew');
|
||||
}
|
||||
|
||||
return CheckResult::ok();
|
||||
}
|
||||
|
||||
@@ -60,8 +65,8 @@ class MacOSToolCheck
|
||||
return CheckResult::ok();
|
||||
}
|
||||
|
||||
#[CheckItem('if homebrew llvm are installed', limit_os: 'Darwin')]
|
||||
public function checkBrewLLVM(): ?CheckResult
|
||||
#[CheckItem('if homebrew or macports llvm are installed', limit_os: 'Darwin')]
|
||||
public function checkBrewOrPortsLLVM(): ?CheckResult
|
||||
{
|
||||
if (getenv('SPC_USE_LLVM') === 'brew') {
|
||||
$homebrew_prefix = getenv('HOMEBREW_PREFIX') ?: (SystemTarget::getTargetArch() === 'aarch64' ? '/opt/homebrew' : '/usr/local/homebrew');
|
||||
@@ -71,6 +76,16 @@ class MacOSToolCheck
|
||||
}
|
||||
return CheckResult::ok($path);
|
||||
}
|
||||
|
||||
if (getenv('SPC_USE_LLVM') === 'port') {
|
||||
$macportsPrefix = '/opt/local';
|
||||
|
||||
if (($path = MacOSUtil::findCommand('clang', ["{$macportsPrefix}/bin"])) === null) {
|
||||
return CheckResult::fail('MacPorts llvm is not installed', 'build-tools', ['missing' => ['llvm']]);
|
||||
}
|
||||
return CheckResult::ok($path);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -91,7 +106,7 @@ class MacOSToolCheck
|
||||
if ($command_path !== []) {
|
||||
return CheckResult::fail("Current {$bison} version is too old: " . $matches[0]);
|
||||
}
|
||||
return $this->checkBisonVersion(['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin']);
|
||||
return $this->checkBisonVersion(['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin', '/opt/local/bin']);
|
||||
}
|
||||
return CheckResult::ok($matches[0]);
|
||||
}
|
||||
@@ -108,6 +123,9 @@ class MacOSToolCheck
|
||||
#[FixItem('build-tools')]
|
||||
public function fixBuildTools(array $missing): bool
|
||||
{
|
||||
$brewPath = MacOSUtil::findCommand('brew');
|
||||
$portPath = MacOSUtil::findCommand('port');
|
||||
|
||||
$replacement = [
|
||||
'glibtoolize' => 'libtool',
|
||||
];
|
||||
@@ -115,7 +133,18 @@ class MacOSToolCheck
|
||||
if (isset($replacement[$cmd])) {
|
||||
$cmd = $replacement[$cmd];
|
||||
}
|
||||
shell()->exec('brew install --formula ' . escapeshellarg($cmd));
|
||||
|
||||
if ($brewPath !== null) {
|
||||
shell()->exec('brew install --formula ' . escapeshellarg($cmd));
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($portPath !== null) {
|
||||
shell()->exec('port install ' . escapeshellarg($cmd));
|
||||
continue;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Package;
|
||||
|
||||
use Package\Artifact\llvm_tools;
|
||||
use StaticPHP\Config\PackageConfig;
|
||||
use StaticPHP\DI\ApplicationContext;
|
||||
use StaticPHP\Exception\SPCException;
|
||||
@@ -12,8 +11,6 @@ use StaticPHP\Exception\SPCInternalException;
|
||||
use StaticPHP\Exception\WrongUsageException;
|
||||
use StaticPHP\Runtime\Shell\Shell;
|
||||
use StaticPHP\Runtime\SystemTarget;
|
||||
use StaticPHP\Toolchain\Interface\ToolchainInterface;
|
||||
use StaticPHP\Toolchain\ZigToolchain;
|
||||
use StaticPHP\Util\FileSystem;
|
||||
use StaticPHP\Util\GlobalPathTrait;
|
||||
use StaticPHP\Util\InteractiveTerm;
|
||||
@@ -181,18 +178,14 @@ class PackageBuilder
|
||||
if (SystemTarget::getTargetOS() === 'Darwin') {
|
||||
shell()->exec("dsymutil -f {$binary_path} -o {$debug_file}");
|
||||
} 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')) {
|
||||
shell()
|
||||
->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 {
|
||||
shell()
|
||||
->exec("{$objcopy} --only-keep-debug {$binary_path} {$debug_file}")
|
||||
->exec("{$objcopy} --add-gnu-debuglink={$debug_file} {$binary_path}");
|
||||
->exec("objcopy --only-keep-debug {$binary_path} {$debug_file}")
|
||||
->exec("objcopy --add-gnu-debuglink={$debug_file} {$binary_path}");
|
||||
}
|
||||
} else {
|
||||
logger()->debug('extractDebugInfo is only supported on Linux and macOS');
|
||||
@@ -206,12 +199,9 @@ class PackageBuilder
|
||||
*/
|
||||
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()) {
|
||||
'Darwin' => "{$strip} -S {$binary_path}",
|
||||
'Linux' => "{$strip} --strip-unneeded {$binary_path}",
|
||||
'Darwin' => "strip -S {$binary_path}",
|
||||
'Linux' => "strip --strip-unneeded {$binary_path}",
|
||||
'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'),
|
||||
});
|
||||
|
||||
@@ -302,9 +302,12 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES "{$include}")
|
||||
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES "{$include}")
|
||||
CMAKE;
|
||||
// Whoops, linux may need CMAKE_AR sometimes
|
||||
// pin AR/RANLIB so cmake uses zig-ar/zig-ranlib instead of system /usr/bin/ranlib (zig archives need it)
|
||||
if (PHP_OS_FAMILY === 'Linux') {
|
||||
$toolchain .= "\nSET(CMAKE_AR \"ar\")";
|
||||
$ar = getenv('SPC_DEFAULT_AR') ?: getenv('AR') ?: 'ar';
|
||||
$ranlib = getenv('SPC_DEFAULT_RANLIB') ?: (getenv('RANLIB') ?: 'ranlib');
|
||||
$toolchain .= "\nSET(CMAKE_AR \"{$ar}\")";
|
||||
$toolchain .= "\nSET(CMAKE_RANLIB \"{$ranlib}\")";
|
||||
}
|
||||
FileSystem::writeFile(SOURCE_PATH . '/toolchain.cmake', $toolchain);
|
||||
return $created = realpath(SOURCE_PATH . '/toolchain.cmake');
|
||||
|
||||
@@ -15,6 +15,7 @@ class ClangBrewToolchain extends ClangNativeToolchain
|
||||
GlobalEnvManager::putenv("SPC_DEFAULT_CC={$homebrew_prefix}/opt/llvm/bin/clang");
|
||||
GlobalEnvManager::putenv("SPC_DEFAULT_CXX={$homebrew_prefix}/opt/llvm/bin/clang++");
|
||||
GlobalEnvManager::putenv("SPC_DEFAULT_AR={$homebrew_prefix}/opt/llvm/bin/llvm-ar");
|
||||
GlobalEnvManager::putenv("SPC_DEFAULT_RANLIB={$homebrew_prefix}/opt/llvm/bin/llvm-ranlib");
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_LD=ld');
|
||||
GlobalEnvManager::addPathIfNotExists("{$homebrew_prefix}/opt/llvm/bin");
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class ClangNativeToolchain implements UnixToolchainInterface
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_CC=clang');
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_CXX=clang++');
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_AR=ar');
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_RANLIB=ranlib');
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_LD=ld');
|
||||
}
|
||||
|
||||
|
||||
20
src/StaticPHP/Toolchain/ClangPortsToolchain.php
Normal file
20
src/StaticPHP/Toolchain/ClangPortsToolchain.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Toolchain;
|
||||
|
||||
use StaticPHP\Util\GlobalEnvManager;
|
||||
|
||||
class ClangPortsToolchain extends ClangNativeToolchain
|
||||
{
|
||||
public function initEnv(): void
|
||||
{
|
||||
$macports_prefix = getenv('MACPORTS_PREFIX') ?: '/opt/local';
|
||||
GlobalEnvManager::putenv("SPC_DEFAULT_CC={$macports_prefix}/bin/clang");
|
||||
GlobalEnvManager::putenv("SPC_DEFAULT_CXX={$macports_prefix}/bin/clang++");
|
||||
GlobalEnvManager::putenv("SPC_DEFAULT_AR={$macports_prefix}/bin/llvm-ar");
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_LD=ld');
|
||||
GlobalEnvManager::addPathIfNotExists("{$macports_prefix}/bin");
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ class GccNativeToolchain implements UnixToolchainInterface
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_CC=gcc');
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_CXX=g++');
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_AR=ar');
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_RANLIB=ranlib');
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_LD=ld');
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ class ToolchainManager
|
||||
'Windows' => MSVCToolchain::class,
|
||||
'Darwin' => match (getenv('SPC_USE_LLVM') ?: 'system') {
|
||||
'brew' => ClangBrewToolchain::class,
|
||||
'port' => ClangPortsToolchain::class,
|
||||
default => ClangNativeToolchain::class,
|
||||
},
|
||||
default => throw new WrongUsageException('Unsupported OS family: ' . PHP_OS_FAMILY),
|
||||
|
||||
@@ -16,6 +16,7 @@ class ZigToolchain implements UnixToolchainInterface
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_CC=zig-cc');
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_CXX=zig-c++');
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_AR=zig-ar');
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_RANLIB=zig-ranlib');
|
||||
GlobalEnvManager::putenv('SPC_DEFAULT_LD=zig-ld.lld');
|
||||
|
||||
// Generate additional objects needed for zig toolchain
|
||||
|
||||
@@ -134,10 +134,10 @@ class GlobalEnvManager
|
||||
}
|
||||
// test bison
|
||||
if (PHP_OS_FAMILY === 'Darwin') {
|
||||
if ($bison = MacOSUtil::findCommand('bison', ['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin'])) {
|
||||
if ($bison = MacOSUtil::findCommand('bison', ['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin', '/opt/local/bin/bison'])) {
|
||||
self::putenv("BISON={$bison}");
|
||||
}
|
||||
if ($yacc = MacOSUtil::findCommand('yacc', ['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin'])) {
|
||||
if ($yacc = MacOSUtil::findCommand('yacc', ['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin', '/opt/local/bin/yacc'])) {
|
||||
self::putenv("YACC={$yacc}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,10 +256,30 @@ function clean_spaces(string $string): string
|
||||
*/
|
||||
function deduplicate_flags(string $flags): string
|
||||
{
|
||||
$tokens = preg_split('/\s+/', trim($flags));
|
||||
// Flags that take their value as a separate token.
|
||||
static $paired = [
|
||||
'-Xclang', '-Xpreprocessor', '-Xlinker', '-Xassembler',
|
||||
'-framework', '-arch', '-target',
|
||||
'-include', '-imacros', '-isystem', '-isysroot', '-iquote', '-idirafter',
|
||||
'-MT', '-MF', '-MQ',
|
||||
];
|
||||
|
||||
$tokens = preg_split('/\s+/', trim($flags)) ?: [];
|
||||
|
||||
// Group paired flag+value into a single atom before dedup.
|
||||
$atoms = [];
|
||||
$n = count($tokens);
|
||||
for ($i = 0; $i < $n; ++$i) {
|
||||
if (in_array($tokens[$i], $paired, true) && $i + 1 < $n) {
|
||||
$atoms[] = $tokens[$i] . ' ' . $tokens[$i + 1];
|
||||
++$i;
|
||||
} else {
|
||||
$atoms[] = $tokens[$i];
|
||||
}
|
||||
}
|
||||
|
||||
// Reverse, unique, reverse back - keeps last occurrence of duplicates
|
||||
$deduplicated = array_reverse(array_unique(array_reverse($tokens)));
|
||||
$deduplicated = array_reverse(array_unique(array_reverse($atoms)));
|
||||
|
||||
return implode(' ', $deduplicated);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user