Compare commits

..

1 Commits

Author SHA1 Message Date
henderkes
6df778f92f llvm-tools: build host llvm-objcopy/strip/profdata under ZigToolchain
Add an `llvm-tools` target artifact that downloads llvm-project source
matching the version of clang shipped by the active zig install,
builds llvm-objcopy, llvm-strip and llvm-profdata into
PKG_ROOT_PATH/llvm-tools/bin, and exposes them through the same
path/binary/isInstalled static surface as the other artifacts.

A new LlvmToolsCheck doctor item runs when the active toolchain is
ZigToolchain and reports whether the three tools are built, with a
fix that installs the package and runs the build.

PackageBuilder now picks the right tool when the active toolchain is
ZigToolchain:
- extractDebugInfo() honours OBJCOPY from the environment, then falls
  back to llvm-tools' llvm-objcopy under Zig and plain objcopy
  otherwise.
- stripBinary() uses llvm-strip under Zig and plain strip otherwise.

System strip/objcopy refuse zig-produced archives and bitcode
sections, so without this the strip stage breaks LTO builds. Other
toolchains keep using the system binaries.

ApplicationContext::tryGet() wraps the container's get() in a
try/catch and returns null on failure, so PackageBuilder can ask
"which toolchain is active right now" without PHP-DI throwing on
autowirable-but-unconstructable classes.

Depends on v3c/artifact-static-helpers (uses zig::isInstalled()
and zig::binary()).
2026-05-24 21:50:57 +07:00
70 changed files with 714 additions and 758 deletions

View File

@@ -38,9 +38,6 @@ jobs:
- name: "windows-x64" - name: "windows-x64"
os: "ubuntu-latest" os: "ubuntu-latest"
filename: "spc-windows-x64.exe" filename: "spc-windows-x64.exe"
permissions:
id-token: write
attestations: write
steps: steps:
- name: "Checkout" - name: "Checkout"
uses: "actions/checkout@v5" uses: "actions/checkout@v5"
@@ -108,12 +105,6 @@ jobs:
fi fi
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" - name: "Copy file"
run: | run: |
if [ "${{ matrix.operating-system.name }}" != "windows-x64" ]; then if [ "${{ matrix.operating-system.name }}" != "windows-x64" ]; then

View File

@@ -10,6 +10,7 @@
"config", "config",
"src", "src",
"vendor/psr", "vendor/psr",
"vendor/laravel/prompts",
"vendor/symfony", "vendor/symfony",
"vendor/php-di", "vendor/php-di",
"vendor/zhamao" "vendor/zhamao"

View File

@@ -12,8 +12,10 @@
"php": ">=8.4", "php": ">=8.4",
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-zlib": "*", "ext-zlib": "*",
"laravel/prompts": "~0.1",
"php-di/php-di": "^7.1", "php-di/php-di": "^7.1",
"symfony/console": "^5.4 || ^6 || ^7", "symfony/console": "^5.4 || ^6 || ^7",
"symfony/process": "^7.2",
"symfony/yaml": "^7.2", "symfony/yaml": "^7.2",
"zhamao/logger": "^1.1.4" "zhamao/logger": "^1.1.4"
}, },

568
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,10 +3,6 @@ ncurses:
license-files: license-files:
- COPYING - COPYING
source: source:
type: filelist
url: 'https://ftp.gnu.org/gnu/ncurses/'
regex: '/href="(?<file>ncurses-(?<version>[^"]+)\.tar\.gz)"/'
source-mirror:
type: filelist type: filelist
url: 'https://ftpmirror.gnu.org/gnu/ncurses/' url: 'https://ftpmirror.gnu.org/gnu/ncurses/'
regex: '/href="(?<file>ncurses-(?<version>[^"]+)\.tar\.gz)"/' regex: '/href="(?<file>ncurses-(?<version>[^"]+)\.tar\.gz)"/'

View File

@@ -68,8 +68,8 @@ SPC_PRESERVE_LOGS="no"
[windows] [windows]
; build target: win7-static ; build target: win7-static
SPC_TARGET=native-windows SPC_TARGET=native-windows
; MSYS2 root directory (msys64 subfolder), used by the Windows toolchain ; php-sdk-binary-tools path
SPC_MSYS2_PATH="${PKG_ROOT_PATH}\msys2-build-essentials\msys64" PHP_SDK_PATH="${WORKING_DIR}\php-sdk-binary-tools"
; upx executable path ; upx executable path
UPX_EXEC="${PKG_ROOT_PATH}\bin\upx.exe" UPX_EXEC="${PKG_ROOT_PATH}\bin\upx.exe"
; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches ; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches

View File

@@ -1,20 +0,0 @@
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

View File

@@ -1,14 +0,0 @@
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

View File

@@ -10,5 +10,3 @@ ext-gmssl:
license: PHP-3.01 license: PHP-3.01
depends: depends:
- gmssl - gmssl
php-extension:
arg-type: with-path

View File

@@ -2,10 +2,6 @@ gettext:
type: library type: library
artifact: artifact:
source: source:
type: filelist
url: 'https://ftp.gnu.org/gnu/gettext/'
regex: '/href="(?<file>gettext-(?<version>[^"]+)\.tar\.xz)"/'
source-mirror:
type: filelist type: filelist
url: 'https://ftpmirror.gnu.org/gnu/gettext/' url: 'https://ftpmirror.gnu.org/gnu/gettext/'
regex: '/href="(?<file>gettext-(?<version>[^"]+)\.tar\.xz)"/' regex: '/href="(?<file>gettext-(?<version>[^"]+)\.tar\.xz)"/'

View File

@@ -2,13 +2,12 @@ gmp:
type: library type: library
artifact: artifact:
source: source:
type: filelist
url: 'https://ftp.gnu.org/gnu/gmp/'
regex: '/href="(?<file>gmp-(?<version>[^"]+)\.tar\.xz)"/'
source-mirror:
type: filelist type: filelist
url: 'https://ftpmirror.gnu.org/gnu/gmp/' url: 'https://ftpmirror.gnu.org/gnu/gmp/'
regex: '/href="(?<file>gmp-(?<version>[^"]+)\.tar\.xz)"/' regex: '/href="(?<file>gmp-(?<version>[^"]+)\.tar\.xz)"/'
source-mirror:
type: url
url: 'https://dl.static-php.dev/static-php-cli/deps/gmp/gmp-6.3.0.tar.xz'
metadata: metadata:
license-files: ['@/gmp.txt'] license-files: ['@/gmp.txt']
license: Custom license: Custom

View File

@@ -2,10 +2,6 @@ idn2:
type: library type: library
artifact: artifact:
source: source:
type: filelist
url: 'https://ftp.gnu.org/gnu/libidn/'
regex: '/href="(?<file>libidn2-(?<version>[^"]+)\.tar\.gz)"/'
source-mirror:
type: filelist type: filelist
url: 'https://ftpmirror.gnu.org/gnu/libidn/' url: 'https://ftpmirror.gnu.org/gnu/libidn/'
regex: '/href="(?<file>libidn2-(?<version>[^"]+)\.tar\.gz)"/' regex: '/href="(?<file>libidn2-(?<version>[^"]+)\.tar\.gz)"/'

View File

@@ -2,10 +2,6 @@ libiconv:
type: library type: library
artifact: artifact:
source: source:
type: filelist
url: 'https://ftp.gnu.org/gnu/libiconv/'
regex: '/href="(?<file>libiconv-(?<version>[^"]+)\.tar\.gz)"/'
source-mirror:
type: filelist type: filelist
url: 'https://ftpmirror.gnu.org/gnu/libiconv/' url: 'https://ftpmirror.gnu.org/gnu/libiconv/'
regex: '/href="(?<file>libiconv-(?<version>[^"]+)\.tar\.gz)"/' regex: '/href="(?<file>libiconv-(?<version>[^"]+)\.tar\.gz)"/'

View File

@@ -2,10 +2,6 @@ libunistring:
type: library type: library
artifact: artifact:
source: source:
type: filelist
url: 'https://ftp.gnu.org/gnu/libunistring/'
regex: '/href="(?<file>libunistring-(?<version>[^"]+)\.tar\.gz)"/'
source-mirror:
type: filelist type: filelist
url: 'https://ftpmirror.gnu.org/gnu/libunistring/' url: 'https://ftpmirror.gnu.org/gnu/libunistring/'
regex: '/href="(?<file>libunistring-(?<version>[^"]+)\.tar\.gz)"/' regex: '/href="(?<file>libunistring-(?<version>[^"]+)\.tar\.gz)"/'

View File

