From ba0796c9ea778dfc29dbf02c7b383db643643329 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 4 Jun 2025 21:42:44 +0700 Subject: [PATCH 1/6] nghttp3 --- config/lib.json | 19 +++++++ config/source.json | 10 ++++ src/SPC/builder/linux/library/nghttp3.php | 12 +++++ src/SPC/builder/macos/library/nghttp3.php | 29 +++++++++++ src/SPC/builder/unix/library/nghttp3.php | 55 +++++++++++++++++++++ src/SPC/builder/windows/library/nghttp3.php | 39 +++++++++++++++ 6 files changed, 164 insertions(+) create mode 100644 src/SPC/builder/linux/library/nghttp3.php create mode 100644 src/SPC/builder/macos/library/nghttp3.php create mode 100644 src/SPC/builder/unix/library/nghttp3.php create mode 100644 src/SPC/builder/windows/library/nghttp3.php diff --git a/config/lib.json b/config/lib.json index 576f1087..8a9337e2 100644 --- a/config/lib.json +++ b/config/lib.json @@ -618,6 +618,25 @@ "libxml2" ] }, + "nghttp3": { + "source": "nghttp3", + "static-libs-unix": [ + "libnghttp3.a" + ], + "static-libs-windows": [ + "nghttp3.lib" + ], + "headers": [ + "nghttp3" + ], + "lib-depends": [ + "zlib", + "openssl" + ], + "lib-suggests": [ + "libxml2" + ] + }, "onig": { "source": "onig", "static-libs-unix": [ diff --git a/config/source.json b/config/source.json index a4b25cb8..fdcebbe8 100644 --- a/config/source.json +++ b/config/source.json @@ -703,6 +703,16 @@ "path": "COPYING" } }, + "nghttp3": { + "type": "ghrel", + "repo": "ngtcp2/nghttp3", + "match": "nghttp3.+\\.tar\\.xz", + "prefer-stable": true, + "license": { + "type": "file", + "path": "COPYING" + } + }, "onig": { "type": "ghrel", "repo": "kkos/oniguruma", diff --git a/src/SPC/builder/linux/library/nghttp3.php b/src/SPC/builder/linux/library/nghttp3.php new file mode 100644 index 00000000..7e3fc11d --- /dev/null +++ b/src/SPC/builder/linux/library/nghttp3.php @@ -0,0 +1,12 @@ + + * + * lwmbs is licensed under Mulan PSL v2. You can use this + * software according to the terms and conditions of the + * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, + * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +declare(strict_types=1); + +namespace SPC\builder\macos\library; + +class nghttp3 extends MacOSLibraryBase +{ + use \SPC\builder\unix\library\nghttp3; + + public const NAME = 'nghttp3'; +} diff --git a/src/SPC/builder/unix/library/nghttp3.php b/src/SPC/builder/unix/library/nghttp3.php new file mode 100644 index 00000000..c12cdaf5 --- /dev/null +++ b/src/SPC/builder/unix/library/nghttp3.php @@ -0,0 +1,55 @@ +builder->makeAutoconfArgs(static::NAME, [ + 'zlib' => null, + 'openssl' => null, + 'libxml2' => null, + 'libev' => null, + 'libcares' => null, + 'libngtcp2' => null, + 'libbpf' => null, + 'libevent-openssl' => null, + 'jansson' => null, + 'jemalloc' => null, + 'systemd' => null, + 'cunit' => null, + ]); + + shell()->cd($this->source_dir) + ->setEnv([ + 'CFLAGS' => $this->getLibExtraCFlags(), + 'LDFLAGS' => $this->getLibExtraLdFlags(), + 'LIBS' => $this->getLibExtraLibs() + ]) + ->execWithEnv( + './configure ' . + '--enable-static ' . + '--disable-shared ' . + '--enable-lib-only ' . + '--with-boost=no ' . + $args . ' ' . + '--prefix=' + ) + ->execWithEnv('make clean') + ->execWithEnv("make -j{$this->builder->concurrency}") + ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + $this->patchPkgconfPrefix(['libnghttp3.pc']); + } +} diff --git a/src/SPC/builder/windows/library/nghttp3.php b/src/SPC/builder/windows/library/nghttp3.php new file mode 100644 index 00000000..5fa21107 --- /dev/null +++ b/src/SPC/builder/windows/library/nghttp3.php @@ -0,0 +1,39 @@ +source_dir . '\build'); + + // start build + cmd()->cd($this->source_dir) + ->execWithWrapper( + $this->builder->makeSimpleWrapper('cmake'), + '-B build ' . + '-A x64 ' . + "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . + '-DCMAKE_BUILD_TYPE=Release ' . + '-DENABLE_SHARED_LIB=OFF ' . + '-DENABLE_STATIC_LIB=ON ' . + '-DBUILD_STATIC_LIBS=ON ' . + '-DBUILD_SHARED_LIBS=OFF ' . + '-DENABLE_STATIC_CRT=ON ' . + '-DENABLE_LIB_ONLY=ON ' . + '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' + ) + ->execWithWrapper( + $this->builder->makeSimpleWrapper('cmake'), + "--build build --config Release --target install -j{$this->builder->concurrency}" + ); + } +} From 8919a2fcca85c11bc170d583fb77bfea4b79b639 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 4 Jun 2025 21:50:28 +0700 Subject: [PATCH 2/6] goddamn windows --- src/SPC/builder/linux/library/nghttp3.php | 2 +- src/SPC/builder/macos/library/nghttp3.php | 19 +------------------ src/SPC/builder/unix/library/nghttp3.php | 2 +- src/SPC/builder/windows/library/nghttp3.php | 2 +- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/SPC/builder/linux/library/nghttp3.php b/src/SPC/builder/linux/library/nghttp3.php index 7e3fc11d..b26ef647 100644 --- a/src/SPC/builder/linux/library/nghttp3.php +++ b/src/SPC/builder/linux/library/nghttp3.php @@ -1,4 +1,4 @@ - - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ + Date: Thu, 5 Jun 2025 09:44:03 +0700 Subject: [PATCH 3/6] add nghttp3 and ngtcp2 --- config/lib.json | 26 +++++++++-- config/source.json | 10 +++++ src/SPC/builder/linux/LinuxBuilder.php | 3 ++ src/SPC/builder/linux/library/ngtcp2.php | 12 ++++++ src/SPC/builder/macos/MacOSBuilder.php | 3 ++ src/SPC/builder/macos/library/ngtcp2.php | 12 ++++++ src/SPC/builder/unix/library/curl.php | 18 ++++++++ src/SPC/builder/unix/library/nghttp2.php | 3 +- src/SPC/builder/unix/library/nghttp3.php | 12 +----- src/SPC/builder/unix/library/ngtcp2.php | 50 ++++++++++++++++++++++ src/SPC/builder/windows/library/ngtcp2.php | 39 +++++++++++++++++ 11 files changed, 172 insertions(+), 16 deletions(-) create mode 100644 src/SPC/builder/linux/library/ngtcp2.php create mode 100644 src/SPC/builder/macos/library/ngtcp2.php create mode 100644 src/SPC/builder/unix/library/ngtcp2.php create mode 100644 src/SPC/builder/windows/library/ngtcp2.php diff --git a/config/lib.json b/config/lib.json index 8a9337e2..78443d0d 100644 --- a/config/lib.json +++ b/config/lib.json @@ -86,6 +86,8 @@ "libssh2", "brotli", "nghttp2", + "nghttp3", + "ngtcp2", "zstd", "libcares" ], @@ -615,7 +617,9 @@ "openssl" ], "lib-suggests": [ - "libxml2" + "libxml2", + "nghttp3", + "ngtcp2" ] }, "nghttp3": { @@ -630,11 +634,27 @@ "nghttp3" ], "lib-depends": [ - "zlib", "openssl" ], "lib-suggests": [ - "libxml2" + "ngtcp2" + ] + }, + "ngtcp2": { + "source": "ngtcp2", + "static-libs-unix": [ + "libngtcp2.a", + "libngtcp2_crypto_ossl.a" + ], + "static-libs-windows": [ + "ngtcp2.lib", + "ngtcp2_crypto_ossl.lib" + ], + "headers": [ + "ngtcp2" + ], + "lib-depends": [ + "openssl" ] }, "onig": { diff --git a/config/source.json b/config/source.json index fdcebbe8..fcbec33f 100644 --- a/config/source.json +++ b/config/source.json @@ -713,6 +713,16 @@ "path": "COPYING" } }, + "ngtcp2": { + "type": "ghrel", + "repo": "ngtcp2/ngtcp2", + "match": "ngtcp2.+\\.tar\\.xz", + "prefer-stable": true, + "license": { + "type": "file", + "path": "COPYING" + } + }, "onig": { "type": "ghrel", "repo": "kkos/oniguruma", diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index e38714f1..66604ecb 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -80,6 +80,9 @@ class LinuxBuilder extends UnixBuilderBase $ret = ''; foreach ($libSpecs as $libName => $arr) { $lib = $this->getLib($libName); + if ($lib === null && str_starts_with($libName, 'lib')) { + $lib = $this->getExt(substr($libName, 3)); + } $arr = $arr ?? []; diff --git a/src/SPC/builder/linux/library/ngtcp2.php b/src/SPC/builder/linux/library/ngtcp2.php new file mode 100644 index 00000000..1e520b0b --- /dev/null +++ b/src/SPC/builder/linux/library/ngtcp2.php @@ -0,0 +1,12 @@ + $arr) { $lib = $this->getLib($libName); + if ($lib === null && str_starts_with($libName, 'lib')) { + $lib = $this->getExt(substr($libName, 3)); + } $arr = $arr ?? []; diff --git a/src/SPC/builder/macos/library/ngtcp2.php b/src/SPC/builder/macos/library/ngtcp2.php new file mode 100644 index 00000000..290e36ee --- /dev/null +++ b/src/SPC/builder/macos/library/ngtcp2.php @@ -0,0 +1,12 @@ +builder->getLib('nghttp3')) { + $extra .= '-DUSE_NGHTTP3=ON ' . + /* @phpstan-ignore-next-line */ + '-DNGHTTP3_LIBRARY="' . $nghttp3->getStaticLibFiles(style: 'cmake') . '" ' . + '-DNGHTTP3_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; + } else { + $extra .= '-DUSE_NGHTTP3=OFF '; + } + // lib:ngtcp2 + if ($ngtcp2 = $this->builder->getLib('ngtcp2')) { + $extra .= '-DUSE_NGTCP2=ON ' + /* @phpstan-ignore-next-line */. + '-DNGTCP2_LIBRARY="' . $ngtcp2->getStaticLibFiles(style: 'cmake') . '" ' . + '-DNGTCP2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; + } else { + $extra .= '-DUSE_NGTCP2=OFF '; + } // lib:ldap $extra .= $this->builder->getLib('ldap') ? '-DCURL_DISABLE_LDAP=OFF ' : '-DCURL_DISABLE_LDAP=ON '; // lib:zstd diff --git a/src/SPC/builder/unix/library/nghttp2.php b/src/SPC/builder/unix/library/nghttp2.php index 8f764c2a..dbbb6415 100644 --- a/src/SPC/builder/unix/library/nghttp2.php +++ b/src/SPC/builder/unix/library/nghttp2.php @@ -30,7 +30,6 @@ trait nghttp2 'jansson' => null, 'jemalloc' => null, 'systemd' => null, - 'cunit' => null, ]); [,,$destdir] = SEPARATED_PATH; @@ -41,8 +40,8 @@ trait nghttp2 './configure ' . '--enable-static ' . '--disable-shared ' . + '--with-pic ' . '--enable-lib-only ' . - '--with-boost=no ' . $args . ' ' . '--prefix=' ) diff --git a/src/SPC/builder/unix/library/nghttp3.php b/src/SPC/builder/unix/library/nghttp3.php index 08d0b419..49a46a67 100644 --- a/src/SPC/builder/unix/library/nghttp3.php +++ b/src/SPC/builder/unix/library/nghttp3.php @@ -20,16 +20,6 @@ trait nghttp3 $args = $this->builder->makeAutoconfArgs(static::NAME, [ 'zlib' => null, 'openssl' => null, - 'libxml2' => null, - 'libev' => null, - 'libcares' => null, - 'libngtcp2' => null, - 'libbpf' => null, - 'libevent-openssl' => null, - 'jansson' => null, - 'jemalloc' => null, - 'systemd' => null, - 'cunit' => null, ]); shell()->cd($this->source_dir) @@ -42,8 +32,8 @@ trait nghttp3 './configure ' . '--enable-static ' . '--disable-shared ' . + '--with-pic ' . '--enable-lib-only ' . - '--with-boost=no ' . $args . ' ' . '--prefix=' ) diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php new file mode 100644 index 00000000..bcf9e9f7 --- /dev/null +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -0,0 +1,50 @@ +builder->makeAutoconfArgs(static::NAME, [ + 'zlib' => null, + 'openssl' => null, + 'libxml2' => null, + 'libev' => null, + 'jemalloc' => null, + ]); + + shell()->cd($this->source_dir) + ->setEnv([ + 'CFLAGS' => $this->getLibExtraCFlags(), + 'LDFLAGS' => $this->getLibExtraLdFlags(), + 'LIBS' => $this->getLibExtraLibs() + ]) + ->execWithEnv( + './configure ' . + '--enable-static ' . + '--disable-shared ' . + '--with-pic ' . + '--enable-lib-only ' . + $args . ' ' . + '--prefix=' + ) + ->execWithEnv('make clean') + ->execWithEnv("make -j{$this->builder->concurrency}") + ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + $this->patchPkgconfPrefix(['libngtcp2.pc']); + } +} diff --git a/src/SPC/builder/windows/library/ngtcp2.php b/src/SPC/builder/windows/library/ngtcp2.php new file mode 100644 index 00000000..d0f557b7 --- /dev/null +++ b/src/SPC/builder/windows/library/ngtcp2.php @@ -0,0 +1,39 @@ +source_dir . '\build'); + + // start build + cmd()->cd($this->source_dir) + ->execWithWrapper( + $this->builder->makeSimpleWrapper('cmake'), + '-B build ' . + '-A x64 ' . + "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . + '-DCMAKE_BUILD_TYPE=Release ' . + '-DENABLE_SHARED_LIB=OFF ' . + '-DENABLE_STATIC_LIB=ON ' . + '-DBUILD_STATIC_LIBS=ON ' . + '-DBUILD_SHARED_LIBS=OFF ' . + '-DENABLE_STATIC_CRT=ON ' . + '-DENABLE_LIB_ONLY=ON ' . + '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' + ) + ->execWithWrapper( + $this->builder->makeSimpleWrapper('cmake'), + "--build build --config Release --target install -j{$this->builder->concurrency}" + ); + } +} From 499c281931202c5ca9f8f0071b01db649921a26f Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 5 Jun 2025 09:50:14 +0700 Subject: [PATCH 4/6] cs fix --- src/SPC/builder/unix/library/curl.php | 4 ++-- src/SPC/builder/unix/library/nghttp3.php | 2 +- src/SPC/builder/unix/library/ngtcp2.php | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/SPC/builder/unix/library/curl.php b/src/SPC/builder/unix/library/curl.php index f1e802ae..23b1c80a 100644 --- a/src/SPC/builder/unix/library/curl.php +++ b/src/SPC/builder/unix/library/curl.php @@ -58,8 +58,8 @@ trait curl } // lib:ngtcp2 if ($ngtcp2 = $this->builder->getLib('ngtcp2')) { - $extra .= '-DUSE_NGTCP2=ON ' - /* @phpstan-ignore-next-line */. + $extra .= '-DUSE_NGTCP2=ON ' . + /* @phpstan-ignore-next-line */ '-DNGTCP2_LIBRARY="' . $ngtcp2->getStaticLibFiles(style: 'cmake') . '" ' . '-DNGTCP2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; } else { diff --git a/src/SPC/builder/unix/library/nghttp3.php b/src/SPC/builder/unix/library/nghttp3.php index 49a46a67..6f677869 100644 --- a/src/SPC/builder/unix/library/nghttp3.php +++ b/src/SPC/builder/unix/library/nghttp3.php @@ -26,7 +26,7 @@ trait nghttp3 ->setEnv([ 'CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), - 'LIBS' => $this->getLibExtraLibs() + 'LIBS' => $this->getLibExtraLibs(), ]) ->execWithEnv( './configure ' . diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php index bcf9e9f7..0c75bba4 100644 --- a/src/SPC/builder/unix/library/ngtcp2.php +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -4,11 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\LibraryBase; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; -use SPC\store\FileSystem; trait ngtcp2 { @@ -31,7 +29,7 @@ trait ngtcp2 ->setEnv([ 'CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), - 'LIBS' => $this->getLibExtraLibs() + 'LIBS' => $this->getLibExtraLibs(), ]) ->execWithEnv( './configure ' . From 8993b3f4f02e5be352d59af3fa9e3892ba29b1c4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 5 Jun 2025 10:06:20 +0700 Subject: [PATCH 5/6] add pkgconf prefix patch for ngtcp2 crypto library --- src/SPC/builder/unix/library/ngtcp2.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php index 0c75bba4..20620499 100644 --- a/src/SPC/builder/unix/library/ngtcp2.php +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -44,5 +44,6 @@ trait ngtcp2 ->execWithEnv("make -j{$this->builder->concurrency}") ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libngtcp2.pc']); + $this->patchPkgconfPrefix(['libngtcp2_crypto_ossl.pc']); } } From 8e5efb923f55d611b15b209bcbdc6f5b00156860 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 5 Jun 2025 10:27:18 +0700 Subject: [PATCH 6/6] update docs --- docs/en/guide/extension-notes.md | 4 +++- docs/zh/guide/extension-notes.md | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/en/guide/extension-notes.md b/docs/en/guide/extension-notes.md index 83c0b787..dc0f1d7a 100644 --- a/docs/en/guide/extension-notes.md +++ b/docs/en/guide/extension-notes.md @@ -6,6 +6,8 @@ which will be listed one by one here. ## curl +HTTP3 support is not enabled by default, compile with `--with-libs="nghttp2,nghttp3,ngtcp2"` to enable HTTP3 support for PHP >= 8.4. + When using curl to request HTTPS, there may be an `error:80000002:system library::No such file or directory` error. For details on the solution, see [FAQ - Unable to use ssl](../faq/#unable-to-use-ssl). @@ -156,4 +158,4 @@ Parallel is only supported on PHP 8.0 ZTS and above. 1. This is not technically an extension, but a library. 2. Building with `--with-libs="mimalloc"` on Linux or macOS will override the default allocator. -3. This is experimental for now, but is recommended in threaded environments. \ No newline at end of file +3. This is experimental for now, but is recommended in threaded environments. diff --git a/docs/zh/guide/extension-notes.md b/docs/zh/guide/extension-notes.md index 762d2df9..c7b3a8d1 100644 --- a/docs/zh/guide/extension-notes.md +++ b/docs/zh/guide/extension-notes.md @@ -4,6 +4,8 @@ ## curl +HTTP3 支持默认未启用,需在编译时添加 `--with-libs="nghttp2,nghttp3,ngtcp2"` 以启用 PHP 8.4 及以上版本的 HTTP3 支持。 + 使用 curl 请求 HTTPS 时,可能存在 `error:80000002:system library::No such file or directory` 错误, 解决办法详见 [FAQ - 无法使用 ssl](../faq/#无法使用-ssl)。