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": {
"analyse": "phpstan analyse --memory-limit 300M",
"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",
"build:phar": "vendor/bin/box compile"
},

View File

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

View File

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

View File

@@ -7,3 +7,7 @@ ext-parallel:
metadata:
license-files: [LICENSE]
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');
}
// 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', $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('Darwin')]
#[CustomPhpConfigureArg('Windows')]
public function getUnixConfigureArg(): string
{
return '';

View File

@@ -19,4 +19,10 @@ class mbstring
$arg .= $installer->isPackageResolved('ext-mbregex') === false ? ' --disable-mbregex' : ' --enable-mbregex';
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',
'-DBUILD_TESTING=OFF',
'-DWITH_JAVA=OFF',
'-DWITH_SIMD=OFF',
'-DWITH_CRT_DLL=OFF',
)
->optionalPackage('zlib', '-DENABLE_ZLIB_COMPRESSION=ON', '-DENABLE_ZLIB_COMPRESSION=OFF')

View File

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

View File

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