@@ -2,10 +2,6 @@ readline:
type: library type: library
artifact: artifact:
source: source:
type: filelist
url: 'https://ftp.gnu.org/gnu/readline/'
regex: '/href="(?<file>readline-(?<version>[^"]+)\.tar\.gz)"/'
source-mirror:
type: filelist type: filelist
url: 'https://ftpmirror.gnu.org/gnu/readline/' url: 'https://ftpmirror.gnu.org/gnu/readline/'
regex: '/href="(?<file>readline-(?<version>[^"]+)\.tar\.gz)"/' regex: '/href="(?<file>readline-(?<version>[^"]+)\.tar\.gz)"/'

View File

@@ -1,5 +0,0 @@
7za-win:
type: target
artifact:
binary:
windows-x86_64: { type: url, url: 'https://dl.static-php.dev/v3/tools/7zip/7za.exe', extract: '{pkg_root_path}/bin/7za.exe' }

View File

@@ -0,0 +1,6 @@
llvm-tools:
type: target
artifact:
binary: custom
depends:
- zig

View File

@@ -1,8 +0,0 @@
msys2-build-essentials:
type: target
artifact:
binary: custom
env:
SPC_MSYS2_PATH: '{pkg_root_path}/msys2-build-essentials/msys64'
path@windows:
- '{pkg_root_path}/msys2-build-essentials/msys64/usr/bin'

View File

@@ -2,4 +2,4 @@ nasm:
type: target type: target
artifact: artifact:
binary: binary:
windows-x86_64: { type: url, url: 'https://dl.static-php.dev/static-php-cli/deps/nasm/nasm-2.16.01-win64.zip', extract: { nasm.exe: '{pkg_root_path}/bin/nasm.exe', ndisasm.exe: '{pkg_root_path}/bin/ndisasm.exe' } } windows-x86_64: { type: url, url: 'https://dl.static-php.dev/static-php-cli/deps/nasm/nasm-2.16.01-win64.zip', extract: { nasm.exe: '{php_sdk_path}/bin/nasm.exe', ndisasm.exe: '{php_sdk_path}/bin/ndisasm.exe' } }

View File

@@ -0,0 +1,5 @@
php-sdk-binary-tools:
type: target
artifact:
binary:
windows-x86_64: { type: git, rev: master, url: 'https://github.com/php/php-sdk-binary-tools.git', extract: '{php_sdk_path}' }

View File

