Fix windows curl build (#368)

* fix curl on windows build needs nghttp2.dll bug

* add curl on windows tests

* cs fix

* fix curl headers

* exit powershell properly

* reproduce zend_mm_heap corrupted

* reproduce zend_mm_heap corrupted

* reproduce zend_mm_heap corrupted

* add for-libs option for download

* add for-libs option for download

* add for-libs option for download
This commit is contained in:
Jerry Ma 2024-03-05 21:43:09 +08:00 committed by GitHub
parent 8e58592a6e
commit 03510073c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 52 additions and 37 deletions

View File

@ -164,7 +164,8 @@ jobs:
timeout_minutes: 10 timeout_minutes: 10
max_attempts: 3 max_attempts: 3
retry_on: error retry_on: error
command: bin/spc download --for-extensions="$(php src/globals/test-extensions.php extensions)" --with-php=${{ matrix.php }} --debug command: |
bin/spc download --for-extensions="$(php src/globals/test-extensions.php extensions)" --with-php=${{ matrix.php }} --debug
- name: "Run Build Tests (build)" - name: "Run Build Tests (build)"
run: bin/spc build "$(php src/globals/test-extensions.php extensions)" $(php src/globals/test-extensions.php libs_cmd) --build-cli --build-micro --build-fpm --debug run: bin/spc build "$(php src/globals/test-extensions.php extensions)" $(php src/globals/test-extensions.php libs_cmd) --build-cli --build-micro --build-fpm --debug

View File

@ -9,3 +9,4 @@ if (-not(Test-Path $PHP_Exec)) {
} }
& "$PHP_Exec" ("bin/spc") @args & "$PHP_Exec" ("bin/spc") @args
exit $LASTEXITCODE

View File

@ -52,6 +52,9 @@
"lib-depends": [ "lib-depends": [
"libxml2", "libxml2",
"zlib" "zlib"
],
"ext-depends-windows": [
"xml"
] ]
}, },
"event": { "event": {

View File

@ -36,7 +36,7 @@
"libcurl.a" "libcurl.a"
], ],
"static-libs-windows": [ "static-libs-windows": [
"libcurl.lib" "libcurl_a.lib"
], ],
"headers": [ "headers": [
"curl" "curl"

View File

@ -88,7 +88,7 @@ class WindowsBuilder extends BuilderBase
if (($logo = $this->getOption('with-micro-logo')) !== null) { if (($logo = $this->getOption('with-micro-logo')) !== null) {
// realpath // realpath
$logo = realpath($logo); $logo = realpath($logo);
$micro_logo = '--enable-micro-logo=' . escapeshellarg($logo) . ' '; $micro_logo = '--enable-micro-logo=' . $logo . ' ';
} else { } else {
$micro_logo = ''; $micro_logo = '';
} }
@ -187,11 +187,13 @@ class WindowsBuilder extends BuilderBase
SourcePatcher::patchMicro(['phar']); SourcePatcher::patchMicro(['phar']);
} }
try {
cmd()->cd(SOURCE_PATH . '\php-src')->exec("{$this->sdk_prefix} nmake_micro_wrapper.bat --task-args micro"); cmd()->cd(SOURCE_PATH . '\php-src')->exec("{$this->sdk_prefix} nmake_micro_wrapper.bat --task-args micro");
} finally {
if ($this->phar_patched) { if ($this->phar_patched) {
SourcePatcher::patchMicro(['phar'], true); SourcePatcher::patchMicro(['phar'], true);
} }
}
$this->deployBinary(BUILD_TARGET_MICRO); $this->deployBinary(BUILD_TARGET_MICRO);
} }

View File

@ -12,29 +12,13 @@ class curl extends WindowsLibraryBase
protected function build(): void protected function build(): void
{ {
// reset cmake cmd()->cd($this->source_dir . '\winbuild')
FileSystem::resetDir($this->source_dir . '\build');
// start build
cmd()->cd($this->source_dir)
->execWithWrapper( ->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'), $this->builder->makeSimpleWrapper('nmake'),
'-B build ' . '/f Makefile.vc WITH_DEVEL=' . BUILD_ROOT_PATH . ' ' .
'-A x64 ' . 'WITH_PREFIX=' . BUILD_ROOT_PATH . ' ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . 'mode=static RTLIBCFG=static WITH_SSL=static WITH_NGHTTP2=static WITH_SSH2=static ENABLE_IPV6=yes WITH_ZLIB=static MACHINE=x64 DEBUG=no'
'-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DBUILD_STATIC_LIBS=ON ' .
'-DBUILD_CURL_EXE=OFF ' .
'-DUSE_ZLIB=ON ' .
'-DCURL_USE_OPENSSL=ON ' .
'-DCURL_USE_LIBLSSH2=ON ' .
'-DUSE_NGHTTP2=ON ' . // php-src with curl needs nghttp2
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
"--build build --config Release --target install -j{$this->builder->concurrency}"
); );
FileSystem::copyDir($this->source_dir . '\include\curl', BUILD_INCLUDE_PATH . '\curl');
} }
} }

View File

@ -23,8 +23,8 @@ class nghttp2 extends WindowsLibraryBase
'-A x64 ' . '-A x64 ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' . '-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' . '-DENABLE_SHARED_LIB=OFF ' .
'-DBUILD_STATIC_LIBS=ON ' . '-DENABLE_STATIC_LIB=ON ' .
'-DENABLE_STATIC_CRT=ON ' . '-DENABLE_STATIC_CRT=ON ' .
'-DENABLE_LIB_ONLY=ON ' . '-DENABLE_LIB_ONLY=ON ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '

View File

