Skip to content

Commit 3d45890

Browse files
authored
Merge pull request #821 from crazywhalecc/fix/windows-curl-sspi
Fix/windows curl sspi
2 parents bb5eb64 + e6a050d commit 3d45890

File tree

7 files changed

+30
-12
lines changed

7 files changed

+30
-12
lines changed

config/env.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ PHP_SDK_PATH="${WORKING_DIR}\php-sdk-binary-tools"
6363
UPX_EXEC="${PKG_ROOT_PATH}\bin\upx.exe"
6464
; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches
6565
SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime140,win32,zend_stream,cli_static
66+
; Windows static linking system libs
67+
SPC_EXTRA_LIBS=""
6668

6769
[linux]
6870
; Linux can use different build toolchain, but the toolchain can not be changed in this file:

config/source.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"license": {
55
"type": "file",
66
"path": "LICENSE"
7-
}
7+
},
8+
"alt": false
89
},
910
"amqp": {
1011
"type": "url",

src/SPC/builder/extension/curl.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ public function patchBeforeConfigure(): bool
5757
return true;
5858
}
5959

60+
public function patchBeforeMake(): bool
61+
{
62+
$extra_libs = getenv('SPC_EXTRA_LIBS');
63+
if (!str_contains($extra_libs, 'secur32.lib')) {
64+
$extra_libs .= ' secur32.lib';
65+
putenv('SPC_EXTRA_LIBS=' . trim($extra_libs));
66+
return true;
67+
}
68+
return false;
69+
}
70+
6071
public function patchBeforeSharedConfigure(): bool
6172
{
6273
$file = $this->source_dir . '/config.m4';

src/SPC/builder/windows/WindowsBuilder.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ public function __construct(array $options = [])
6161
*/
6262
public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
6363
{
64-
// ---------- Update extra-libs ----------
65-
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
66-
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles());
67-
f_putenv('SPC_EXTRA_LIBS=' . $extra_libs);
68-
6964
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
7065
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
7166
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
@@ -162,8 +157,10 @@ public function buildCli(): void
162157
{
163158
SourcePatcher::patchWindowsCLITarget();
164159

160+
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
161+
165162
// add nmake wrapper
166-
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= %*");
163+
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= %*");
167164

168165
cmd()->cd(SOURCE_PATH . '\php-src')->exec("{$this->sdk_prefix} nmake_cli_wrapper.bat --task-args php.exe");
169166

@@ -197,9 +194,11 @@ public function buildMicro(): void
197194
}
198195
FileSystem::writeFile(SOURCE_PATH . '\php-src\Makefile', $makefile);
199196

197+
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
198+
200199
// add nmake wrapper
201200
$fake_cli = $this->getOption('with-micro-fake-cli', false) ? ' /DPHP_MICRO_FAKE_CLI" ' : '';
202-
$wrapper = "nmake /nologo LIBS_MICRO=\"{$this->getOption('extra-libs')} ws2_32.lib shell32.lib\" CFLAGS_MICRO=\"/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1{$fake_cli}\" %*";
201+
$wrapper = "nmake /nologo LIBS_MICRO=\"ws2_32.lib shell32.lib {$extra_libs}\" CFLAGS_MICRO=\"/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1{$fake_cli}\" %*";
203202
FileSystem::writeFile(SOURCE_PATH . '\php-src\nmake_micro_wrapper.bat', $wrapper);
204203

205204
// phar patch for micro

src/SPC/builder/windows/library/curl.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ protected function build(): void
3737
'-DBUILD_EXAMPLES=OFF ' . // disable examples
3838
'-DUSE_LIBIDN2=OFF ' . // disable libidn2
3939
'-DCURL_USE_LIBPSL=OFF ' . // disable libpsl
40+
'-DUSE_WINDOWS_SSPI=ON ' . // use Schannel instead of OpenSSL
4041
'-DCURL_USE_SCHANNEL=ON ' . // use Schannel instead of OpenSSL
4142
'-DCURL_USE_OPENSSL=OFF ' . // disable openssl due to certificate issue
4243
'-DCURL_ENABLE_SSL=ON ' .

src/SPC/command/DownloadCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,15 @@ public function handle(): int
245245
}
246246
// if download failed, we will try to download alternative sources
247247
logger()->warning("Download failed: {$e->getMessage()}");
248-
logger()->notice("Trying to download alternative sources for {$source}");
249248
$alt_sources = Config::getSource($source)['alt'] ?? null;
250249
if ($alt_sources === null) {
250+
logger()->warning("No alternative sources found for {$source}, using default alternative source");
251251
$alt_config = array_merge($config, $this->getDefaultAlternativeSource($source));
252+
} elseif ($alt_sources === false) {
253+
logger()->warning("No alternative sources found for {$source}, skipping alternative download");
254+
throw $e;
252255
} else {
256+
logger()->notice("Trying to download alternative sources for {$source}");
253257
$alt_config = array_merge($config, $alt_sources);
254258
}
255259
Downloader::downloadSource($source, $alt_config, $force_all || in_array($source, $force_list));

src/globals/test-extensions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
// 'macos-13', // bin/spc for x86_64
2525
// 'macos-14', // bin/spc for arm64
2626
// 'macos-15', // bin/spc for arm64
27-
'ubuntu-latest', // bin/spc-alpine-docker for x86_64
27+
// 'ubuntu-latest', // bin/spc-alpine-docker for x86_64
2828
// 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64
2929
// 'ubuntu-24.04', // bin/spc for x86_64
3030
// 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64
3131
// 'ubuntu-24.04-arm', // bin/spc for arm64
32-
// 'windows-latest', // .\bin\spc.ps1
32+
'windows-latest', // .\bin\spc.ps1
3333
];
3434

3535
// whether enable thread safe
@@ -49,7 +49,7 @@
4949
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
5050
$extensions = match (PHP_OS_FAMILY) {
5151
'Linux', 'Darwin' => 'imap,swoole',
52-
'Windows' => 'intl',
52+
'Windows' => 'curl',
5353
};
5454

5555
// If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`).

0 commit comments

Comments
 (0)