Compare commits

...

7 Commits

Author SHA1 Message Date
crazywhalecc
cd803c75c5 Add filtering options for extensions, libs, and OS in test matrix generation 2026-05-09 10:44:04 +08:00
crazywhalecc
ad7475246f Merge remote-tracking branch 'origin/v3-docs/readme' into v3-docs/readme 2026-05-09 10:33:10 +08:00
crazywhalecc
b09cc968e6 Add curl execute output log 2026-05-09 10:19:16 +08:00
crazywhalecc
bf308e89a5 Remove duplicate phar patch for micro 2026-05-09 09:49:53 +08:00
crazywhalecc
bf326de985 Fix extracting hosted type for zip archive caused overwriting 2026-05-09 08:17:03 +08:00
crazywhalecc
4f9a555bf3 ds use git (pecl have buggy config.w32) 2026-05-09 08:16:11 +08:00
crazywhalecc
04df87cd5f Make intl use c++17 2026-05-09 08:15:45 +08:00
7 changed files with 161 additions and 81 deletions

View File

@@ -2,8 +2,10 @@ ext-ds:
type: php-extension
artifact:
source:
type: pecl
name: ds
type: git
url: 'https://github.com/php-ds/ext-ds.git'
rev: master
extract: php-src/ext/ds
metadata:
license-files: [LICENSE]
license: MIT

View File

@@ -16,7 +16,7 @@ use StaticPHP\Util\FileSystem;
class intl extends PhpExtensionPackage
{
#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-intl')]
#[PatchDescription('Fix intl config.w32: replace hardcoded true with PHP_INTL_SHARED for static build support')]
#[PatchDescription('Fix intl config.w32: replace hardcoded true with PHP_INTL_SHARED for static build support; add /std:c++17 required by ICU 73+')]
public function patchBeforeBuildconfForWindows(PackageInstaller $installer): void
{
$php_src = $installer->getTargetPackage('php')->getSourceDir();
@@ -25,5 +25,11 @@ class intl extends PhpExtensionPackage
'EXTENSION("intl", "php_intl.c intl_convert.c intl_convertcpp.cpp intl_error.c ", true,',
'EXTENSION("intl", "php_intl.c intl_convert.c intl_convertcpp.cpp intl_error.c ", PHP_INTL_SHARED,'
);
// ICU 73+ headers (char16ptr.h etc.) unconditionally include <string_view> which requires C++17.
FileSystem::replaceFileStr(
"{$php_src}/ext/intl/config.w32",
'ADD_FLAG("CFLAGS_INTL", "/EHsc',
'ADD_FLAG("CFLAGS_INTL", "/std:c++17 /EHsc'
);
}
}

View File