@ -104,8 +104,8 @@ class BuildCliCommand extends BuildCommand
$indent_texts = [ $indent_texts = [
'Build OS' => PHP_OS_FAMILY . ' (' . php_uname('m') . ')', 'Build OS' => PHP_OS_FAMILY . ' (' . php_uname('m') . ')',
'Build SAPI' => $builder->getBuildTypeName($rule), 'Build SAPI' => $builder->getBuildTypeName($rule),
'Extensions (' . count($extensions) . ')' => implode(', ', $extensions), 'Extensions (' . count($extensions) . ')' => implode(',', $extensions),
'Libraries (' . count($libraries) . ')' => implode(', ', $libraries), 'Libraries (' . count($libraries) . ')' => implode(',', $libraries),
'Strip Binaries' => $builder->getOption('no-strip') ? 'no' : 'yes', 'Strip Binaries' => $builder->getOption('no-strip') ? 'no' : 'yes',
'Enable ZTS' => $builder->getOption('enable-zts') ? 'yes' : 'no', 'Enable ZTS' => $builder->getOption('enable-zts') ? 'yes' : 'no',
]; ];

View File

@ -36,6 +36,7 @@ class DownloadCommand extends BaseCommand
$this->addOption('custom-url', 'U', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Specify custom source download url, e.g "php-src:https://downloads.php.net/~eric/php-8.3.0beta1.tar.gz"'); $this->addOption('custom-url', 'U', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Specify custom source download url, e.g "php-src:https://downloads.php.net/~eric/php-8.3.0beta1.tar.gz"');
$this->addOption('from-zip', 'Z', InputOption::VALUE_REQUIRED, 'Fetch from zip archive'); $this->addOption('from-zip', 'Z', InputOption::VALUE_REQUIRED, 'Fetch from zip archive');
$this->addOption('for-extensions', 'e', InputOption::VALUE_REQUIRED, 'Fetch by extensions, e.g "openssl,mbstring"'); $this->addOption('for-extensions', 'e', InputOption::VALUE_REQUIRED, 'Fetch by extensions, e.g "openssl,mbstring"');
$this->addOption('for-libs', 'l', InputOption::VALUE_REQUIRED, 'Fetch by libraries, e.g "libcares,openssl,onig"');
$this->addOption('without-suggestions', null, null, 'Do not fetch suggested sources when using --for-extensions'); $this->addOption('without-suggestions', null, null, 'Do not fetch suggested sources when using --for-extensions');
} }
@ -46,6 +47,7 @@ class DownloadCommand extends BaseCommand
|| $input->getOption('clean') || $input->getOption('clean')
|| $input->getOption('from-zip') || $input->getOption('from-zip')
|| $input->getOption('for-extensions') || $input->getOption('for-extensions')
|| $input->getOption('for-libs')
) { ) {
$input->setArgument('sources', ''); $input->setArgument('sources', '');
} }
@ -112,6 +114,9 @@ class DownloadCommand extends BaseCommand
$ext = array_map('trim', array_filter(explode(',', $for_ext))); $ext = array_map('trim', array_filter(explode(',', $for_ext)));
$sources = $this->calculateSourcesByExt($ext, !$this->getOption('without-suggestions')); $sources = $this->calculateSourcesByExt($ext, !$this->getOption('without-suggestions'));
array_unshift($sources, 'php-src', 'micro', 'pkg-config'); array_unshift($sources, 'php-src', 'micro', 'pkg-config');
} elseif ($for_lib = $this->getOption('for-libs')) {
$lib = array_map('trim', array_filter(explode(',', $for_lib)));
$sources = $this->calculateSourcesByLib($lib, !$this->getOption('without-suggestions'));
} else { } else {
// get source list that will be downloaded // get source list that will be downloaded
$sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources')))); $sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources'))));
@ -209,6 +214,7 @@ class DownloadCommand extends BaseCommand
* Calculate the sources by extensions * Calculate the sources by extensions
* *
* @param array $extensions extension list * @param array $extensions extension list
* @param bool $include_suggests include suggested libs and extensions (default: true)
* @throws FileSystemException * @throws FileSystemException
* @throws WrongUsageException * @throws WrongUsageException
*/ */
@ -226,4 +232,22 @@ class DownloadCommand extends BaseCommand
} }
return array_values(array_unique($sources)); return array_values(array_unique($sources));
} }
/**
* Calculate the sources by libraries
*
* @param array $libs library list
* @param bool $include_suggests include suggested libs (default: true)
* @throws FileSystemException
* @throws WrongUsageException
*/
private function calculateSourcesByLib(array $libs, bool $include_suggests = true): array
{
$libs = DependencyUtil::getLibs($libs, $include_suggests);
$sources = [];
foreach ($libs as $library) {
$sources[] = Config::getLib($library, 'source');
}
return array_values(array_unique($sources));
}
} }

View File

@ -13,8 +13,8 @@ declare(strict_types=1);
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) { $extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'swoole,swoole-hook-mysql,swoole-hook-pgsql,swoole-hook-sqlite,openssl,curl,pdo_mysql', 'Linux', 'Darwin' => 'zlib,openssl,curl,pcntl,posix,mbstring,tokenizer,phar',
'Windows' => 'mbstring,pdo_sqlite,mbregex,ffi', 'Windows' => 'mbstring,pdo_sqlite,mbregex,ffi,curl',
}; };
// If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`). // If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).
@ -27,7 +27,7 @@ $with_libs = match (PHP_OS_FAMILY) {
// You can use `common`, `bulk`, `minimal` or `none`. // You can use `common`, `bulk`, `minimal` or `none`.
// note: combination is only available for *nix platform. Windows must use `none` combination // note: combination is only available for *nix platform. Windows must use `none` combination
$base_combination = match (PHP_OS_FAMILY) { $base_combination = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'minimal', 'Linux', 'Darwin' => 'none',
'Windows' => 'none', 'Windows' => 'none',
}; };