From 83db186972c917908234ff5ed7d1c39a7977b9a0 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Thu, 17 Jul 2025 12:21:13 +0800 Subject: [PATCH 1/5] Fix curl static build for Windows --- config/env.ini | 2 ++ src/SPC/builder/extension/curl.php | 11 +++++++++++ src/SPC/builder/windows/WindowsBuilder.php | 8 ++++++-- src/SPC/builder/windows/library/curl.php | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/config/env.ini b/config/env.ini index 95a3d946..b6713991 100644 --- a/config/env.ini +++ b/config/env.ini @@ -63,6 +63,8 @@ PHP_SDK_PATH="${WORKING_DIR}\php-sdk-binary-tools" UPX_EXEC="${PKG_ROOT_PATH}\bin\upx.exe" ; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime140,win32,zend_stream,cli_static +; Windows static linking system libs +SPC_WINDOWS_EXEC_LIBS="ws2_32.lib shell32.lib" [linux] ; Linux can use different build toolchain, but the toolchain can not be changed in this file: diff --git a/src/SPC/builder/extension/curl.php b/src/SPC/builder/extension/curl.php index 0c5de6a5..6262f868 100644 --- a/src/SPC/builder/extension/curl.php +++ b/src/SPC/builder/extension/curl.php @@ -57,6 +57,17 @@ class curl extends Extension return true; } + public function patchBeforeMake(): bool + { + $extra_libs = getenv('SPC_WINDOWS_EXEC_LIBS'); + if (!str_contains($extra_libs, 'secur32.lib')) { + $extra_libs .= ' secur32.lib'; + putenv('SPC_WINDOWS_EXEC_LIBS=' . $extra_libs); + return true; + } + return false; + } + public function patchBeforeSharedConfigure(): bool { $file = $this->source_dir . '/config.m4'; diff --git a/src/SPC/builder/windows/WindowsBuilder.php b/src/SPC/builder/windows/WindowsBuilder.php index 25a503eb..4ce27bc2 100644 --- a/src/SPC/builder/windows/WindowsBuilder.php +++ b/src/SPC/builder/windows/WindowsBuilder.php @@ -162,8 +162,10 @@ class WindowsBuilder extends BuilderBase { SourcePatcher::patchWindowsCLITarget(); + $extra_libs = getenv('SPC_WINDOWS_EXEC_LIBS') ?: ''; + // add nmake wrapper - FileSystem::writeFile(SOURCE_PATH . '\php-src\nmake_cli_wrapper.bat', "nmake /nologo LIBS_CLI=\"{$this->getOption('extra-libs')} ws2_32.lib shell32.lib\" EXTRA_LD_FLAGS_PROGRAM= %*"); + FileSystem::writeFile(SOURCE_PATH . '\php-src\nmake_cli_wrapper.bat', "nmake /nologo LIBS_CLI=\"{$extra_libs}\" EXTRA_LD_FLAGS_PROGRAM= %*"); cmd()->cd(SOURCE_PATH . '\php-src')->exec("{$this->sdk_prefix} nmake_cli_wrapper.bat --task-args php.exe"); @@ -197,9 +199,11 @@ class WindowsBuilder extends BuilderBase } FileSystem::writeFile(SOURCE_PATH . '\php-src\Makefile', $makefile); + $extra_libs = getenv('SPC_WINDOWS_EXEC_LIBS') ?: ''; + // add nmake wrapper $fake_cli = $this->getOption('with-micro-fake-cli', false) ? ' /DPHP_MICRO_FAKE_CLI" ' : ''; - $wrapper = "nmake /nologo LIBS_MICRO=\"{$this->getOption('extra-libs')} ws2_32.lib shell32.lib\" CFLAGS_MICRO=\"/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1{$fake_cli}\" %*"; + $wrapper = "nmake /nologo LIBS_MICRO=\"{$extra_libs}\" CFLAGS_MICRO=\"/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1{$fake_cli}\" %*"; FileSystem::writeFile(SOURCE_PATH . '\php-src\nmake_micro_wrapper.bat', $wrapper); // phar patch for micro diff --git a/src/SPC/builder/windows/library/curl.php b/src/SPC/builder/windows/library/curl.php index a758bf05..1229dbd6 100644 --- a/src/SPC/builder/windows/library/curl.php +++ b/src/SPC/builder/windows/library/curl.php @@ -37,6 +37,7 @@ class curl extends WindowsLibraryBase '-DBUILD_EXAMPLES=OFF ' . // disable examples '-DUSE_LIBIDN2=OFF ' . // disable libidn2 '-DCURL_USE_LIBPSL=OFF ' . // disable libpsl + '-DUSE_WINDOWS_SSPI=ON ' . // use Schannel instead of OpenSSL '-DCURL_USE_SCHANNEL=ON ' . // use Schannel instead of OpenSSL '-DCURL_USE_OPENSSL=OFF ' . // disable openssl due to certificate issue '-DCURL_ENABLE_SSL=ON ' . From c604f886855637b639085f9176a539454511fe49 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Thu, 17 Jul 2025 12:21:50 +0800 Subject: [PATCH 2/5] Disallow alt for php-src --- config/source.json | 3 ++- src/SPC/command/DownloadCommand.php | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config/source.json b/config/source.json index b3c9cd62..d31a9af2 100644 --- a/config/source.json +++ b/config/source.json @@ -4,7 +4,8 @@ "license": { "type": "file", "path": "LICENSE" - } + }, + "alt": false }, "amqp": { "type": "url", diff --git a/src/SPC/command/DownloadCommand.php b/src/SPC/command/DownloadCommand.php index 1e895bdb..27360bb9 100644 --- a/src/SPC/command/DownloadCommand.php +++ b/src/SPC/command/DownloadCommand.php @@ -245,11 +245,15 @@ class DownloadCommand extends BaseCommand } // if download failed, we will try to download alternative sources logger()->warning("Download failed: {$e->getMessage()}"); - logger()->notice("Trying to download alternative sources for {$source}"); $alt_sources = Config::getSource($source)['alt'] ?? null; if ($alt_sources === null) { + logger()->warning("No alternative sources found for {$source}, using default alternative source"); $alt_config = array_merge($config, $this->getDefaultAlternativeSource($source)); - } else { + } elseif ($alt_sources === false) { + logger()->warning("No alternative sources found for {$source}, skipping alternative download"); + throw $e; + } else{ + logger()->notice("Trying to download alternative sources for {$source}"); $alt_config = array_merge($config, $alt_sources); } Downloader::downloadSource($source, $alt_config, $force_all || in_array($source, $force_list)); From e56c628becd75bfadc0e7d500cd13619c3649406 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Thu, 17 Jul 2025 12:23:03 +0800 Subject: [PATCH 3/5] Add windows tests --- src/globals/test-extensions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index ffb03701..07d2e039 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -24,12 +24,12 @@ $test_os = [ // 'macos-13', // bin/spc for x86_64 // 'macos-14', // bin/spc for arm64 // 'macos-15', // bin/spc for arm64 - 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 + // 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 // 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64 // 'ubuntu-24.04', // bin/spc for x86_64 // 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64 // 'ubuntu-24.04-arm', // bin/spc for arm64 - // 'windows-latest', // .\bin\spc.ps1 + 'windows-latest', // .\bin\spc.ps1 ]; // whether enable thread safe @@ -49,7 +49,7 @@ $prefer_pre_built = false; // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { 'Linux', 'Darwin' => 'imap,swoole', - 'Windows' => 'intl', + 'Windows' => 'curl', }; // If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`). From 7e7eb844a7212b3294944e9de4a22e49cbef4b4d Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Thu, 17 Jul 2025 12:26:30 +0800 Subject: [PATCH 4/5] cs-fix --- src/SPC/command/DownloadCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/command/DownloadCommand.php b/src/SPC/command/DownloadCommand.php index 27360bb9..f77c80f9 100644 --- a/src/SPC/command/DownloadCommand.php +++ b/src/SPC/command/DownloadCommand.php @@ -252,7 +252,7 @@ class DownloadCommand extends BaseCommand } elseif ($alt_sources === false) { logger()->warning("No alternative sources found for {$source}, skipping alternative download"); throw $e; - } else{ + } else { logger()->notice("Trying to download alternative sources for {$source}"); $alt_config = array_merge($config, $alt_sources); } From e6a050de82bf30722973a4feed85fc0df6152c28 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Thu, 17 Jul 2025 13:14:18 +0800 Subject: [PATCH 5/5] Use SPC_EXTRA_LIBS instead of SPC_WINDOWS_EXEC_LIBS --- config/env.ini | 2 +- src/SPC/builder/extension/curl.php | 4 ++-- src/SPC/builder/windows/WindowsBuilder.php | 13 ++++--------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/config/env.ini b/config/env.ini index b6713991..afbce73c 100644 --- a/config/env.ini +++ b/config/env.ini @@ -64,7 +64,7 @@ UPX_EXEC="${PKG_ROOT_PATH}\bin\upx.exe" ; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime140,win32,zend_stream,cli_static ; Windows static linking system libs -SPC_WINDOWS_EXEC_LIBS="ws2_32.lib shell32.lib" +SPC_EXTRA_LIBS="" [linux] ; Linux can use different build toolchain, but the toolchain can not be changed in this file: diff --git a/src/SPC/builder/extension/curl.php b/src/SPC/builder/extension/curl.php index 6262f868..a0207a1b 100644 --- a/src/SPC/builder/extension/curl.php +++ b/src/SPC/builder/extension/curl.php @@ -59,10 +59,10 @@ class curl extends Extension public function patchBeforeMake(): bool { - $extra_libs = getenv('SPC_WINDOWS_EXEC_LIBS'); + $extra_libs = getenv('SPC_EXTRA_LIBS'); if (!str_contains($extra_libs, 'secur32.lib')) { $extra_libs .= ' secur32.lib'; - putenv('SPC_WINDOWS_EXEC_LIBS=' . $extra_libs); + putenv('SPC_EXTRA_LIBS=' . trim($extra_libs)); return true; } return false; diff --git a/src/SPC/builder/windows/WindowsBuilder.php b/src/SPC/builder/windows/WindowsBuilder.php index 4ce27bc2..4becc926 100644 --- a/src/SPC/builder/windows/WindowsBuilder.php +++ b/src/SPC/builder/windows/WindowsBuilder.php @@ -61,11 +61,6 @@ class WindowsBuilder extends BuilderBase */ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void { - // ---------- Update extra-libs ---------- - $extra_libs = getenv('SPC_EXTRA_LIBS') ?: ''; - $extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles()); - f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); - $enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI; $enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM; $enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO; @@ -162,10 +157,10 @@ class WindowsBuilder extends BuilderBase { SourcePatcher::patchWindowsCLITarget(); - $extra_libs = getenv('SPC_WINDOWS_EXEC_LIBS') ?: ''; + $extra_libs = getenv('SPC_EXTRA_LIBS') ?: ''; // add nmake wrapper - FileSystem::writeFile(SOURCE_PATH . '\php-src\nmake_cli_wrapper.bat', "nmake /nologo LIBS_CLI=\"{$extra_libs}\" EXTRA_LD_FLAGS_PROGRAM= %*"); + FileSystem::writeFile(SOURCE_PATH . '\php-src\nmake_cli_wrapper.bat', "nmake /nologo LIBS_CLI=\"ws2_32.lib shell32.lib {$extra_libs}\" EXTRA_LD_FLAGS_PROGRAM= %*"); cmd()->cd(SOURCE_PATH . '\php-src')->exec("{$this->sdk_prefix} nmake_cli_wrapper.bat --task-args php.exe"); @@ -199,11 +194,11 @@ class WindowsBuilder extends BuilderBase } FileSystem::writeFile(SOURCE_PATH . '\php-src\Makefile', $makefile); - $extra_libs = getenv('SPC_WINDOWS_EXEC_LIBS') ?: ''; + $extra_libs = getenv('SPC_EXTRA_LIBS') ?: ''; // add nmake wrapper $fake_cli = $this->getOption('with-micro-fake-cli', false) ? ' /DPHP_MICRO_FAKE_CLI" ' : ''; - $wrapper = "nmake /nologo LIBS_MICRO=\"{$extra_libs}\" CFLAGS_MICRO=\"/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1{$fake_cli}\" %*"; + $wrapper = "nmake /nologo LIBS_MICRO=\"ws2_32.lib shell32.lib {$extra_libs}\" CFLAGS_MICRO=\"/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1{$fake_cli}\" %*"; FileSystem::writeFile(SOURCE_PATH . '\php-src\nmake_micro_wrapper.bat', $wrapper); // phar patch for micro