Refactor extension configuration and improve Windows build support

This commit is contained in:
crazywhalecc
2026-04-08 11:08:05 +08:00
parent 921870eaea
commit ee854eed41
12 changed files with 119 additions and 19 deletions

View File

@@ -49,7 +49,7 @@
"scripts": { "scripts": {
"analyse": "phpstan analyse --memory-limit 300M", "analyse": "phpstan analyse --memory-limit 300M",
"cs-fix": "php-cs-fixer fix", "cs-fix": "php-cs-fixer fix",
"lint-config": "bin/spc dev:lint-config", "lint-config": "php bin/spc dev:lint-config",
"test": "vendor/bin/phpunit tests/ --no-coverage", "test": "vendor/bin/phpunit tests/ --no-coverage",
"build:phar": "vendor/bin/box compile" "build:phar": "vendor/bin/box compile"
}, },

View File

@@ -9,6 +9,14 @@ ext-bz2:
arg-type@windows: with arg-type@windows: with
ext-calendar: ext-calendar:
type: php-extension type: php-extension
ext-com_dotnet:
type: php-extension
php-extension:
support:
Linux: 'no'
Darwin: 'no'
BSD: 'no'
arg-type@windows: '--enable-com-dotnet=yes'
ext-ctype: ext-ctype:
type: php-extension type: php-extension
ext-curl: ext-curl:
@@ -30,17 +38,20 @@ ext-dba:
ext-dom: ext-dom:
type: php-extension type: php-extension
depends: depends:
- libxml2
- ext-xml - ext-xml
php-extension: php-extension:
arg-type: '--enable-dom@shared_suffix@ --with-libxml=@build_root_path@' arg-type: enable
arg-type@windows: with arg-type@windows: with
ext-exif: ext-exif:
type: php-extension type: php-extension
depends@windows:
- ext-mbstring
ext-ffi: ext-ffi:
type: php-extension type: php-extension
depends@unix: depends@unix:
- libffi - libffi
depends@windows:
- libffi-win
php-extension: php-extension:
arg-type@unix: '--with-ffi=@shared_suffix@ --enable-zend-signals' arg-type@unix: '--with-ffi=@shared_suffix@ --enable-zend-signals'
arg-type@windows: with arg-type@windows: with
@@ -101,11 +112,12 @@ ext-ldap:
ext-libxml: ext-libxml:
type: php-extension type: php-extension
depends: depends:
- ext-xml - libxml2
php-extension: php-extension:
build-with-php: true build-with-php: true
build-shared: false build-shared: false
arg-type: none arg-type@unix: with-path
arg-type@windows: with
ext-mbregex: ext-mbregex:
type: php-extension type: php-extension
depends: depends:
@@ -239,7 +251,7 @@ ext-simplexml:
depends: depends:
- ext-xml - ext-xml
php-extension: php-extension:
arg-type@unix: '--enable-simplexml@shared_suffix@ --with-libxml=@build_root_path@' arg-type@unix: enable
arg-type@windows: with arg-type@windows: with
build-with-php: true build-with-php: true
ext-snmp: ext-snmp:
@@ -254,7 +266,7 @@ ext-soap:
- ext-xml - ext-xml
- ext-session - ext-session
php-extension: php-extension:
arg-type@unix: '--enable-soap@shared_suffix@ --with-libxml=@build_root_path@' arg-type@unix: enable
arg-type@windows: with arg-type@windows: with
build-with-php: true build-with-php: true
ext-sockets: ext-sockets:
@@ -306,27 +318,27 @@ ext-tokenizer:
ext-xml: ext-xml:
type: php-extension type: php-extension
depends: depends:
- libxml2 - ext-libxml
depends@windows: depends@windows:
- libxml2
- ext-iconv - ext-iconv
- ext-libxml
php-extension: php-extension:
arg-type: '--enable-xml@shared_suffix@ --with-libxml=@build_root_path@' arg-type@unix: enable
arg-type@windows: with arg-type@windows: with
build-with-php: true build-with-php: true
ext-xmlreader: ext-xmlreader:
type: php-extension type: php-extension
depends: depends:
- libxml2 - ext-xml
php-extension: php-extension:
arg-type: '--enable-xmlreader@shared_suffix@ --with-libxml=@build_root_path@' arg-type: enable
build-with-php: true build-with-php: true
ext-xmlwriter: ext-xmlwriter:
type: php-extension type: php-extension
depends: depends:
- libxml2 - ext-xml
php-extension: php-extension:
arg-type: '--enable-xmlwriter@shared_suffix@ --with-libxml=@build_root_path@' arg-type: enable
build-with-php: true build-with-php: true
ext-xsl: ext-xsl:
type: php-extension type: php-extension

