mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-08 09:25:35 +08:00
fable output
This commit is contained in:
@@ -22,6 +22,7 @@ class gettext_win
|
||||
{
|
||||
$ver = WindowsUtil::findVisualStudio();
|
||||
$vs_ver_dir = match ($ver['major_version']) {
|
||||
'18', // VS 2026 reuses the VS2022 (MSVC17) solution, which msbuild builds via forward compatibility.
|
||||
'17' => '\MSVC17',
|
||||
'16' => '\MSVC16',
|
||||
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"),
|
||||
@@ -44,7 +45,9 @@ class gettext_win
|
||||
{
|
||||
$vs_ver_dir = ApplicationContext::get('gettext_win_vs_ver_dir');
|
||||
cmd()->cd("{$lib->getSourceDir()}{$vs_ver_dir}\\libintl_static")
|
||||
->exec('msbuild libintl_static.vcxproj /t:Rebuild /p:Configuration=Release /p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0');
|
||||
// WholeProgramOptimization (/GL) emits LTCG objects that frankenphp's lld-link cannot
|
||||
// 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->getIncludeDir());
|
||||
// libintl_a.lib is the static library output; copy as libintl.lib for linker compatibility
|
||||
|
||||
@@ -6,6 +6,7 @@ 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;
|
||||
@@ -15,6 +16,67 @@ use StaticPHP\Util\FileSystem;
|
||||
#[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).
|
||||
cmd()->cd("{$work}\\Configure")
|
||||
->exec('Configure.Release.x64.exe /noWizard /VS2026 /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,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
|
||||
|
||||
@@ -21,6 +21,7 @@ class libffi_win
|
||||
{
|
||||
$ver = WindowsUtil::findVisualStudio();
|
||||
$vs_ver_dir = match ($ver['major_version']) {
|
||||
'18', // VS 2026 reuses the vs17 solution, which msbuild builds via forward compatibility.
|
||||
'17' => '\win32\vs17_x64',
|
||||
'16' => '\win32\vs16_x64',
|
||||
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported!"),
|
||||
@@ -33,7 +34,9 @@ class libffi_win
|
||||
{
|
||||
$vs_ver_dir = ApplicationContext::get('libffi_win_vs_ver_dir');
|
||||
cmd()->cd("{$lib->getSourceDir()}{$vs_ver_dir}")
|
||||
->exec('msbuild libffi-msvc.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64');
|
||||
// WholeProgramOptimization (/GL) emits LTCG objects that frankenphp's lld-link cannot
|
||||
// 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->getIncludeDir());
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class libiconv_win
|
||||
{
|
||||
$ver = WindowsUtil::findVisualStudio();
|
||||
$vs_ver_dir = match ($ver['major_version']) {
|
||||
'18', // VS 2026 reuses the VS2022 (MSVC17) solution, which msbuild builds via forward compatibility.
|
||||
'17' => '\MSVC17',
|
||||
'16' => '\MSVC16',
|
||||
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"),
|
||||
@@ -33,7 +34,9 @@ class libiconv_win
|
||||
{
|
||||
$vs_ver_dir = ApplicationContext::get('vs_ver_dir');
|
||||
cmd()->cd("{$lib->getSourceDir()}{$vs_ver_dir}")
|
||||
->exec('msbuild libiconv.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64');
|
||||
// WholeProgramOptimization (/GL) emits LTCG objects that frankenphp's lld-link cannot
|
||||
// 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->getIncludeDir());
|
||||
FileSystem::copy("{$lib->getSourceDir()}{$vs_ver_dir}\\x64\\lib\\libiconv.lib", "{$lib->getLibDir()}\\libiconv.lib");
|
||||
|
||||
@@ -42,13 +42,16 @@ class libsodium
|
||||
{
|
||||
$ver = WindowsUtil::findVisualStudio();
|
||||
$vs_ver_dir = match ($ver['major_version']) {
|
||||
'18', // VS 2026 reuses the vs2022 solution, which msbuild builds via forward compatibility.
|
||||
'17' => '\vs2022',
|
||||
'16' => '\vs2019',
|
||||
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"),
|
||||
};
|
||||
|
||||
cmd()->cd("{$lib->getSourceDir()}\\builds\\msvc{$vs_ver_dir}")
|
||||
->exec('msbuild libsodium.sln /t:Rebuild /p:Configuration=StaticRelease /p:Platform=x64 /p:PreprocessorDefinitions="SODIUM_STATIC=1"');
|
||||
// WholeProgramOptimization (/GL) emits LTCG objects that frankenphp's lld-link cannot
|
||||
// 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->getIncludeDir());
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class mpir
|
||||
{
|
||||
$ver = WindowsUtil::findVisualStudio();
|
||||
$vs_ver_dir = match ($ver['major_version']) {
|
||||
'18', // VS 2026 reuses the build.vc17 solution, which msbuild builds via forward compatibility.
|
||||
'17' => '\build.vc17',
|
||||
'16' => '\build.vc16',
|
||||
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user