@@ -266,43 +266,32 @@ trait unix
#[PatchDescription('Patch phar extension for micro SAPI to support compressed phar')]
public function makeMicroForUnix(TargetPackage $package, PackageInstaller $installer, PackageBuilder $builder): void
{
$phar_patched = false;
try {
if ($installer->isPackageResolved('ext-phar')) {
$phar_patched = true;
SourcePatcher::patchMicroPhar(self::getPHPVersionID());
}
InteractiveTerm::setMessage('Building php: ' . ConsoleColor::yellow('make micro'));
// apply --with-micro-fake-cli option
$vars = $this->makeVars($installer);
$vars['EXTRA_CFLAGS'] .= $package->getBuildOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '';
$makeArgs = $this->makeVarsToArgs($vars);
// build
shell()->cd($package->getSourceDir())
->setEnv($vars)
->exec("make -j{$builder->concurrency} {$makeArgs} micro");
InteractiveTerm::setMessage('Building php: ' . ConsoleColor::yellow('make micro'));
// apply --with-micro-fake-cli option
$vars = $this->makeVars($installer);
$vars['EXTRA_CFLAGS'] .= $package->getBuildOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '';
$makeArgs = $this->makeVarsToArgs($vars);
// build
shell()->cd($package->getSourceDir())
->setEnv($vars)
->exec("make -j{$builder->concurrency} {$makeArgs} micro");
$dst = BUILD_BIN_PATH . '/micro.sfx';
$builder->deployBinary($package->getSourceDir() . '/sapi/micro/micro.sfx', $dst);
// patch after UPX-ed micro.sfx (Linux only)
if (SystemTarget::getTargetOS() === 'Linux' && $builder->getOption('with-upx-pack')) {
// cut binary with readelf to remove UPX extra segment
[$ret, $out] = shell()->execWithResult("readelf -l {$dst} | awk '/LOAD|GNU_STACK/ {getline; print \\$1, \\$2, \\$3, \\$4, \\$6, \\$7}'");
$out[1] = explode(' ', $out[1]);
$offset = $out[1][0];
if ($ret !== 0 || !str_starts_with($offset, '0x')) {
throw new PatchException('phpmicro UPX patcher', 'Cannot find offset in readelf output');
}
$offset = hexdec($offset);
// remove upx extra wastes
file_put_contents($dst, substr(file_get_contents($dst), 0, $offset));
}
$package->setOutput('Binary path for micro SAPI', $dst);
} finally {
if ($phar_patched) {
SourcePatcher::unpatchMicroPhar();
$dst = BUILD_BIN_PATH . '/micro.sfx';
$builder->deployBinary($package->getSourceDir() . '/sapi/micro/micro.sfx', $dst);
// patch after UPX-ed micro.sfx (Linux only)
if (SystemTarget::getTargetOS() === 'Linux' && $builder->getOption('with-upx-pack')) {
// cut binary with readelf to remove UPX extra segment
[$ret, $out] = shell()->execWithResult("readelf -l {$dst} | awk '/LOAD|GNU_STACK/ {getline; print \\$1, \\$2, \\$3, \\$4, \\$6, \\$7}'");
$out[1] = explode(' ', $out[1]);
$offset = $out[1][0];
if ($ret !== 0 || !str_starts_with($offset, '0x')) {
throw new PatchException('phpmicro UPX patcher', 'Cannot find offset in readelf output');
}
$offset = hexdec($offset);
// remove upx extra wastes
file_put_contents($dst, substr(file_get_contents($dst), 0, $offset));
}
$package->setOutput('Binary path for micro SAPI', $dst);
}
#[Stage]

View File

@@ -293,21 +293,8 @@ trait windows
$fake_cli = $package->getBuildOption('with-micro-fake-cli', false) ? ' /DPHP_MICRO_FAKE_CLI' : '';
// phar patch for micro
$phar_patched = false;
if ($installer->isPackageResolved('ext-phar')) {
$phar_patched = true;
SourcePatcher::patchMicroPhar(self::getPHPVersionID());
}
try {
cmd()->cd($package->getSourceDir())
->exec("nmake /nologo {$debug_overrides}LIBS_MICRO=\"ws2_32.lib shell32.lib {$extra_libs}\" CFLAGS_MICRO=\"/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1{$fake_cli}\" EXTRA_LD_FLAGS_PROGRAM= micro");
} finally {
if ($phar_patched) {
SourcePatcher::unpatchMicroPhar();
}
}
cmd()->cd($package->getSourceDir())
->exec("nmake /nologo {$debug_overrides}LIBS_MICRO=\"ws2_32.lib shell32.lib {$extra_libs}\" CFLAGS_MICRO=\"/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1{$fake_cli}\" EXTRA_LD_FLAGS_PROGRAM= micro");
$this->deployWindowsBinary($builder, $package, 'php-micro');
}

View File

@@ -242,7 +242,10 @@ class ArtifactExtractor
}
logger()->info("Extracting binary [{$name}] to {$target_path}...");
$this->doStandardExtract($name, $cache_info, $target_path);
// When a binary artifact targets the shared buildroot, merge into it instead of wiping it.
// Wiping buildroot would destroy files installed by packages processed earlier in the build queue.
$merge = (FileSystem::convertPath($target_path) === FileSystem::convertPath(BUILD_ROOT_PATH));
$this->doStandardExtract($name, $cache_info, $target_path, $merge);
$artifact->emitAfterBinaryExtract($target_path, $platform);
logger()->debug("Emitted after-binary-extract hooks for [{$name}]");
@@ -256,8 +259,10 @@ class ArtifactExtractor
/**
* Standard extraction: extract entire archive to target directory.
*
* @param bool $merge when true, merge extracted files into existing target dir instead of wiping it
*/
protected function doStandardExtract(string $name, array $cache_info, string $target_path): void
protected function doStandardExtract(string $name, array $cache_info, string $target_path, bool $merge = false): void
{
$source_file = $this->cache->getCacheFullPath($cache_info);
$cache_type = $cache_info['cache_type'];
@@ -265,7 +270,7 @@ class ArtifactExtractor
// Validate source file exists before extraction
$this->validateSourceFile($name, $source_file, $cache_type);
$this->extractWithType($cache_type, $source_file, $target_path);
$this->extractWithType($cache_type, $source_file, $target_path, $merge);
}
/**
@@ -443,10 +448,10 @@ class ArtifactExtractor
* @param string $source_file Path to source file or directory
* @param string $target_path Target extraction path
*/
protected function extractWithType(string $cache_type, string $source_file, string $target_path): void
protected function extractWithType(string $cache_type, string $source_file, string $target_path, bool $merge = false): void
{
match ($cache_type) {
'archive' => $this->extractArchive($source_file, $target_path),
'archive' => $this->extractArchive($source_file, $target_path, $merge),
'file' => $this->copyFile($source_file, $target_path),
'git' => FileSystem::copyDir(FileSystem::convertPath($source_file), $target_path),
'local' => symlink(FileSystem::convertPath($source_file), $target_path),
@@ -458,8 +463,10 @@ class ArtifactExtractor
* Extract archive file to target directory.
*
* Supports: tar, tar.gz, tgz, tar.bz2, tar.xz, txz, zip, exe
*
* @param bool $merge when true, merge zip contents into existing target dir instead of wiping it
*/
protected function extractArchive(string $filename, string $target): void
protected function extractArchive(string $filename, string $target, bool $merge = false): void
{
$target = FileSystem::convertPath($target);
$filename = FileSystem::convertPath($filename);
@@ -476,7 +483,7 @@ class ArtifactExtractor
'Windows' => match ($extname) {
'tar' => default_shell()->executeTarExtract($filename, $target, 'none'),
'xz', 'txz', 'gz', 'tgz', 'bz2' => default_shell()->execute7zExtract($filename, $target),
'zip' => $this->unzipWithStrip($filename, $target),
'zip' => $this->unzipWithStrip($filename, $target, $merge),
'exe' => $this->copyFile($filename, $target),
default => throw new FileSystemException("Unknown archive format: {$filename}"),
},
@@ -485,7 +492,7 @@ class ArtifactExtractor
'gz', 'tgz' => default_shell()->executeTarExtract($filename, $target, 'gz'),
'bz2' => default_shell()->executeTarExtract($filename, $target, 'bz2'),
'xz', 'txz' => default_shell()->executeTarExtract($filename, $target, 'xz'),
'zip' => $this->unzipWithStrip($filename, $target),
'zip' => $this->unzipWithStrip($filename, $target, $merge),
'exe' => $this->copyFile($filename, $target),
default => throw new FileSystemException("Unknown archive format: {$filename}"),
},
@@ -496,7 +503,7 @@ class ArtifactExtractor
/**
* Unzip file with stripping top-level directory.
*/
protected function unzipWithStrip(string $zip_file, string $extract_path): bool
protected function unzipWithStrip(string $zip_file, string $extract_path, bool $merge = false): bool
{
$temp_dir = FileSystem::convertPath(sys_get_temp_dir() . '/spc_unzip_' . bin2hex(random_bytes(16)));
$zip_file = FileSystem::convertPath($zip_file);
@@ -517,15 +524,22 @@ class ArtifactExtractor
throw new FileSystemException('Cannot scan unzip temp dir: ' . $temp_dir);
}
// If extract path already exists, remove it
if (is_dir($extract_path)) {
FileSystem::removeDir($extract_path);
if (!$merge) {
// Replace mode: wipe the target directory before extracting
if (is_dir($extract_path)) {
FileSystem::removeDir($extract_path);
}
}
// If only one dir, move its contents to extract_path
// If only one dir, move/merge its contents to extract_path
$subdir = FileSystem::convertPath("{$temp_dir}/{$contents[0]}");
if (count($contents) === 1 && is_dir($subdir)) {
$this->moveFileOrDir($subdir, $extract_path);
if ($merge) {
$this->mergeDirContent($subdir, $extract_path);
FileSystem::removeDir($subdir);
} else {
$this->moveFileOrDir($subdir, $extract_path);
}
} else {
// Else, if it contains only one dir, strip dir and copy other files
$dircount = 0;
@@ -550,26 +564,36 @@ class ArtifactExtractor
throw new FileSystemException("Cannot scan unzip temp sub-dir: {$dir[0]}");
}
foreach ($sub_contents as $sub_item) {
$this->moveFileOrDir(
FileSystem::convertPath("{$temp_dir}/{$dir[0]}/{$sub_item}"),
FileSystem::convertPath("{$extract_path}/{$sub_item}")
);
$src = FileSystem::convertPath("{$temp_dir}/{$dir[0]}/{$sub_item}");
$dst = FileSystem::convertPath("{$extract_path}/{$sub_item}");
if ($merge && is_dir($src)) {
$this->mergeDirContent($src, $dst);
} else {
$this->moveFileOrDir($src, $dst);
}
}
} else {
foreach ($dir as $item) {
$this->moveFileOrDir(
FileSystem::convertPath("{$temp_dir}/{$item}"),
FileSystem::convertPath("{$extract_path}/{$item}")
);
$src = FileSystem::convertPath("{$temp_dir}/{$item}");
$dst = FileSystem::convertPath("{$extract_path}/{$item}");
if ($merge) {
$this->mergeDirContent($src, $dst);
} else {
$this->moveFileOrDir($src, $dst);
}
}
}
// Move top-level files to extract_path
// Move or copy top-level files to extract_path
foreach ($top_files as $top_file) {
$this->moveFileOrDir(
FileSystem::convertPath("{$temp_dir}/{$top_file}"),
FileSystem::convertPath("{$extract_path}/{$top_file}")
);
$src = FileSystem::convertPath("{$temp_dir}/{$top_file}");
$dst = FileSystem::convertPath("{$extract_path}/{$top_file}");
if ($merge) {
FileSystem::createDir(dirname($dst));
copy($src, $dst);
} else {
$this->moveFileOrDir($src, $dst);
}
}
}
@@ -595,6 +619,25 @@ class ArtifactExtractor
return str_replace(array_keys($replacement), array_values($replacement), $path);
}
private function mergeDirContent(string $src_dir, string $dest_dir): void
{
FileSystem::createDir($dest_dir);
$items = FileSystem::scanDirFiles($src_dir, false, true, true);
if ($items === false || empty($items)) {
return;
}
foreach ($items as $item) {
$src_item = FileSystem::convertPath("{$src_dir}/{$item}");
$dest_item = FileSystem::convertPath("{$dest_dir}/{$item}");
if (is_dir($src_item)) {
$this->mergeDirContent($src_item, $dest_item);
} else {
FileSystem::createDir(dirname($dest_item));
copy($src_item, $dest_item);
}
}
}
/**
* Move file or directory, handling cross-device scenarios
* Uses rename() if possible, falls back to copy+delete for cross-device moves

View File

@@ -7,6 +7,7 @@ namespace StaticPHP\Command\Dev;
use StaticPHP\Command\BaseCommand;
use StaticPHP\Config\PackageConfig;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;
#[AsCommand('dev:gen-ext-test-matrix', 'Generate GitHub Actions extension test matrix JSON', [], true)]
class GenExtTestMatrixCommand extends BaseCommand
@@ -53,8 +54,20 @@ class GenExtTestMatrixCommand extends BaseCommand
'intl',
];
/**
* Maximum number of orphan extensions per matrix entry.
*/
private const int ORPHAN_BATCH_SIZE = 15;
protected bool $no_motd = true;
public function configure(): void
{
$this->addOption('for-extensions', null, InputOption::VALUE_OPTIONAL, 'Filter by extension display names, comma-separated', '')
->addOption('for-libs', null, InputOption::VALUE_OPTIONAL, 'Filter by lib names (depends+suggests), comma-separated', '')
->addOption('os', null, InputOption::VALUE_OPTIONAL, 'Filter by OS (Linux/Darwin/Windows), comma-separated', '');
}
public function handle(): int
{
if (!spc_mode(SPC_MODE_SOURCE)) {
@@ -62,6 +75,11 @@ class GenExtTestMatrixCommand extends BaseCommand
return static::USER_ERROR;
}
$parse_option = fn (string $name): array => array_values(array_filter(array_map('trim', explode(',', (string) $this->input->getOption($name)))));
$filter_extensions = $parse_option('for-extensions');
$filter_libs = $parse_option('for-libs');
$filter_os_keys = $parse_option('os');
$all = PackageConfig::getAll();
// Separate into regular and virtual extensions (build-static:false excluded globally)
@@ -81,9 +99,14 @@ class GenExtTestMatrixCommand extends BaseCommand
}
}
$entries = [];
$os_runners = empty($filter_os_keys)
? self::OS_RUNNERS
: array_filter(self::OS_RUNNERS, fn ($info) => in_array($info['os_key'], $filter_os_keys, true));
foreach (self::OS_RUNNERS as $os => $os_info) {
$entries = [];
$all_ext_lib_deps = [];
foreach ($os_runners as $os => $os_info) {
$os_key = $os_info['os_key'];
// Filter by OS support
@@ -99,6 +122,7 @@ class GenExtTestMatrixCommand extends BaseCommand
// Compute ext_deps for every pool member: union of depends + suggests, limited to pool
$ext_deps = [];
$os_lib_deps = [];
foreach (array_merge($os_regular, $os_virtual) as $pkg_name => $config) {
$raw = array_merge(
$this->resolvePlatformList($config, 'depends', $os),
@@ -108,7 +132,12 @@ class GenExtTestMatrixCommand extends BaseCommand
$raw,
fn ($d) => isset($pool_set[$d]) && $d !== $pkg_name
));
$os_lib_deps[$this->displayName($pkg_name)] = array_values(array_filter(
$raw,
fn ($d) => !str_starts_with($d, 'ext-')
));
}
$all_ext_lib_deps[$os] = $os_lib_deps;
// Which regular exts are reachable as a dep/suggest from another regular ext?
$depended_on = [];
@@ -174,6 +203,26 @@ class GenExtTestMatrixCommand extends BaseCommand
}
}
if (!empty($filter_extensions)) {
$entries = array_values(array_filter($entries, function (array $entry) use ($filter_extensions): bool {
$names = explode(',', $entry['extension']);
return count(array_intersect($names, $filter_extensions)) > 0;
}));
}
if (!empty($filter_libs)) {
$entries = array_values(array_filter($entries, function (array $entry) use ($filter_libs, $all_ext_lib_deps): bool {
$names = explode(',', $entry['extension']);
$lib_deps = $all_ext_lib_deps[$entry['os']] ?? [];
foreach ($names as $name) {
if (count(array_intersect($lib_deps[$name] ?? [], $filter_libs)) > 0) {
return true;
}
}
return false;
}));
}
$this->output->write(json_encode($entries, JSON_UNESCAPED_SLASHES));
return static::SUCCESS;
}
@@ -227,6 +276,9 @@ class GenExtTestMatrixCommand extends BaseCommand
foreach ($orphans as $ext) {
$placed = false;
foreach ($batches as &$batch) {
if (count($batch) >= self::ORPHAN_BATCH_SIZE) {
continue;
}
$conflict = false;
foreach ($batch as $member) {
if (isset($adjacency[$ext][$member])) {

View File

@@ -44,6 +44,7 @@ class DefaultShell extends Shell
$cmd = SPC_CURL_EXEC . " -sfSL --max-time 3600 {$retry_arg} {$compressed_arg} {$method_arg} {$header_arg} {$url_arg}";
$this->logCommandInfo($cmd);
logger()->debug("[CURL EXECUTE] {$cmd}");
$result = $this->passthru($cmd, capture_output: true, throw_on_error: false);
$ret = $result['code'];
$output = $result['output'];