View File

@@ -7,3 +7,7 @@ ext-excimer:
metadata: metadata:
license-files: [LICENSE] license-files: [LICENSE]
license: PHP-3.01 license: PHP-3.01
php-extension:
os:
- Linux
- Darwin

View File

@@ -7,3 +7,7 @@ ext-parallel:
metadata: metadata:
license-files: [LICENSE] license-files: [LICENSE]
license: PHP-3.01 license: PHP-3.01
depends@windows:
- pthreads4w
php-extension:
arg-type@windows: with

View File

@@ -45,7 +45,13 @@ class php_src
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/gd/libgd/gdft.c', '#ifndef MSWIN32', '#ifndef _WIN32'); FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/gd/libgd/gdft.c', '#ifndef MSWIN32', '#ifndef _WIN32');
} }
// custom config.w32, because official config.w32 is hard-coded many things // custom config.w32, because official config.w32 is hard-coded many things
$origin = $ver_id >= 80100 ? file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_81.w32') : file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_80.w32'); if ($ver_id >= 80500) {
$origin = file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_85.w32');
} elseif ($ver_id >= 80100) {
$origin = file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_81.w32');
} else {
$origin = file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_80.w32');
}
file_put_contents(SOURCE_PATH . '/php-src/ext/gd/config.w32.bak', file_get_contents(SOURCE_PATH . '/php-src/ext/gd/config.w32')); file_put_contents(SOURCE_PATH . '/php-src/ext/gd/config.w32.bak', file_get_contents(SOURCE_PATH . '/php-src/ext/gd/config.w32'));
file_put_contents(SOURCE_PATH . '/php-src/ext/gd/config.w32', $origin); file_put_contents(SOURCE_PATH . '/php-src/ext/gd/config.w32', $origin);
} }

View File

@@ -0,0 +1,30 @@
<?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\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;
#[Extension('ev')]
class ev extends PhpExtensionPackage
{
#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-ev')]
public function patchBeforeBuildconf(): bool
{
/*
* replace EXTENSION('ev', php_ev_sources, true, ' /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
* to EXTENSION('ev', php_ev_sources, PHP_EV_SHARED, ' /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
*/
FileSystem::replaceFileLineContainsString(
"{$this->getSourceDir()}\\config.w32",
'EXTENSION(\'ev\'',
" EXTENSION('ev', php_ev_sources, PHP_EV_SHARED, ' /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');"
);
return true;
}
}

View File

@@ -0,0 +1,29 @@
<?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\PackageInstaller;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;
#[Extension('intl')]
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')]
public function patchBeforeBuildconfForWindows(PackageInstaller $installer): void
{
$php_src = $installer->getTargetPackage('php')->getSourceDir();
FileSystem::replaceFileStr(
"{$php_src}/ext/intl/config.w32",
'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,'
);
}
}

View File

