mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-09 09:55:37 +08:00
Compare commits
22 Commits
392733b7c3
...
fable-v3-w
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
323f21a6f2 | ||
|
|
ab30c9dc49 | ||
|
|
f1722a0f3e | ||
|
|
8034ae37ea | ||
|
|
c9f24b980d | ||
|
|
5ffbf2d5fe | ||
|
|
facc7bc5a7 | ||
|
|
160d7f5537 | ||
|
|
afa5f535e9 | ||
|
|
0dde151632 | ||
|
|
e906edb332 | ||
|
|
83ce54b62b | ||
|
|
7d6c082c86 | ||
|
|
db4f7c6a0c | ||
|
|
ca0167c83e | ||
|
|
5a5c784c4f | ||
|
|
331da67049 | ||
|
|
cc448d463b | ||
|
|
dc55881b78 | ||
|
|
a59473e4ab | ||
|
|
c6a227f4de | ||
|
|
f66e68754e |
48
.github/workflows/post-test-bot-comment.yml
vendored
Normal file
48
.github/workflows/post-test-bot-comment.yml
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
name: Post Test Bot Comment
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["v3 Tests"]
|
||||
types: [completed]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
actions: read
|
||||
|
||||
jobs:
|
||||
post-comment:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- name: Download bot output
|
||||
id: download
|
||||
uses: actions/download-artifact@v4
|
||||
continue-on-error: true
|
||||
with:
|
||||
name: bot-output
|
||||
run-id: ${{ github.event.workflow_run.id }}
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Post/Update comment
|
||||
if: steps.download.outcome == 'success'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
COMMENT_BODY=$(jq -r '.comment_body' bot-output.json)
|
||||
PR_NUMBER=$(jq -r '.pr_number' bot-output.json)
|
||||
MARKER="<!-- spc-test-bot -->"
|
||||
|
||||
# Find existing bot comment id
|
||||
EXISTING_ID=$(gh api \
|
||||
"repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" \
|
||||
--jq "[.[] | select(.body | startswith(\"${MARKER}\")) | .id] | first // empty")
|
||||
|
||||
if [ -n "$EXISTING_ID" ]; then
|
||||
gh api --method PATCH \
|
||||
"repos/${{ github.repository }}/issues/comments/${EXISTING_ID}" \
|
||||
-f body="$COMMENT_BODY"
|
||||
else
|
||||
gh pr comment "$PR_NUMBER" \
|
||||
--repo "${{ github.repository }}" \
|
||||
--body "$COMMENT_BODY"
|
||||
fi
|
||||
27
.github/workflows/tests.yml
vendored
27
.github/workflows/tests.yml
vendored
@@ -131,7 +131,6 @@ jobs:
|
||||
if: needs.check-gate.outputs.enabled == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: read
|
||||
outputs:
|
||||
need_test: ${{ steps.bot.outputs.need_test }}
|
||||
@@ -168,23 +167,17 @@ jobs:
|
||||
echo "php_versions=$(echo "$BOT_JSON" | jq -c '.php_versions')" >> "$GITHUB_OUTPUT"
|
||||
echo "tier2=$(echo "$BOT_JSON" | jq -r '.tier2')" >> "$GITHUB_OUTPUT"
|
||||
|
||||
COMMENT_BODY=$(echo "$BOT_JSON" | jq -r '.comment_body')
|
||||
MARKER="<!-- spc-test-bot -->"
|
||||
# Save JSON for the comment-posting workflow
|
||||
jq -n --argjson bot "$BOT_JSON" \
|
||||
--arg pr '${{ github.event.pull_request.number }}' \
|
||||
'$bot + {pr_number: $pr}' > bot-output.json
|
||||
|
||||
# Find existing bot comment id
|
||||
EXISTING_ID=$(gh api \
|
||||
repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
|
||||
--jq "[.[] | select(.body | startswith(\"$MARKER\")) | .id] | first // empty")
|
||||
|
||||
if [ -n "$EXISTING_ID" ]; then
|
||||
gh api --method PATCH \
|
||||
repos/${{ github.repository }}/issues/comments/"$EXISTING_ID" \
|
||||
-f body="$COMMENT_BODY"
|
||||
else
|
||||
gh pr comment ${{ github.event.pull_request.number }} \
|
||||
--repo ${{ github.repository }} \
|
||||
--body "$COMMENT_BODY"
|
||||
fi
|
||||
- name: Upload bot output
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: bot-output
|
||||
path: bot-output.json
|
||||
retention-days: 1
|
||||
|
||||
gen-matrix:
|
||||
name: "Generate test matrix"
|
||||
|
||||
@@ -13,4 +13,5 @@ ext-imagick:
|
||||
os:
|
||||
- Linux
|
||||
- Darwin
|
||||
- Windows
|
||||
arg-type: custom
|
||||
|
||||
@@ -16,13 +16,59 @@ imagemagick:
|
||||
- libtiff
|
||||
- libheif
|
||||
- bzip2
|
||||
depends@windows:
|
||||
- zlib
|
||||
suggests:
|
||||
- zstd
|
||||
- xz
|
||||
- libzip
|
||||
- libxml2
|
||||
headers@windows:
|
||||
- imagemagick/MagickWand/MagickWand.h
|
||||
lang: cpp
|
||||
pkg-configs:
|
||||
- Magick++-7.Q16HDRI
|
||||
- MagickCore-7.Q16HDRI
|
||||
- MagickWand-7.Q16HDRI
|
||||
static-libs@windows:
|
||||
- CORE_RL_MagickWand_.lib
|
||||
- CORE_RL_MagickCore_.lib
|
||||
- CORE_RL_coders_.lib
|
||||
- CORE_RL_filters_.lib
|
||||
- CORE_RL_aom_.lib
|
||||
- CORE_RL_brotli_.lib
|
||||
- CORE_RL_bzip2_.lib
|
||||
- CORE_RL_cairo_.lib
|
||||
- CORE_RL_croco_.lib
|
||||
- CORE_RL_de265_.lib
|
||||
- CORE_RL_exr_.lib
|
||||
- CORE_RL_ffi_.lib
|
||||
- CORE_RL_freetype_.lib
|
||||
- CORE_RL_fribidi_.lib
|
||||
- CORE_RL_gdk-pixbuf_.lib
|
||||
- CORE_RL_glib_.lib
|
||||
- CORE_RL_harfbuzz_.lib
|
||||
- CORE_RL_heif_.lib
|
||||
- CORE_RL_highway_.lib
|
||||
- CORE_RL_imath_.lib
|
||||
- CORE_RL_jpeg-turbo-12_.lib
|
||||
- CORE_RL_jpeg-turbo-16_.lib
|
||||
- CORE_RL_jpeg-turbo_.lib
|
||||
- CORE_RL_jpeg-xl_.lib
|
||||
- CORE_RL_lcms_.lib
|
||||
- CORE_RL_lqr_.lib
|
||||
- CORE_RL_lzma_.lib
|
||||
- CORE_RL_openh264_.lib
|
||||
- CORE_RL_openjpeg_.lib
|
||||
- CORE_RL_openjph_.lib
|
||||
- CORE_RL_pango_.lib
|
||||
- CORE_RL_pixman_.lib
|
||||
- CORE_RL_png_.lib
|
||||
- CORE_RL_raqm_.lib
|
||||
- CORE_RL_raw_.lib
|
||||
- CORE_RL_rsvg_.lib
|
||||
- CORE_RL_tiff_.lib
|
||||
- CORE_RL_webp_.lib
|
||||
- CORE_RL_xml_.lib
|
||||
- CORE_RL_zip_.lib
|
||||
- CORE_RL_zlib_.lib
|
||||
|
||||
@@ -11,6 +11,10 @@ libzip:
|
||||
license: BSD-3-Clause
|
||||
depends:
|
||||
- zlib
|
||||
depends@windows:
|
||||
- zlib
|
||||
- bzip2
|
||||
- xz
|
||||
suggests:
|
||||
- bzip2
|
||||
- xz
|
||||
|
||||
@@ -5,8 +5,6 @@ postgresql:
|
||||
type: ghtagtar
|
||||
repo: postgres/postgres
|
||||
match: REL_18_\d+
|
||||
binary:
|
||||
windows-x86_64: { type: url, url: 'https://get.enterprisedb.com/postgresql/postgresql-16.8-1-windows-x64-binaries.zip', extract: { lib/libpq.lib: '{build_root_path}/lib/libpq.lib', lib/libpgport.lib: '{build_root_path}/lib/libpgport.lib', lib/libpgcommon.lib: '{build_root_path}/lib/libpgcommon.lib', include/libpq-fe.h: '{build_root_path}/include/libpq-fe.h', include/postgres_ext.h: '{build_root_path}/include/postgres_ext.h', include/pg_config_ext.h: '{build_root_path}/include/pg_config_ext.h', include/libpq/libpq-fs.h: '{build_root_path}/include/libpq/libpq-fs.h' } }
|
||||
metadata:
|
||||
license-files: ['@/postgresql.txt']
|
||||
license: PostgreSQL
|
||||
@@ -16,6 +14,9 @@ postgresql:
|
||||
- openssl
|
||||
- zlib
|
||||
- libedit
|
||||
depends@windows:
|
||||
- openssl
|
||||
- zlib
|
||||
suggests@unix:
|
||||
- icu
|
||||
- libxslt
|
||||
|
||||
@@ -20,7 +20,7 @@ class curl
|
||||
// which requires secur32.lib for SSL/TLS functions (SslEncryptPackage, etc.).
|
||||
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
|
||||
if (!str_contains($extra_libs, 'secur32.lib')) {
|
||||
putenv('SPC_EXTRA_LIBS=' . trim($extra_libs . ' secur32.lib'));
|
||||
putenv('SPC_EXTRA_LIBS=' . trim("{$extra_libs} secur32.lib"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,17 @@ declare(strict_types=1);
|
||||
|
||||
namespace Package\Extension;
|
||||
|
||||
use Package\Target\php;
|
||||
use StaticPHP\Attribute\Package\BeforeStage;
|
||||
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
|
||||
use StaticPHP\Attribute\Package\Extension;
|
||||
use StaticPHP\Attribute\PatchDescription;
|
||||
use StaticPHP\Package\PackageBuilder;
|
||||
use StaticPHP\Package\PhpExtensionPackage;
|
||||
use StaticPHP\Util\FileSystem;
|
||||
|
||||
#[Extension('imagick')]
|
||||
class imagick
|
||||
class imagick extends PhpExtensionPackage
|
||||
{
|
||||
#[CustomPhpConfigureArg('Darwin')]
|
||||
#[CustomPhpConfigureArg('Linux')]
|
||||
@@ -18,4 +23,35 @@ class imagick
|
||||
$disable_omp = ' ac_cv_func_omp_pause_resource_all=no';
|
||||
return '--with-imagick=' . ($shared ? 'shared,' : '') . $builder->getBuildRootPath() . $disable_omp;
|
||||
}
|
||||
|
||||
#[CustomPhpConfigureArg('Windows')]
|
||||
public function getWindowsConfigureArg(bool $shared): string
|
||||
{
|
||||
// config.w32 uses PHP_IMAGICK as an extra search path for CORE_RL_*.lib; the static
|
||||
// ImageMagick libs are installed flat in buildroot/lib (headers in buildroot/include/imagemagick).
|
||||
return '--with-imagick=' . BUILD_LIB_PATH;
|
||||
}
|
||||
|
||||
#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-imagick')]
|
||||
#[PatchDescription('Add the Win32 system libraries the static ImageMagick stack needs')]
|
||||
public function patchConfigW32ForWindows(): void
|
||||
{
|
||||
$config = $this->getSourceDir() . '/config.w32';
|
||||
|
||||
// Idempotency guard (the source dir may be patched in place and reused across builds).
|
||||
if (str_contains(FileSystem::readFile($config), 'LIBS_IMAGICK')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The static ImageMagick stack needs several Win32 system libraries (GDI/GDI+, WIC, urlmon, ...)
|
||||
// that aren't already pulled in by the other extensions. (imagick itself builds as plain C:
|
||||
// ImageMagick is built with a 32-bit channel mask, see imagemagick.php buildWin, so the
|
||||
// MagickCore headers don't require a C++ translation unit.)
|
||||
FileSystem::replaceFileStr(
|
||||
$config,
|
||||
"AC_DEFINE('HAVE_IMAGICK', 1);",
|
||||
'ADD_FLAG("LIBS_IMAGICK", "gdi32.lib gdiplus.lib urlmon.lib msimg32.lib oleaut32.lib windowscodecs.lib iphlpapi.lib");' . "\n\t\t" .
|
||||
"AC_DEFINE('HAVE_IMAGICK', 1);"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +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\Package\PackageInstaller;
|
||||
use StaticPHP\Util\FileSystem;
|
||||
|
||||
#[Extension('pdo_sqlite')]
|
||||
class pdo_sqlite
|
||||
{
|
||||
#[BeforeStage('php', [php::class, 'configureForUnix'], 'ext-pdo_sqlite')]
|
||||
public function patchBeforeConfigure(PackageInstaller $installer): void
|
||||
{
|
||||
FileSystem::replaceFileRegex(
|
||||
"{$installer->getTargetPackage('php')->getSourceDir()}/configure",
|
||||
'/sqlite3_column_table_name=yes/',
|
||||
'sqlite3_column_table_name=no'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -50,8 +50,9 @@ class simdjson extends PhpExtensionPackage
|
||||
if (!str_contains((string) $extra, '-lstdc++')) {
|
||||
f_putenv('SPC_COMPILER_EXTRA=' . clean_spaces($extra . ' -lstdc++'));
|
||||
}
|
||||
$env['CFLAGS'] .= ' -Xclang -target-feature -Xclang +evex512';
|
||||
$env['CXXFLAGS'] .= ' -Xclang -target-feature -Xclang +evex512';
|
||||
|
||||
$env['CFLAGS'] .= ' -fno-sanitize=undefined -Xclang -target-feature -Xclang +evex512';
|
||||
$env['CXXFLAGS'] .= ' -fno-sanitize=undefined -Xclang -target-feature -Xclang +evex512';
|
||||
}
|
||||
return $env;
|
||||
}
|
||||
@@ -63,8 +64,8 @@ class simdjson extends PhpExtensionPackage
|
||||
return;
|
||||
}
|
||||
$extra_cflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') ?: '';
|
||||
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . trim($extra_cflags . ' -Xclang -target-feature -Xclang +evex512'));
|
||||
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . trim($extra_cflags . ' -fno-sanitize=undefined -Xclang -target-feature -Xclang +evex512'));
|
||||
$extra_cxxflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CXXFLAGS') ?: '';
|
||||
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CXXFLAGS=' . trim($extra_cxxflags . ' -Xclang -target-feature -Xclang +evex512'));
|
||||
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CXXFLAGS=' . trim($extra_cxxflags . ' -fno-sanitize=undefined -Xclang -target-feature -Xclang +evex512'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ class swoole extends PhpExtensionPackage
|
||||
if ($installer->getPhpExtensionPackage('swoole-hook-odbc') && $installer->getPhpExtensionPackage('pdo_odbc')?->isBuildStatic()) {
|
||||
throw new WrongUsageException('swoole-hook-odbc provides pdo_odbc, if you enable odbc hook for swoole, you must remove pdo_odbc extension.');
|
||||
}
|
||||
|
||||
// swoole-hook-pgsql conflicts with pdo_pgsql
|
||||
if ($installer->getPhpExtensionPackage('swoole-hook-pgsql') && $installer->getPhpExtensionPackage('pdo_pgsql')?->isBuildStatic()) {
|
||||
throw new WrongUsageException('swoole-hook-pgsql provides pdo_pgsql, if you enable pgsql hook for swoole, you must remove pdo_pgsql extension.');
|
||||
|
||||
@@ -6,15 +6,86 @@ namespace Package\Library;
|
||||
|
||||
use StaticPHP\Attribute\Package\BuildFor;
|
||||
use StaticPHP\Attribute\Package\Library;
|
||||
use StaticPHP\Exception\EnvironmentException;
|
||||
use StaticPHP\Package\LibraryPackage;
|
||||
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
|
||||
use StaticPHP\Runtime\SystemTarget;
|
||||
use StaticPHP\Toolchain\Interface\ToolchainInterface;
|
||||
use StaticPHP\Util\FileSystem;
|
||||
use StaticPHP\Util\System\WindowsUtil;
|
||||
|
||||
#[Library('imagemagick')]
|
||||
class imagemagick
|
||||
{
|
||||
/**
|
||||
* Build a fully static, self-contained ImageMagick 7 (Q16-HDRI, /MT) on Windows using the
|
||||
* official VisualMagick build (the ImageMagick/Windows + Configure + Dependencies repos), which
|
||||
* bundles every delegate. ImageMagick has no autoconf/CMake build on Windows, so this clones the
|
||||
* VisualMagick tree, generates a static x64 solution via the Configure tool, and builds it with
|
||||
* msbuild. The resulting CORE_RL_*.lib static libraries + MagickWand/MagickCore headers are
|
||||
* installed into the build root for ext-imagick to link.
|
||||
*
|
||||
* A short working directory is used (VisualMagick's tree is deeply nested and otherwise exceeds
|
||||
* MAX_PATH); override with SPC_IMAGEMAGICK_BUILD_DIR.
|
||||
*/
|
||||
#[BuildFor('Windows')]
|
||||
public function buildWin(LibraryPackage $lib): void
|
||||
{
|
||||
$work = getenv('SPC_IMAGEMAGICK_BUILD_DIR') ?: 'C:\im';
|
||||
$configure_release = '2026.05.30.2033';
|
||||
$configure_url = "https://github.com/ImageMagick/Configure/releases/download/{$configure_release}/Configure.Release.x64.exe";
|
||||
|
||||
FileSystem::createDir($work);
|
||||
// Clone the VisualMagick repos (ImageMagick source + Configure + Dependencies + all delegates).
|
||||
if (!is_dir("{$work}\\ImageMagick")) {
|
||||
cmd()->cd($work)->exec(SPC_GIT_EXEC . ' clone --depth 1 https://github.com/ImageMagick/Windows.git .');
|
||||
cmd()->cd($work)->exec('bash clone-repositories.sh --imagemagick7');
|
||||
}
|
||||
// Use the prebuilt Configure tool (building it from source needs the MFC components).
|
||||
default_shell()->executeCurlDownload($configure_url, "{$work}\\Configure\\Configure.Release.x64.exe", retries: 2);
|
||||
|
||||
// Generate a static, /MT (linkRuntime), x64, Q16-HDRI solution with the configs embedded
|
||||
// (zeroConfigurationSupport) and OpenMP off (no vcomp runtime dependency).
|
||||
$ver = WindowsUtil::findVisualStudio();
|
||||
$vs_major = is_array($ver) ? $ver['major_version'] : 'unknown';
|
||||
$vs_arg = match ($vs_major) {
|
||||
'18',
|
||||
'17' => '/VS2022',
|
||||
'16' => '/VS2019',
|
||||
default => throw new EnvironmentException("Current VS version {$vs_major} is not supported yet!"),
|
||||
};
|
||||
cmd()->cd("{$work}\\Configure")
|
||||
->exec("Configure.Release.x64.exe /noWizard {$vs_arg} /x64 /static /linkRuntime /noOpenMP /zeroConfigurationSupport");
|
||||
|
||||
// x64 IM7 defaults to a 64-bit channel mask, whose magick-baseconfig.h #errors unless the
|
||||
// consuming translation unit is C++. ext-imagick is plain C, so force a 32-bit channel mask
|
||||
// (ample: 32 channels >> RGBA/CMYK) before building, keeping libs and the installed header in sync.
|
||||
FileSystem::replaceFileStr(
|
||||
"{$work}\\ImageMagick\\MagickCore\\magick-baseconfig.h",
|
||||
'#define MAGICKCORE_CHANNEL_MASK_DEPTH 64',
|
||||
'#define MAGICKCORE_CHANNEL_MASK_DEPTH 32'
|
||||
);
|
||||
|
||||
cmd()->cd($work)
|
||||
->exec('msbuild IM7.Static.x64.sln /m /t:Rebuild /nologo /p:Configuration=Release /p:Platform=x64');
|
||||
|
||||
$artifacts = "{$work}\\Artifacts\\lib";
|
||||
if (!is_dir($artifacts)) {
|
||||
throw new EnvironmentException('ImageMagick VisualMagick build produced no Artifacts/lib; build failed.');
|
||||
}
|
||||
// Install the static libs (flat, onto the build-root lib path) and the public headers.
|
||||
FileSystem::createDir($lib->getLibDir());
|
||||
foreach (glob("{$artifacts}\\CORE_RL_*.lib") as $f) {
|
||||
FileSystem::copy($f, $lib->getLibDir() . '\\' . basename($f));
|
||||
}
|
||||
foreach (['MagickWand', 'MagickCore'] as $dir) {
|
||||
FileSystem::createDir($lib->getIncludeDir() . "\\imagemagick\\{$dir}");
|
||||
foreach (glob("{$work}\\ImageMagick\\{$dir}\\*.h") as $h) {
|
||||
FileSystem::copy($h, $lib->getIncludeDir() . "\\imagemagick\\{$dir}\\" . basename($h));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[BuildFor('Darwin')]
|
||||
#[BuildFor('Linux')]
|
||||
public function buildUnix(LibraryPackage $lib, ToolchainInterface $toolchain): void
|
||||
|
||||
@@ -20,6 +20,7 @@ class libde265 extends LibraryPackage
|
||||
->addConfigureArgs(
|
||||
'-DENABLE_SDL=OFF',
|
||||
'-DENABLE_DECODER=OFF',
|
||||
'-DENABLE_SIMD=OFF',
|
||||
'-DHAVE_NEON=OFF',
|
||||
)
|
||||
->build();
|
||||
|
||||
@@ -37,6 +37,10 @@ class postgresql extends LibraryPackage
|
||||
#[PatchDescription('Various patches before building PostgreSQL')]
|
||||
public function patchBeforeBuild(): bool
|
||||
{
|
||||
// These patches target the autoconf/Make build; the Windows build uses Meson (see buildWin).
|
||||
if (SystemTarget::getTargetOS() === 'Windows') {
|
||||
return true;
|
||||
}
|
||||
// skip the test on platforms where libpq infrastructure may be provided by statically-linked libraries
|
||||
FileSystem::replaceFileStr("{$this->getSourceDir()}/src/interfaces/libpq/Makefile", 'invokes exit\'; exit 1;', 'invokes exit\';');
|
||||
// disable shared libs build
|
||||
@@ -53,6 +57,72 @@ class postgresql extends LibraryPackage
|
||||
return true;
|
||||
}
|
||||
|
||||
#[BuildFor('Windows')]
|
||||
public function buildWin(LibraryPackage $lib): void
|
||||
{
|
||||
$src = $lib->getSourceDir();
|
||||
$build_root = $lib->getBuildRootPath();
|
||||
$lib_dir = $lib->getLibDir();
|
||||
$inc_dir = $lib->getIncludeDir();
|
||||
$build = "{$src}\\build";
|
||||
|
||||
// Export the public pg_char_to_encoding()/pg_encoding_to_char() from libpgcommon.a so a
|
||||
// statically-linked libpq.a resolves them (PHP's ext/pgsql relies on them too). This mirrors
|
||||
// the Unix build's -UUSE_PRIVATE_ENCODING_FUNCS patch, but for the Meson build.
|
||||
FileSystem::replaceFileStr(
|
||||
"{$src}\\src\\common\\meson.build",
|
||||
"'c_args': ['-DUSE_PRIVATE_ENCODING_FUNCS'],",
|
||||
"'c_args': [],"
|
||||
);
|
||||
|
||||
// Fresh Meson build dir (Meson refuses to reuse a dir configured differently).
|
||||
if (is_dir($build)) {
|
||||
FileSystem::removeDir($build);
|
||||
}
|
||||
|
||||
// Meson's OpenSSL detection link-tests CRYPTO_new_ex_data; our static libcrypto needs its
|
||||
// Win32 deps (and zlib, since OpenSSL was built with zlib) on the link line to succeed.
|
||||
$ld = 'ws2_32.lib gdi32.lib advapi32.lib crypt32.lib user32.lib secur32.lib zlibstatic.lib';
|
||||
|
||||
$configure = 'meson setup build'
|
||||
. ' --prefix=' . escapeshellarg($build_root)
|
||||
. ' -Ddefault_library=static' // static libpq.a / libpgcommon.a / libpgport.a
|
||||
. ' -Db_vscrt=mt' // /MT static CRT, matching the rest of the build
|
||||
. ' -Dssl=openssl'
|
||||
// Everything libpq doesn't need: keeps deps minimal and avoids server-only detection.
|
||||
. ' -Dzlib=disabled -Dnls=disabled -Dreadline=disabled -Dicu=disabled'
|
||||
. ' -Dlz4=disabled -Dzstd=disabled -Dtap_tests=disabled'
|
||||
. ' -Dplperl=disabled -Dplpython=disabled -Dpltcl=disabled'
|
||||
. ' -Dgssapi=disabled -Dldap=disabled -Dlibxml=disabled -Dlibxslt=disabled'
|
||||
. ' -Dextra_include_dirs=' . escapeshellarg("{$build_root}\\include")
|
||||
. ' -Dextra_lib_dirs=' . escapeshellarg($lib_dir);
|
||||
|
||||
// Build only the three frontend static libs (not the server) — keeps it fast and avoids
|
||||
// needing every backend dependency. meson/ninja/win_bison/win_flex/perl come from PATH.
|
||||
$targets = 'src/interfaces/libpq/libpq.a src/common/libpgcommon.a src/port/libpgport.a';
|
||||
|
||||
cmd()->cd($src)
|
||||
->setEnv([
|
||||
'LIB' => $lib_dir . ';' . (getenv('LIB') ?: ''),
|
||||
'LDFLAGS' => $ld,
|
||||
])
|
||||
->exec($configure)
|
||||
->exec("ninja -C build {$targets}");
|
||||
|
||||
// Install the static libs under the names PHP's ext/pgsql + frankenphp expect (.lib).
|
||||
FileSystem::createDir($lib_dir);
|
||||
FileSystem::createDir($inc_dir);
|
||||
FileSystem::copy("{$build}\\src\\interfaces\\libpq\\libpq.a", "{$lib_dir}\\libpq.lib");
|
||||
FileSystem::copy("{$build}\\src\\common\\libpgcommon.a", "{$lib_dir}\\libpgcommon.lib");
|
||||
FileSystem::copy("{$build}\\src\\port\\libpgport.a", "{$lib_dir}\\libpgport.lib");
|
||||
|
||||
// Install the public libpq headers (PG18 no longer ships pg_config_ext.h).
|
||||
FileSystem::copy("{$src}\\src\\interfaces\\libpq\\libpq-fe.h", "{$inc_dir}\\libpq-fe.h");
|
||||
FileSystem::copy("{$src}\\src\\include\\postgres_ext.h", "{$inc_dir}\\postgres_ext.h");
|
||||
FileSystem::createDir("{$inc_dir}\\libpq");
|
||||
FileSystem::copy("{$src}\\src\\include\\libpq\\libpq-fs.h", "{$inc_dir}\\libpq\\libpq-fs.h");
|
||||
}
|
||||
|
||||
#[BuildFor('Darwin')]
|
||||
#[BuildFor('Linux')]
|
||||
public function buildUnix(PackageInstaller $installer, PackageBuilder $builder): void
|
||||
|
||||
@@ -19,7 +19,12 @@ class sqlite
|
||||
#[BuildFor('Linux')]
|
||||
public function buildUnix(LibraryPackage $lib): void
|
||||
{
|
||||
UnixAutoconfExecutor::create($lib)->configure()->make();
|
||||
UnixAutoconfExecutor::create($lib)
|
||||
->appendEnv([
|
||||
'CFLAGS' => '-DSQLITE_ENABLE_COLUMN_METADATA=1',
|
||||
])
|
||||
->configure()
|
||||
->make();
|
||||
$lib->patchPkgconfPrefix(['sqlite3.pc']);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,12 +35,16 @@ class curl
|
||||
#[BuildFor('Windows')]
|
||||
public function buildWin(LibraryPackage $lib): void
|
||||
{
|
||||
$lib_dir = str_replace('\\', '/', $lib->getLibDir());
|
||||
$zstd_lib = "{$lib_dir}/zstd_static.lib";
|
||||
$extra_libs = "{$lib_dir}/libcrypto.lib {$lib_dir}/libssl.lib ws2_32.lib gdi32.lib advapi32.lib crypt32.lib user32.lib";
|
||||
WindowsCMakeExecutor::create($lib)
|
||||
->optionalPackage('zstd', ...cmake_boolean_args('CURL_ZSTD'))
|
||||
->optionalPackage('brotli', ...cmake_boolean_args('CURL_BROTLI'))
|
||||
->addConfigureArgs(
|
||||
'-DBUILD_CURL_EXE=ON',
|
||||
'-DZSTD_LIBRARY=' . BUILD_LIB_PATH . '/zstd_static.lib',
|
||||
'-DCMAKE_C_STANDARD_LIBRARIES=' . escapeshellarg($extra_libs),
|
||||
'-DZSTD_LIBRARY=' . escapeshellarg($zstd_lib),
|
||||
'-DBUILD_TESTING=OFF',
|
||||
'-DBUILD_EXAMPLES=OFF',
|
||||
'-DUSE_LIBIDN2=OFF',
|
||||
|
||||
@@ -233,10 +233,21 @@ trait frankenphp
|
||||
$dep_libs = array_unique($dep_libs);
|
||||
$lib_dir = str_replace('\\', '/', BUILD_LIB_PATH);
|
||||
$php_embed_lib = "-lphp{$major}embed";
|
||||
$win_sys_libs = '-lkernel32 -lole32 -luser32 -ladvapi32 -lshell32 -lws2_32 -ldnsapi -lpsapi -lbcrypt';
|
||||
// pathcch: PathCchCanonicalizeEx etc. used by frankenphp/caddy path handling.
|
||||
// secur32: InitSecurityInterfaceA (curl Schannel/SSPI). crypt32/gdi32: OpenSSL + Schannel.
|
||||
$win_sys_libs = '-lkernel32 -lole32 -luser32 -ladvapi32 -lshell32 -lws2_32 -ldnsapi -lpsapi -lbcrypt -lpathcch -lsecur32 -lcrypt32 -lgdi32';
|
||||
$cgo_ldflags = clean_spaces(implode(' ', array_filter([
|
||||
"-L{$lib_dir}",
|
||||
$php_embed_lib,
|
||||
// FrankenPHP's cgo code references PHP/lexbor/zend symbols via __declspec(dllimport).
|
||||
// Their definitions live in php{N}embed.lib but are only pulled in if the plain symbol
|
||||
// is referenced, so the __imp_ refs go unresolved. Force-include one symbol from each
|
||||
// defining object (zend_atomic.obj, lexbor url.obj, lexbor idna.obj) to pull them in;
|
||||
// lld then auto-imports the __imp_ refs. (/WHOLEARCHIVE would also drag in libxml2.res,
|
||||
// which collides with Go's own resource object: "more than one resource obj file".)
|
||||
'-Wl,/INCLUDE:zend_atomic_bool_store',
|
||||
'-Wl,/INCLUDE:lxb_url_parse',
|
||||
'-Wl,/INCLUDE:lxb_unicode_idna_init',
|
||||
implode(' ', $dep_libs),
|
||||
$win_sys_libs,
|
||||
'-llibcmt',
|
||||
@@ -262,10 +273,11 @@ trait frankenphp
|
||||
// Fix: prepend clang's directory to PATH and use plain executable names instead,
|
||||
// which matches FrankenPHP's official CI approach (CC=clang, CXX=clang++).
|
||||
$clang_dir = dirname($clang_info['clang']);
|
||||
[$cc, $cxx] = $this->windowsCgoCompilers($package, $clang_info['clang']);
|
||||
$env = [
|
||||
'CGO_ENABLED' => '1',
|
||||
'CC' => 'clang.exe',
|
||||
'CXX' => 'clang++.exe',
|
||||
'CC' => $cc,
|
||||
'CXX' => $cxx,
|
||||
'PATH' => $clang_dir . ';' . getenv('PATH'),
|
||||
'CGO_CFLAGS' => clean_spaces($cgo_cflags),
|
||||
'CGO_LDFLAGS' => $cgo_ldflags,
|
||||
@@ -366,6 +378,41 @@ trait frankenphp
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the [CC, CXX] cgo should use to build FrankenPHP on Windows.
|
||||
*
|
||||
* Go passes the MinGW-only `-mthreads` flag to the C compiler for cgo builds;
|
||||
* Clang >= 20 rejects it for the MSVC target. When it does, wrap Clang with
|
||||
* a tiny .bat that strips the flag before forwarding.
|
||||
*
|
||||
* Workaround for https://github.com/golang/go/issues/80290, remove once Go
|
||||
* stops passing the flag.
|
||||
*
|
||||
* @return array{0: string, 1: string}
|
||||
*/
|
||||
protected function windowsCgoCompilers(TargetPackage $package, string $clang): array
|
||||
{
|
||||
$probe = $package->getSourceDir() . '\mthreads-probe.c';
|
||||
file_put_contents($probe, "int main(void){return 0;}\n");
|
||||
[$ret] = cmd()->execWithResult('"' . $clang . '" -mthreads -c ' . escapeshellarg($probe) . ' -o ' . escapeshellarg($probe . '.o'), false);
|
||||
FileSystem::removeFileIfExists($probe);
|
||||
FileSystem::removeFileIfExists($probe . '.o');
|
||||
if ($ret === 0) {
|
||||
return ['clang.exe', 'clang++.exe'];
|
||||
}
|
||||
|
||||
logger()->info('Clang rejects -mthreads; wrapping it to strip the flag (golang/go#80290)');
|
||||
$dir = dirname($clang);
|
||||
$cc = $package->getSourceDir() . '\cc-nothreads.bat';
|
||||
$cxx = $package->getSourceDir() . '\cxx-nothreads.bat';
|
||||
// %*: the whole command line; the substring replace drops the -mthreads token,
|
||||
// preserving quoting of paths that a for-loop would mangle.
|
||||
file_put_contents($cc, "@echo off\r\nset \"a=%*\"\r\nset \"a=%a: -mthreads = %\"\r\n\"{$dir}\\clang.exe\" %a%\r\n");
|
||||
file_put_contents($cxx, "@echo off\r\nset \"a=%*\"\r\nset \"a=%a: -mthreads = %\"\r\n\"{$dir}\\clang++.exe\" %a%\r\n");
|
||||
|
||||
return [$cc, $cxx];
|
||||
}
|
||||
|
||||
protected function getFrankenPHPVersion(TargetPackage $package): string
|
||||
{
|
||||
if ($version = getenv('FRANKENPHP_VERSION')) {
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Package\Target\php;
|
||||
|
||||
use Package\Target\php;
|
||||
use StaticPHP\Attribute\Package\BeforeStage;
|
||||
use StaticPHP\Attribute\Package\BuildFor;
|
||||
use StaticPHP\Attribute\Package\Stage;
|
||||
@@ -126,7 +127,10 @@ trait windows
|
||||
throw new PatchException('Windows Makefile patching for php.exe target', 'Cannot patch windows CLI Makefile, Makefile does not contain "$(BUILD_DIR)\php.exe:" line');
|
||||
}
|
||||
$lines[$line_num] = '$(BUILD_DIR)\php.exe: generated_files $(DEPS_CLI) $(PHP_GLOBAL_OBJS) $(CLI_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(ASM_OBJS) $(BUILD_DIR)\php.exe.res $(BUILD_DIR)\php.exe.manifest';
|
||||
$lines[$line_num + 1] = "\t" . '"$(LINK)" /nologo $(PHP_GLOBAL_OBJS_RESP) $(CLI_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(ASM_OBJS) $(LIBS) $(LIBS_CLI) $(BUILD_DIR)\php.exe.res /out:$(BUILD_DIR)\php.exe $(LDFLAGS) $(LDFLAGS_CLI) /ltcg /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /ignore:4286';
|
||||
// /FORCE:MULTIPLE: extensions may bundle their own static copies of common libraries (e.g.
|
||||
// imagick's ImageMagick ships its own zlib/png/jpeg, duplicating gd's); let the first
|
||||
// definition win instead of failing with LNK2005. /ignore:4006 silences the resulting noise.
|
||||
$lines[$line_num + 1] = "\t" . '"$(LINK)" /nologo $(PHP_GLOBAL_OBJS_RESP) $(CLI_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(ASM_OBJS) $(LIBS) $(LIBS_CLI) $(BUILD_DIR)\php.exe.res /out:$(BUILD_DIR)\php.exe $(LDFLAGS) $(LDFLAGS_CLI) /ltcg /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /ignore:4286 /FORCE:MULTIPLE /ignore:4006';
|
||||
FileSystem::writeFile("{$package->getSourceDir()}\\Makefile", implode("\r\n", $lines));
|
||||
}
|
||||
|
||||
@@ -714,12 +718,18 @@ C_CODE;
|
||||
// MSVC cl.exe format: compiler flags must come before /link, linker flags after
|
||||
// ldflags contains /LIBPATH which must be after /link
|
||||
// /FORCE:MULTIPLE: in ZTS mode both zend.obj and php_embed.obj (both packed into the fat php8embed.lib) define _tsrm_ls_cache as a __declspec(thread) variable.
|
||||
// /INCLUDE: php8embed.lib's ext/uri (uri_parser_whatwg.obj) references lexbor lxb_url_*/
|
||||
// lxb_unicode_idna_* via __declspec(dllimport); their definitions live in url.obj/idna.obj
|
||||
// but are only pulled in if the plain symbol is referenced. Force-include one symbol from
|
||||
// each so the objects are linked and the __imp_ refs auto-import. (FrankenPHP needs the same.)
|
||||
// System libs add pathcch (PathCchCanonicalizeEx), secur32 (curl Schannel InitSecurityInterface),
|
||||
// crypt32/gdi32 (OpenSSL + Schannel) on top of the Makefile LIBS set.
|
||||
$compile_cmd = sprintf(
|
||||
'cl.exe /nologo /O2 /MT /Z7 %s embed.c /Fe:embed.exe /link /FORCE:MULTIPLE /LIBPATH:"%s\lib" %s %s',
|
||||
'cl.exe /nologo /O2 /MT /Z7 %s embed.c /Fe:embed.exe /link /FORCE:MULTIPLE /INCLUDE:lxb_url_parse /INCLUDE:lxb_unicode_idna_init /LIBPATH:"%s\lib" %s %s',
|
||||
$include_flags,
|
||||
BUILD_ROOT_PATH,
|
||||
$config['libs'],
|
||||
'kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib dnsapi.lib psapi.lib bcrypt.lib' // Windows system libs (match Makefile LIBS)
|
||||
'kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib dnsapi.lib psapi.lib bcrypt.lib pathcch.lib secur32.lib crypt32.lib gdi32.lib' // Windows system libs (match Makefile LIBS) + curl/openssl deps
|
||||
);
|
||||
|
||||
// Log command explicitly (workaround for cmd() not logging complex commands properly)
|
||||
@@ -733,9 +743,11 @@ C_CODE;
|
||||
);
|
||||
}
|
||||
|
||||
// Run the embed test
|
||||
// Run the embed test. Use a ".\" prefix: cmd.exe does not resolve a bare "embed.exe" from
|
||||
// the current directory, while the cwd must remain $test_dir so the script's relative
|
||||
// "embed.php" is found.
|
||||
InteractiveTerm::setMessage('Running php-embed run smoke test');
|
||||
[$ret, $output] = cmd()->cd($test_dir)->execWithResult('embed.exe');
|
||||
[$ret, $output] = cmd()->cd($test_dir)->execWithResult('.\embed.exe');
|
||||
$raw_output = implode('', $output);
|
||||
if ($ret !== 0 || trim($raw_output) !== 'hello') {
|
||||
throw new ValidationException(
|
||||
|
||||
@@ -107,7 +107,12 @@ class GenExtTestMatrixCommand extends BaseCommand
|
||||
// Separate into regular and virtual extensions (build-static:false excluded globally)
|
||||
$all_regular = [];
|
||||
$all_virtual = [];
|
||||
$all_libraries = [];
|
||||
foreach ($all as $pkg_name => $config) {
|
||||
if (($config['type'] ?? '') === 'library') {
|
||||
$all_libraries[$pkg_name] = $config;
|
||||
continue;
|
||||
}
|
||||
if (($config['type'] ?? '') !== 'php-extension') {
|
||||
continue;
|
||||
}
|
||||
@@ -154,10 +159,7 @@ 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-')
|
||||
));
|
||||
$os_lib_deps[$this->displayName($pkg_name)] = $this->collectLibraryDeps($raw, $all_libraries, $os);
|
||||
}
|
||||
$all_ext_lib_deps[$os] = $os_lib_deps;
|
||||
|
||||
@@ -246,22 +248,23 @@ class GenExtTestMatrixCommand extends BaseCommand
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($filter_extensions)) {
|
||||
$entries = array_values(array_filter($entries, function (array $entry) use ($filter_extensions): bool {
|
||||
if (!empty($filter_extensions) || !empty($filter_libs)) {
|
||||
$entries = array_values(array_filter($entries, function (array $entry) use ($filter_extensions, $filter_libs, $all_ext_lib_deps): 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;
|
||||
if (!empty($filter_extensions) && count(array_intersect($names, $filter_extensions)) > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!empty($filter_libs)) {
|
||||
$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;
|
||||
}));
|
||||
}
|
||||
@@ -300,6 +303,41 @@ class GenExtTestMatrixCommand extends BaseCommand
|
||||
return str_starts_with($pkg_name, 'ext-') ? substr($pkg_name, 4) : $pkg_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect direct and transitive library dependencies from a package dependency list.
|
||||
*
|
||||
* @param string[] $deps
|
||||
* @param array<string, mixed[]> $library_configs
|
||||
* @param array<string, true> $seen
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function collectLibraryDeps(array $deps, array $library_configs, string $platform, array $seen = []): array
|
||||
{
|
||||
$collected = [];
|
||||
foreach ($deps as $dep) {
|
||||
if (str_starts_with($dep, 'ext-') || isset($seen[$dep])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$seen[$dep] = true;
|
||||
$collected[$dep] = $dep;
|
||||
|
||||
if (!isset($library_configs[$dep])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$child_deps = array_merge(
|
||||
$this->resolvePlatformList($library_configs[$dep], 'depends', $platform),
|
||||
$this->resolvePlatformList($library_configs[$dep], 'suggests', $platform),
|
||||
);
|
||||
foreach ($this->collectLibraryDeps($child_deps, $library_configs, $platform, $seen) as $child_dep) {
|
||||
$collected[$child_dep] = $child_dep;
|
||||
}
|
||||
}
|
||||
return array_values($collected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split orphans into batches such that no two conflicting extensions share a batch.
|
||||
* Uses a greedy graph-coloring approach.
|
||||
|
||||
@@ -111,7 +111,7 @@ class ExceptionHandler
|
||||
|
||||
private static function logError($message, int $indent_space = 0, bool $output_log = true, string $color = 'red'): void
|
||||
{
|
||||
$spc_log = fopen(SPC_OUTPUT_LOG, 'a');
|
||||
$spc_log = spc_log_stream(SPC_OUTPUT_LOG);
|
||||
$msg = explode("\n", (string) $message);
|
||||
foreach ($msg as $v) {
|
||||
$line = str_pad($v, strlen($v) + $indent_space, ' ', STR_PAD_LEFT);
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Runtime\Shell;
|
||||
|
||||
use StaticPHP\Exception\ExecutionException;
|
||||
use StaticPHP\Exception\InterruptException;
|
||||
use StaticPHP\Exception\SPCInternalException;
|
||||
use StaticPHP\Runtime\SystemTarget;
|
||||
@@ -153,7 +154,7 @@ class DefaultShell extends Shell
|
||||
|
||||
$this->logCommandInfo($cmd);
|
||||
logger()->debug("[TAR EXTRACT] {$cmd}");
|
||||
$this->passthru($cmd, $this->console_putput);
|
||||
$this->passthruTolerateSymlinks($cmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -200,7 +201,7 @@ class DefaultShell extends Shell
|
||||
$run = function ($cmd) {
|
||||
$this->logCommandInfo($cmd);
|
||||
logger()->debug("[7Z EXTRACT] {$cmd}");
|
||||
$this->passthru($cmd, $this->console_putput);
|
||||
$this->passthruTolerateSymlinks($cmd);
|
||||
};
|
||||
|
||||
$extname = FileSystem::extname($archive_path);
|
||||
@@ -214,4 +215,67 @@ class DefaultShell extends Shell
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run an extraction command, tolerating symbolic links that the host cannot create.
|
||||
*
|
||||
* Windows tar.exe (bsdtar) cannot create the symbolic links some archives ship (e.g. zstd's
|
||||
* tests/cli-tests/bin/unzstd -> zstd), failing each with "Can't create '...': Invalid argument"
|
||||
* and exiting non-zero. Those entries are never needed to build, so on Windows we swallow a
|
||||
* failure whose only errors are such symlink creations and continue. Any other failure still throws.
|
||||
*/
|
||||
private function passthruTolerateSymlinks(string $cmd): void
|
||||
{
|
||||
// Symlink creation only fails on a Windows host; elsewhere extraction handles symlinks fine.
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
$this->passthru($cmd, $this->console_putput);
|
||||
return;
|
||||
}
|
||||
|
||||
$result = $this->passthru($cmd, $this->console_putput, capture_output: true, throw_on_error: false);
|
||||
if ($result['code'] === 0) {
|
||||
return;
|
||||
}
|
||||
if ($this->isSymlinkOnlyExtractFailure($result['output'])) {
|
||||
logger()->warning('Some symbolic links could not be created during extraction and were skipped (not supported on this Windows host). This is harmless for building.');
|
||||
return;
|
||||
}
|
||||
throw new ExecutionException(
|
||||
cmd: $cmd,
|
||||
message: "Command exited with non-zero code: {$result['code']}",
|
||||
code: $result['code'],
|
||||
cd: $this->cd,
|
||||
env: $this->env,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide whether an extraction failure was caused solely by symbolic links that could not be
|
||||
* created on Windows. Returns true only when at least one such error is present and no other
|
||||
* error-looking output is found, so genuine extraction failures still propagate.
|
||||
*/
|
||||
private function isSymlinkOnlyExtractFailure(string $output): bool
|
||||
{
|
||||
$saw_symlink_error = false;
|
||||
foreach (preg_split('/\r\n|\r|\n/', $output) ?: [] as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '') {
|
||||
continue;
|
||||
}
|
||||
// bsdtar's trailing summary line; not an error on its own.
|
||||
if (str_contains($line, 'Error exit delayed from previous errors')) {
|
||||
continue;
|
||||
}
|
||||
// The symlink (or other unsupported special file) that Windows refused to create.
|
||||
if (str_contains($line, "Can't create") && str_contains($line, 'Invalid argument')) {
|
||||
$saw_symlink_error = true;
|
||||
continue;
|
||||
}
|
||||
// Any other error-looking line means this was not a clean symlink-only failure.
|
||||
if (preg_match('/\berror\b|cannot|can\'t|failed|denied|no space|not permitted/i', $line)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $saw_symlink_error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,8 +114,8 @@ abstract class Shell
|
||||
if (!$this->enable_log_file) {
|
||||
return;
|
||||
}
|
||||
// write executed command to log file using spc_write_log
|
||||
$log_file = fopen(SPC_SHELL_LOG, 'a');
|
||||
// write executed command to log file using spc_write_log (shared handle, see spc_log_stream)
|
||||
$log_file = spc_log_stream(SPC_SHELL_LOG);
|
||||
spc_write_log($log_file, "\n>>>>>>>>>>>>>>>>>>>>>>>>>> [" . date('Y-m-d H:i:s') . "]\n");
|
||||
spc_write_log($log_file, "> Executing command: {$cmd}\n");
|
||||
// get the backtrace to find the file and line number
|
||||
@@ -154,8 +154,8 @@ abstract class Shell
|
||||
): array {
|
||||
$file_res = null;
|
||||
if ($this->enable_log_file) {
|
||||
// write executed command to the log file using spc_write_log
|
||||
$file_res = fopen(SPC_SHELL_LOG, 'a');
|
||||
// write executed command to the log file using spc_write_log (shared handle, see spc_log_stream)
|
||||
$file_res = spc_log_stream(SPC_SHELL_LOG);
|
||||
}
|
||||
if ($console_output) {
|
||||
$console_res = STDOUT;
|
||||
@@ -263,9 +263,7 @@ abstract class Shell
|
||||
}
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
if ($file_res !== null) {
|
||||
fclose($file_res);
|
||||
}
|
||||
// $file_res is a shared, process-wide handle (see spc_log_stream); do not close it here.
|
||||
proc_close($process);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,11 +66,10 @@ if (filter_var(getenv('SPC_ENABLE_LOG_FILE'), FILTER_VALIDATE_BOOLEAN)) {
|
||||
}
|
||||
}
|
||||
|
||||
$log_file_fd = fopen(SPC_OUTPUT_LOG, 'a');
|
||||
$ob_logger->addLogCallback(function ($level, $output) use ($log_file_fd) {
|
||||
if ($log_file_fd) {
|
||||
spc_write_log($log_file_fd, strip_ansi_colors($output) . "\n");
|
||||
}
|
||||
// Use a single shared handle (see spc_log_stream) so the file is opened exactly once;
|
||||
// on Windows a second concurrent open fails while child processes hold an inherited handle.
|
||||
$ob_logger->addLogCallback(function ($level, $output) {
|
||||
spc_write_log(spc_log_stream(SPC_OUTPUT_LOG), strip_ansi_colors($output) . "\n");
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
16
src/globals/ext-tests/pdo_sqlite.php
Normal file
16
src/globals/ext-tests/pdo_sqlite.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$pdo = new PDO('sqlite::memory:');
|
||||
$pdo->exec('CREATE TABLE spc_column_metadata_test (id INTEGER)');
|
||||
|
||||
$stmt = $pdo->query('SELECT id FROM spc_column_metadata_test');
|
||||
if ($stmt === false) {
|
||||
throw new RuntimeException('Failed to query SQLite metadata test table.');
|
||||
}
|
||||
|
||||
$metadata = $stmt->getColumnMeta(0);
|
||||
if (($metadata['table'] ?? null) !== 'spc_column_metadata_test') {
|
||||
throw new RuntimeException('PDO SQLite column metadata does not include the origin table.');
|
||||
}
|
||||
10
src/globals/ext-tests/sqlite3.php
Normal file
10
src/globals/ext-tests/sqlite3.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$sqlite = new SQLite3(':memory:');
|
||||
$enabled = $sqlite->querySingle("SELECT sqlite_compileoption_used('ENABLE_COLUMN_METADATA')");
|
||||
|
||||
if ((int) $enabled !== 1) {
|
||||
throw new RuntimeException('SQLite was not built with SQLITE_ENABLE_COLUMN_METADATA.');
|
||||
}
|
||||
@@ -137,6 +137,11 @@ function spc_add_log_filter(array|string $filter): void
|
||||
|
||||
function spc_write_log(mixed $stream, string $data): false|int
|
||||
{
|
||||
// Defensive: a log stream may be false/null when its file could not be opened
|
||||
// (e.g. transient sharing violations on Windows). Never let logging crash the run.
|
||||
if (!is_resource($stream)) {
|
||||
return false;
|
||||
}
|
||||
// get filter
|
||||
global $spc_log_filters;
|
||||
if (is_array($spc_log_filters)) {
|
||||
@@ -145,6 +150,29 @@ function spc_write_log(mixed $stream, string $data): false|int
|
||||
return fwrite($stream, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single, process-wide shared append handle for the given log file.
|
||||
*
|
||||
* The handle is opened lazily once and reused for the lifetime of the process. This is
|
||||
* important on Windows: every time a log file is opened with fopen() its handle is inherited
|
||||
* by child processes spawned via proc_open() (curl, git, tar, ...). While such a child is
|
||||
* alive it keeps the file open, and any *additional* open of the same file fails with a
|
||||
* sharing violation ("The process cannot access the file because it is being used by another
|
||||
* process."). During parallel downloads many children run at once, so opening a fresh handle
|
||||
* per log line crashes. Keeping exactly one handle per file means there is never a second open
|
||||
* to violate. Returns null when the file cannot be opened.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
function spc_log_stream(string $file): mixed
|
||||
{
|
||||
static $streams = [];
|
||||
if (!isset($streams[$file]) || !is_resource($streams[$file])) {
|
||||
$streams[$file] = @fopen($file, 'a') ?: null;
|
||||
}
|
||||
return $streams[$file];
|
||||
}
|
||||
|
||||
// ------- function f_* part -------
|
||||
// f_ means standard function wrapper
|
||||
|
||||
|
||||
@@ -176,6 +176,31 @@ class GenExtTestMatrixCommandTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* --for-libs must include extensions that depend on the library through other libraries.
|
||||
*/
|
||||
public function testForLibsFilterIncludesTransitiveLibraryDeps(): void
|
||||
{
|
||||
$matrix = $this->runMatrix(['--os' => 'Linux', '--for-libs' => 'libde265']);
|
||||
|
||||
$this->assertNotEmpty($matrix, '--for-libs=libde265 must yield at least one entry');
|
||||
foreach ($matrix as $entry) {
|
||||
$parts = explode(',', $entry['extension']);
|
||||
$this->assertContains('imagick', $parts, "Entry {$entry['extension']} should not appear in --for-libs=libde265 results");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple filters should include entries matching any changed package.
|
||||
*/
|
||||
public function testExtensionAndLibraryFiltersAreCombinedAsUnion(): void
|
||||
{
|
||||
$matrix = $this->runMatrix(['--os' => 'Linux', '--for-extensions' => 'simdjson', '--for-libs' => 'libde265']);
|
||||
|
||||
$this->assertNotEmpty($this->findEntriesContaining($matrix, 'simdjson'), 'simdjson entry must be included');
|
||||
$this->assertNotEmpty($this->findEntriesContaining($matrix, 'imagick'), 'imagick entry must be included through libde265');
|
||||
}
|
||||
|
||||
/**
|
||||
* --tier2 must produce only Tier2 runners and no Windows entries.
|
||||
*/
|
||||
@@ -258,14 +283,17 @@ class GenExtTestMatrixCommandTest extends TestCase
|
||||
* - ext-swoole-hook-* virtual (arg-type: none) — must be bundled with swoole
|
||||
* - ext-curl simple orphan, depended on by swoole but must NOT be pulled into swoole entry
|
||||
* - ext-redis simple orphan
|
||||
* - ext-simdjson simple orphan used for combined filter tests
|
||||
* - ext-xml depends on lib 'libxml2'
|
||||
* - ext-dom depends on ext-xml (DFS chain)
|
||||
* - ext-imagick depends on imagemagick -> libheif -> libde265
|
||||
* - ext-linux-only restricted to Linux via os: [Linux]
|
||||
*/
|
||||
private static function buildFixture(): array
|
||||
{
|
||||
// php-extension must be a non-empty assoc array ([] fails is_assoc_array() check).
|
||||
$ext = static fn (array $phpExt = ['arg-type' => 'standard'], array $topLevel = []): array => array_merge(['type' => 'php-extension', 'php-extension' => $phpExt], $topLevel);
|
||||
$lib = static fn (array $topLevel = []): array => array_merge(['type' => 'library', 'artifact' => ['source' => 'custom']], $topLevel);
|
||||
|
||||
return [
|
||||
// Isolated standalones
|
||||
@@ -279,11 +307,18 @@ class GenExtTestMatrixCommandTest extends TestCase
|
||||
// Simple orphans
|
||||
'ext-curl' => $ext(),
|
||||
'ext-redis' => $ext(),
|
||||
'ext-simdjson' => $ext(),
|
||||
|
||||
// DFS chain: dom depends on xml; xml depends on lib 'libxml2'
|
||||
'ext-xml' => $ext(['arg-type' => 'standard'], ['depends' => ['libxml2']]),
|
||||
'ext-dom' => $ext(['arg-type' => 'standard'], ['depends' => ['ext-xml']]),
|
||||
|
||||
// Transitive library chain: imagick -> imagemagick -> libheif -> libde265
|
||||
'ext-imagick' => $ext(['arg-type' => 'standard'], ['depends' => ['imagemagick']]),
|
||||
'imagemagick' => $lib(['depends' => ['libheif']]),
|
||||
'libheif' => $lib(['depends' => ['libde265']]),
|
||||
'libde265' => $lib(),
|
||||
|
||||
// OS-restricted to Linux only
|
||||
'ext-linux-only' => $ext(['os' => ['Linux']]),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user