@@ -229,7 +229,7 @@ The following path placeholders are supported in string values of the `path`, `e
| `{working_dir}` | Working directory (project root) | | `{working_dir}` | Working directory (project root) |
| `{download_path}` | Download cache directory (`downloads/`) | | `{download_path}` | Download cache directory (`downloads/`) |
| `{source_path}` | Extracted source directory (`source/`) | | `{source_path}` | Extracted source directory (`source/`) |
| `{spc_msys2_path}` | MSYS2 root directory (`msys64/`) — Windows only | | `{php_sdk_path}` | Windows PHP SDK directory |
## target Package Type ## target Package Type

View File

@@ -58,13 +58,7 @@ A single-file hook API for lightweight patches may be provided in a future relea
### Windows-only: `--with-sdk-binary-dir` and `--vs-ver` ### Windows-only: `--with-sdk-binary-dir` and `--vs-ver`
These options are no longer accepted on the command line. In v3, the `php-sdk-binary-tools` dependency has been completely removed. v3 now manages its own **MSYS2** environment to support autotools-based library builds on Windows. Run `spc doctor --install` to download and configure MSYS2 automatically. These options are no longer accepted on the command line. Instead, set the `PHP_SDK_PATH` environment variable to point to your PHP SDK binary tools directory. The Visual Studio version is now managed by the toolchain configuration.
If you need to point to a custom MSYS2 installation, set the `SPC_MSYS2_PATH` environment variable to the `msys64` directory (e.g. `C:\msys64`). Visual Studio is now auto-detected by the toolchain — no manual version flag needed.
::: warning Migrating from v2
v2 relied on `php-sdk-binary-tools` and required `--with-sdk-binary-dir` and `--vs-ver` on every build invocation. In v3 these options are gone. Remove them from all CI scripts and run `spc doctor --install` once to set up the Windows build environment.
:::
## Renamed / Deprecated Options ## Renamed / Deprecated Options

View File

@@ -223,7 +223,7 @@ openssl:
| `{working_dir}` | 工作目录(项目根目录) | | `{working_dir}` | 工作目录(项目根目录) |
| `{download_path}` | 下载缓存目录(`downloads/` | | `{download_path}` | 下载缓存目录(`downloads/` |
| `{source_path}` | 解压源码目录(`source/` | | `{source_path}` | 解压源码目录(`source/` |
| `{spc_msys2_path}` | MSYS2 根目录(`msys64/`)——仅 Windows | | `{php_sdk_path}` | Windows PHP SDK 目录 |
## target 包类型 ## target 包类型

View File

@@ -58,13 +58,7 @@ curl -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-x86_64
### Windows 专有:`--with-sdk-binary-dir` 和 `--vs-ver` ### Windows 专有:`--with-sdk-binary-dir` 和 `--vs-ver`
这两个选项已不再被命令行接受。在 v3 中,`php-sdk-binary-tools` 依赖已被完全移除。v3 现在通过管理自己的 **MSYS2** 环境来支持 Windows 上基于 autotools 的库构建。运行 `spc doctor --install` 即可自动下载并配置 MSYS2 这两个选项已不再被命令行接受。请改为设置 `PHP_SDK_PATH` 环境变量,指向你的 PHP SDK binary tools 目录。Visual Studio 版本现在由工具链配置统一管理
如需指向自定义 MSYS2 安装目录,请设置 `SPC_MSYS2_PATH` 环境变量,值为 `msys64` 目录路径(例如 `C:\msys64`。Visual Studio 版本现在由工具链自动检测,无需手动指定版本号。
::: warning 从 v2 迁移
v2 依赖 `php-sdk-binary-tools`,并在每次构建时需要传入 `--with-sdk-binary-dir``--vs-ver` 参数。在 v3 中这些选项已被移除。请从所有 CI 脚本中删除这些参数,并使用 `spc doctor --install` 一次性完成 Windows 构建环境的配置。
:::
## 已重命名 / 已弃用的选项 ## 已重命名 / 已弃用的选项

View File

@@ -1,6 +1,6 @@
parameters: parameters:
reportUnmatchedIgnoredErrors: false reportUnmatchedIgnoredErrors: false
level: 5 level: 4
phpVersion: 80400 phpVersion: 80400
paths: paths:
- ./src/ - ./src/

View 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;
}
}

View File

@@ -1,93 +0,0 @@
<?php
declare(strict_types=1);
namespace Package\Artifact;
use StaticPHP\Artifact\ArtifactDownloader;
use StaticPHP\Artifact\Downloader\DownloadResult;
use StaticPHP\Attribute\Artifact\AfterBinaryExtract;
use StaticPHP\Attribute\Artifact\BinaryExtract;
use StaticPHP\Attribute\Artifact\CustomBinary;
use StaticPHP\Exception\DownloaderException;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\GlobalEnvManager;
class msys2_build_essentials
{
// MSYS subsystem packages required for autotools-based builds.
private const REQUIRED_PACKAGES = ['make', 'autoconf', 'automake', 'libtool', 'pkgconf', 'perl'];
#[CustomBinary('msys2-build-essentials', ['windows-x86_64'])]
public function downBinary(ArtifactDownloader $downloader): DownloadResult
{
// MSYS2 nightly self-extracting archive; running it with `-y -oTARGET` extracts to TARGET\msys64\.
$url = 'https://github.com/msys2/msys2-installer/releases/download/nightly-x86_64/msys2-base-x86_64-latest.sfx.exe';
$filename = 'msys2-base-x86_64-latest.sfx.exe';
$path = DOWNLOAD_PATH . DIRECTORY_SEPARATOR . $filename;
default_shell()->executeCurlDownload($url, $path, retries: $downloader->getRetry());
return DownloadResult::file(
$filename,
['url' => $url, 'version' => 'nightly'],
version: 'nightly',
extract: '{pkg_root_path}/msys2-build-essentials',
);
}
#[BinaryExtract('msys2-build-essentials', ['windows-x86_64'])]
public function extractBinary(string $source_file, string $target_path): void
{
$target_path = FileSystem::convertPath($target_path);
$source_file = FileSystem::convertPath($source_file);
// Guard: skip re-extraction if already initialized (marker written at end of this method).
$marker = "{$target_path}\\.spc-msys2-initialized";
if (file_exists($marker)) {
return;
}
if (!is_dir($target_path)) {
FileSystem::createDir($target_path);
}
cmd()->exec("\"{$source_file}\" -y -o\"{$target_path}\"");
$msys2_bin = "{$target_path}\\msys64\\usr\\bin";
if (!file_exists("{$msys2_bin}\\bash.exe")) {
throw new DownloaderException("MSYS2 extraction failed: bash.exe not found at {$msys2_bin}\\bash.exe");
}
// Add MSYS2 usr\bin to PATH so pacman.exe can load msys-2.0.dll.
GlobalEnvManager::addPathIfNotExists($msys2_bin);
GlobalEnvManager::putenv('CHERE_INVOKING=yes');
GlobalEnvManager::putenv('MSYSTEM=MSYS');
// Disable PGP signature checking: pacman-key --init requires a pseudo-TTY which is unavailable
// from PHP. Patching pacman.conf is the standard approach for CI pipelines.
$pacman_conf = "{$target_path}\\msys64\\etc\\pacman.conf";
FileSystem::replaceFileRegex($pacman_conf, '/^SigLevel\s*=.*$/m', 'SigLevel = Never');
$pacman = "{$target_path}\\msys64\\usr\\bin\\pacman.exe";
// Two-pass update as recommended by MSYS2 CI docs.
cmd()->exec("\"{$pacman}\" --noconfirm -Syuu");
cmd()->exec("\"{$pacman}\" --noconfirm -Syuu");
$pkgs = implode(' ', self::REQUIRED_PACKAGES);
cmd()->exec("\"{$pacman}\" --noconfirm -S --needed {$pkgs}");
FileSystem::writeFile($marker, date('Y-m-d H:i:s'));
}
#[AfterBinaryExtract('msys2-build-essentials', ['windows-x86_64'])]
public function afterExtract(string $target_path): void
{
$target_path = FileSystem::convertPath($target_path);
$msys2_root = "{$target_path}\\msys64";
GlobalEnvManager::putenv("SPC_MSYS2_PATH={$msys2_root}");
GlobalEnvManager::addPathIfNotExists("{$msys2_root}\\usr\\bin");
}
}

View File

@@ -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',

View File

@@ -1,45 +0,0 @@
<?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\PatchDescription;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;
#[Extension('gmssl')]
class gmssl extends PhpExtensionPackage
{
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-gmssl')]
#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-gmssl')]
#[PatchDescription('Fix ext-gmssl v1.1.1 compatibility with GmSSL >= 3.1.0 where SM2_VERIFY_CTX was removed (unified into SM2_SIGN_CTX)')]
public function patchSm2VerifyCtx(): void
{
// See: https://github.com/crazywhalecc/static-php-cli/issues/1182
FileSystem::replaceFileStr(
"{$this->getSourceDir()}/gmssl.c",
'SM2_VERIFY_CTX',
'SM2_SIGN_CTX'
);
}
#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-gmssl')]
#[PatchDescription('Add CHECK_LIB to config.w32 for static Windows builds')]
public function patchBeforeBuildconfWin(): bool
{
$configW32 = "{$this->getSourceDir()}/config.w32";
if (str_contains(FileSystem::readFile($configW32), 'CHECK_LIB(')) {
return false;
}
FileSystem::replaceFileStr(
$configW32,
'AC_DEFINE(',
'CHECK_LIB("gmssl.lib", "gmssl", PHP_GMSSL);' . PHP_EOL . 'AC_DEFINE('
);
return true;
}
}

View File

@@ -22,7 +22,6 @@ class gettext_win
{ {
$ver = WindowsUtil::findVisualStudio(); $ver = WindowsUtil::findVisualStudio();
$vs_ver_dir = match ($ver['major_version']) { $vs_ver_dir = match ($ver['major_version']) {
'18', // VS 2026 reuses the VS2022 (MSVC17) solution, which msbuild builds via forward compatibility.
'17' => '\MSVC17', '17' => '\MSVC17',
'16' => '\MSVC16', '16' => '\MSVC16',
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"), default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"),
@@ -45,9 +44,7 @@ class gettext_win
{ {
$vs_ver_dir = ApplicationContext::get('gettext_win_vs_ver_dir'); $vs_ver_dir = ApplicationContext::get('gettext_win_vs_ver_dir');
cmd()->cd("{$lib->getSourceDir()}{$vs_ver_dir}\\libintl_static") cmd()->cd("{$lib->getSourceDir()}{$vs_ver_dir}\\libintl_static")
// WholeProgramOptimization (/GL) emits LTCG objects that frankenphp's lld-link cannot ->exec('msbuild libintl_static.vcxproj /t:Rebuild /p:Configuration=Release /p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0');
// read ("is not a native COFF file"); disable it so the .lib stays plain COFF.
->exec('msbuild libintl_static.vcxproj /t:Rebuild /p:Configuration=Release /p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0 /p:WholeProgramOptimization=false');
FileSystem::createDir($lib->getLibDir()); FileSystem::createDir($lib->getLibDir());
FileSystem::createDir($lib->getIncludeDir()); FileSystem::createDir($lib->getIncludeDir());
// libintl_a.lib is the static library output; copy as libintl.lib for linker compatibility // libintl_a.lib is the static library output; copy as libintl.lib for linker compatibility

View File

@@ -18,9 +18,7 @@ class gmssl
#[BuildFor('Darwin')] #[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void public function build(LibraryPackage $lib): void
{ {
UnixCMakeExecutor::create($lib) UnixCMakeExecutor::create($lib)->build();
->addConfigureArgs('-DENABLE_SM2_PRIVATE_KEY_EXPORT=ON')
->build();
} }
#[BuildFor('Windows')] #[BuildFor('Windows')]
@@ -35,7 +33,6 @@ class gmssl
'-G "NMake Makefiles"', '-G "NMake Makefiles"',
'-DWIN32=ON', '-DWIN32=ON',
'-DBUILD_SHARED_LIBS=OFF', '-DBUILD_SHARED_LIBS=OFF',
'-DENABLE_SM2_PRIVATE_KEY_EXPORT=ON',
'-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /DNDEBUG"', '-DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /DNDEBUG"',
'-DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /DNDEBUG"', '-DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /DNDEBUG"',

View File

@@ -21,7 +21,6 @@ class libffi_win
{ {
$ver = WindowsUtil::findVisualStudio(); $ver = WindowsUtil::findVisualStudio();
$vs_ver_dir = match ($ver['major_version']) { $vs_ver_dir = match ($ver['major_version']) {
'18', // VS 2026 reuses the vs17 solution, which msbuild builds via forward compatibility.
'17' => '\win32\vs17_x64', '17' => '\win32\vs17_x64',
'16' => '\win32\vs16_x64', '16' => '\win32\vs16_x64',
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported!"), default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported!"),
@@ -34,9 +33,7 @@ class libffi_win
{ {
$vs_ver_dir = ApplicationContext::get('libffi_win_vs_ver_dir'); $vs_ver_dir = ApplicationContext::get('libffi_win_vs_ver_dir');
cmd()->cd("{$lib->getSourceDir()}{$vs_ver_dir}") cmd()->cd("{$lib->getSourceDir()}{$vs_ver_dir}")
// WholeProgramOptimization (/GL) emits LTCG objects that frankenphp's lld-link cannot ->exec('msbuild libffi-msvc.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64');
// read ("is not a native COFF file"); disable it so the .lib stays plain COFF.
->exec('msbuild libffi-msvc.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64 /p:WholeProgramOptimization=false');
FileSystem::createDir($lib->getLibDir()); FileSystem::createDir($lib->getLibDir());
FileSystem::createDir($lib->getIncludeDir()); FileSystem::createDir($lib->getIncludeDir());

View File

@@ -21,7 +21,6 @@ class libiconv_win
{ {
$ver = WindowsUtil::findVisualStudio(); $ver = WindowsUtil::findVisualStudio();
$vs_ver_dir = match ($ver['major_version']) { $vs_ver_dir = match ($ver['major_version']) {
'18', // VS 2026 reuses the VS2022 (MSVC17) solution, which msbuild builds via forward compatibility.
'17' => '\MSVC17', '17' => '\MSVC17',
'16' => '\MSVC16', '16' => '\MSVC16',
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"), default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"),
@@ -34,9 +33,7 @@ class libiconv_win
{ {
$vs_ver_dir = ApplicationContext::get('vs_ver_dir'); $vs_ver_dir = ApplicationContext::get('vs_ver_dir');
cmd()->cd("{$lib->getSourceDir()}{$vs_ver_dir}") cmd()->cd("{$lib->getSourceDir()}{$vs_ver_dir}")
// WholeProgramOptimization (/GL) emits LTCG objects that frankenphp's lld-link cannot ->exec('msbuild libiconv.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64');
// read ("is not a native COFF file"); disable it so the .lib stays plain COFF.
->exec('msbuild libiconv.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64 /p:WholeProgramOptimization=false');
FileSystem::createDir($lib->getLibDir()); FileSystem::createDir($lib->getLibDir());
FileSystem::createDir($lib->getIncludeDir()); FileSystem::createDir($lib->getIncludeDir());
FileSystem::copy("{$lib->getSourceDir()}{$vs_ver_dir}\\x64\\lib\\libiconv.lib", "{$lib->getLibDir()}\\libiconv.lib"); FileSystem::copy("{$lib->getSourceDir()}{$vs_ver_dir}\\x64\\lib\\libiconv.lib", "{$lib->getLibDir()}\\libiconv.lib");

View File

@@ -42,16 +42,13 @@ class libsodium
{ {
$ver = WindowsUtil::findVisualStudio(); $ver = WindowsUtil::findVisualStudio();
$vs_ver_dir = match ($ver['major_version']) { $vs_ver_dir = match ($ver['major_version']) {
'18', // VS 2026 reuses the vs2022 solution, which msbuild builds via forward compatibility.
'17' => '\vs2022', '17' => '\vs2022',
'16' => '\vs2019', '16' => '\vs2019',
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"), default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"),
}; };
cmd()->cd("{$lib->getSourceDir()}\\builds\\msvc{$vs_ver_dir}") cmd()->cd("{$lib->getSourceDir()}\\builds\\msvc{$vs_ver_dir}")
// WholeProgramOptimization (/GL) emits LTCG objects that frankenphp's lld-link cannot ->exec('msbuild libsodium.sln /t:Rebuild /p:Configuration=StaticRelease /p:Platform=x64 /p:PreprocessorDefinitions="SODIUM_STATIC=1"');
// read ("is not a native COFF file"); disable it so the .lib stays plain COFF.
->exec('msbuild libsodium.sln /t:Rebuild /p:Configuration=StaticRelease /p:Platform=x64 /p:WholeProgramOptimization=false /p:PreprocessorDefinitions="SODIUM_STATIC=1"');
FileSystem::createDir($lib->getLibDir()); FileSystem::createDir($lib->getLibDir());
FileSystem::createDir($lib->getIncludeDir()); FileSystem::createDir($lib->getIncludeDir());

View File

@@ -21,7 +21,6 @@ class mpir
{ {
$ver = WindowsUtil::findVisualStudio(); $ver = WindowsUtil::findVisualStudio();
$vs_ver_dir = match ($ver['major_version']) { $vs_ver_dir = match ($ver['major_version']) {
'18', // VS 2026 reuses the build.vc17 solution, which msbuild builds via forward compatibility.
'17' => '\build.vc17', '17' => '\build.vc17',
'16' => '\build.vc16', '16' => '\build.vc16',
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"), default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"),

View File

@@ -20,8 +20,8 @@ class unixodbc extends LibraryPackage
{ {
$sysconf_selector = match ($os = SystemTarget::getTargetOS()) { $sysconf_selector = match ($os = SystemTarget::getTargetOS()) {
'Darwin' => match (SystemTarget::getTargetArch()) { 'Darwin' => match (SystemTarget::getTargetArch()) {
'x86_64' => is_dir('/usr/local/etc') ? '/usr/local/etc' : '/opt/local/etc', 'x86_64' => '/usr/local/etc',
'aarch64' => is_dir('/opt/homebrew/etc') ? '/opt/homebrew/etc' : '/opt/local/etc', 'aarch64' => '/opt/homebrew/etc',
default => throw new WrongUsageException('Unsupported architecture: ' . GNU_ARCH), default => throw new WrongUsageException('Unsupported architecture: ' . GNU_ARCH),
}, },
'Linux' => '/etc', 'Linux' => '/etc',

View File

@@ -512,7 +512,6 @@ HEADER;
$vc_matches = ['unknown', 'unknown']; $vc_matches = ['unknown', 'unknown'];
} else { } else {
$vc_matches = match ($vc['major_version']) { $vc_matches = match ($vc['major_version']) {
'18', // VS 2026 shares the VS2022 (v143) runtime conventions, so it reports as VS17.
'17' => ['VS17', 'Visual C++ 2022'], '17' => ['VS17', 'Visual C++ 2022'],
'16' => ['VS16', 'Visual C++ 2019'], '16' => ['VS16', 'Visual C++ 2019'],
default => ['unknown', 'unknown'], default => ['unknown', 'unknown'],

View File

@@ -644,7 +644,7 @@ class Artifact
'{artifact_name}' => $this->name, '{artifact_name}' => $this->name,
'{pkg_root_path}' => PKG_ROOT_PATH, '{pkg_root_path}' => PKG_ROOT_PATH,
'{build_root_path}' => BUILD_ROOT_PATH, '{build_root_path}' => BUILD_ROOT_PATH,
'{spc_msys2_path}' => getenv('SPC_MSYS2_PATH'), '{php_sdk_path}' => getenv('PHP_SDK_PATH') ?: WORKING_DIR . '/php-sdk-binary-tools',
'{working_dir}' => WORKING_DIR, '{working_dir}' => WORKING_DIR,
'{download_path}' => DOWNLOAD_PATH, '{download_path}' => DOWNLOAD_PATH,
'{source_path}' => SOURCE_PATH, '{source_path}' => SOURCE_PATH,

View File

@@ -614,7 +614,7 @@ class ArtifactExtractor
'{source_path}' => SOURCE_PATH, '{source_path}' => SOURCE_PATH,
'{download_path}' => DOWNLOAD_PATH, '{download_path}' => DOWNLOAD_PATH,
'{working_dir}' => WORKING_DIR, '{working_dir}' => WORKING_DIR,
'{spc_msys2_path}' => getenv('SPC_MSYS2_PATH') ?: '', '{php_sdk_path}' => getenv('PHP_SDK_PATH') ?: '',
]; ];
return str_replace(array_keys($replacement), array_values($replacement), $path); return str_replace(array_keys($replacement), array_values($replacement), $path);
} }

View File

@@ -76,10 +76,9 @@ class DownloadResult
?string $version = null, ?string $version = null,
array $metadata = [], array $metadata = [],
?string $downloader = null, ?string $downloader = null,
mixed $extract = null,
): DownloadResult { ): DownloadResult {
$cache_type = self::isArchiveFile($filename) ? 'archive' : 'file'; $cache_type = self::isArchiveFile($filename) ? 'archive' : 'file';
return new self($cache_type, config: $config, filename: $filename, extract: $extract, verified: $verified, version: $version, metadata: $metadata, downloader: $downloader); return new self($cache_type, config: $config, filename: $filename, verified: $verified, version: $version, metadata: $metadata, downloader: $downloader);
} }
/** /**

View File

@@ -45,11 +45,7 @@ class FileList implements DownloadTypeInterface, CheckUpdateInterface
throw new DownloaderException("Failed to get {$name} file list from {$config['url']}"); throw new DownloaderException("Failed to get {$name} file list from {$config['url']}");
} }
$versions = []; $versions = [];
$cnt = count($matches['version']); logger()->debug('Matched ' . count($matches['version']) . " versions for {$name}");
if ($cnt === 0) {
throw new DownloaderException("Failed to get {$name} file list from {$config['url']}: no version parsed");
}
logger()->debug("Matched {$cnt} versions for {$name}");
foreach ($matches['version'] as $i => $version) { foreach ($matches['version'] as $i => $version) {
$lower = strtolower($version); $lower = strtolower($version);
foreach (['alpha', 'beta', 'rc', 'pre', 'nightly', 'snapshot', 'dev'] as $beta) { foreach (['alpha', 'beta', 'rc', 'pre', 'nightly', 'snapshot', 'dev'] as $beta) {

View File

@@ -110,7 +110,7 @@ class CraftCommand extends BaseCommand
* shared-extensions: array<string>, * shared-extensions: array<string>,
* packages: array<string>, * packages: array<string>,
* sapi: array<string>, * sapi: array<string>,
* verbosity: 128|16|256|32|64|8, * verbosity: int,
* debug: bool, * debug: bool,
* clean-build: bool, * clean-build: bool,
* build-options: array<string, mixed>, * build-options: array<string, mixed>,
@@ -171,16 +171,11 @@ class CraftCommand extends BaseCommand
} }
// verbosity // verbosity
$verbosity_level = $craft['verbosity'] ?? OutputInterface::VERBOSITY_NORMAL;
$debug = $craft['debug'] ?? false; $debug = $craft['debug'] ?? false;
$verbosity_level = $debug if ($debug) {
? OutputInterface::VERBOSITY_DEBUG $verbosity_level = OutputInterface::VERBOSITY_DEBUG;
: match ((int) ($craft['verbosity'] ?? 0)) { }
OutputInterface::VERBOSITY_QUIET => OutputInterface::VERBOSITY_QUIET,
OutputInterface::VERBOSITY_VERBOSE => OutputInterface::VERBOSITY_VERBOSE,
OutputInterface::VERBOSITY_VERY_VERBOSE => OutputInterface::VERBOSITY_VERY_VERBOSE,
OutputInterface::VERBOSITY_DEBUG => OutputInterface::VERBOSITY_DEBUG,
default => OutputInterface::VERBOSITY_NORMAL,
};
$craft['verbosity'] = $verbosity_level; $craft['verbosity'] = $verbosity_level;
// clean-build (if true, reset before all builds) // clean-build (if true, reset before all builds)

View File

@@ -16,7 +16,7 @@ class GenExtTestMatrixCommand extends BaseCommand
private const array OS_RUNNERS = [ private const array OS_RUNNERS = [
'linux' => ['arch' => 'x86_64', 'runner' => 'ubuntu-latest', 'os_key' => 'Linux'], 'linux' => ['arch' => 'x86_64', 'runner' => 'ubuntu-latest', 'os_key' => 'Linux'],
'windows' => ['arch' => 'x86_64', 'runner' => 'windows-2025', 'os_key' => 'Windows'], 'windows' => ['arch' => 'x86_64', 'runner' => 'windows-latest', 'os_key' => 'Windows'],
'macos' => ['arch' => 'aarch64', 'runner' => 'macos-15', 'os_key' => 'Darwin'], 'macos' => ['arch' => 'aarch64', 'runner' => 'macos-15', 'os_key' => 'Darwin'],
]; ];
@@ -60,8 +60,6 @@ class GenExtTestMatrixCommand extends BaseCommand
'glfw', 'glfw',
'imagick', 'imagick',
'intl', 'intl',
'mongodb',
'gmssl',
]; ];
/** /**

View File

@@ -154,7 +154,7 @@ class TestBotCommand extends BaseCommand
'targets' => array_values($targets), 'targets' => array_values($targets),
'gen_matrix_args' => $gen_matrix_args, 'gen_matrix_args' => $gen_matrix_args,
'gen_matrix_args_tier2' => $gen_matrix_args_tier2, 'gen_matrix_args_tier2' => $gen_matrix_args_tier2,
'php_versions' => $php_versions, 'php_versions' => array_values($php_versions),
'tier2' => $tier2, 'tier2' => $tier2,
'comment_body' => $comment_body, 'comment_body' => $comment_body,
]; ];

View File

@@ -4,14 +4,13 @@ declare(strict_types=1);
namespace StaticPHP\Command; namespace StaticPHP\Command;
use StaticPHP\Exception\SPCInternalException;
use StaticPHP\Runtime\Shell\Shell; use StaticPHP\Runtime\Shell\Shell;
use StaticPHP\Util\FileSystem; use StaticPHP\Util\FileSystem;
use StaticPHP\Util\InteractiveTerm; use StaticPHP\Util\InteractiveTerm;
use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use function Laravel\Prompts\confirm;
#[AsCommand('reset')] #[AsCommand('reset')]
class ResetCommand extends BaseCommand class ResetCommand extends BaseCommand
@@ -47,11 +46,7 @@ class ResetCommand extends BaseCommand
// Confirm with user unless --yes is specified // Confirm with user unless --yes is specified
if (!$this->input->getOption('yes')) { if (!$this->input->getOption('yes')) {
$helper = $this->getHelper('question'); if (!confirm('Are you sure you want to continue?', false)) {
if (!$helper instanceof QuestionHelper) {
throw new SPCInternalException('Question helper not provided');
}
if (!$helper->ask($this->input, $this->output, new ConfirmationQuestion('Are you sure you want to continue? [y/N] ', false))) {
InteractiveTerm::error(message: 'Reset operation cancelled.'); InteractiveTerm::error(message: 'Reset operation cancelled.');
return static::SUCCESS; return static::SUCCESS;
} }

View File

@@ -79,11 +79,11 @@ class ApplicationContext
/** /**
* Get a service from the container. * Get a service from the container.
* *
* @template T of object * @template T
* *
* @param class-string<T>|string $id Service identifier * @param class-string<T> $id Service identifier
* *
* @return ($id is class-string<T> ? T : mixed) * @return null|T
*/ */
public static function get(string $id): mixed public static function get(string $id): mixed
{ {
@@ -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.

View File

@@ -11,14 +11,11 @@ use StaticPHP\Registry\DoctorLoader;
use StaticPHP\Runtime\Shell\Shell; use StaticPHP\Runtime\Shell\Shell;
use StaticPHP\Runtime\SystemTarget; use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\InteractiveTerm; use StaticPHP\Util\InteractiveTerm;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use ZM\Logger\ConsoleColor; use ZM\Logger\ConsoleColor;
use function Laravel\Prompts\confirm;
readonly class Doctor readonly class Doctor
{ {
public function __construct(private ?OutputInterface $output = null, private int $auto_fix = FIX_POLICY_PROMPT, public readonly bool $interactive = true) public function __construct(private ?OutputInterface $output = null, private int $auto_fix = FIX_POLICY_PROMPT, public readonly bool $interactive = true)
@@ -128,14 +125,9 @@ readonly class Doctor
return false; return false;
} }
// prompt for fix // prompt for fix
if ($this->auto_fix === FIX_POLICY_PROMPT) { if ($this->auto_fix === FIX_POLICY_PROMPT && !confirm('Do you want to try to fix this issue now?')) {
$helper = new QuestionHelper(); $this->output?->writeln('<comment>You canceled fix.</comment>');
$input = ApplicationContext::has(InputInterface::class) ? ApplicationContext::get(InputInterface::class) : new ArrayInput([]); return false;
$output = ApplicationContext::has(OutputInterface::class) ? ApplicationContext::get(OutputInterface::class) : $this->output ?? new ConsoleOutput();
if (!$helper->ask($input, $output, new ConfirmationQuestion('Do you want to try to fix this issue now? [Y/n] ', true))) {
$this->output?->writeln('<comment>You canceled fix.</comment>');
return false;
}
} }
// perform fix // perform fix
InteractiveTerm::indicateProgress("Fixing {$result->getFixItem()} ... "); InteractiveTerm::indicateProgress("Fixing {$result->getFixItem()} ... ");

View File

@@ -73,20 +73,13 @@ class LinuxMuslCheck
$prefix = 'sudo '; $prefix = 'sudo ';
logger()->warning('Current user is not root, using sudo for running command'); 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') $shell = shell()->cd(SOURCE_PATH . '/musl-wrapper')
->setEnv($sysEnv) ->exec('CC=gcc CXX=g++ AR=ar LD=ld ./configure --disable-gcc-wrapper')
->exec('./configure --disable-gcc-wrapper') ->exec('CC=gcc CXX=g++ AR=ar LD=ld make -j');
->exec('make -j');
if ($prefix !== '') { if ($prefix !== '') {
f_passthru('cd ' . SOURCE_PATH . "/musl-wrapper && {$envFlags} {$prefix}make install"); f_passthru('cd ' . SOURCE_PATH . "/musl-wrapper && CC=gcc CXX=g++ AR=ar LD=ld {$prefix}make install");
} else { } else {
$shell->exec("{$prefix}make install"); $shell->exec("CC=gcc CXX=g++ AR=ar LD=ld {$prefix}make install");
} }
return true; return true;
} }

View 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();
}
}

View File

@@ -33,20 +33,15 @@ class MacOSToolCheck
'glibtoolize', 'glibtoolize',
]; ];
#[CheckItem('if homebrew or macports has installed', limit_os: 'Darwin', level: 998)] #[CheckItem('if homebrew has installed', limit_os: 'Darwin', level: 998)]
public function checkBrewOrPorts(): ?CheckResult public function checkBrew(): ?CheckResult
{ {
$brewPath = MacOSUtil::findCommand('brew'); if (($path = MacOSUtil::findCommand('brew')) === null) {
$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::fail('Homebrew is not installed', 'brew');
} }
if ($path !== '/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/ !');
}
return CheckResult::ok(); return CheckResult::ok();
} }
@@ -65,8 +60,8 @@ class MacOSToolCheck
return CheckResult::ok(); return CheckResult::ok();
} }
#[CheckItem('if homebrew or macports llvm are installed', limit_os: 'Darwin')] #[CheckItem('if homebrew llvm are installed', limit_os: 'Darwin')]
public function checkBrewOrPortsLLVM(): ?CheckResult public function checkBrewLLVM(): ?CheckResult
{ {
if (getenv('SPC_USE_LLVM') === 'brew') { if (getenv('SPC_USE_LLVM') === 'brew') {
$homebrew_prefix = getenv('HOMEBREW_PREFIX') ?: (SystemTarget::getTargetArch() === 'aarch64' ? '/opt/homebrew' : '/usr/local/homebrew'); $homebrew_prefix = getenv('HOMEBREW_PREFIX') ?: (SystemTarget::getTargetArch() === 'aarch64' ? '/opt/homebrew' : '/usr/local/homebrew');
@@ -76,16 +71,6 @@ class MacOSToolCheck
} }
return CheckResult::ok($path); 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; return null;
} }
@@ -106,7 +91,7 @@ class MacOSToolCheck
if ($command_path !== []) { if ($command_path !== []) {
return CheckResult::fail("Current {$bison} version is too old: " . $matches[0]); return CheckResult::fail("Current {$bison} version is too old: " . $matches[0]);
} }
return $this->checkBisonVersion(['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin', '/opt/local/bin']); return $this->checkBisonVersion(['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin']);
} }
return CheckResult::ok($matches[0]); return CheckResult::ok($matches[0]);
} }
@@ -123,9 +108,6 @@ class MacOSToolCheck
#[FixItem('build-tools')] #[FixItem('build-tools')]
public function fixBuildTools(array $missing): bool public function fixBuildTools(array $missing): bool
{ {
$brewPath = MacOSUtil::findCommand('brew');
$portPath = MacOSUtil::findCommand('port');
$replacement = [ $replacement = [
'glibtoolize' => 'libtool', 'glibtoolize' => 'libtool',
]; ];
@@ -133,18 +115,7 @@ class MacOSToolCheck
if (isset($replacement[$cmd])) { if (isset($replacement[$cmd])) {
$cmd = $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; return true;
} }

View File

@@ -54,24 +54,13 @@ class WindowsToolCheck
return CheckResult::ok(); return CheckResult::ok();
} }
#[CheckItem('if msys2-build-essentials is installed', limit_os: 'Windows', level: 996)] #[CheckItem('if php-sdk-binary-tools are downloaded', limit_os: 'Windows', level: 996)]
public function checkMsys2(): ?CheckResult public function checkSDK(): ?CheckResult
{ {
$marker = PKG_ROOT_PATH . '\msys2-build-essentials\.spc-msys2-initialized'; if (!file_exists(getenv('PHP_SDK_PATH') . DIRECTORY_SEPARATOR . 'phpsdk-starter.bat')) {
if (!file_exists($marker)) { return CheckResult::fail('php-sdk-binary-tools not downloaded', 'install-php-sdk');
return CheckResult::fail('msys2-build-essentials not installed', 'install-msys2-build-essentials');
} }
return CheckResult::ok(PKG_ROOT_PATH . '\msys2-build-essentials\msys64'); return CheckResult::ok(getenv('PHP_SDK_PATH'));
}
#[CheckItem('if 7za.exe is installed', limit_os: 'Windows', level: 999)]
public function check7zaWin(): ?CheckResult
{
$path = FileSystem::convertPath(PKG_ROOT_PATH . '\bin\7za.exe');
if (!file_exists($path)) {
return CheckResult::fail('7za.exe not found', 'install-7za-win');
}
return CheckResult::ok($path);
} }
#[CheckItem('if nasm installed', level: 995)] #[CheckItem('if nasm installed', level: 995)]
@@ -123,20 +112,12 @@ class WindowsToolCheck
return true; return true;
} }
#[FixItem('install-msys2-build-essentials')] #[FixItem('install-php-sdk')]
public function installMsys2(): bool public function installSDK(): bool
{ {
FileSystem::removeDir(getenv('PHP_SDK_PATH'));
$installer = new PackageInstaller(interactive: false); $installer = new PackageInstaller(interactive: false);
$installer->addInstallPackage('msys2-build-essentials'); $installer->addInstallPackage('php-sdk-binary-tools');
$installer->run(true);
return true;
}
#[FixItem('install-7za-win')]
public function install7zaWin(): bool
{
$installer = new PackageInstaller(interactive: false);
$installer->addInstallPackage('7za-win');
$installer->run(true); $installer->run(true);
return true; return true;
} }

View File

@@ -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'),
}); });

View File

@@ -75,9 +75,6 @@ class PackageInstaller
} }
// special check for php target packages // special check for php target packages
if (in_array($package->getName(), ['php', 'php-cli', 'php-fpm', 'php-micro', 'php-cgi', 'php-embed', 'frankenphp'], true)) { if (in_array($package->getName(), ['php', 'php-cli', 'php-fpm', 'php-micro', 'php-cgi', 'php-embed', 'frankenphp'], true)) {
if (!$package instanceof TargetPackage) {
throw new WrongUsageException("Package '{$package->getName()}' is expected to be a TargetPackage.");
}
$this->handlePhpTargetPackage($package); $this->handlePhpTargetPackage($package);
return $this; return $this;
} }

View File

@@ -117,7 +117,7 @@ class UnixAutoconfExecutor extends Executor
/** /**
* Add configure args. * Add configure args.
*/ */
public function addConfigureArgs(string ...$args): static public function addConfigureArgs(...$args): static
{ {
$this->configure_args = [...$this->configure_args, ...$args]; $this->configure_args = [...$this->configure_args, ...$args];
return $this; return $this;
@@ -126,7 +126,7 @@ class UnixAutoconfExecutor extends Executor
/** /**
* Remove some configure args, to bypass the configure option checking for some libs. * Remove some configure args, to bypass the configure option checking for some libs.
*/ */
public function removeConfigureArgs(string ...$args): static public function removeConfigureArgs(...$args): static
{ {
$this->configure_args = array_diff($this->configure_args, $args); $this->configure_args = array_diff($this->configure_args, $args);
return $this; return $this;

View File

@@ -135,7 +135,7 @@ class UnixCMakeExecutor extends Executor
/** /**
* Add configure args. * Add configure args.
*/ */
public function addConfigureArgs(string ...$args): static public function addConfigureArgs(...$args): static
{ {
$this->configure_args = [...$this->configure_args, ...$args]; $this->configure_args = [...$this->configure_args, ...$args];
return $this; return $this;
@@ -144,7 +144,7 @@ class UnixCMakeExecutor extends Executor
/** /**
* Remove some configure args, to bypass the configure option checking for some libs. * Remove some configure args, to bypass the configure option checking for some libs.
*/ */
public function removeConfigureArgs(string ...$args): static public function removeConfigureArgs(...$args): static
{ {
$this->ignore_args = [...$this->ignore_args, ...$args]; $this->ignore_args = [...$this->ignore_args, ...$args];
return $this; return $this;
@@ -302,12 +302,9 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES "{$include}") set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES "{$include}")
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES "{$include}") set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES "{$include}")
CMAKE; CMAKE;
// pin AR/RANLIB so cmake uses zig-ar/zig-ranlib instead of system /usr/bin/ranlib (zig archives need it) // Whoops, linux may need CMAKE_AR sometimes
if (PHP_OS_FAMILY === 'Linux') { if (PHP_OS_FAMILY === 'Linux') {
$ar = getenv('SPC_DEFAULT_AR') ?: getenv('AR') ?: 'ar'; $toolchain .= "\nSET(CMAKE_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); FileSystem::writeFile(SOURCE_PATH . '/toolchain.cmake', $toolchain);
return $created = realpath(SOURCE_PATH . '/toolchain.cmake'); return $created = realpath(SOURCE_PATH . '/toolchain.cmake');

View File

@@ -99,7 +99,7 @@ class WindowsCMakeExecutor extends Executor
/** /**
* Add configure args. * Add configure args.
*/ */
public function addConfigureArgs(string ...$args): static public function addConfigureArgs(...$args): static
{ {
$this->configure_args = [...$this->configure_args, ...$args]; $this->configure_args = [...$this->configure_args, ...$args];
return $this; return $this;
@@ -108,7 +108,7 @@ class WindowsCMakeExecutor extends Executor
/** /**
* Remove some configure args, to bypass the configure option checking for some libs. * Remove some configure args, to bypass the configure option checking for some libs.
*/ */
public function removeConfigureArgs(string ...$args): static public function removeConfigureArgs(...$args): static
{ {
$this->ignore_args = [...$this->ignore_args, ...$args]; $this->ignore_args = [...$this->ignore_args, ...$args];
return $this; return $this;
@@ -189,10 +189,6 @@ class WindowsCMakeExecutor extends Executor
{ {
return $this->custom_default_args ?? [ return $this->custom_default_args ?? [
'-A x64', '-A x64',
// CMake 4.x hard-errors on projects requesting compatibility with CMake < 3.5
// (e.g. wineditline). This is the documented escape hatch; modern projects and
// older CMake releases ignore it.
'-DCMAKE_POLICY_VERSION_MINIMUM=3.5',
'-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_BUILD_TYPE=Release',
'-DBUILD_SHARED_LIBS=OFF', '-DBUILD_SHARED_LIBS=OFF',
'-DBUILD_STATIC_LIBS=ON', '-DBUILD_STATIC_LIBS=ON',

View File

@@ -184,14 +184,12 @@ class DefaultShell extends Shell
*/ */
public function execute7zExtract(string $archive_path, string $target_path): bool public function execute7zExtract(string $archive_path, string $target_path): bool
{ {
// 7za.exe is installed by the 7za-win target package into PKG_ROOT_PATH\bin, $sdk_path = getenv('PHP_SDK_PATH');
// which is added to PATH by MSVCToolchain::initEnv(). if ($sdk_path === false) {
$_7z_path = FileSystem::convertPath(PKG_ROOT_PATH . '\bin\7za.exe'); throw new SPCInternalException('PHP_SDK_PATH environment variable is not set');
if (!file_exists($_7z_path)) {
throw new SPCInternalException('7za.exe not found. Please install the 7za-win target package.');
} }
$_7z = escapeshellarg(FileSystem::convertPath($_7z_path)); $_7z = escapeshellarg(FileSystem::convertPath($sdk_path . '/bin/7za.exe'));
$archive_arg = escapeshellarg(FileSystem::convertPath($archive_path)); $archive_arg = escapeshellarg(FileSystem::convertPath($archive_path));
$target_arg = escapeshellarg(FileSystem::convertPath($target_path)); $target_arg = escapeshellarg(FileSystem::convertPath($target_path));

View File

@@ -15,7 +15,6 @@ class ClangBrewToolchain extends ClangNativeToolchain
GlobalEnvManager::putenv("SPC_DEFAULT_CC={$homebrew_prefix}/opt/llvm/bin/clang"); 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_CXX={$homebrew_prefix}/opt/llvm/bin/clang++");
GlobalEnvManager::putenv("SPC_DEFAULT_AR={$homebrew_prefix}/opt/llvm/bin/llvm-ar"); 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::putenv('SPC_DEFAULT_LD=ld');
GlobalEnvManager::addPathIfNotExists("{$homebrew_prefix}/opt/llvm/bin"); GlobalEnvManager::addPathIfNotExists("{$homebrew_prefix}/opt/llvm/bin");
} }

View File

@@ -21,7 +21,6 @@ class ClangNativeToolchain implements UnixToolchainInterface
GlobalEnvManager::putenv('SPC_DEFAULT_CC=clang'); GlobalEnvManager::putenv('SPC_DEFAULT_CC=clang');
GlobalEnvManager::putenv('SPC_DEFAULT_CXX=clang++'); GlobalEnvManager::putenv('SPC_DEFAULT_CXX=clang++');
GlobalEnvManager::putenv('SPC_DEFAULT_AR=ar'); GlobalEnvManager::putenv('SPC_DEFAULT_AR=ar');
GlobalEnvManager::putenv('SPC_DEFAULT_RANLIB=ranlib');
GlobalEnvManager::putenv('SPC_DEFAULT_LD=ld'); GlobalEnvManager::putenv('SPC_DEFAULT_LD=ld');
} }

View File

@@ -1,20 +0,0 @@
<?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");
}
}

View File

@@ -18,7 +18,6 @@ class GccNativeToolchain implements UnixToolchainInterface
GlobalEnvManager::putenv('SPC_DEFAULT_CC=gcc'); GlobalEnvManager::putenv('SPC_DEFAULT_CC=gcc');
GlobalEnvManager::putenv('SPC_DEFAULT_CXX=g++'); GlobalEnvManager::putenv('SPC_DEFAULT_CXX=g++');
GlobalEnvManager::putenv('SPC_DEFAULT_AR=ar'); GlobalEnvManager::putenv('SPC_DEFAULT_AR=ar');
GlobalEnvManager::putenv('SPC_DEFAULT_RANLIB=ranlib');
GlobalEnvManager::putenv('SPC_DEFAULT_LD=ld'); GlobalEnvManager::putenv('SPC_DEFAULT_LD=ld');
} }

View File

@@ -14,14 +14,10 @@ class MSVCToolchain implements ToolchainInterface
public function initEnv(): void public function initEnv(): void
{ {
GlobalEnvManager::addPathIfNotExists(PKG_ROOT_PATH . '\bin'); GlobalEnvManager::addPathIfNotExists(PKG_ROOT_PATH . '\bin');
// msys2-build-essentials: add MSYS2 usr\bin to PATH so that 7za.exe, make, autoconf, etc. are available. $sdk = getenv('PHP_SDK_PATH');
// This must be done here because msys2-build-essentials is not a dependency of any library package, if ($sdk !== false) {
// so its path@windows entries are not automatically applied by the package installer at runtime. GlobalEnvManager::addPathIfNotExists($sdk . '\bin');
$msys2_path = getenv('SPC_MSYS2_PATH') ?: (PKG_ROOT_PATH . '\msys2-build-essentials\msys64'); GlobalEnvManager::addPathIfNotExists($sdk . '\msys2\usr\bin');
if (is_dir($msys2_path)) {
GlobalEnvManager::putenv("SPC_MSYS2_PATH={$msys2_path}");
GlobalEnvManager::addPathIfNotExists($msys2_path . '\usr\bin');
GlobalEnvManager::addPathIfNotExists("{$msys2_path}\\usr\\lib\\p7zip");
} }
// strawberry-perl // strawberry-perl
if (is_dir(PKG_ROOT_PATH . '\strawberry-perl')) { if (is_dir(PKG_ROOT_PATH . '\strawberry-perl')) {

View File

@@ -41,7 +41,6 @@ class ToolchainManager
'Windows' => MSVCToolchain::class, 'Windows' => MSVCToolchain::class,
'Darwin' => match (getenv('SPC_USE_LLVM') ?: 'system') { 'Darwin' => match (getenv('SPC_USE_LLVM') ?: 'system') {
'brew' => ClangBrewToolchain::class, 'brew' => ClangBrewToolchain::class,
'port' => ClangPortsToolchain::class,
default => ClangNativeToolchain::class, default => ClangNativeToolchain::class,
}, },
default => throw new WrongUsageException('Unsupported OS family: ' . PHP_OS_FAMILY), default => throw new WrongUsageException('Unsupported OS family: ' . PHP_OS_FAMILY),

View File

@@ -16,7 +16,6 @@ class ZigToolchain implements UnixToolchainInterface
GlobalEnvManager::putenv('SPC_DEFAULT_CC=zig-cc'); GlobalEnvManager::putenv('SPC_DEFAULT_CC=zig-cc');
GlobalEnvManager::putenv('SPC_DEFAULT_CXX=zig-c++'); GlobalEnvManager::putenv('SPC_DEFAULT_CXX=zig-c++');
GlobalEnvManager::putenv('SPC_DEFAULT_AR=zig-ar'); GlobalEnvManager::putenv('SPC_DEFAULT_AR=zig-ar');
GlobalEnvManager::putenv('SPC_DEFAULT_RANLIB=zig-ranlib');
GlobalEnvManager::putenv('SPC_DEFAULT_LD=zig-ld.lld'); GlobalEnvManager::putenv('SPC_DEFAULT_LD=zig-ld.lld');
// Generate additional objects needed for zig toolchain // Generate additional objects needed for zig toolchain

View File

@@ -411,7 +411,7 @@ class FileSystem
$replacement = [ $replacement = [
'{build_root_path}' => BUILD_ROOT_PATH, '{build_root_path}' => BUILD_ROOT_PATH,
'{pkg_root_path}' => PKG_ROOT_PATH, '{pkg_root_path}' => PKG_ROOT_PATH,
'{spc_msys2_path}' => getenv('SPC_MSYS2_PATH') ?: (PKG_ROOT_PATH . DIRECTORY_SEPARATOR . 'msys2-build-essentials' . DIRECTORY_SEPARATOR . 'msys64'), '{php_sdk_path}' => getenv('PHP_SDK_PATH') ? getenv('PHP_SDK_PATH') : WORKING_DIR . '/php-sdk-binary-tools',
'{working_dir}' => WORKING_DIR, '{working_dir}' => WORKING_DIR,
'{download_path}' => DOWNLOAD_PATH, '{download_path}' => DOWNLOAD_PATH,
'{source_path}' => SOURCE_PATH, '{source_path}' => SOURCE_PATH,

View File

@@ -134,10 +134,10 @@ class GlobalEnvManager
} }
// test bison // test bison
if (PHP_OS_FAMILY === 'Darwin') { if (PHP_OS_FAMILY === 'Darwin') {
if ($bison = MacOSUtil::findCommand('bison', ['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin', '/opt/local/bin/bison'])) { if ($bison = MacOSUtil::findCommand('bison', ['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin'])) {
self::putenv("BISON={$bison}"); self::putenv("BISON={$bison}");
} }
if ($yacc = MacOSUtil::findCommand('yacc', ['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin', '/opt/local/bin/yacc'])) { if ($yacc = MacOSUtil::findCommand('yacc', ['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin'])) {
self::putenv("YACC={$yacc}"); self::putenv("YACC={$yacc}");
} }
} }

View File

@@ -17,8 +17,8 @@ class InteractiveTerm
public static function notice(string $message, bool $indent = false): void public static function notice(string $message, bool $indent = false): void
{ {
$no_ansi = (bool) ApplicationContext::get(InputInterface::class)->getOption('no-ansi'); $no_ansi = ApplicationContext::get(InputInterface::class)?->getOption('no-ansi') ?? false;
$output = ApplicationContext::get(OutputInterface::class); $output = ApplicationContext::get(OutputInterface::class) ?? new ConsoleOutput();
if ($output->isVerbose()) { if ($output->isVerbose()) {
logger()->notice(strip_ansi_colors($message)); logger()->notice(strip_ansi_colors($message));
} else { } else {
@@ -29,8 +29,8 @@ class InteractiveTerm
public static function success(string $message, bool $indent = false): void public static function success(string $message, bool $indent = false): void
{ {
$no_ansi = (bool) ApplicationContext::get(InputInterface::class)->getOption('no-ansi'); $no_ansi = ApplicationContext::get(InputInterface::class)?->getOption('no-ansi') ?? false;
$output = ApplicationContext::get(OutputInterface::class); $output = ApplicationContext::get(OutputInterface::class) ?? new ConsoleOutput();
if ($output->isVerbose()) { if ($output->isVerbose()) {
logger()->info(strip_ansi_colors($message)); logger()->info(strip_ansi_colors($message));
} else { } else {
@@ -41,8 +41,8 @@ class InteractiveTerm
public static function plain(string $message, string $level = 'info'): void public static function plain(string $message, string $level = 'info'): void
{ {
$no_ansi = (bool) ApplicationContext::get(InputInterface::class)->getOption('no-ansi'); $no_ansi = ApplicationContext::get(InputInterface::class)?->getOption('no-ansi') ?? false;
$output = ApplicationContext::get(OutputInterface::class); $output = ApplicationContext::get(OutputInterface::class) ?? new ConsoleOutput();
if ($output->isVerbose()) { if ($output->isVerbose()) {
match ($level) { match ($level) {
'debug' => logger()->debug(strip_ansi_colors($message)), 'debug' => logger()->debug(strip_ansi_colors($message)),
@@ -59,8 +59,8 @@ class InteractiveTerm
public static function info(string $message): void public static function info(string $message): void
{ {
$no_ansi = (bool) ApplicationContext::get(InputInterface::class)->getOption('no-ansi'); $no_ansi = ApplicationContext::get(InputInterface::class)?->getOption('no-ansi') ?? false;
$output = ApplicationContext::get(OutputInterface::class); $output = ApplicationContext::get(OutputInterface::class) ?? new ConsoleOutput();
if (!$output->isVerbose()) { if (!$output->isVerbose()) {
$output->writeln(($no_ansi ? 'strip_ansi_colors' : 'strval')(ConsoleColor::green('▶ ') . $message)); $output->writeln(($no_ansi ? 'strip_ansi_colors' : 'strval')(ConsoleColor::green('▶ ') . $message));
} }
@@ -69,8 +69,8 @@ class InteractiveTerm
public static function error(string $message, bool $indent = true): void public static function error(string $message, bool $indent = true): void
{ {
$no_ansi = (bool) ApplicationContext::get(InputInterface::class)->getOption('no-ansi'); $no_ansi = ApplicationContext::get(InputInterface::class)?->getOption('no-ansi') ?? false;
$output = ApplicationContext::get(OutputInterface::class); $output = ApplicationContext::get(OutputInterface::class) ?? new ConsoleOutput();
if ($output->isVerbose()) { if ($output->isVerbose()) {
logger()->error(strip_ansi_colors($message)); logger()->error(strip_ansi_colors($message));
} else { } else {
@@ -86,16 +86,16 @@ class InteractiveTerm
public static function setMessage(string $message): void public static function setMessage(string $message): void
{ {
$no_ansi = (bool) ApplicationContext::get(InputInterface::class)->getOption('no-ansi'); $no_ansi = ApplicationContext::get(InputInterface::class)?->getOption('no-ansi') ?? false;
self::$indicator?->setMessage(($no_ansi ? 'strip_ansi_colors' : 'strval')($message)); self::$indicator?->setMessage(($no_ansi ? 'strip_ansi_colors' : 'strval')($message));
logger()->debug(strip_ansi_colors($message)); logger()->debug(strip_ansi_colors($message));
} }
public static function finish(string $message, bool $status = true): void public static function finish(string $message, bool $status = true): void
{ {
$no_ansi = (bool) ApplicationContext::get(InputInterface::class)->getOption('no-ansi'); $no_ansi = ApplicationContext::get(InputInterface::class)?->getOption('no-ansi') ?? false;
$message = $no_ansi ? strip_ansi_colors($message) : $message; $message = $no_ansi ? strip_ansi_colors($message) : $message;
$output = ApplicationContext::get(OutputInterface::class); $output = ApplicationContext::get(OutputInterface::class) ?? new ConsoleOutput();
if ($output->isVerbose()) { if ($output->isVerbose()) {
if ($status) { if ($status) {
logger()->info($message); logger()->info($message);
@@ -116,8 +116,8 @@ class InteractiveTerm
public static function indicateProgress(string $message): void public static function indicateProgress(string $message): void
{ {
$no_ansi = (bool) ApplicationContext::get(InputInterface::class)->getOption('no-ansi'); $no_ansi = ApplicationContext::get(InputInterface::class)?->getOption('no-ansi') ?? false;
$output = ApplicationContext::get(OutputInterface::class); $output = ApplicationContext::get(OutputInterface::class) ?? new ConsoleOutput();
if ($output->isVerbose()) { if ($output->isVerbose()) {
logger()->info(strip_ansi_colors($message)); logger()->info(strip_ansi_colors($message));
return; return;

View File

@@ -256,30 +256,10 @@ function clean_spaces(string $string): string
*/ */
function deduplicate_flags(string $flags): string function deduplicate_flags(string $flags): string
{ {
// Flags that take their value as a separate token. $tokens = preg_split('/\s+/', trim($flags));
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 // Reverse, unique, reverse back - keeps last occurrence of duplicates
$deduplicated = array_reverse(array_unique(array_reverse($atoms))); $deduplicated = array_reverse(array_unique(array_reverse($tokens)));
return implode(' ', $deduplicated); return implode(' ', $deduplicated);
} }

View File

@@ -3,11 +3,22 @@
declare(strict_types=1); declare(strict_types=1);
// static-php-cli version string // static-php-cli version string
use Laravel\Prompts\ConfirmPrompt;
use Laravel\Prompts\Prompt;
use Laravel\Prompts\TextPrompt;
use StaticPHP\ConsoleApplication; use StaticPHP\ConsoleApplication;
use StaticPHP\DI\ApplicationContext;
use StaticPHP\Util\FileSystem; use StaticPHP\Util\FileSystem;
use StaticPHP\Util\System\LinuxUtil; use StaticPHP\Util\System\LinuxUtil;
use StaticPHP\Util\System\MacOSUtil; use StaticPHP\Util\System\MacOSUtil;
use StaticPHP\Util\System\WindowsUtil; use StaticPHP\Util\System\WindowsUtil;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
const SPC_VERSION = ConsoleApplication::VERSION; const SPC_VERSION = ConsoleApplication::VERSION;
// output path for everything, other paths are defined relative to this by default // output path for everything, other paths are defined relative to this by default
@@ -64,3 +75,31 @@ putenv('CPU_COUNT=' . CPU_COUNT);
putenv('SPC_ARCH=' . php_uname('m')); putenv('SPC_ARCH=' . php_uname('m'));
putenv('GNU_ARCH=' . GNU_ARCH); putenv('GNU_ARCH=' . GNU_ARCH);
putenv('MAC_ARCH=' . MAC_ARCH); putenv('MAC_ARCH=' . MAC_ARCH);
// initialize windows prompt fallback for laravel-prompts
Prompt::fallbackWhen(PHP_OS_FAMILY === 'Windows');
ConfirmPrompt::fallbackUsing(function (ConfirmPrompt $prompt) {
$helper = new QuestionHelper();
$case = $prompt->default ? ' [Y/n] ' : ' [y/N] ';
$question = new ConfirmationQuestion($prompt->label . $case, $prompt->default);
if (ApplicationContext::has(InputInterface::class) && ApplicationContext::has(OutputInterface::class)) {
$input = ApplicationContext::get(InputInterface::class);
$output = ApplicationContext::get(OutputInterface::class);
} else {
$input = new ArrayInput([]);
$output = new ConsoleOutput();
}
return $helper->ask($input, $output, $question);
});
TextPrompt::fallbackUsing(function (TextPrompt $prompt) {
$helper = new QuestionHelper();
$question = new Question($prompt->label . ' ', $prompt->default);
if (ApplicationContext::has(InputInterface::class) && ApplicationContext::has(OutputInterface::class)) {
$input = ApplicationContext::get(InputInterface::class);
$output = ApplicationContext::get(OutputInterface::class);
} else {
$input = new ArrayInput([]);
$output = new ConsoleOutput();
}
return $helper->ask($input, $output, $question);
});