@@ -12,6 +12,7 @@ class mbregex
{ {
#[CustomPhpConfigureArg('Linux')] #[CustomPhpConfigureArg('Linux')]
#[CustomPhpConfigureArg('Darwin')] #[CustomPhpConfigureArg('Darwin')]
#[CustomPhpConfigureArg('Windows')]
public function getUnixConfigureArg(): string public function getUnixConfigureArg(): string
{ {
return ''; return '';

View File

@@ -19,4 +19,10 @@ class mbstring
$arg .= $installer->isPackageResolved('ext-mbregex') === false ? ' --disable-mbregex' : ' --enable-mbregex'; $arg .= $installer->isPackageResolved('ext-mbregex') === false ? ' --disable-mbregex' : ' --enable-mbregex';
return $arg; return $arg;
} }
#[CustomPhpConfigureArg('Windows')]
public function getWinConfigureArg(PackageInstaller $installer): string
{
return '--enable-mbstring ' . ($installer->isPackageResolved('ext-mbregex') ? '--enable-mbregex' : ' --disable-mbregex');
}
} }

View File

@@ -37,6 +37,7 @@ class libjpeg
'-DENABLE_STATIC=ON', '-DENABLE_STATIC=ON',
'-DBUILD_TESTING=OFF', '-DBUILD_TESTING=OFF',
'-DWITH_JAVA=OFF', '-DWITH_JAVA=OFF',
'-DWITH_SIMD=OFF',
'-DWITH_CRT_DLL=OFF', '-DWITH_CRT_DLL=OFF',
) )
->optionalPackage('zlib', '-DENABLE_ZLIB_COMPRESSION=ON', '-DENABLE_ZLIB_COMPRESSION=OFF') ->optionalPackage('zlib', '-DENABLE_ZLIB_COMPRESSION=ON', '-DENABLE_ZLIB_COMPRESSION=OFF')

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace StaticPHP\Command; namespace StaticPHP\Command;
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;
@@ -87,20 +88,24 @@ class ResetCommand extends BaseCommand
// Try using PowerShell for force deletion // Try using PowerShell for force deletion
$escaped_path = escapeshellarg($path); $escaped_path = escapeshellarg($path);
Shell::passthruCallback(fn () => InteractiveTerm::advance());
// Use PowerShell Remove-Item with -Force and -Recurse // Use PowerShell Remove-Item with -Force and -Recurse
$ps_cmd = "powershell -Command \"Remove-Item -Path {$escaped_path} -Recurse -Force -ErrorAction SilentlyContinue\""; $result = cmd()->execWithResult("powershell -Command \"Remove-Item -Path {$escaped_path} -Recurse -Force -ErrorAction SilentlyContinue\"", false);
f_exec($ps_cmd, $output, $ret_code); $ret_code = $result[0];
// If PowerShell fails or directory still exists, try cmd rmdir // If PowerShell fails or directory still exists, try cmd rmdir
if ($ret_code !== 0 || is_dir($path)) { if ($ret_code !== 0 || is_dir($path)) {
$cmd_command = "rmdir /s /q {$escaped_path}"; $cmd_command = "rmdir /s /q {$escaped_path}";
f_exec($cmd_command, $output, $ret_code); $result = cmd()->execWithResult($cmd_command, false);
if ($result[0] === 0) {
return;
}
} }
// Final fallback: use FileSystem::removeDir // Final fallback: use FileSystem::removeDir
if (is_dir($path)) { if (is_dir($path)) {
FileSystem::removeDir($path); FileSystem::removeDir($path);
} }
Shell::passthruCallback(null);
} }
} }

View File

@@ -34,6 +34,7 @@ class ConfigValidator
'build-with-php' => ConfigType::BOOL, 'build-with-php' => ConfigType::BOOL,
'notes' => ConfigType::BOOL, 'notes' => ConfigType::BOOL,
'display-name' => ConfigType::STRING, 'display-name' => ConfigType::STRING,
'os' => ConfigType::LIST_ARRAY,
// library and target fields // library and target fields
'headers' => ConfigType::LIST_ARRAY, // @ 'headers' => ConfigType::LIST_ARRAY, // @
@@ -88,6 +89,7 @@ class ConfigValidator
'build-with-php' => false, 'build-with-php' => false,
'notes' => false, 'notes' => false,
'display-name' => false, 'display-name' => false,
'os' => false,
]; ];
public const array ARTIFACT_TYPE_FIELDS = [ // [required_fields, optional_fields] public const array ARTIFACT_TYPE_FIELDS = [ // [required_fields, optional_fields]