From bb7e0f6f89f1854019d0e692778df11ae898f690 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 5 Jun 2025 09:44:03 +0700 Subject: [PATCH] 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}" + ); + } +}