From a0579efbc29ebb0a7794be14398fe6100f5bb1e0 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 6 Jun 2025 14:32:28 +0700 Subject: [PATCH 01/10] test --- src/globals/test-extensions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 95362357..4a386212 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -22,13 +22,13 @@ $test_php_version = [ // test os (macos-13, macos-14, macos-15, ubuntu-latest, windows-latest are available) $test_os = [ 'macos-13', - 'macos-14', + // 'macos-14', 'macos-15', 'ubuntu-latest', 'ubuntu-22.04', - 'ubuntu-24.04', + // 'ubuntu-24.04', 'ubuntu-22.04-arm', - 'ubuntu-24.04-arm', + // 'ubuntu-24.04-arm', // 'windows-latest', ]; @@ -57,7 +57,7 @@ $shared_extensions = match (PHP_OS_FAMILY) { // If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`). $with_libs = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => '', + 'Linux', 'Darwin' => 'nghttp2,nghttp3,ngtcp2', 'Windows' => '', }; From df7cfa0d6a871ddb01ac26ae3226c27d07baa067 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 6 Jun 2025 14:33:39 +0700 Subject: [PATCH 02/10] different extension combination fails? --- src/globals/test-extensions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 4a386212..af59c409 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -45,7 +45,7 @@ $prefer_pre_built = false; // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'lz4', + 'Linux', 'Darwin' => 'openssl,curl', 'Windows' => 'xlswriter,openssl', }; From f5fa49338d8db2bcf7c25d493ee207c840bfdab5 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 6 Jun 2025 14:49:09 +0700 Subject: [PATCH 03/10] macos is stupid now? --- src/SPC/builder/unix/library/ngtcp2.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php index 20620499..bb13dd42 100644 --- a/src/SPC/builder/unix/library/ngtcp2.php +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\linux\LinuxBuilder; +use SPC\builder\macos\MacOSBuilder; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; @@ -17,13 +19,21 @@ trait ngtcp2 */ protected function build(): void { - $args = $this->builder->makeAutoconfArgs(static::NAME, [ - 'zlib' => null, + $available = [ 'openssl' => null, - 'libxml2' => null, 'libev' => null, 'jemalloc' => null, - ]); + ]; + if ($this->builder instanceof LinuxBuilder) { + $available = [...$available, ...[ + 'zlib' => null, + 'libxml2' => null, + ]]; + } + $args = $this->builder->makeAutoconfArgs(static::NAME, $available); + if ($this->builder instanceof MacOSBuilder) { + $args = str_replace('=yes', '=' . BUILD_ROOT_PATH, $args); + } shell()->cd($this->source_dir) ->setEnv([ From 9fa1fb7b444c5612d2aa01aa5d1404f6bdf45015 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 6 Jun 2025 14:58:18 +0700 Subject: [PATCH 04/10] fix cs --- src/SPC/builder/unix/library/ngtcp2.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php index bb13dd42..fadf4c28 100644 --- a/src/SPC/builder/unix/library/ngtcp2.php +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -24,14 +24,14 @@ trait ngtcp2 'libev' => null, 'jemalloc' => null, ]; - if ($this->builder instanceof LinuxBuilder) { + if (PHP_OS_FAMILY === 'Linux') { $available = [...$available, ...[ 'zlib' => null, 'libxml2' => null, ]]; } $args = $this->builder->makeAutoconfArgs(static::NAME, $available); - if ($this->builder instanceof MacOSBuilder) { + if (PHP_OS_FAMILY === 'Darwin') { $args = str_replace('=yes', '=' . BUILD_ROOT_PATH, $args); } @@ -53,7 +53,6 @@ trait ngtcp2 ->execWithEnv('make clean') ->execWithEnv("make -j{$this->builder->concurrency}") ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); - $this->patchPkgconfPrefix(['libngtcp2.pc']); - $this->patchPkgconfPrefix(['libngtcp2_crypto_ossl.pc']); + $this->patchPkgconfPrefix(['libngtcp2.pc', 'libngtcp2_crypto_ossl.pc']); } } From a0c05550891ef7c3be9a9af75b3f0386039fc1f7 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 6 Jun 2025 16:00:24 +0700 Subject: [PATCH 05/10] add -lpthread -dl --- src/SPC/builder/unix/library/ngtcp2.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php index fadf4c28..3e92c7d5 100644 --- a/src/SPC/builder/unix/library/ngtcp2.php +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -4,8 +4,6 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\linux\LinuxBuilder; -use SPC\builder\macos\MacOSBuilder; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; @@ -31,8 +29,8 @@ trait ngtcp2 ]]; } $args = $this->builder->makeAutoconfArgs(static::NAME, $available); - if (PHP_OS_FAMILY === 'Darwin') { - $args = str_replace('=yes', '=' . BUILD_ROOT_PATH, $args); + if (PHP_OS_FAMILY === 'Linux') { + $args = preg_replace('/OPENSSL_LIBS="(.*?)"/', 'OPENSSL_LIBS="\1 -lpthread -ldl"', $args); } shell()->cd($this->source_dir) From 560f684f7fb1ec9e16c6405a24331862b0468779 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 6 Jun 2025 16:20:34 +0700 Subject: [PATCH 06/10] remove more unused options --- config/lib.json | 6 +++--- src/SPC/builder/unix/library/nghttp3.php | 8 -------- src/SPC/builder/unix/library/ngtcp2.php | 12 +++--------- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/config/lib.json b/config/lib.json index 78443d0d..582abd2e 100644 --- a/config/lib.json +++ b/config/lib.json @@ -635,9 +635,6 @@ ], "lib-depends": [ "openssl" - ], - "lib-suggests": [ - "ngtcp2" ] }, "ngtcp2": { @@ -655,6 +652,9 @@ ], "lib-depends": [ "openssl" + ], + "lib-suggests": [ + "nghttp3" ] }, "onig": { diff --git a/src/SPC/builder/unix/library/nghttp3.php b/src/SPC/builder/unix/library/nghttp3.php index 6f677869..03d4d481 100644 --- a/src/SPC/builder/unix/library/nghttp3.php +++ b/src/SPC/builder/unix/library/nghttp3.php @@ -6,22 +6,15 @@ namespace SPC\builder\unix\library; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; -use SPC\exception\WrongUsageException; trait nghttp3 { /** * @throws FileSystemException * @throws RuntimeException - * @throws WrongUsageException */ protected function build(): void { - $args = $this->builder->makeAutoconfArgs(static::NAME, [ - 'zlib' => null, - 'openssl' => null, - ]); - shell()->cd($this->source_dir) ->setEnv([ 'CFLAGS' => $this->getLibExtraCFlags(), @@ -34,7 +27,6 @@ trait nghttp3 '--disable-shared ' . '--with-pic ' . '--enable-lib-only ' . - $args . ' ' . '--prefix=' ) ->execWithEnv('make clean') diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php index 3e92c7d5..fef32b75 100644 --- a/src/SPC/builder/unix/library/ngtcp2.php +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -17,18 +17,12 @@ trait ngtcp2 */ protected function build(): void { - $available = [ + $args = $this->builder->makeAutoconfArgs(static::NAME, [ 'openssl' => null, 'libev' => null, 'jemalloc' => null, - ]; - if (PHP_OS_FAMILY === 'Linux') { - $available = [...$available, ...[ - 'zlib' => null, - 'libxml2' => null, - ]]; - } - $args = $this->builder->makeAutoconfArgs(static::NAME, $available); + 'libnghttp3' => null, + ]); if (PHP_OS_FAMILY === 'Linux') { $args = preg_replace('/OPENSSL_LIBS="(.*?)"/', 'OPENSSL_LIBS="\1 -lpthread -ldl"', $args); } From 92ad792eff778382a355904e1a4219b9c5d0505c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 6 Jun 2025 16:24:52 +0700 Subject: [PATCH 07/10] oops --- src/SPC/builder/linux/LinuxBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 66604ecb..9c404dd9 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -81,7 +81,7 @@ class LinuxBuilder extends UnixBuilderBase foreach ($libSpecs as $libName => $arr) { $lib = $this->getLib($libName); if ($lib === null && str_starts_with($libName, 'lib')) { - $lib = $this->getExt(substr($libName, 3)); + $lib = $this->getLib(substr($libName, 3)); } $arr = $arr ?? []; From 617b0de31fe348290f147f949a711f45bfe9bdfa Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 6 Jun 2025 16:56:08 +0700 Subject: [PATCH 08/10] add -lpthread and -ldl in openssl::getStaticLibFiles --- config/lib.json | 3 ++- src/SPC/builder/linux/library/openssl.php | 9 +++++++++ src/SPC/builder/macos/MacOSBuilder.php | 2 +- src/SPC/builder/unix/library/ngtcp2.php | 5 +++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/config/lib.json b/config/lib.json index 582abd2e..0d4941f0 100644 --- a/config/lib.json +++ b/config/lib.json @@ -654,7 +654,8 @@ "openssl" ], "lib-suggests": [ - "nghttp3" + "nghttp3", + "brotli" ] }, "onig": { diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index 5c07ec7e..d57265dd 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -92,4 +92,13 @@ class openssl extends LinuxLibraryBase FileSystem::replaceFileRegex(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', '/Libs.private:.*/m', 'Libs.private: ${libdir}/libz.a'); FileSystem::replaceFileRegex(BUILD_LIB_PATH . '/cmake/OpenSSL/OpenSSLConfig.cmake', '/set\(OPENSSL_LIBCRYPTO_DEPENDENCIES .*\)/m', 'set(OPENSSL_LIBCRYPTO_DEPENDENCIES "${OPENSSL_LIBRARY_DIR}/libz.a")'); } + + public function getStaticLibFiles(string $style = 'autoconf', bool $recursive = true): string + { + $libFiles = parent::getStaticLibFiles($style, $recursive); + if (!str_contains('-ldl -lpthread', $libFiles)) { + $libFiles .= ' -ldl -lpthread'; + } + return $libFiles; + } } diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 36b8583f..d9a0c505 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -56,7 +56,7 @@ class MacOSBuilder extends UnixBuilderBase foreach ($lib_specs as $libName => $arr) { $lib = $this->getLib($libName); if ($lib === null && str_starts_with($libName, 'lib')) { - $lib = $this->getExt(substr($libName, 3)); + $lib = $this->getLib(substr($libName, 3)); } $arr = $arr ?? []; diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php index fef32b75..4393d610 100644 --- a/src/SPC/builder/unix/library/ngtcp2.php +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -23,8 +23,9 @@ trait ngtcp2 'jemalloc' => null, 'libnghttp3' => null, ]); - if (PHP_OS_FAMILY === 'Linux') { - $args = preg_replace('/OPENSSL_LIBS="(.*?)"/', 'OPENSSL_LIBS="\1 -lpthread -ldl"', $args); + if ($brotli = $this->builder->getLib('brotli')) { + $args .= ' --with-libbrotlidec=yes LIBBROTLIDEC_CFLAGS="-I' . BUILD_ROOT_PATH . '/include" LIBBROTLIDEC_LIBS="' . $brotli->getStaticLibFiles() . '"'; + $args .= ' --with-libbrotlienc=yes LIBBROTLIENC_CFLAGS="-I' . BUILD_ROOT_PATH . '/include" LIBBROTLIENC_LIBS="' . $brotli->getStaticLibFiles() . '"'; } shell()->cd($this->source_dir) From 500c19d90067be9819add077bbb05f0fd8268c85 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 6 Jun 2025 16:59:36 +0700 Subject: [PATCH 09/10] phpstan --- src/SPC/builder/unix/library/ngtcp2.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php index 4393d610..654bb8e5 100644 --- a/src/SPC/builder/unix/library/ngtcp2.php +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -24,7 +24,9 @@ trait ngtcp2 'libnghttp3' => null, ]); if ($brotli = $this->builder->getLib('brotli')) { + /* @phpstan-ignore-next-line */ $args .= ' --with-libbrotlidec=yes LIBBROTLIDEC_CFLAGS="-I' . BUILD_ROOT_PATH . '/include" LIBBROTLIDEC_LIBS="' . $brotli->getStaticLibFiles() . '"'; + /* @phpstan-ignore-next-line */ $args .= ' --with-libbrotlienc=yes LIBBROTLIENC_CFLAGS="-I' . BUILD_ROOT_PATH . '/include" LIBBROTLIENC_LIBS="' . $brotli->getStaticLibFiles() . '"'; } From 301f2d8a975b0269451521bfbb3b7e0c5a28905b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 6 Jun 2025 17:02:35 +0700 Subject: [PATCH 10/10] nghttp2 has brotlienc and brotlidec too --- src/SPC/builder/unix/library/nghttp2.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/SPC/builder/unix/library/nghttp2.php b/src/SPC/builder/unix/library/nghttp2.php index dbbb6415..202b2959 100644 --- a/src/SPC/builder/unix/library/nghttp2.php +++ b/src/SPC/builder/unix/library/nghttp2.php @@ -31,6 +31,12 @@ trait nghttp2 'jemalloc' => null, 'systemd' => null, ]); + if ($brotli = $this->builder->getLib('brotli')) { + /* @phpstan-ignore-next-line */ + $args .= ' --with-libbrotlidec=yes LIBBROTLIDEC_CFLAGS="-I' . BUILD_ROOT_PATH . '/include" LIBBROTLIDEC_LIBS="' . $brotli->getStaticLibFiles() . '"'; + /* @phpstan-ignore-next-line */ + $args .= ' --with-libbrotlienc=yes LIBBROTLIENC_CFLAGS="-I' . BUILD_ROOT_PATH . '/include" LIBBROTLIENC_LIBS="' . $brotli->getStaticLibFiles() . '"'; + } [,,$destdir] = SEPARATED_PATH;