Skip to content

Commit 95d7414

Browse files
authored
Fix windows curl build (using cmake) (#600)
1 parent 21de1a2 commit 95d7414

File tree

7 files changed

+47
-20
lines changed

7 files changed

+47
-20
lines changed

config/lib.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"libcurl.a"
3535
],
3636
"static-libs-windows": [
37-
"libcurl_a.lib"
37+
"libcurl.lib"
3838
],
3939
"headers": [
4040
"curl"

src/SPC/ConsoleApplication.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
final class ConsoleApplication extends Application
3333
{
34-
public const VERSION = '2.4.4';
34+
public const VERSION = '2.4.5';
3535

3636
public function __construct()
3737
{

src/SPC/builder/Extension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function runCliCheckWindows(): void
203203
// Run compile check if build target is cli
204204
// If you need to run some check, overwrite this or add your assert in src/globals/ext-tests/{extension_name}.php
205205
// If check failed, throw RuntimeException
206-
[$ret] = cmd()->execWithResult(BUILD_ROOT_PATH . '/bin/php.exe --ri "' . $this->getDistName() . '"', false);
206+
[$ret] = cmd()->execWithResult(BUILD_ROOT_PATH . '/bin/php.exe -n --ri "' . $this->getDistName() . '"', false);
207207
if ($ret !== 0) {
208208
throw new RuntimeException('extension ' . $this->getName() . ' failed compile check: php-cli returned ' . $ret);
209209
}
@@ -216,7 +216,7 @@ public function runCliCheckWindows(): void
216216
file_get_contents(FileSystem::convertPath(ROOT_DIR . '/src/globals/ext-tests/' . $this->getName() . '.php'))
217217
);
218218

219-
[$ret] = cmd()->execWithResult(BUILD_ROOT_PATH . '/bin/php.exe -r "' . trim($test) . '"');
219+
[$ret] = cmd()->execWithResult(BUILD_ROOT_PATH . '/bin/php.exe -n -r "' . trim($test) . '"');
220220
if ($ret !== 0) {
221221
throw new RuntimeException('extension ' . $this->getName() . ' failed sanity check');
222222
}

src/SPC/builder/extension/mbregex.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function runCliCheckUnix(): void
3434

3535
public function runCliCheckWindows(): void
3636
{
37-
[$ret, $out] = cmd()->execWithResult(BUILD_ROOT_PATH . '/bin/php --ri "mbstring"', false);
37+
[$ret, $out] = cmd()->execWithResult(BUILD_ROOT_PATH . '/bin/php -n --ri "mbstring"', false);
3838
if ($ret !== 0) {
3939
throw new RuntimeException('extension ' . $this->getName() . ' failed compile check: compiled php-cli does not contain mbstring !');
4040
}

src/SPC/builder/windows/WindowsBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public function sanityCheck(mixed $build_target): void
277277
// sanity check for php-cli
278278
if (($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI) {
279279
logger()->info('running cli sanity check');
280-
[$ret, $output] = cmd()->execWithResult(BUILD_ROOT_PATH . '\bin\php.exe -r "echo \"hello\";"');
280+
[$ret, $output] = cmd()->execWithResult(BUILD_ROOT_PATH . '\bin\php.exe -n -r "echo \"hello\";"');
281281
if ($ret !== 0 || trim(implode('', $output)) !== 'hello') {
282282
throw new RuntimeException('cli failed sanity check');
283283
}

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

+34-7
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,41 @@ class curl extends WindowsLibraryBase
1212

1313
protected function build(): void
1414
{
15-
FileSystem::createDir(BUILD_BIN_PATH);
16-
cmd()->cd($this->source_dir . '\winbuild')
15+
// reset cmake
16+
FileSystem::resetDir($this->source_dir . '\cmakebuild');
17+
18+
// lib:zstd
19+
$alt = $this->builder->getLib('zstd') ? '' : '-DCURL_ZSTD=OFF';
20+
// lib:brotli
21+
$alt .= $this->builder->getLib('brotli') ? '' : ' -DCURL_BROTLI=OFF';
22+
23+
// start build
24+
cmd()->cd($this->source_dir)
25+
->execWithWrapper(
26+
$this->builder->makeSimpleWrapper('cmake'),
27+
'-B cmakebuild ' .
28+
'-A x64 ' .
29+
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
30+
'-DCMAKE_BUILD_TYPE=Release ' .
31+
'-DBUILD_SHARED_LIBS=OFF ' .
32+
'-DBUILD_STATIC_LIBS=ON ' .
33+
'-DCURL_STATICLIB=ON ' .
34+
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
35+
'-DBUILD_CURL_EXE=OFF ' . // disable curl.exe
36+
'-DBUILD_TESTING=OFF ' . // disable tests
37+
'-DBUILD_EXAMPLES=OFF ' . // disable examples
38+
'-DUSE_LIBIDN2=OFF ' . // disable libidn2
39+
'-DCURL_USE_LIBPSL=OFF ' . // disable libpsl
40+
'-DCURL_ENABLE_SSL=ON ' .
41+
'-DUSE_NGHTTP2=ON ' . // enable nghttp2
42+
'-DCURL_USE_LIBSSH2=ON ' . // enable libssh2
43+
'-DENABLE_IPV6=ON ' . // enable ipv6
44+
'-DNGHTTP2_CFLAGS="/DNGHTTP2_STATICLIB" ' .
45+
$alt
46+
)
1747
->execWithWrapper(
18-
$this->builder->makeSimpleWrapper('nmake'),
19-
'/f Makefile.vc WITH_DEVEL=' . BUILD_ROOT_PATH . ' ' .
20-
'WITH_PREFIX=' . BUILD_ROOT_PATH . ' ' .
21-
'mode=static RTLIBCFG=static WITH_SSL=static WITH_NGHTTP2=static WITH_SSH2=static ENABLE_IPV6=yes WITH_ZLIB=static MACHINE=x64 DEBUG=no'
48+
$this->builder->makeSimpleWrapper('cmake'),
49+
"--build cmakebuild --config Release --target install -j{$this->builder->concurrency}"
2250
);
23-
FileSystem::copyDir($this->source_dir . '\include\curl', BUILD_INCLUDE_PATH . '\curl');
2451
}
2552
}

src/globals/test-extensions.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@
2121

2222
// test os (macos-13, macos-14, ubuntu-latest, windows-latest are available)
2323
$test_os = [
24-
'macos-13',
25-
'macos-14',
26-
'ubuntu-latest',
24+
// 'macos-13',
25+
// 'macos-14',
26+
// 'ubuntu-latest',
2727
'windows-latest',
2828
];
2929

3030
// whether enable thread safe
31-
$zts = false;
31+
$zts = true;
3232

3333
$no_strip = false;
3434

3535
// compress with upx
3636
$upx = false;
3737

3838
// prefer downloading pre-built packages to speed up the build process
39-
$prefer_pre_built = true;
39+
$prefer_pre_built = false;
4040

4141
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
4242
$extensions = match (PHP_OS_FAMILY) {
43-
'Linux', 'Darwin' => 'opentelemetry',
44-
'Windows' => 'opentelemetry',
43+
'Linux', 'Darwin' => 'curl',
44+
'Windows' => 'curl',
4545
};
4646

4747
// If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).

0 commit comments

Comments
 (0)