mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-07 08:45:40 +08:00
Add curl extension and enhance Windows build process
This commit is contained in:
26
src/Package/Extension/curl.php
Normal file
26
src/Package/Extension/curl.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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;
|
||||
|
||||
#[Extension('curl')]
|
||||
class curl
|
||||
{
|
||||
#[BeforeStage('php', [php::class, 'makeForWindows'], 'ext-curl')]
|
||||
#[PatchDescription('Inject secur32.lib into SPC_EXTRA_LIBS for Schannel SSL support')]
|
||||
public function addSecur32LibForWindows(): void
|
||||
{
|
||||
// curl on Windows uses Schannel (USE_WINDOWS_SSPI=ON, CURL_USE_SCHANNEL=ON),
|
||||
// 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'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ use StaticPHP\Attribute\Package\Library;
|
||||
use StaticPHP\Package\LibraryPackage;
|
||||
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
|
||||
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
|
||||
use StaticPHP\Util\FileSystem;
|
||||
|
||||
#[Library('nghttp2')]
|
||||
class nghttp2
|
||||
@@ -26,6 +27,9 @@ class nghttp2
|
||||
'-DBUILD_TESTING=OFF',
|
||||
)
|
||||
->build();
|
||||
|
||||
FileSystem::replaceFileStr($lib->getIncludeDir() . '\nghttp2\nghttp2.h', '#ifdef NGHTTP2_STATICLIB', '#if 1');
|
||||
|
||||
}
|
||||
|
||||
#[BuildFor('Linux')]
|
||||
|
||||
@@ -12,6 +12,7 @@ use StaticPHP\Attribute\Package\BeforeStage;
|
||||
use StaticPHP\Attribute\Package\Info;
|
||||
use StaticPHP\Attribute\Package\InitPackage;
|
||||
use StaticPHP\Attribute\Package\ResolveBuild;
|
||||
use StaticPHP\Attribute\Package\Stage;
|
||||
use StaticPHP\Attribute\Package\Target;
|
||||
use StaticPHP\Attribute\Package\Validate;
|
||||
use StaticPHP\Config\PackageConfig;
|
||||
@@ -29,6 +30,7 @@ use StaticPHP\Toolchain\Interface\ToolchainInterface;
|
||||
use StaticPHP\Toolchain\ToolchainManager;
|
||||
use StaticPHP\Util\DependencyResolver;
|
||||
use StaticPHP\Util\FileSystem;
|
||||
use StaticPHP\Util\InteractiveTerm;
|
||||
use StaticPHP\Util\SourcePatcher;
|
||||
use StaticPHP\Util\V2CompatLayer;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
@@ -339,6 +341,35 @@ class php extends TargetPackage
|
||||
FileSystem::removeDir(BUILD_MODULES_PATH);
|
||||
}
|
||||
|
||||
#[Stage('postInstall')]
|
||||
public function postInstall(TargetPackage $package, PackageInstaller $installer): void
|
||||
{
|
||||
if ($package->getName() === 'frankenphp') {
|
||||
$package->runStage([$this, 'smokeTestFrankenphpForUnix']);
|
||||
return;
|
||||
}
|
||||
if ($package->getName() !== 'php') {
|
||||
return;
|
||||
}
|
||||
if (SystemTarget::isUnix()) {
|
||||
if ($installer->interactive) {
|
||||
InteractiveTerm::indicateProgress('Running PHP smoke tests');
|
||||
}
|
||||
$package->runStage([$this, 'smokeTestForUnix']);
|
||||
if ($installer->interactive) {
|
||||
InteractiveTerm::finish('PHP smoke tests passed');
|
||||
}
|
||||
} elseif (SystemTarget::getTargetOS() === 'Windows') {
|
||||
if ($installer->interactive) {
|
||||
InteractiveTerm::indicateProgress('Running PHP smoke tests');
|
||||
}
|
||||
$package->runStage([$this, 'smokeTestForWindows']);
|
||||
if ($installer->interactive) {
|
||||
InteractiveTerm::finish('PHP smoke tests passed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function makeStaticExtensionString(PackageInstaller $installer): string
|
||||
{
|
||||
$arg = [];
|
||||
|
||||
@@ -469,27 +469,6 @@ trait unix
|
||||
$package->runStage([$this, 'unixBuildSharedExt']);
|
||||
}
|
||||
|
||||
#[Stage('postInstall')]
|
||||
public function postInstall(TargetPackage $package, PackageInstaller $installer): void
|
||||
{
|
||||
if ($package->getName() === 'frankenphp') {
|
||||
$package->runStage([$this, 'smokeTestFrankenphpForUnix']);
|
||||
return;
|
||||
}
|
||||
if ($package->getName() !== 'php') {
|
||||
return;
|
||||
}
|
||||
if (SystemTarget::isUnix()) {
|
||||
if ($installer->interactive) {
|
||||
InteractiveTerm::indicateProgress('Running PHP smoke tests');
|
||||
}
|
||||
$package->runStage([$this, 'smokeTestForUnix']);
|
||||
if ($installer->interactive) {
|
||||
InteractiveTerm::finish('PHP smoke tests passed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch phpize and php-config if needed
|
||||
*/
|
||||
@@ -662,7 +641,7 @@ trait unix
|
||||
/**
|
||||
* Generate micro extension test php code.
|
||||
*/
|
||||
private function generateMicroExtTests(PackageInstaller $installer): string
|
||||
protected function generateMicroExtTests(PackageInstaller $installer): string
|
||||
{
|
||||
$php = "<?php\n\necho '[micro-test-start]' . PHP_EOL;\n";
|
||||
foreach ($installer->getResolvedPackages(PhpExtensionPackage::class) as $ext) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user