From 9a98fd9cff3334740e20c14c0a37458156eb2df3 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 22 Jun 2025 15:52:01 +0700 Subject: [PATCH 001/278] patch things for zig compatibility --- src/SPC/builder/Extension.php | 4 ++-- src/SPC/builder/unix/library/ldap.php | 3 +++ src/SPC/builder/unix/library/liblz4.php | 3 ++- src/SPC/builder/unix/library/pkgconfig.php | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 3f63c84b8..6bb877821 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -387,8 +387,8 @@ public function buildUnixShared(): void // macOS ld64 doesn't understand these, while Linux and BSD do // use them to make sure that all symbols are picked up, even if a library has already been visited before - $preStatic = PHP_OS_FAMILY !== 'Darwin' ? '-Wl,-Bstatic -Wl,--start-group ' : ''; - $postStatic = PHP_OS_FAMILY !== 'Darwin' ? ' -Wl,--end-group -Wl,-Bdynamic ' : ' '; + $preStatic = PHP_OS_FAMILY !== 'Darwin' ? '-Wl,--start-group ' : ''; + $postStatic = PHP_OS_FAMILY !== 'Darwin' ? ' -Wl,--end-group ' : ' '; $env = [ 'CFLAGS' => $config['cflags'], 'CXXFLAGS' => $config['cflags'], diff --git a/src/SPC/builder/unix/library/ldap.php b/src/SPC/builder/unix/library/ldap.php index 62f7bcd75..6c5eeae5d 100644 --- a/src/SPC/builder/unix/library/ldap.php +++ b/src/SPC/builder/unix/library/ldap.php @@ -26,8 +26,11 @@ protected function build(): void '--disable-slapd', '--without-systemd', '--without-cyrus-sasl', + '--without-cyrus-sasl', + 'ac_cv_func_pthread_kill_other_threads_np=no' ) ->appendEnv([ + 'CFLAGS' => '-Wno-date-time', 'LDFLAGS' => "-L{$this->getLibDir()}", 'CPPFLAGS' => "-I{$this->getIncludeDir()}", ]) diff --git a/src/SPC/builder/unix/library/liblz4.php b/src/SPC/builder/unix/library/liblz4.php index 73108d953..b5970f747 100644 --- a/src/SPC/builder/unix/library/liblz4.php +++ b/src/SPC/builder/unix/library/liblz4.php @@ -19,7 +19,8 @@ protected function build(): void { shell()->cd($this->source_dir)->initializeEnv($this) ->exec("make PREFIX='' clean") - ->exec("make -j{$this->builder->concurrency} PREFIX=''") + ->exec("make lib -j{$this->builder->concurrency} PREFIX=''") + ->exec("sed -i 's/^\\$(MAKE) -C \\$(PRGDIR) \\$@/#\\$(MAKE) -C \\$(PRGDIR) \\$@/' Makefile") ->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['liblz4.pc']); diff --git a/src/SPC/builder/unix/library/pkgconfig.php b/src/SPC/builder/unix/library/pkgconfig.php index 05727f96a..462e73448 100644 --- a/src/SPC/builder/unix/library/pkgconfig.php +++ b/src/SPC/builder/unix/library/pkgconfig.php @@ -13,7 +13,7 @@ protected function build(): void { UnixAutoconfExecutor::create($this) ->appendEnv([ - 'CFLAGS' => PHP_OS_FAMILY !== 'Linux' ? '-Wimplicit-function-declaration -Wno-int-conversion' : '', + 'CFLAGS' => '-Wimplicit-function-declaration -Wno-int-conversion', 'LDFLAGS' => !($this instanceof LinuxLibraryBase) || getenv('SPC_LIBC') === 'glibc' ? '' : '--static', ]) ->configure( From 7e35de8a0e3e3553c4841d3211e6d7f7c5ffb8f0 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 22 Jun 2025 16:19:01 +0700 Subject: [PATCH 002/278] CXX for watcher-c --- src/SPC/builder/unix/library/watcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/watcher.php b/src/SPC/builder/unix/library/watcher.php index 2463cc4f8..19f881b79 100644 --- a/src/SPC/builder/unix/library/watcher.php +++ b/src/SPC/builder/unix/library/watcher.php @@ -18,7 +18,7 @@ protected function build(): void { shell()->cd($this->source_dir . '/watcher-c') ->initializeEnv($this) - ->exec(getenv('CC') . ' -c -o libwatcher-c.o ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -Wall -Wextra -fPIC') + ->exec(getenv('CXX') . ' -c -o libwatcher-c.o ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -Wall -Wextra -fPIC') ->exec(getenv('AR') . ' rcs libwatcher-c.a libwatcher-c.o'); copy($this->source_dir . '/watcher-c/libwatcher-c.a', BUILD_LIB_PATH . '/libwatcher-c.a'); From 2cce02bfa99a0af36388126aa879b179115a9434 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 22 Jun 2025 17:01:08 +0700 Subject: [PATCH 003/278] liblz4 replacement --- config/env.ini | 7 ++++--- src/SPC/builder/unix/library/liblz4.php | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/config/env.ini b/config/env.ini index d80bc3e7c..1d3931e88 100644 --- a/config/env.ini +++ b/config/env.ini @@ -70,9 +70,10 @@ CC=${SPC_LINUX_DEFAULT_CC} CXX=${SPC_LINUX_DEFAULT_CXX} AR=${SPC_LINUX_DEFAULT_AR} LD=${SPC_LINUX_DEFAULT_LD} +DISABLED_WARNINGS="-Wno-error -Wno-date-time -Wno-int-conversion -Wno-implicit-function-declaration" ; default compiler flags, used in CMake toolchain file, openssl and pkg-config build -SPC_DEFAULT_C_FLAGS="-fPIC -Os" -SPC_DEFAULT_CXX_FLAGS="-fPIC -Os" +SPC_DEFAULT_C_FLAGS="-fPIC -Os -Wno-error -Wno-date-time -Wno-int-conversion -Wno-implicit-function-declaration" +SPC_DEFAULT_CXX_FLAGS="-fPIC -Os -Wno-error -Wno-date-time -Wno-int-conversion -Wno-implicit-function-declaration" ; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated) SPC_EXTRA_LIBS= ; upx executable path @@ -100,7 +101,7 @@ SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" ; LIBS for configuring php SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lpthread -lm" ; EXTRA_CFLAGS for `make` php -SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}" +SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS} -Wno-error -Wno-date-time -Wno-int-conversion -Wno-implicit-function-declaration" ; EXTRA_LIBS for `make` php SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm" ; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so diff --git a/src/SPC/builder/unix/library/liblz4.php b/src/SPC/builder/unix/library/liblz4.php index b5970f747..757cc4beb 100644 --- a/src/SPC/builder/unix/library/liblz4.php +++ b/src/SPC/builder/unix/library/liblz4.php @@ -19,8 +19,11 @@ protected function build(): void { shell()->cd($this->source_dir)->initializeEnv($this) ->exec("make PREFIX='' clean") - ->exec("make lib -j{$this->builder->concurrency} PREFIX=''") - ->exec("sed -i 's/^\\$(MAKE) -C \\$(PRGDIR) \\$@/#\\$(MAKE) -C \\$(PRGDIR) \\$@/' Makefile") + ->exec("make lib -j{$this->builder->concurrency} PREFIX=''"); + + FileSystem::replaceFileStr($this->source_dir . '/Makefile', '$(MAKE) -C \$(PRGDIR)', ''); + + shell()->cd($this->source_dir) ->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['liblz4.pc']); From 15fbde29d444c925852d7f6a829e675c7acd1727 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 22 Jun 2025 17:02:16 +0700 Subject: [PATCH 004/278] remove duplicate --- src/SPC/builder/unix/library/ldap.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SPC/builder/unix/library/ldap.php b/src/SPC/builder/unix/library/ldap.php index 6c5eeae5d..d19b2e893 100644 --- a/src/SPC/builder/unix/library/ldap.php +++ b/src/SPC/builder/unix/library/ldap.php @@ -26,7 +26,6 @@ protected function build(): void '--disable-slapd', '--without-systemd', '--without-cyrus-sasl', - '--without-cyrus-sasl', 'ac_cv_func_pthread_kill_other_threads_np=no' ) ->appendEnv([ From 32a1fd45dfe9df4866a1dd765fc786ccd643c04b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 22 Jun 2025 17:21:28 +0700 Subject: [PATCH 005/278] don't disable warnings --- config/env.ini | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/config/env.ini b/config/env.ini index 1d3931e88..d80bc3e7c 100644 --- a/config/env.ini +++ b/config/env.ini @@ -70,10 +70,9 @@ CC=${SPC_LINUX_DEFAULT_CC} CXX=${SPC_LINUX_DEFAULT_CXX} AR=${SPC_LINUX_DEFAULT_AR} LD=${SPC_LINUX_DEFAULT_LD} -DISABLED_WARNINGS="-Wno-error -Wno-date-time -Wno-int-conversion -Wno-implicit-function-declaration" ; default compiler flags, used in CMake toolchain file, openssl and pkg-config build -SPC_DEFAULT_C_FLAGS="-fPIC -Os -Wno-error -Wno-date-time -Wno-int-conversion -Wno-implicit-function-declaration" -SPC_DEFAULT_CXX_FLAGS="-fPIC -Os -Wno-error -Wno-date-time -Wno-int-conversion -Wno-implicit-function-declaration" +SPC_DEFAULT_C_FLAGS="-fPIC -Os" +SPC_DEFAULT_CXX_FLAGS="-fPIC -Os" ; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated) SPC_EXTRA_LIBS= ; upx executable path @@ -101,7 +100,7 @@ SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" ; LIBS for configuring php SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lpthread -lm" ; EXTRA_CFLAGS for `make` php -SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS} -Wno-error -Wno-date-time -Wno-int-conversion -Wno-implicit-function-declaration" +SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}" ; EXTRA_LIBS for `make` php SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm" ; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so From 955b5869087d7ae68a7854d8021b606e1aa4a7ee Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 22 Jun 2025 19:51:55 +0700 Subject: [PATCH 006/278] fix lz4 --- src/SPC/builder/unix/library/liblz4.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/liblz4.php b/src/SPC/builder/unix/library/liblz4.php index 757cc4beb..2dc2b46fc 100644 --- a/src/SPC/builder/unix/library/liblz4.php +++ b/src/SPC/builder/unix/library/liblz4.php @@ -21,7 +21,7 @@ protected function build(): void ->exec("make PREFIX='' clean") ->exec("make lib -j{$this->builder->concurrency} PREFIX=''"); - FileSystem::replaceFileStr($this->source_dir . '/Makefile', '$(MAKE) -C \$(PRGDIR)', ''); + FileSystem::replaceFileStr($this->source_dir . '/Makefile', '$(MAKE) -C $(PRGDIR) $@', ''); shell()->cd($this->source_dir) ->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); From 7628847a461461f0154f82cf678227398056a513 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 23 Jun 2025 12:57:00 +0700 Subject: [PATCH 007/278] suboptimal solutions, but a bit closer to building --- config/env.ini | 2 +- src/SPC/builder/extension/amqp.php | 2 +- src/SPC/builder/extension/imagick.php | 2 +- src/SPC/builder/unix/UnixBuilderBase.php | 2 +- src/SPC/builder/unix/library/librdkafka.php | 2 ++ src/SPC/util/SPCConfigUtil.php | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/config/env.ini b/config/env.ini index d80bc3e7c..cebc39d8c 100644 --- a/config/env.ini +++ b/config/env.ini @@ -71,7 +71,7 @@ CXX=${SPC_LINUX_DEFAULT_CXX} AR=${SPC_LINUX_DEFAULT_AR} LD=${SPC_LINUX_DEFAULT_LD} ; default compiler flags, used in CMake toolchain file, openssl and pkg-config build -SPC_DEFAULT_C_FLAGS="-fPIC -Os" +SPC_DEFAULT_C_FLAGS="-fPIC -Os -Wno-error=date-time" SPC_DEFAULT_CXX_FLAGS="-fPIC -Os" ; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated) SPC_EXTRA_LIBS= diff --git a/src/SPC/builder/extension/amqp.php b/src/SPC/builder/extension/amqp.php index 7e0ea2dec..3a9d2ae2f 100644 --- a/src/SPC/builder/extension/amqp.php +++ b/src/SPC/builder/extension/amqp.php @@ -25,7 +25,7 @@ public function patchBeforeMake(): bool public function getUnixConfigureArg(bool $shared = false): string { - return '--with-amqp' . ($shared ? '=shared' : '') . ' --with-librabbitmq-dir=' . BUILD_ROOT_PATH; + return '--with-amqp' . ($sh PKG_ROOT_PATH . '/go', 'CGO_ENABLED' => '1', 'CGO_CFLAGS' => $config['cflags'], - 'CGO_LDFLAGS' => "{$config['ldflags']} {$config['libs']} {$lrt}", + 'CGO_LDFLAGS' => "{$config['ldflags']} {$config['libs']} {$lrt} -L/usr/lib64", 'XCADDY_GO_BUILD_FLAGS' => '-buildmode=pie ' . '-ldflags \"-linkmode=external ' . $extLdFlags . ' ' . $debugFlags . '-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' . diff --git a/src/SPC/builder/unix/library/librdkafka.php b/src/SPC/builder/unix/library/librdkafka.php index 32f389e15..9ba10e057 100644 --- a/src/SPC/builder/unix/library/librdkafka.php +++ b/src/SPC/builder/unix/library/librdkafka.php @@ -6,6 +6,7 @@ use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\store\FileSystem; use SPC\util\executor\UnixAutoconfExecutor; trait librdkafka @@ -16,6 +17,7 @@ trait librdkafka */ protected function build(): void { + FileSystem::replaceFileStr($this->source_dir . '/lds-gen.py', "funcs.append('rd_ut_coverage_check')", ''); UnixAutoconfExecutor::create($this) ->optionalLib( 'zstd', diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index 8e69e89ce..ee13c4e9e 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -147,7 +147,7 @@ private function getLibsString(array $libraries, bool $withDependencies = false) } // patch: imagick (imagemagick wrapper) for linux needs libgomp if (in_array('imagemagick', $libraries) && PHP_OS_FAMILY === 'Linux' && !(getenv('SPC_LIBC') === 'glibc' && str_contains(getenv('CC'), 'devtoolset-10'))) { - $short_name[] = '-lgomp'; + $short_name[] = '-lomp'; } return implode(' ', $short_name); } From 864c55feafc6ff44671b1d84296ec06e10faf4bd Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 23 Jun 2025 13:12:40 +0700 Subject: [PATCH 008/278] oops --- src/SPC/builder/extension/amqp.php | 2 +- src/SPC/builder/extension/imagick.php | 2 +- src/SPC/builder/unix/UnixBuilderBase.php | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/extension/amqp.php b/src/SPC/builder/extension/amqp.php index 3a9d2ae2f..7e0ea2dec 100644 --- a/src/SPC/builder/extension/amqp.php +++ b/src/SPC/builder/extension/amqp.php @@ -25,7 +25,7 @@ public function patchBeforeMake(): bool public function getUnixConfigureArg(bool $shared = false): string { - return '--with-amqp' . ($shgetPHPVersion(); if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { From f9af24e24624e807995f784cae09231e9f37f940 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 23 Jun 2025 13:23:13 +0700 Subject: [PATCH 009/278] dont fail on -lomp --- src/SPC/builder/extension/imagick.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 6255e3fb1..74a63ebc3 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -19,7 +19,7 @@ public function patchBeforeMake(): bool return false; } // imagick with calls omp_pause_all, which requires openmp, on non-musl we build imagick without openmp - $extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -L/usr/lib64 -lomp'); + $extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -lomp'); f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); return true; } @@ -38,6 +38,9 @@ protected function getStaticAndSharedLibs(): array $static .= ' -lstdc++'; $shared = str_replace('-lstdc++', '', $shared); } + if (str_contains(getenv('CC'), 'zig')) { + $shared = str_replace('-lomp', '/usr/lib64/libomp.so', $shared); + } return [$static, $shared]; } } From bd863dba34ff4855b31010de75c0213add782994 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 23 Jun 2025 15:26:39 +0700 Subject: [PATCH 010/278] zig is clang --- src/SPC/builder/linux/LinuxBuilder.php | 44 ++++++++++++++------------ src/SPC/builder/linux/SystemUtil.php | 1 + 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 722601d18..cd581a954 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -292,27 +292,31 @@ protected function buildEmbed(): void if (preg_match('/-release\s+(\S+)/', $ldflags, $matches)) { $release = $matches[1]; $realLibName = 'libphp-' . $release . '.so'; - $realLib = BUILD_LIB_PATH . '/' . $realLibName; - rename(BUILD_LIB_PATH . '/libphp.so', $realLib); $cwd = getcwd(); - chdir(BUILD_LIB_PATH); - symlink($realLibName, 'libphp.so'); - chdir(BUILD_MODULES_PATH); - foreach ($this->getExts() as $ext) { - if (!$ext->isBuildShared()) { - continue; - } - $name = $ext->getName(); - $versioned = "{$name}-{$release}.so"; - $unversioned = "{$name}.so"; - if (is_file(BUILD_MODULES_PATH . "/{$versioned}")) { - rename(BUILD_MODULES_PATH . "/{$versioned}", BUILD_MODULES_PATH . "/{$unversioned}"); - shell()->cd(BUILD_MODULES_PATH) - ->exec(sprintf( - 'patchelf --set-soname %s %s', - escapeshellarg($unversioned), - escapeshellarg($unversioned) - )); + if (file_exists($realLibName)) { + $realLib = BUILD_LIB_PATH . '/' . $realLibName; + rename(BUILD_LIB_PATH . '/libphp.so', $realLib); + chdir(BUILD_LIB_PATH); + symlink($realLibName, 'libphp.so'); + } + if (is_dir(BUILD_MODULES_PATH)) { + chdir(BUILD_MODULES_PATH); + foreach ($this->getExts() as $ext) { + if (!$ext->isBuildShared()) { + continue; + } + $name = $ext->getName(); + $versioned = "{$name}-{$release}.so"; + $unversioned = "{$name}.so"; + if (is_file(BUILD_MODULES_PATH . "/{$versioned}")) { + rename(BUILD_MODULES_PATH . "/{$versioned}", BUILD_MODULES_PATH . "/{$unversioned}"); + shell()->cd(BUILD_MODULES_PATH) + ->exec(sprintf( + 'patchelf --set-soname %s %s', + escapeshellarg($unversioned), + escapeshellarg($unversioned) + )); + } } } chdir($cwd); diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index a85f3dec6..852ff657a 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -81,6 +81,7 @@ public static function getCpuCount(): int public static function getCCType(string $cc): string { return match (true) { + str_contains($cc, 'zig') => 'clang', str_ends_with($cc, 'c++'), str_ends_with($cc, 'cc'), str_ends_with($cc, 'g++'), str_ends_with($cc, 'gcc') => 'gcc', $cc === 'clang++', $cc === 'clang', str_starts_with($cc, 'musl-clang') => 'clang', default => throw new RuntimeException("unknown cc type: {$cc}"), From ee0de6933f10dd8067d3d879946cd619cedc8ed0 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 23 Jun 2025 19:21:51 +0700 Subject: [PATCH 011/278] deprecated linker option --- config/env.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/env.ini b/config/env.ini index cebc39d8c..d771ee978 100644 --- a/config/env.ini +++ b/config/env.ini @@ -106,7 +106,7 @@ SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm" ; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS="" ; EXTRA_LDFLAGS_PROGRAM for `make` php -SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-all-static -Wl,-O1 -pie" +SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-all-static -pie" [macos] ; compiler environments From 74849a8d48166043aa55adf07487592dc8bf0183 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 24 Jun 2025 09:05:44 +0700 Subject: [PATCH 012/278] -fno-sanitize=undefined is enabled in zig by default, not in gcc and clang --- config/env.ini | 6 +++--- src/SPC/builder/extension/opcache.php | 11 +++++++++++ src/SPC/builder/linux/LinuxBuilder.php | 7 +++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/config/env.ini b/config/env.ini index d771ee978..5c093fc7d 100644 --- a/config/env.ini +++ b/config/env.ini @@ -71,7 +71,7 @@ CXX=${SPC_LINUX_DEFAULT_CXX} AR=${SPC_LINUX_DEFAULT_AR} LD=${SPC_LINUX_DEFAULT_LD} ; default compiler flags, used in CMake toolchain file, openssl and pkg-config build -SPC_DEFAULT_C_FLAGS="-fPIC -Os -Wno-error=date-time" +SPC_DEFAULT_C_FLAGS="-fPIC -Os -Wno-error=date-time -fno-sanitize=undefined" SPC_DEFAULT_CXX_FLAGS="-fPIC -Os" ; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated) SPC_EXTRA_LIBS= @@ -98,11 +98,11 @@ SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}" ; LDFLAGS for configuring php SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" ; LIBS for configuring php -SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lpthread -lm" +SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil" ; EXTRA_CFLAGS for `make` php SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}" ; EXTRA_LIBS for `make` php -SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm" +SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil" ; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS="" ; EXTRA_LDFLAGS_PROGRAM for `make` php diff --git a/src/SPC/builder/extension/opcache.php b/src/SPC/builder/extension/opcache.php index 5d9dda0ad..34673a9d2 100644 --- a/src/SPC/builder/extension/opcache.php +++ b/src/SPC/builder/extension/opcache.php @@ -51,4 +51,15 @@ public function getDistName(): string { return 'Zend Opcache'; } + + public function patchBeforeMake(): bool + { + if (!str_contains(getenv('CC'), 'zig')) { + return false; + } + // opcache requires -lunwind, the equivalent to -lgcc_s that gcc automatically links + $extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -lunwind'); + f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); + return true; + } } diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index cd581a954..29eb92e61 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -103,6 +103,10 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $zts = ''; } $disable_jit = $this->getOption('disable-opcache-jit', false) ? '--disable-opcache-jit ' : ''; + $cc = trim(getenv('CC')); + if (!$disable_jit && $this->getExt('opcache') && str_contains($cc, 'zig')) { + f_putenv("CC=$cc -fno-sanitize=undefined"); + } $config_file_path = $this->getOption('with-config-file-path', false) ? ('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : ''; @@ -175,6 +179,9 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void } $this->buildEmbed(); } + if (!$disable_jit && $this->getExt('opcache') && str_contains($cc, 'zig')) { + f_putenv("CC=$cc"); + } if ($enableFrankenphp) { logger()->info('building frankenphp'); $this->buildFrankenphp(); From 1b0b551fc633b97dcb950195c149c94f6d8e9c3a Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 24 Jun 2025 12:10:01 +0700 Subject: [PATCH 013/278] handle case where libphp.so is built instead of libphp-release.so --- src/SPC/builder/linux/LinuxBuilder.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 29eb92e61..eb49f579f 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -105,7 +105,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $disable_jit = $this->getOption('disable-opcache-jit', false) ? '--disable-opcache-jit ' : ''; $cc = trim(getenv('CC')); if (!$disable_jit && $this->getExt('opcache') && str_contains($cc, 'zig')) { - f_putenv("CC=$cc -fno-sanitize=undefined"); + f_putenv("CC={$cc} -fno-sanitize=undefined"); } $config_file_path = $this->getOption('with-config-file-path', false) ? @@ -180,7 +180,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $this->buildEmbed(); } if (!$disable_jit && $this->getExt('opcache') && str_contains($cc, 'zig')) { - f_putenv("CC=$cc"); + f_putenv("CC={$cc}"); } if ($enableFrankenphp) { logger()->info('building frankenphp'); @@ -300,9 +300,13 @@ protected function buildEmbed(): void $release = $matches[1]; $realLibName = 'libphp-' . $release . '.so'; $cwd = getcwd(); - if (file_exists($realLibName)) { - $realLib = BUILD_LIB_PATH . '/' . $realLibName; - rename(BUILD_LIB_PATH . '/libphp.so', $realLib); + $libphpPath = BUILD_LIB_PATH . '/libphp.so'; + $libphpRelease = BUILD_LIB_PATH . '/' . $realLibName; + if (!file_exists($libphpRelease) && file_exists($libphpPath)) { + rename($libphpPath, $libphpRelease); + } + if (file_exists($libphpRelease)) { + rename(BUILD_LIB_PATH . '/libphp.so', $libphpRelease); chdir(BUILD_LIB_PATH); symlink($realLibName, 'libphp.so'); } From 24337522733541e48f11a9ac9d4f06ac1706c54b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 24 Jun 2025 13:17:43 +0700 Subject: [PATCH 014/278] needless default --- src/SPC/builder/unix/library/gettext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/gettext.php b/src/SPC/builder/unix/library/gettext.php index 257fa3051..f0fdae547 100644 --- a/src/SPC/builder/unix/library/gettext.php +++ b/src/SPC/builder/unix/library/gettext.php @@ -31,7 +31,7 @@ protected function build(): void $autoconf->addConfigureArgs('--disable-threads'); } - $autoconf->configure()->make(with_clean: true); + $autoconf->configure()->make(); $this->patchLaDependencyPrefix(); } } From e1028b0348cd21e1446a59d059f78c089b119f99 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 24 Jun 2025 20:43:38 +0700 Subject: [PATCH 015/278] swoole has date time conversion error in c++ code, clang needs -lunwind --- config/env.ini | 4 ++-- src/SPC/builder/linux/LinuxBuilder.php | 7 ++++++- src/SPC/util/SPCConfigUtil.php | 4 ++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config/env.ini b/config/env.ini index 5c093fc7d..8c25fe66f 100644 --- a/config/env.ini +++ b/config/env.ini @@ -72,7 +72,7 @@ AR=${SPC_LINUX_DEFAULT_AR} LD=${SPC_LINUX_DEFAULT_LD} ; default compiler flags, used in CMake toolchain file, openssl and pkg-config build SPC_DEFAULT_C_FLAGS="-fPIC -Os -Wno-error=date-time -fno-sanitize=undefined" -SPC_DEFAULT_CXX_FLAGS="-fPIC -Os" +SPC_DEFAULT_CXX_FLAGS="-fPIC -Os -Wno-error=date-time" ; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated) SPC_EXTRA_LIBS= ; upx executable path @@ -96,7 +96,7 @@ SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -fPIE" ; CPPFLAGS for configuring php SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}" ; LDFLAGS for configuring php -SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" +SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH} -L/usr/lib64" ; LIBS for configuring php SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil" ; EXTRA_CFLAGS for `make` php diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index eb49f579f..9d8c52085 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -80,6 +80,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void } // add libstdc++, some extensions or libraries need it $extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lstdc++ ' : ''); + $extra_libs .= (SystemUtil::getCCType(getenv('CC')) === 'clang' ? ' -lunwind' : ''); f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); $cflags = $this->arch_c_flags; f_putenv('CFLAGS=' . $cflags); @@ -337,12 +338,16 @@ protected function buildEmbed(): void private function getMakeExtraVars(): array { - return [ + $env = [ 'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'), 'EXTRA_LIBS' => getenv('SPC_EXTRA_LIBS') . ' ' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS'), 'EXTRA_LDFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'), 'EXTRA_LDFLAGS_PROGRAM' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM'), ]; + if (str_contains(getenv('CC'), 'zig')) { + $env['LDFLAGS'] = getenv('LDFLAGS') . ' -L/usr/lib64'; + } + return $env; } /** diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index ee13c4e9e..e2f18b08b 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -6,6 +6,7 @@ use SPC\builder\BuilderBase; use SPC\builder\BuilderProvider; +use SPC\builder\linux\SystemUtil; use SPC\builder\macos\MacOSBuilder; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; @@ -70,6 +71,9 @@ public function config(array $extensions = [], array $libraries = [], bool $incl if ($this->builder->hasCpp()) { $libs .= $this->builder instanceof MacOSBuilder ? ' -lc++' : ' -lstdc++'; } + if (SystemUtil::getCCType(getenv('CC')) === 'clang') { + $libs .= ' -lunwind'; + } // mimalloc must come first if (str_contains($libs, BUILD_LIB_PATH . '/mimalloc.o')) { $libs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace(BUILD_LIB_PATH . '/mimalloc.o', '', $libs); From 832c0230e2e1519c1968c81471ae84bff1e5214e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 24 Jun 2025 21:03:32 +0700 Subject: [PATCH 016/278] getcctype default --- src/SPC/builder/extension/imagick.php | 3 --- src/SPC/builder/linux/SystemUtil.php | 3 ++- src/SPC/builder/linux/library/openssl.php | 2 +- src/SPC/util/SPCConfigUtil.php | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 74a63ebc3..16a8fa641 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -38,9 +38,6 @@ protected function getStaticAndSharedLibs(): array $static .= ' -lstdc++'; $shared = str_replace('-lstdc++', '', $shared); } - if (str_contains(getenv('CC'), 'zig')) { - $shared = str_replace('-lomp', '/usr/lib64/libomp.so', $shared); - } return [$static, $shared]; } } diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index 852ff657a..cc751533d 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -78,8 +78,9 @@ public static function getCpuCount(): int /** * @throws RuntimeException */ - public static function getCCType(string $cc): string + public static function getCCType(?string $cc = null): string { + $cc ??= getenv('CC'); return match (true) { str_contains($cc, 'zig') => 'clang', str_ends_with($cc, 'c++'), str_ends_with($cc, 'cc'), str_ends_with($cc, 'g++'), str_ends_with($cc, 'gcc') => 'gcc', diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index 252eb47fb..2a36fe81b 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -62,7 +62,7 @@ public function build(): void $ex_lib = trim($ex_lib); - $clang_postfix = SystemUtil::getCCType(getenv('CC')) === 'clang' ? '-clang' : ''; + $clang_postfix = SystemUtil::getCCType() === 'clang' ? '-clang' : ''; shell()->cd($this->source_dir)->initializeEnv($this) ->exec( diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index e2f18b08b..5b7a0d5a2 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -71,7 +71,7 @@ public function config(array $extensions = [], array $libraries = [], bool $incl if ($this->builder->hasCpp()) { $libs .= $this->builder instanceof MacOSBuilder ? ' -lc++' : ' -lstdc++'; } - if (SystemUtil::getCCType(getenv('CC')) === 'clang') { + if (SystemUtil::getCCType() === 'clang') { $libs .= ' -lunwind'; } // mimalloc must come first From 63fcdd9db4316ebf8db7f7099e1bd64806b34f66 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 24 Jun 2025 21:04:08 +0700 Subject: [PATCH 017/278] default param --- 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 9d8c52085..a08b86e46 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -80,7 +80,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void } // add libstdc++, some extensions or libraries need it $extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lstdc++ ' : ''); - $extra_libs .= (SystemUtil::getCCType(getenv('CC')) === 'clang' ? ' -lunwind' : ''); + $extra_libs .= (SystemUtil::getCCType() === 'clang' ? ' -lunwind' : ''); f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); $cflags = $this->arch_c_flags; f_putenv('CFLAGS=' . $cflags); From 5a60f4c02b53b8eb3cabf71abeba4e4c9284fbd4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 24 Jun 2025 22:56:48 +0700 Subject: [PATCH 018/278] another librdkafka patch --- src/SPC/builder/unix/library/librdkafka.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/librdkafka.php b/src/SPC/builder/unix/library/librdkafka.php index 9ba10e057..66f7e7598 100644 --- a/src/SPC/builder/unix/library/librdkafka.php +++ b/src/SPC/builder/unix/library/librdkafka.php @@ -17,8 +17,18 @@ trait librdkafka */ protected function build(): void { - FileSystem::replaceFileStr($this->source_dir . '/lds-gen.py', "funcs.append('rd_ut_coverage_check')", ''); + FileSystem::replaceFileStr( + $this->source_dir . '/lds-gen.py', + "funcs.append('rd_ut_coverage_check')", + '' + ); + FileSystem::replaceFileStr( + $this->source_dir . '/src/rd.h', + '#error "IOV_MAX not defined"', + '#define IOV_MAX 1024' . "\n#define __GNU__" + ); UnixAutoconfExecutor::create($this) + ->appendEnv(['CFLAGS' => '-Wno-int-conversion -Wno-unused-but-set-variable -Wno-unused-variable']) ->optionalLib( 'zstd', function ($lib) { From 253206de229bbaf3810a45af1f21b1be7bb70ac5 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 24 Jun 2025 22:57:12 +0700 Subject: [PATCH 019/278] better --- src/SPC/builder/unix/library/librdkafka.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/librdkafka.php b/src/SPC/builder/unix/library/librdkafka.php index 66f7e7598..3df7a931a 100644 --- a/src/SPC/builder/unix/library/librdkafka.php +++ b/src/SPC/builder/unix/library/librdkafka.php @@ -25,7 +25,7 @@ protected function build(): void FileSystem::replaceFileStr( $this->source_dir . '/src/rd.h', '#error "IOV_MAX not defined"', - '#define IOV_MAX 1024' . "\n#define __GNU__" + "#define IOV_MAX 1024\n#define __GNU__" ); UnixAutoconfExecutor::create($this) ->appendEnv(['CFLAGS' => '-Wno-int-conversion -Wno-unused-but-set-variable -Wno-unused-variable']) From 5334727528e5f85111b2810e80dbe8e37f1b421e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 24 Jun 2025 23:07:17 +0700 Subject: [PATCH 020/278] remove -L/usr/lib64 (need to put it in the zig-cc script, stupid to add it in 15 different places instead) --- config/env.ini | 2 +- src/SPC/builder/linux/LinuxBuilder.php | 6 +----- src/SPC/builder/unix/UnixBuilderBase.php | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/config/env.ini b/config/env.ini index 8c25fe66f..90168b0e2 100644 --- a/config/env.ini +++ b/config/env.ini @@ -96,7 +96,7 @@ SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -fPIE" ; CPPFLAGS for configuring php SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}" ; LDFLAGS for configuring php -SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH} -L/usr/lib64" +SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" ; LIBS for configuring php SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil" ; EXTRA_CFLAGS for `make` php diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index a08b86e46..e73cc91d4 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -338,16 +338,12 @@ protected function buildEmbed(): void private function getMakeExtraVars(): array { - $env = [ + return [ 'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'), 'EXTRA_LIBS' => getenv('SPC_EXTRA_LIBS') . ' ' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS'), 'EXTRA_LDFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'), 'EXTRA_LDFLAGS_PROGRAM' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM'), ]; - if (str_contains(getenv('CC'), 'zig')) { - $env['LDFLAGS'] = getenv('LDFLAGS') . ' -L/usr/lib64'; - } - return $env; } /** diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index d1106894c..bd4bee44d 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -351,7 +351,7 @@ protected function buildFrankenphp(): void 'GOPATH' => PKG_ROOT_PATH . '/go', 'CGO_ENABLED' => '1', 'CGO_CFLAGS' => $config['cflags'], - 'CGO_LDFLAGS' => "{$config['ldflags']} {$config['libs']} {$lrt} -L/usr/lib64", + 'CGO_LDFLAGS' => "{$config['ldflags']} {$config['libs']} {$lrt}", 'XCADDY_GO_BUILD_FLAGS' => '-buildmode=pie ' . '-ldflags \"-linkmode=external ' . $extLdFlags . ' ' . $debugFlags . '-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' . From 40ac705c465856c60dc7fd5ab49f60efa183d21d Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 25 Jun 2025 11:21:58 +0700 Subject: [PATCH 021/278] remove openmp support entirely, system packages distribute it disabled, the ini disables it by default and the authors recommend disabling it. WIth a distinction between libgomp, libomp and the non-existent usable static libraries for them, it's just not worth it. --- docs/en/guide/extension-notes.md | 8 ++++---- docs/zh/guide/extension-notes.md | 6 +++--- src/SPC/builder/extension/imagick.php | 19 ++----------------- src/SPC/builder/unix/library/imagemagick.php | 3 +-- src/SPC/util/SPCConfigUtil.php | 4 ---- 5 files changed, 10 insertions(+), 30 deletions(-) diff --git a/docs/en/guide/extension-notes.md b/docs/en/guide/extension-notes.md index aa11c3772..91ea531e3 100644 --- a/docs/en/guide/extension-notes.md +++ b/docs/en/guide/extension-notes.md @@ -48,17 +48,17 @@ This extension contains an implementation of the coroutine environment for `pdo_ ## swow -1. Only PHP 8.0 ~ 8.4 is supported. +1. Only PHP 8.0+ is supported. ## imagick -1. The imagick extension currently only has openmp support on musl libc. This means that multithreading is disabled on glibc or other operating systems. The extension is still fully functional. +1. Openmp support is disabled, this is recommended by the maintainers and also the case system packages. ## imap 1. Kerberos is not supported -2. ext-imap is not thread safe due to the underlying c-client. It's not possible to use it in --enable-zts builds. -3. Because the extension may be dropped from php, we recommend you look for an alternative implementation, such as [Webklex/php-imap](https://github.com/Webklex/php-imap) +2. ext-imap is not thread safe due to the underlying c-client. It's not possible to use it in `--enable-zts` builds. +3. The extension was dropped from php 8.4, we recommend you look for an alternative implementation, such as [Webklex/php-imap](https://github.com/Webklex/php-imap) ## gd diff --git a/docs/zh/guide/extension-notes.md b/docs/zh/guide/extension-notes.md index 10e62eb06..dd1538173 100644 --- a/docs/zh/guide/extension-notes.md +++ b/docs/zh/guide/extension-notes.md @@ -45,17 +45,17 @@ swoole-hook-sqlite 与 `pdo_sqlite` 扩展冲突。如需使用 Swoole 和 `pdo_ ## swow -1. swow 仅支持 PHP 8.0 ~ 8.4 版本。 +1. swow 仅支持 PHP 8.0+ 版本。 ## imagick -imagick 扩展目前仅在 musl libc 上支持 OpenMP(libgomp)。使用 glibc 方式构建的 imagick 扩展无法支持多线程特性。 +1. OpenMP 支持已被禁用,这是维护者推荐的做法,系统软件包也是如此配置。 ## imap 1. 该扩展目前不支持 Kerberos。 2. 由于底层的 c-client、ext-imap 不是线程安全的。 无法在 `--enable-zts` 构建中使用它。 -3. 由于该扩展可能会从未来的 PHP 中删除,因此我们建议您寻找替代实现,例如 [Webklex/php-imap](https://github.com/Webklex/php-imap)。 +3. 该扩展已在 PHP 8.4 中被移除,因此我们建议您寻找替代实现,例如 [Webklex/php-imap](https://github.com/Webklex/php-imap)。 ## gd diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 16a8fa641..8623b8f3b 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -10,31 +10,16 @@ #[CustomExt('imagick')] class imagick extends Extension { - public function patchBeforeMake(): bool - { - if (PHP_OS_FAMILY !== 'Linux') { - return false; - } - if (getenv('SPC_LIBC') === 'glibc' && str_contains(getenv('CC'), 'devtoolset-10')) { - return false; - } - // imagick with calls omp_pause_all, which requires openmp, on non-musl we build imagick without openmp - $extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -lomp'); - f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); - return true; - } - public function getUnixConfigureArg(bool $shared = false): string { - $disable_omp = !(getenv('SPC_LIBC') === 'glibc' && str_contains(getenv('CC'), 'devtoolset-10')) ? '' : ' ac_cv_func_omp_pause_resource_all=no'; - return '--with-imagick=' . ($shared ? 'shared,' : '') . BUILD_ROOT_PATH . $disable_omp; + return '--with-imagick=' . ($shared ? 'shared,' : '') . BUILD_ROOT_PATH . ' ac_cv_func_omp_pause_resource_all=no'; } protected function getStaticAndSharedLibs(): array { // on centos 7, it will use the symbol _ZTINSt6thread6_StateE, which is not defined in system libstdc++.so.6 [$static, $shared] = parent::getStaticAndSharedLibs(); - if (getenv('SPC_LIBC') === 'glibc' && str_contains(getenv('CC'), 'devtoolset-10')) { + if (str_contains(getenv('CC'), 'devtoolset-10')) { $static .= ' -lstdc++'; $shared = str_replace('-lstdc++', '', $shared); } diff --git a/src/SPC/builder/unix/library/imagemagick.php b/src/SPC/builder/unix/library/imagemagick.php index ead786a22..8f4a7dadf 100644 --- a/src/SPC/builder/unix/library/imagemagick.php +++ b/src/SPC/builder/unix/library/imagemagick.php @@ -32,8 +32,7 @@ protected function build(): void ->optionalLib('freetype', ...ac_with_args('freetype')) ->optionalLib('bzip2', ...ac_with_args('bzlib')) ->addConfigureArgs( - // TODO: glibc rh 10 toolset's libgomp.a was built without -fPIC so we can't use openmp without depending on libgomp.so - getenv('SPC_LIBC') === 'glibc' && str_contains(getenv('CC'), 'devtoolset-10') ? '--disable-openmp' : '--enable-openmp', + '--disable-openmp', '--without-jxl', '--without-x', ); diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index 5b7a0d5a2..c5177bc62 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -149,10 +149,6 @@ private function getLibsString(array $libraries, bool $withDependencies = false) } } } - // patch: imagick (imagemagick wrapper) for linux needs libgomp - if (in_array('imagemagick', $libraries) && PHP_OS_FAMILY === 'Linux' && !(getenv('SPC_LIBC') === 'glibc' && str_contains(getenv('CC'), 'devtoolset-10'))) { - $short_name[] = '-lomp'; - } return implode(' ', $short_name); } From cb62ffdfc214a8f58daa2e54f429f40fda68247e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 25 Jun 2025 11:24:01 +0700 Subject: [PATCH 022/278] we manage -fno-sanitize in code, only needed for opcache with jit --- config/env.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/env.ini b/config/env.ini index 90168b0e2..c00aafc35 100644 --- a/config/env.ini +++ b/config/env.ini @@ -71,7 +71,7 @@ CXX=${SPC_LINUX_DEFAULT_CXX} AR=${SPC_LINUX_DEFAULT_AR} LD=${SPC_LINUX_DEFAULT_LD} ; default compiler flags, used in CMake toolchain file, openssl and pkg-config build -SPC_DEFAULT_C_FLAGS="-fPIC -Os -Wno-error=date-time -fno-sanitize=undefined" +SPC_DEFAULT_C_FLAGS="-fPIC -Os -Wno-error=date-time" SPC_DEFAULT_CXX_FLAGS="-fPIC -Os -Wno-error=date-time" ; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated) SPC_EXTRA_LIBS= From 6f5fc43490b7b9c0038813570b1fe6784f856767 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 25 Jun 2025 11:26:45 +0700 Subject: [PATCH 023/278] remove extra -lunwind patch since we don't only need it in opcache --- src/SPC/builder/extension/opcache.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/SPC/builder/extension/opcache.php b/src/SPC/builder/extension/opcache.php index 34673a9d2..5d9dda0ad 100644 --- a/src/SPC/builder/extension/opcache.php +++ b/src/SPC/builder/extension/opcache.php @@ -51,15 +51,4 @@ public function getDistName(): string { return 'Zend Opcache'; } - - public function patchBeforeMake(): bool - { - if (!str_contains(getenv('CC'), 'zig')) { - return false; - } - // opcache requires -lunwind, the equivalent to -lgcc_s that gcc automatically links - $extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -lunwind'); - f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); - return true; - } } From 55f01149e444a76dcc29014ea6be4ac09aaa9811 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 25 Jun 2025 13:56:12 +0700 Subject: [PATCH 024/278] prevent warning --- src/SPC/builder/linux/LinuxBuilder.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index e73cc91d4..d0704a5eb 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -307,7 +307,6 @@ protected function buildEmbed(): void rename($libphpPath, $libphpRelease); } if (file_exists($libphpRelease)) { - rename(BUILD_LIB_PATH . '/libphp.so', $libphpRelease); chdir(BUILD_LIB_PATH); symlink($realLibName, 'libphp.so'); } From 9a3a5364795e8d665117a37e0053bab48eddc40c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 25 Jun 2025 14:32:00 +0700 Subject: [PATCH 025/278] runtime object patch for shared extensions --- config/env.ini | 3 +++ src/SPC/builder/Extension.php | 11 ++++++++++- src/SPC/builder/extension/uv.php | 1 + src/SPC/builder/linux/LinuxBuilder.php | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config/env.ini b/config/env.ini index c00aafc35..48de32a05 100644 --- a/config/env.ini +++ b/config/env.ini @@ -108,6 +108,9 @@ SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS="" ; EXTRA_LDFLAGS_PROGRAM for `make` php SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-all-static -pie" +# Zig +ZIG_SHARED_EXTENSION_EXTRA_OBJECTS="/usr/lib/gcc/x86_64-redhat-linux/14/crtbeginS.o /usr/lib/gcc/x86_64-redhat-linux/14/crtendS.o" + [macos] ; compiler environments CC=clang diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 6bb877821..b4b4827d6 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -215,7 +215,16 @@ public function patchBeforeSharedConfigure(): bool */ public function patchBeforeSharedMake(): bool { - return false; + if (!str_contains(getenv('CC'), 'zig')) { + return false; + } + $extra = getenv('ZIG_SHARED_EXTENSION_EXTRA_OBJECTS'); + FileSystem::replaceFileRegex( + $this->source_dir . '/Makefile', + "/^(shared_objects_{$this->getName()}\s*=.*)$/m", + "$1 {$extra}", + ); + return true; } /** diff --git a/src/SPC/builder/extension/uv.php b/src/SPC/builder/extension/uv.php index 8c54e007c..d803a7506 100644 --- a/src/SPC/builder/extension/uv.php +++ b/src/SPC/builder/extension/uv.php @@ -20,6 +20,7 @@ public function validate(): void public function patchBeforeSharedMake(): bool { + parent::patchBeforeSharedMake(); if (PHP_OS_FAMILY !== 'Linux' || arch2gnu(php_uname('m')) !== 'aarch64') { return false; } diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index d0704a5eb..f9e9b6a10 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -308,6 +308,9 @@ protected function buildEmbed(): void } if (file_exists($libphpRelease)) { chdir(BUILD_LIB_PATH); + if (file_exists($libphpPath)) { + unlink($libphpPath); + } symlink($realLibName, 'libphp.so'); } if (is_dir(BUILD_MODULES_PATH)) { From b142610800c7e285f1d63df57b5443a6fcb9d5a4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 25 Jun 2025 14:52:50 +0700 Subject: [PATCH 026/278] move to systemutil --- config/env.ini | 3 --- src/SPC/builder/Extension.php | 7 +++--- src/SPC/builder/linux/SystemUtil.php | 36 ++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/config/env.ini b/config/env.ini index 48de32a05..c00aafc35 100644 --- a/config/env.ini +++ b/config/env.ini @@ -108,9 +108,6 @@ SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS="" ; EXTRA_LDFLAGS_PROGRAM for `make` php SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-all-static -pie" -# Zig -ZIG_SHARED_EXTENSION_EXTRA_OBJECTS="/usr/lib/gcc/x86_64-redhat-linux/14/crtbeginS.o /usr/lib/gcc/x86_64-redhat-linux/14/crtendS.o" - [macos] ; compiler environments CC=clang diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index b4b4827d6..459f5f02b 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -4,6 +4,7 @@ namespace SPC\builder; +use SPC\builder\linux\SystemUtil; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; @@ -215,13 +216,13 @@ public function patchBeforeSharedConfigure(): bool */ public function patchBeforeSharedMake(): bool { - if (!str_contains(getenv('CC'), 'zig')) { + $extra = SystemUtil::getExtraRuntimeObjects(); + if (!$extra) { return false; } - $extra = getenv('ZIG_SHARED_EXTENSION_EXTRA_OBJECTS'); FileSystem::replaceFileRegex( $this->source_dir . '/Makefile', - "/^(shared_objects_{$this->getName()}\s*=.*)$/m", + "/^(shared_objects_{$this->getName()}\\s*=.*)$/m", "$1 {$extra}", ); return true; diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index cc751533d..41095e22d 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -13,6 +13,8 @@ class SystemUtil public static ?string $libc_version = null; + private static ?string $extra_runtime_objects = null; + /** @noinspection PhpMissingBreakStatementInspection */ public static function getOSRelease(): array { @@ -226,4 +228,38 @@ public static function getLibcVersionIfExists(): ?string } return null; } + + public static function getExtraRuntimeObjects(): string + { + $cc = getenv('CC'); + if (!$cc || !str_contains($cc, 'zig')) { + return ''; + } + + if (self::$extra_runtime_objects !== null) { + return self::$extra_runtime_objects; + } + + $paths = ['/usr/lib/gcc', '/usr/local/lib/gcc']; + $objects = ['crtbeginS.o', 'crtendS.o']; + $found = []; + + foreach ($objects as $obj) { + $located = null; + foreach ($paths as $base) { + $output = shell_exec("find {$base} -name {$obj} -print -quit 2>/dev/null"); + $line = trim((string) $output); + if ($line !== '') { + $located = $line; + break; + } + } + if ($located) { + $found[] = escapeshellarg($located); + } + } + + self::$extra_runtime_objects = implode(' ', $found); + return implode(' ', $found); + } } From 625bfd1bec3832bffb0181d2b4870ca9729e4f09 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 11:18:34 +0700 Subject: [PATCH 027/278] don't escape --- src/SPC/builder/linux/SystemUtil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index 41095e22d..018a22c5e 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -255,7 +255,7 @@ public static function getExtraRuntimeObjects(): string } } if ($located) { - $found[] = escapeshellarg($located); + $found[] = $located; } } From 8d75a85d6d36662d2a6f6f94cf3ba408be818256 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 12:29:58 +0700 Subject: [PATCH 028/278] ziggy --- config/pkg.json | 15 +++ src/SPC/store/Downloader.php | 2 +- src/SPC/store/pkg/Zig.php | 148 ++++++++++++++++++++++++++++++ src/SPC/util/GlobalEnvManager.php | 4 + 4 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 src/SPC/store/pkg/Zig.php diff --git a/config/pkg.json b/config/pkg.json index e0762cac7..080958b4f 100644 --- a/config/pkg.json +++ b/config/pkg.json @@ -54,5 +54,20 @@ }, "go-xcaddy-aarch64-macos": { "type": "custom" + }, + "zig-x86_64-linux": { + "type": "custom" + }, + "zig-aarch64-linux": { + "type": "custom" + }, + "zig-x86_64-macos": { + "type": "custom" + }, + "zig-aarch64-macos": { + "type": "custom" + }, + "zig-x86_64-win": { + "type": "custom" } } diff --git a/src/SPC/store/Downloader.php b/src/SPC/store/Downloader.php index ba0cd124d..41fcb25d1 100644 --- a/src/SPC/store/Downloader.php +++ b/src/SPC/store/Downloader.php @@ -365,8 +365,8 @@ public static function downloadPackage(string $name, ?array $pkg = null, bool $f $cls = new $class(); if (in_array($name, $cls->getSupportName())) { (new $class())->fetch($name, $force, $pkg); + break; } - break; } } break; diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php new file mode 100644 index 000000000..380205795 --- /dev/null +++ b/src/SPC/store/pkg/Zig.php @@ -0,0 +1,148 @@ + "{$pkgroot}/{$name}/bin/zig.exe", + default => "{$pkgroot}/{$name}/bin/zig", + }; + + if (file_exists($zig_exec) && !$force) { + return; + } + + $parts = explode('-', $name); + $arch = $parts[1]; + $os = $parts[2]; + + $zig_arch = match ($arch) { + 'x86_64', 'aarch64' => $arch, + default => throw new \InvalidArgumentException('Unsupported architecture: ' . $arch), + }; + + $zig_os = match ($os) { + 'linux' => 'linux', + 'macos' => 'macos', + 'win' => 'windows', + default => throw new \InvalidArgumentException('Unsupported OS: ' . $os), + }; + + $index_json = json_decode(Downloader::curlExec('https://ziglang.org/download/index.json', hooks: [[CurlHook::class, 'setupGithubToken']]), true); + + $latest_version = null; + foreach ($index_json as $version => $data) { + $latest_version = $version; + break; + } + + if (!$latest_version) { + throw new \RuntimeException('Could not determine latest Zig version'); + } + + logger()->info("Installing Zig version {$latest_version}"); + + $platform_key = "{$zig_arch}-{$zig_os}"; + if (!isset($index_json[$latest_version][$platform_key])) { + throw new \RuntimeException("No download available for {$platform_key} in Zig version {$latest_version}"); + } + + $download_info = $index_json[$latest_version][$platform_key]; + $url = $download_info['tarball']; + $filename = basename($url); + + $config = [ + 'type' => 'url', + 'url' => $url, + 'filename' => $filename, + ]; + + Downloader::downloadPackage($name, $config, $force); + } + + public function extract(string $name): void + { + $pkgroot = PKG_ROOT_PATH; + $zig_bin_dir = "{$pkgroot}/{$name}"; + $zig_exec = match (PHP_OS_FAMILY) { + 'Windows' => "{$zig_bin_dir}/zig.exe", + default => "{$zig_bin_dir}/zig", + }; + + if (file_exists($zig_exec)) { + if (!file_exists("{$zig_bin_dir}/zig-cc")) { + $this->createZigCcScript($zig_bin_dir); + return; + } + return; + } + + $lock = json_decode(FileSystem::readFile(LockFile::LOCK_FILE), true); + $source_type = $lock[$name]['source_type']; + $filename = DOWNLOAD_PATH . '/' . ($lock[$name]['filename'] ?? $lock[$name]['dirname']); + $extract = "{$pkgroot}/{$name}"; + + + FileSystem::extractPackage($name, $source_type, $filename, $extract); + + $this->createZigCcScript($zig_bin_dir); + } + + private function createZigCcScript(string $bin_dir): void + { + $zig_cc_path = "{$bin_dir}/zig-cc"; + + $script_content = <<<'EOF' +#!/usr/bin/env bash + +SPC_TARGET="${SPC_TARGET:-native-native}" +SPC_LIBC="${SPC_LIBC}" +SPC_LIBC_VERSION="${SPC_LIBC_VERSION}" + +if [ "$SPC_LIBC" = "glibc" ]; then + SPC_LIBC="gnu" +fi + +if [ "$SPC_TARGET" = "native-native" ] && [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then + exec zig cc "$@" +elif [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then + exec zig cc -target ${SPC_TARGET} "$@" +elif [ -z "$SPC_LIBC_VERSION" ]; then + exec zig cc -target ${SPC_TARGET}-${SPC_LIBC} -L/usr/lib64 -lstdc++ "$@" +else + error_output=$(zig cc -target ${SPC_TARGET}-${SPC_LIBC}.${SPC_LIBC_VERSION} "$@" 2>&1 >/dev/null) + if echo "$error_output" | grep -q "zig: error: version '.*' in target triple '${SPC_TARGET}-${SPC_LIBC}\..*' is invalid"; then + exec zig cc -target ${SPC_TARGET}-${SPC_LIBC} -L/usr/lib64 -lstdc++ "$@" + else + exec zig cc -target ${SPC_TARGET}-${SPC_LIBC}.${SPC_LIBC_VERSION} -L/usr/lib64 -lstdc++ "$@" + fi +fi + +EOF; + + file_put_contents($zig_cc_path, $script_content); + chmod($zig_cc_path, 0755); + } +} diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index 177852057..6f04b3286 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -108,6 +108,10 @@ public static function init(?BuilderBase $builder = null): void 'BSD' => self::applyConfig($ini['freebsd']), default => null, }; + + if (str_contains(getenv('CC'), 'zig')) { + // add to path + } } public static function putenv(string $val): void From fae2878c41f1bccb901102ed78cd0c78f720e122 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 14:24:00 +0700 Subject: [PATCH 029/278] refactor env var logic out to packages, abomination of a zig-cc script... --- src/SPC/builder/unix/UnixBuilderBase.php | 23 +----- src/SPC/store/pkg/CustomPackage.php | 7 +- src/SPC/store/pkg/GoXcaddy.php | 22 ++++++ src/SPC/store/pkg/Zig.php | 98 +++++++++++++++++++++--- src/SPC/util/GlobalEnvManager.php | 9 +++ 5 files changed, 125 insertions(+), 34 deletions(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index bd4bee44d..519475d34 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -15,6 +15,7 @@ use SPC\store\CurlHook; use SPC\store\Downloader; use SPC\store\FileSystem; +use SPC\store\pkg\GoXcaddy; use SPC\util\DependencyUtil; use SPC\util\SPCConfigUtil; @@ -301,18 +302,6 @@ protected function patchPhpScripts(): void */ protected function buildFrankenphp(): void { - $os = match (PHP_OS_FAMILY) { - 'Linux' => 'linux', - 'Windows' => 'win', - 'Darwin' => 'macos', - 'BSD' => 'freebsd', - default => throw new RuntimeException('Unsupported OS: ' . PHP_OS_FAMILY), - }; - $arch = arch2gnu(php_uname('m')); - - // define executables for go and xcaddy - $xcaddy_exec = PKG_ROOT_PATH . "/go-xcaddy-{$arch}-{$os}/bin/xcaddy"; - $nobrotli = $this->getLib('brotli') === null ? ',nobrotli' : ''; $nowatcher = $this->getLib('watcher') === null ? ',nowatcher' : ''; $xcaddyModules = getenv('SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES'); @@ -344,11 +333,7 @@ protected function buildFrankenphp(): void $config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list, with_dependencies: true); - $env = [ - 'PATH' => PKG_ROOT_PATH . "/go-xcaddy-{$arch}-{$os}/bin:" . getenv('PATH'), - 'GOROOT' => PKG_ROOT_PATH . "/go-xcaddy-{$arch}-{$os}", - 'GOBIN' => PKG_ROOT_PATH . "/go-xcaddy-{$arch}-{$os}/bin", - 'GOPATH' => PKG_ROOT_PATH . '/go', + $env = [...GoXcaddy::getEnvironment(), ...[ 'CGO_ENABLED' => '1', 'CGO_CFLAGS' => $config['cflags'], 'CGO_LDFLAGS' => "{$config['ldflags']} {$config['libs']} {$lrt}", @@ -358,9 +343,9 @@ protected function buildFrankenphp(): void "{$frankenPhpVersion} PHP {$libphpVersion} Caddy'\\\" " . "-tags={$muslTags}nobadger,nomysql,nopgx{$nobrotli}{$nowatcher}", 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, - ]; + ]]; shell()->cd(BUILD_BIN_PATH) ->setEnv($env) - ->exec("{$xcaddy_exec} build --output frankenphp {$xcaddyModules}"); + ->exec("xcaddy build --output frankenphp {$xcaddyModules}"); } } diff --git a/src/SPC/store/pkg/CustomPackage.php b/src/SPC/store/pkg/CustomPackage.php index 89edb17e3..bc6f6e46b 100644 --- a/src/SPC/store/pkg/CustomPackage.php +++ b/src/SPC/store/pkg/CustomPackage.php @@ -10,8 +10,7 @@ abstract public function getSupportName(): array; abstract public function fetch(string $name, bool $force = false, ?array $config = null): void; - public function extract(string $name): void - { - throw new \RuntimeException("Extract method not implemented for package: {$name}"); - } + abstract public function extract(string $name): void; + + abstract public static function getEnvironment(): array; } diff --git a/src/SPC/store/pkg/GoXcaddy.php b/src/SPC/store/pkg/GoXcaddy.php index e0c7c5b96..5c089fc9d 100644 --- a/src/SPC/store/pkg/GoXcaddy.php +++ b/src/SPC/store/pkg/GoXcaddy.php @@ -73,4 +73,26 @@ public function extract(string $name): void ]) ->exec("{$go_exec} install github.com/caddyserver/xcaddy/cmd/xcaddy@latest"); } + + public static function getEnvironment(): array + { + $arch = arch2gnu(php_uname('m')); + $os = match (PHP_OS_FAMILY) { + 'Windows' => 'win', + 'Darwin' => 'macos', + 'BSD' => 'freebsd', + default => 'linux', + }; + + $packageName = "go-xcaddy-{$arch}-{$os}"; + $pkgroot = PKG_ROOT_PATH; + + return [ + 'PATH' => "{$pkgroot}/{$packageName}/bin", + 'GOROOT' => "{$pkgroot}/{$packageName}", + 'GOBIN' => "{$pkgroot}/{$packageName}/bin", + 'GOPATH' => "{$pkgroot}/go", + ]; + } + } diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index 380205795..6784361ca 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -112,12 +112,65 @@ public function extract(string $name): void private function createZigCcScript(string $bin_dir): void { - $zig_cc_path = "{$bin_dir}/zig-cc"; $script_content = <<<'EOF' #!/usr/bin/env bash -SPC_TARGET="${SPC_TARGET:-native-native}" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BUILDROOT_ABS="$(realpath "$SCRIPT_DIR/../../buildroot/include" 2>/dev/null || echo "")" +PARSED_ARGS=() + +while [[ $# -gt 0 ]]; do + case "$1" in + -isystem) + shift + ARG="$1" + [[ -n "$ARG" ]] && shift || break + ARG_ABS="$(realpath "$ARG" 2>/dev/null || echo "")" + if [[ -n "$ARG_ABS" && "$ARG_ABS" == "$BUILDROOT_ABS" ]]; then + PARSED_ARGS+=("-I$ARG") + else + PARSED_ARGS+=("-isystem" "$ARG") + fi + ;; + -isystem*) + ARG="${1#-isystem}" + shift + ARG_ABS="$(realpath "$ARG" 2>/dev/null || echo "")" + if [[ -n "$ARG_ABS" && "$ARG_ABS" == "$BUILDROOT_ABS" ]]; then + PARSED_ARGS+=("-I$ARG") + else + PARSED_ARGS+=("-isystem$ARG") + fi + ;; + *) + PARSED_ARGS+=("$1") + shift + ;; + esac +done + +SPC_TARGET_WAS_SET=1 +if [ -z "${SPC_TARGET+x}" ]; then + SPC_TARGET_WAS_SET=0 +fi + +UNAME_M="$(uname -m)" +UNAME_S="$(uname -s)" + +case "$UNAME_M" in + x86_64) ARCH="x86_64" ;; + aarch64|arm64) ARCH="aarch64" ;; + *) echo "Unsupported architecture: $UNAME_M" >&2; exit 1 ;; +esac + +case "$UNAME_S" in + Linux) OS="linux" ;; + Darwin) OS="macos" ;; + *) echo "Unsupported OS: $UNAME_S" >&2; exit 1 ;; +esac + +SPC_TARGET="${SPC_TARGET:-$ARCH-$OS}" SPC_LIBC="${SPC_LIBC}" SPC_LIBC_VERSION="${SPC_LIBC_VERSION}" @@ -125,24 +178,47 @@ private function createZigCcScript(string $bin_dir): void SPC_LIBC="gnu" fi -if [ "$SPC_TARGET" = "native-native" ] && [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then - exec zig cc "$@" +if [ "$SPC_TARGET_WAS_SET" -eq 0 ] && [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then + exec zig cc "${PARSED_ARGS[@]}" elif [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then - exec zig cc -target ${SPC_TARGET} "$@" + exec zig cc -target ${SPC_TARGET} "${PARSED_ARGS[@]}" elif [ -z "$SPC_LIBC_VERSION" ]; then - exec zig cc -target ${SPC_TARGET}-${SPC_LIBC} -L/usr/lib64 -lstdc++ "$@" + exec zig cc -target ${SPC_TARGET}-${SPC_LIBC} -L/usr/lib64 -lstdc++ "${PARSED_ARGS[@]}" else - error_output=$(zig cc -target ${SPC_TARGET}-${SPC_LIBC}.${SPC_LIBC_VERSION} "$@" 2>&1 >/dev/null) + error_output=$(zig cc -target ${SPC_TARGET}-${SPC_LIBC}.${SPC_LIBC_VERSION} "${PARSED_ARGS[@]}" 2>&1 >/dev/null) if echo "$error_output" | grep -q "zig: error: version '.*' in target triple '${SPC_TARGET}-${SPC_LIBC}\..*' is invalid"; then - exec zig cc -target ${SPC_TARGET}-${SPC_LIBC} -L/usr/lib64 -lstdc++ "$@" + exec zig cc -target ${SPC_TARGET}-${SPC_LIBC} -L/usr/lib64 -lstdc++ "${PARSED_ARGS[@]}" else - exec zig cc -target ${SPC_TARGET}-${SPC_LIBC}.${SPC_LIBC_VERSION} -L/usr/lib64 -lstdc++ "$@" + exec zig cc -target ${SPC_TARGET}-${SPC_LIBC}.${SPC_LIBC_VERSION} -L/usr/lib64 -lstdc++ "${PARSED_ARGS[@]}" fi fi EOF; - file_put_contents($zig_cc_path, $script_content); - chmod($zig_cc_path, 0755); + file_put_contents("{$bin_dir}/zig-cc", $script_content); + chmod("{$bin_dir}/zig-cc", 0755); + + $script_content = str_replace('zig cc', 'zig c++', $script_content); + file_put_contents("{$bin_dir}/zig-c++", $script_content); + chmod("{$bin_dir}/zig-c++", 0755); + } + + public static function getEnvironment(): array + { + $arch = arch2gnu(php_uname('m')); + $os = match (PHP_OS_FAMILY) { + 'Linux' => 'linux', + 'Windows' => 'win', + 'Darwin' => 'macos', + 'BSD' => 'freebsd', + default => 'linux', + }; + + $packageName = "zig-{$arch}-{$os}"; + $path = PKG_ROOT_PATH . "/{$packageName}"; + + return [ + 'PATH' => $path + ]; } } diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index fa5c9cf54..8f916716c 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -7,6 +7,7 @@ use SPC\builder\linux\SystemUtil; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; +use SPC\store\pkg\Zig; /** * Environment variable manager @@ -100,6 +101,14 @@ public static function init(): void self::putenv("{$k}={$v}"); } } + if (str_contains(getenv('CC'), 'zig') || str_contains(getenv('CXX'), 'zig')) { + $zigEnv = Zig::getEnvironment(); + foreach ($zigEnv as $key => $value) { + if ($key === 'PATH') { + self::addPathIfNotExists($value); + } + } + } } public static function putenv(string $val): void From 935f3fc37c365a0603a0b913c2179eef7af18331 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 14:29:00 +0700 Subject: [PATCH 030/278] cs fix --- src/SPC/store/pkg/GoXcaddy.php | 1 - src/SPC/store/pkg/Zig.php | 40 ++++++++++++++++------------------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/SPC/store/pkg/GoXcaddy.php b/src/SPC/store/pkg/GoXcaddy.php index 5c089fc9d..c61511a30 100644 --- a/src/SPC/store/pkg/GoXcaddy.php +++ b/src/SPC/store/pkg/GoXcaddy.php @@ -94,5 +94,4 @@ public static function getEnvironment(): array 'GOPATH' => "{$pkgroot}/go", ]; } - } diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index 6784361ca..8b4be5832 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -104,15 +104,32 @@ public function extract(string $name): void $filename = DOWNLOAD_PATH . '/' . ($lock[$name]['filename'] ?? $lock[$name]['dirname']); $extract = "{$pkgroot}/{$name}"; - FileSystem::extractPackage($name, $source_type, $filename, $extract); $this->createZigCcScript($zig_bin_dir); } - private function createZigCcScript(string $bin_dir): void + public static function getEnvironment(): array { + $arch = arch2gnu(php_uname('m')); + $os = match (PHP_OS_FAMILY) { + 'Linux' => 'linux', + 'Windows' => 'win', + 'Darwin' => 'macos', + 'BSD' => 'freebsd', + default => 'linux', + }; + $packageName = "zig-{$arch}-{$os}"; + $path = PKG_ROOT_PATH . "/{$packageName}"; + + return [ + 'PATH' => $path, + ]; + } + + private function createZigCcScript(string $bin_dir): void + { $script_content = <<<'EOF' #!/usr/bin/env bash @@ -202,23 +219,4 @@ private function createZigCcScript(string $bin_dir): void file_put_contents("{$bin_dir}/zig-c++", $script_content); chmod("{$bin_dir}/zig-c++", 0755); } - - public static function getEnvironment(): array - { - $arch = arch2gnu(php_uname('m')); - $os = match (PHP_OS_FAMILY) { - 'Linux' => 'linux', - 'Windows' => 'win', - 'Darwin' => 'macos', - 'BSD' => 'freebsd', - default => 'linux', - }; - - $packageName = "zig-{$arch}-{$os}"; - $path = PKG_ROOT_PATH . "/{$packageName}"; - - return [ - 'PATH' => $path - ]; - } } From a8c7057aba7d9ed22a840115533fee67a3700096 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 14:30:42 +0700 Subject: [PATCH 031/278] fix windows --- src/SPC/util/GlobalEnvManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index 8f916716c..0edcc429d 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -101,7 +101,7 @@ public static function init(): void self::putenv("{$k}={$v}"); } } - if (str_contains(getenv('CC'), 'zig') || str_contains(getenv('CXX'), 'zig')) { + if (str_contains((string)getenv('CC'), 'zig') || str_contains((string)getenv('CXX'), 'zig')) { $zigEnv = Zig::getEnvironment(); foreach ($zigEnv as $key => $value) { if ($key === 'PATH') { From 762c5544683005e2376ddf92b063626871a2701c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 14:39:49 +0700 Subject: [PATCH 032/278] test zig --- src/SPC/util/GlobalEnvManager.php | 2 +- src/globals/test-extensions.php | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index 0edcc429d..baf38e7ac 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -101,7 +101,7 @@ public static function init(): void self::putenv("{$k}={$v}"); } } - if (str_contains((string)getenv('CC'), 'zig') || str_contains((string)getenv('CXX'), 'zig')) { + if (str_contains((string) getenv('CC'), 'zig') || str_contains((string) getenv('CXX'), 'zig')) { $zigEnv = Zig::getEnvironment(); foreach ($zigEnv as $key => $value) { if ($key === 'PATH') { diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 70758f855..a1c4f470e 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -13,9 +13,9 @@ // test php version (8.1 ~ 8.4 available, multiple for matrix) $test_php_version = [ - '8.1', - '8.2', - '8.3', + // '8.1', + // '8.2', + // '8.3', '8.4', ]; @@ -26,12 +26,21 @@ // 'macos-15', // 'ubuntu-latest', // 'ubuntu-22.04', - // 'ubuntu-24.04', // 'ubuntu-22.04-arm', - // 'ubuntu-24.04-arm', - 'windows-latest', + 'ubuntu-24.04', + 'ubuntu-24.04-arm', + // 'windows-latest', ]; +$zig = true; +// temporary! +if ($zig) { + putenv('SPC_LIBC=glibc'); + putenv('SPC_LIBC_VERSION=2.17'); + putenv('CC=zig-cc'); + putenv('CXX=zig-c++'); +} + // whether enable thread safe $zts = true; @@ -48,13 +57,13 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'curl', + 'Linux', 'Darwin' => 'curl,iconv', 'Windows' => 'intl', }; // If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`). $shared_extensions = match (PHP_OS_FAMILY) { - 'Linux' => 'uv', + 'Linux' => 'event,uv,intl,gettext', 'Darwin' => '', 'Windows' => '', }; @@ -208,6 +217,9 @@ function quote2(string $param): string passthru($prefix . $down_cmd, $retcode); break; case 'build_cmd': + if ($zig) { + passthru("{$prefix}install-pkg zig --debug", $retcode); + } passthru($prefix . $build_cmd . ' --build-cli --build-micro', $retcode); break; case 'build_embed_cmd': From b5356002976d637422d60c5d7879a6e8d5071179 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 15:44:21 +0700 Subject: [PATCH 033/278] this is insane --- src/SPC/store/pkg/Zig.php | 40 +++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index 8b4be5832..b085b686e 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -133,7 +133,8 @@ private function createZigCcScript(string $bin_dir): void $script_content = <<<'EOF' #!/usr/bin/env bash -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +LIBDIR="$(realpath "$(dirname "$(gcc -print-file-name=libc.so)")")" +SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" BUILDROOT_ABS="$(realpath "$SCRIPT_DIR/../../buildroot/include" 2>/dev/null || echo "")" PARSED_ARGS=() @@ -188,8 +189,6 @@ private function createZigCcScript(string $bin_dir): void esac SPC_TARGET="${SPC_TARGET:-$ARCH-$OS}" -SPC_LIBC="${SPC_LIBC}" -SPC_LIBC_VERSION="${SPC_LIBC_VERSION}" if [ "$SPC_LIBC" = "glibc" ]; then SPC_LIBC="gnu" @@ -199,17 +198,38 @@ private function createZigCcScript(string $bin_dir): void exec zig cc "${PARSED_ARGS[@]}" elif [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then exec zig cc -target ${SPC_TARGET} "${PARSED_ARGS[@]}" -elif [ -z "$SPC_LIBC_VERSION" ]; then - exec zig cc -target ${SPC_TARGET}-${SPC_LIBC} -L/usr/lib64 -lstdc++ "${PARSED_ARGS[@]}" else - error_output=$(zig cc -target ${SPC_TARGET}-${SPC_LIBC}.${SPC_LIBC_VERSION} "${PARSED_ARGS[@]}" 2>&1 >/dev/null) - if echo "$error_output" | grep -q "zig: error: version '.*' in target triple '${SPC_TARGET}-${SPC_LIBC}\..*' is invalid"; then - exec zig cc -target ${SPC_TARGET}-${SPC_LIBC} -L/usr/lib64 -lstdc++ "${PARSED_ARGS[@]}" + TARGET="${SPC_TARGET}-${SPC_LIBC}" + [ -n "$SPC_LIBC_VERSION" ] && TARGET="${TARGET}.${SPC_LIBC_VERSION}" + + output=$(zig cc -target "$TARGET" -L"$LIBDIR" -lstdc++ "${PARSED_ARGS[@]}" 2>&1) + status=$? + + filtered_output=$(echo "$output" | grep -v "version '.*' in target triple") + + if [ $status -eq 0 ]; then + echo "$filtered_output" + exit 0 + fi + + if echo "$output" | grep -q "version '.*' in target triple"; then + TARGET_FALLBACK="${SPC_TARGET}-${SPC_LIBC}" + output=$(zig cc -target "$TARGET_FALLBACK" -L"$LIBDIR" -lstdc++ "${PARSED_ARGS[@]}" 2>&1) + status=$? + + filtered_output=$(echo "$output" | grep -v "version '.*' in target triple") + + if [ $status -eq 0 ]; then + echo "$filtered_output" + exit 0 + else + exec zig cc -target "$TARGET_FALLBACK" "${PARSED_ARGS[@]}" + fi else - exec zig cc -target ${SPC_TARGET}-${SPC_LIBC}.${SPC_LIBC_VERSION} -L/usr/lib64 -lstdc++ "${PARSED_ARGS[@]}" + echo "$filtered_output" + exec zig cc -target "$TARGET" "${PARSED_ARGS[@]}" fi fi - EOF; file_put_contents("{$bin_dir}/zig-cc", $script_content); From e408a2cf1ddc9d7f3fb1d4f9c0b593e7b02b4d85 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 15:55:41 +0700 Subject: [PATCH 034/278] suggestion and aarch64 fix --- docs/en/guide/extension-notes.md | 2 +- src/SPC/builder/linux/library/openssl.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/en/guide/extension-notes.md b/docs/en/guide/extension-notes.md index 91ea531e3..7b0f91aad 100644 --- a/docs/en/guide/extension-notes.md +++ b/docs/en/guide/extension-notes.md @@ -52,7 +52,7 @@ This extension contains an implementation of the coroutine environment for `pdo_ ## imagick -1. Openmp support is disabled, this is recommended by the maintainers and also the case system packages. +1. OpenMP support is disabled, this is recommended by the maintainers and also the case system packages. ## imap diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index 2a36fe81b..76049ccc5 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -62,7 +62,8 @@ public function build(): void $ex_lib = trim($ex_lib); - $clang_postfix = SystemUtil::getCCType() === 'clang' ? '-clang' : ''; + /* @phpstan-ignore-next-line */ + $clang_postfix = SystemUtil::getCCType() === 'clang' && (GNU_ARCH === 'x86_64' || PHP_OS_FAMILY === 'Darwin') ? '-clang' : ''; shell()->cd($this->source_dir)->initializeEnv($this) ->exec( From fff16b4019a61b92c963611285ae4ac737d74258 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 16:03:57 +0700 Subject: [PATCH 035/278] refactor our --- src/SPC/store/pkg/Zig.php | 103 +------------------------------- src/SPC/store/scripts/zig-cc.sh | 99 ++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 101 deletions(-) create mode 100644 src/SPC/store/scripts/zig-cc.sh diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index b085b686e..7b1f9fcd6 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -130,107 +130,8 @@ public static function getEnvironment(): array private function createZigCcScript(string $bin_dir): void { - $script_content = <<<'EOF' -#!/usr/bin/env bash - -LIBDIR="$(realpath "$(dirname "$(gcc -print-file-name=libc.so)")")" -SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" -BUILDROOT_ABS="$(realpath "$SCRIPT_DIR/../../buildroot/include" 2>/dev/null || echo "")" -PARSED_ARGS=() - -while [[ $# -gt 0 ]]; do - case "$1" in - -isystem) - shift - ARG="$1" - [[ -n "$ARG" ]] && shift || break - ARG_ABS="$(realpath "$ARG" 2>/dev/null || echo "")" - if [[ -n "$ARG_ABS" && "$ARG_ABS" == "$BUILDROOT_ABS" ]]; then - PARSED_ARGS+=("-I$ARG") - else - PARSED_ARGS+=("-isystem" "$ARG") - fi - ;; - -isystem*) - ARG="${1#-isystem}" - shift - ARG_ABS="$(realpath "$ARG" 2>/dev/null || echo "")" - if [[ -n "$ARG_ABS" && "$ARG_ABS" == "$BUILDROOT_ABS" ]]; then - PARSED_ARGS+=("-I$ARG") - else - PARSED_ARGS+=("-isystem$ARG") - fi - ;; - *) - PARSED_ARGS+=("$1") - shift - ;; - esac -done - -SPC_TARGET_WAS_SET=1 -if [ -z "${SPC_TARGET+x}" ]; then - SPC_TARGET_WAS_SET=0 -fi - -UNAME_M="$(uname -m)" -UNAME_S="$(uname -s)" - -case "$UNAME_M" in - x86_64) ARCH="x86_64" ;; - aarch64|arm64) ARCH="aarch64" ;; - *) echo "Unsupported architecture: $UNAME_M" >&2; exit 1 ;; -esac - -case "$UNAME_S" in - Linux) OS="linux" ;; - Darwin) OS="macos" ;; - *) echo "Unsupported OS: $UNAME_S" >&2; exit 1 ;; -esac - -SPC_TARGET="${SPC_TARGET:-$ARCH-$OS}" - -if [ "$SPC_LIBC" = "glibc" ]; then - SPC_LIBC="gnu" -fi - -if [ "$SPC_TARGET_WAS_SET" -eq 0 ] && [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then - exec zig cc "${PARSED_ARGS[@]}" -elif [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then - exec zig cc -target ${SPC_TARGET} "${PARSED_ARGS[@]}" -else - TARGET="${SPC_TARGET}-${SPC_LIBC}" - [ -n "$SPC_LIBC_VERSION" ] && TARGET="${TARGET}.${SPC_LIBC_VERSION}" - - output=$(zig cc -target "$TARGET" -L"$LIBDIR" -lstdc++ "${PARSED_ARGS[@]}" 2>&1) - status=$? - - filtered_output=$(echo "$output" | grep -v "version '.*' in target triple") - - if [ $status -eq 0 ]; then - echo "$filtered_output" - exit 0 - fi - - if echo "$output" | grep -q "version '.*' in target triple"; then - TARGET_FALLBACK="${SPC_TARGET}-${SPC_LIBC}" - output=$(zig cc -target "$TARGET_FALLBACK" -L"$LIBDIR" -lstdc++ "${PARSED_ARGS[@]}" 2>&1) - status=$? - - filtered_output=$(echo "$output" | grep -v "version '.*' in target triple") - - if [ $status -eq 0 ]; then - echo "$filtered_output" - exit 0 - else - exec zig cc -target "$TARGET_FALLBACK" "${PARSED_ARGS[@]}" - fi - else - echo "$filtered_output" - exec zig cc -target "$TARGET" "${PARSED_ARGS[@]}" - fi -fi -EOF; + $script_path = __DIR__ . '/../scripts/zig-cc.sh'; + $script_content = file_get_contents($script_path); file_put_contents("{$bin_dir}/zig-cc", $script_content); chmod("{$bin_dir}/zig-cc", 0755); diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh new file mode 100644 index 000000000..e9574a16c --- /dev/null +++ b/src/SPC/store/scripts/zig-cc.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash + +LIBDIR="$(realpath "$(dirname "$(gcc -print-file-name=libc.so)")")" +SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" +BUILDROOT_ABS="$(realpath "$SCRIPT_DIR/../../buildroot/include" 2>/dev/null || echo "")" +PARSED_ARGS=() + +while [[ $# -gt 0 ]]; do + case "$1" in + -isystem) + shift + ARG="$1" + [[ -n "$ARG" ]] && shift || break + ARG_ABS="$(realpath "$ARG" 2>/dev/null || echo "")" + if [[ -n "$ARG_ABS" && "$ARG_ABS" == "$BUILDROOT_ABS" ]]; then + PARSED_ARGS+=("-I$ARG") + else + PARSED_ARGS+=("-isystem" "$ARG") + fi + ;; + -isystem*) + ARG="${1#-isystem}" + shift + ARG_ABS="$(realpath "$ARG" 2>/dev/null || echo "")" + if [[ -n "$ARG_ABS" && "$ARG_ABS" == "$BUILDROOT_ABS" ]]; then + PARSED_ARGS+=("-I$ARG") + else + PARSED_ARGS+=("-isystem$ARG") + fi + ;; + *) + PARSED_ARGS+=("$1") + shift + ;; + esac +done + +SPC_TARGET_WAS_SET=1 +if [ -z "${SPC_TARGET+x}" ]; then + SPC_TARGET_WAS_SET=0 +fi + +UNAME_M="$(uname -m)" +UNAME_S="$(uname -s)" + +case "$UNAME_M" in + x86_64) ARCH="x86_64" ;; + aarch64|arm64) ARCH="aarch64" ;; + *) echo "Unsupported architecture: $UNAME_M" >&2; exit 1 ;; +esac + +case "$UNAME_S" in + Linux) OS="linux" ;; + Darwin) OS="macos" ;; + *) echo "Unsupported OS: $UNAME_S" >&2; exit 1 ;; +esac + +SPC_TARGET="${SPC_TARGET:-$ARCH-$OS}" + +if [ "$SPC_LIBC" = "glibc" ]; then + SPC_LIBC="gnu" +fi + +if [ "$SPC_TARGET_WAS_SET" -eq 0 ] && [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then + exec zig cc "${PARSED_ARGS[@]}" +elif [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then + exec zig cc -target ${SPC_TARGET} "${PARSED_ARGS[@]}" +else + TARGET="${SPC_TARGET}-${SPC_LIBC}" + [ -n "$SPC_LIBC_VERSION" ] && TARGET="${TARGET}.${SPC_LIBC_VERSION}" + + output=$(zig cc -target "$TARGET" -L"$LIBDIR" -lstdc++ "${PARSED_ARGS[@]}" 2>&1) + status=$? + + filtered_output=$(echo "$output" | grep -v "version '.*' in target triple") + + if [ $status -eq 0 ]; then + echo "$filtered_output" + exit 0 + fi + + if echo "$output" | grep -q "version '.*' in target triple"; then + TARGET_FALLBACK="${SPC_TARGET}-${SPC_LIBC}" + output=$(zig cc -target "$TARGET_FALLBACK" -L"$LIBDIR" -lstdc++ "${PARSED_ARGS[@]}" 2>&1) + status=$? + + filtered_output=$(echo "$output" | grep -v "version '.*' in target triple") + + if [ $status -eq 0 ]; then + echo "$filtered_output" + exit 0 + else + exec zig cc -target "$TARGET_FALLBACK" "${PARSED_ARGS[@]}" + fi + else + echo "$filtered_output" + exec zig cc -target "$TARGET" "${PARSED_ARGS[@]}" + fi +fi From 815ba75c76aa3d4b8647a79e3f59c52f7eec22af Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 16:43:37 +0700 Subject: [PATCH 036/278] we can build musl with zig cc too, don't need musl toolchain --- src/SPC/builder/linux/LinuxBuilder.php | 2 +- src/SPC/builder/unix/library/attr.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index b2181c7f9..89bee4366 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -30,7 +30,7 @@ public function __construct(array $options = []) GlobalEnvManager::init(); - if (getenv('SPC_LIBC') === 'musl' && !SystemUtil::isMuslDist()) { + if (getenv('SPC_LIBC') === 'musl' && !SystemUtil::isMuslDist() && !str_contains((string)getenv('CC'), 'zig')) { $this->setOptionIfNotExist('library_path', "LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\""); $this->setOptionIfNotExist('ld_library_path', "LD_LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\""); $configure = getenv('SPC_CMD_PREFIX_PHP_CONFIGURE'); diff --git a/src/SPC/builder/unix/library/attr.php b/src/SPC/builder/unix/library/attr.php index 439acf38e..71fe2623d 100644 --- a/src/SPC/builder/unix/library/attr.php +++ b/src/SPC/builder/unix/library/attr.php @@ -15,6 +15,9 @@ trait attr protected function build(): void { UnixAutoconfExecutor::create($this) + ->appendEnv([ + 'CFLAGS' => '-Wno-int-conversion -Wno-implicit-function-declaration', + ]) ->exec('libtoolize --force --copy') ->exec('./autogen.sh || autoreconf -if') ->configure('--disable-nls') From 5801d05047fcfbea7b8d91d413e72d964b41f89e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 16:47:07 +0700 Subject: [PATCH 037/278] test musl (I have not tested this yet!) --- src/SPC/builder/linux/LinuxBuilder.php | 2 +- src/globals/test-extensions.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 89bee4366..a4b35403c 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -30,7 +30,7 @@ public function __construct(array $options = []) GlobalEnvManager::init(); - if (getenv('SPC_LIBC') === 'musl' && !SystemUtil::isMuslDist() && !str_contains((string)getenv('CC'), 'zig')) { + if (getenv('SPC_LIBC') === 'musl' && !SystemUtil::isMuslDist() && !str_contains((string) getenv('CC'), 'zig')) { $this->setOptionIfNotExist('library_path', "LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\""); $this->setOptionIfNotExist('ld_library_path', "LD_LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\""); $configure = getenv('SPC_CMD_PREFIX_PHP_CONFIGURE'); diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index a1c4f470e..a3876569f 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -35,7 +35,7 @@ $zig = true; // temporary! if ($zig) { - putenv('SPC_LIBC=glibc'); + putenv('SPC_LIBC=musl'); putenv('SPC_LIBC_VERSION=2.17'); putenv('CC=zig-cc'); putenv('CXX=zig-c++'); @@ -63,7 +63,7 @@ // If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`). $shared_extensions = match (PHP_OS_FAMILY) { - 'Linux' => 'event,uv,intl,gettext', + 'Linux' => '', 'Darwin' => '', 'Windows' => '', }; From 176e5627e581264655c284605d326c8488890f7f Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 16:49:26 +0700 Subject: [PATCH 038/278] hahaha, musl 2.17 is a little far away --- 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 a3876569f..490e1d809 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -36,7 +36,7 @@ // temporary! if ($zig) { putenv('SPC_LIBC=musl'); - putenv('SPC_LIBC_VERSION=2.17'); + // putenv('SPC_LIBC_VERSION=2.17'); putenv('CC=zig-cc'); putenv('CXX=zig-c++'); } From 03a33d87ff6f3b44b228492e79093420ca228c94 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 17:23:37 +0700 Subject: [PATCH 039/278] fix frankenphp build --- src/SPC/builder/unix/UnixBuilderBase.php | 23 +++++++++++++++++------ src/SPC/util/GlobalEnvManager.php | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 519475d34..71de56091 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -16,7 +16,9 @@ use SPC\store\Downloader; use SPC\store\FileSystem; use SPC\store\pkg\GoXcaddy; +use SPC\store\pkg\Zig; use SPC\util\DependencyUtil; +use SPC\util\GlobalEnvManager; use SPC\util\SPCConfigUtil; abstract class UnixBuilderBase extends BuilderBase @@ -52,7 +54,7 @@ public function getAllStaticLibFiles(): array array_unshift($libFiles, ...$lib->getStaticLibs()); } } - return array_map(fn ($x) => realpath(BUILD_LIB_PATH . "/{$x}"), $libFiles); + return array_map(fn($x) => realpath(BUILD_LIB_PATH . "/{$x}"), $libFiles); } /** @@ -98,7 +100,8 @@ public function makeAutoconfArgs(string $name, array $libSpecs): string if ($lib instanceof LinuxLibraryBase || $lib instanceof MacOSLibraryBase || $lib instanceof BSDLibraryBase) { logger()->info("{$name} \033[32;1mwith\033[0;1m {$libName} support"); $ret .= "--with-{$libName}=yes " . $lib->makeAutoconfEnv($prefix) . ' '; - } else { + } + else { logger()->info("{$name} \033[31;1mwithout\033[0;1m {$libName} support"); $ret .= ($disableArgs ?? "--with-{$libName}=no") . ' '; } @@ -212,7 +215,8 @@ protected function sanityCheck(int $build_target): void if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { $ext_path = 'LD_LIBRARY_PATH=' . BUILD_ROOT_PATH . '/lib:$LD_LIBRARY_PATH '; FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.a'); - } else { + } + else { $ext_path = ''; FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.so'); } @@ -241,7 +245,7 @@ protected function sanityCheck(int $build_target): void /** * 将编译好的二进制文件发布到 buildroot * - * @param int $type 发布类型 + * @param int $type 发布类型 * @throws RuntimeException * @throws FileSystemException */ @@ -333,7 +337,7 @@ protected function buildFrankenphp(): void $config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list, with_dependencies: true); - $env = [...GoXcaddy::getEnvironment(), ...[ + $env = [ 'CGO_ENABLED' => '1', 'CGO_CFLAGS' => $config['cflags'], 'CGO_LDFLAGS' => "{$config['ldflags']} {$config['libs']} {$lrt}", @@ -343,7 +347,14 @@ protected function buildFrankenphp(): void "{$frankenPhpVersion} PHP {$libphpVersion} Caddy'\\\" " . "-tags={$muslTags}nobadger,nomysql,nopgx{$nobrotli}{$nowatcher}", 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, - ]]; + ]; + foreach (GoXcaddy::getEnvironment() as $key => $value) { + if ($key === 'PATH') { + GlobalEnvManager::addPathIfNotExists($value); + } else { + $env[$key] = $value; + } + } shell()->cd(BUILD_BIN_PATH) ->setEnv($env) ->exec("xcaddy build --output frankenphp {$xcaddyModules}"); diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index baf38e7ac..80f770168 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -117,7 +117,7 @@ public static function putenv(string $val): void self::$env_cache[] = $val; } - private static function addPathIfNotExists(string $path): void + public static function addPathIfNotExists(string $path): void { if (is_unix() && !str_contains(getenv('PATH'), $path)) { self::putenv("PATH={$path}:" . getenv('PATH')); From 2ff78e531e8b420f9d849e35b875707e6e5d9fce Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 17:25:46 +0700 Subject: [PATCH 040/278] cs fix, where did that come from? --- src/SPC/builder/unix/UnixBuilderBase.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 71de56091..367df0361 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -16,7 +16,6 @@ use SPC\store\Downloader; use SPC\store\FileSystem; use SPC\store\pkg\GoXcaddy; -use SPC\store\pkg\Zig; use SPC\util\DependencyUtil; use SPC\util\GlobalEnvManager; use SPC\util\SPCConfigUtil; @@ -54,7 +53,7 @@ public function getAllStaticLibFiles(): array array_unshift($libFiles, ...$lib->getStaticLibs()); } } - return array_map(fn($x) => realpath(BUILD_LIB_PATH . "/{$x}"), $libFiles); + return array_map(fn ($x) => realpath(BUILD_LIB_PATH . "/{$x}"), $libFiles); } /** @@ -100,8 +99,7 @@ public function makeAutoconfArgs(string $name, array $libSpecs): string if ($lib instanceof LinuxLibraryBase || $lib instanceof MacOSLibraryBase || $lib instanceof BSDLibraryBase) { logger()->info("{$name} \033[32;1mwith\033[0;1m {$libName} support"); $ret .= "--with-{$libName}=yes " . $lib->makeAutoconfEnv($prefix) . ' '; - } - else { + } else { logger()->info("{$name} \033[31;1mwithout\033[0;1m {$libName} support"); $ret .= ($disableArgs ?? "--with-{$libName}=no") . ' '; } @@ -215,8 +213,7 @@ protected function sanityCheck(int $build_target): void if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { $ext_path = 'LD_LIBRARY_PATH=' . BUILD_ROOT_PATH . '/lib:$LD_LIBRARY_PATH '; FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.a'); - } - else { + } else { $ext_path = ''; FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.so'); } @@ -245,7 +242,7 @@ protected function sanityCheck(int $build_target): void /** * 将编译好的二进制文件发布到 buildroot * - * @param int $type 发布类型 + * @param int $type 发布类型 * @throws RuntimeException * @throws FileSystemException */ From 9a3ce775a8a03f174c5e9c2bc686f8d94f8417b5 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 17:36:50 +0700 Subject: [PATCH 041/278] complete test suite --- src/globals/test-extensions.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 490e1d809..f27055328 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -36,7 +36,7 @@ // temporary! if ($zig) { putenv('SPC_LIBC=musl'); - // putenv('SPC_LIBC_VERSION=2.17'); + putenv('SPC_LIBC_VERSION=2.17'); putenv('CC=zig-cc'); putenv('CXX=zig-c++'); } @@ -57,13 +57,13 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'curl,iconv', + 'Linux', 'Darwin' => 'apcu,ast,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,iconv,libxml,mbregex,mbstring,opcache,openssl,pcntl,phar,posix,readline,session,simplexml,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter,zip,zlib', 'Windows' => 'intl', }; // If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`). $shared_extensions = match (PHP_OS_FAMILY) { - 'Linux' => '', + 'Linux' => ' amqp,brotli,bz2,dio,ds,ev,event,ffi,ftp,gd,gettext,gmp,gmssl,igbinary,imagick,inotify,intl,ldap,lz4,memcache,memcached,mongodb,msgpack,mysqli,mysqlnd,odbc,opentelemetry,parallel,pdo,pdo_mysql,pdo_odbc,pdo_pgsql,pdo_sqlite,pdo_sqlsrv,pgsql,protobuf,rar,redis,rdkafka,shmop,spx,sqlite3,sqlsrv,ssh2,swoole,sysvmsg,sysvsem,sysvshm,tidy,uuid,uv,xdebug,xhprof,xlswriter,xsl,xz,yac,yaml,zstd', 'Darwin' => '', 'Windows' => '', }; @@ -117,7 +117,8 @@ function _getCombination(string $type = 'common'): string if (PHP_OS_FAMILY === 'Windows') { $final_extensions_cmd = '"' . $final_extensions . '"'; -} else { +} +else { $final_extensions_cmd = $final_extensions; } @@ -175,7 +176,8 @@ function quote2(string $param): string $shared_cmd = ''; break; } -} else { +} +else { $shared_cmd = ''; } From 2b4eb7127d75a21bbcd97bf7827a667683164bee Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 17:39:05 +0700 Subject: [PATCH 042/278] what the frick is going on with my phpstorm --- src/globals/test-extensions.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index f27055328..3c3617176 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -117,8 +117,7 @@ function _getCombination(string $type = 'common'): string if (PHP_OS_FAMILY === 'Windows') { $final_extensions_cmd = '"' . $final_extensions . '"'; -} -else { +} else { $final_extensions_cmd = $final_extensions; } @@ -176,8 +175,7 @@ function quote2(string $param): string $shared_cmd = ''; break; } -} -else { +} else { $shared_cmd = ''; } From 7edd8e6e1905ebd98c97f78c87c3446d7783425e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 17:39:42 +0700 Subject: [PATCH 043/278] test glibc of course --- 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 3c3617176..dda53a770 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -35,7 +35,7 @@ $zig = true; // temporary! if ($zig) { - putenv('SPC_LIBC=musl'); + putenv('SPC_LIBC=glibc'); putenv('SPC_LIBC_VERSION=2.17'); putenv('CC=zig-cc'); putenv('CXX=zig-c++'); From 8c7049913b36b1d8f744f12eb6d2ccdc22bb1956 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 17:56:33 +0700 Subject: [PATCH 044/278] can build shared extensions on ubuntu 24.04 now --- src/globals/test-extensions.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index dda53a770..66116fc38 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -165,6 +165,12 @@ function quote2(string $param): string case 'ubuntu-22.04-arm': $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; break; + case 'ubuntu-24.04': + case 'ubuntu-24.04-arm': + if (getenv('SPC_LIBC') === 'glibc') { + $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; + } + break; case 'macos-13': case 'macos-14': case 'macos-15': From 6dec25b4f429c11bc6dabd74c2d7a40fa4c20f48 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 26 Jun 2025 22:03:08 +0700 Subject: [PATCH 045/278] space --- 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 66116fc38..01568c942 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -63,7 +63,7 @@ // If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`). $shared_extensions = match (PHP_OS_FAMILY) { - 'Linux' => ' amqp,brotli,bz2,dio,ds,ev,event,ffi,ftp,gd,gettext,gmp,gmssl,igbinary,imagick,inotify,intl,ldap,lz4,memcache,memcached,mongodb,msgpack,mysqli,mysqlnd,odbc,opentelemetry,parallel,pdo,pdo_mysql,pdo_odbc,pdo_pgsql,pdo_sqlite,pdo_sqlsrv,pgsql,protobuf,rar,redis,rdkafka,shmop,spx,sqlite3,sqlsrv,ssh2,swoole,sysvmsg,sysvsem,sysvshm,tidy,uuid,uv,xdebug,xhprof,xlswriter,xsl,xz,yac,yaml,zstd', + 'Linux' => 'amqp,brotli,bz2,dio,ds,ev,event,ffi,ftp,gd,gettext,gmp,gmssl,igbinary,imagick,inotify,intl,ldap,lz4,memcache,memcached,mongodb,msgpack,mysqli,mysqlnd,odbc,opentelemetry,parallel,pdo,pdo_mysql,pdo_odbc,pdo_pgsql,pdo_sqlite,pdo_sqlsrv,pgsql,protobuf,rar,redis,rdkafka,shmop,spx,sqlite3,sqlsrv,ssh2,swoole,sysvmsg,sysvsem,sysvshm,tidy,uuid,uv,xdebug,xhprof,xlswriter,xsl,xz,yac,yaml,zstd', 'Darwin' => '', 'Windows' => '', }; From d94542049c9fe756b695fb007ec319c749d35947 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 26 Jun 2025 22:58:48 +0700 Subject: [PATCH 046/278] Update test-extensions.php no debug do I can see where it 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 01568c942..bcffa5ded 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -196,7 +196,7 @@ function quote2(string $param): string $build_cmd .= $upx ? '--with-upx-pack ' : ''; $build_cmd .= $final_libs === '' ? '' : ('--with-libs=' . quote2($final_libs) . ' '); $build_cmd .= str_starts_with($argv[2], 'windows-') ? '' : '--build-fpm '; - $build_cmd .= '--debug '; + $build_cmd .= ''; } echo match ($argv[1]) { From 55d78579c83881b94db1744b9345881579b2648f Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 00:11:21 +0700 Subject: [PATCH 047/278] pgsql x86_64 fix? --- src/SPC/builder/Extension.php | 8 ++++++++ src/SPC/builder/extension/pgsql.php | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 459f5f02b..6666c429d 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -414,6 +414,7 @@ public function buildUnixShared(): void // prepare configure args shell()->cd($this->source_dir) ->setEnv($env) + ->appendEnv($this->getExtraEnv()) ->exec(BUILD_BIN_PATH . '/phpize'); if ($this->patchBeforeSharedConfigure()) { @@ -422,6 +423,7 @@ public function buildUnixShared(): void shell()->cd($this->source_dir) ->setEnv($env) + ->appendEnv($this->getExtraEnv()) ->exec( './configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config ' . @@ -441,6 +443,7 @@ public function buildUnixShared(): void shell()->cd($this->source_dir) ->setEnv($env) + ->appendEnv($this->getExtraEnv()) ->exec('make clean') ->exec('make -j' . $this->builder->concurrency) ->exec('make install'); @@ -577,4 +580,9 @@ private function getLibraryDependencies(bool $recursive = false): array } return $deps; } + + protected function getExtraEnv(): array + { + return []; + } } diff --git a/src/SPC/builder/extension/pgsql.php b/src/SPC/builder/extension/pgsql.php index a70c1fb72..12545fd6d 100644 --- a/src/SPC/builder/extension/pgsql.php +++ b/src/SPC/builder/extension/pgsql.php @@ -57,4 +57,11 @@ public function getWindowsConfigureArg(bool $shared = false): string } return '--with-pgsql=' . BUILD_ROOT_PATH; } + + protected function getExtraEnv(): array + { + return [ + 'CFLAGS' => '-Wno-int-conversion -Wno-implicit-function-declaration' + ]; + } } From cc4ec4b598a19158c36f87b53ed667d52c0c2af2 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 00:17:24 +0700 Subject: [PATCH 048/278] add back debug --- src/SPC/builder/Extension.php | 10 +++++----- src/SPC/builder/extension/pgsql.php | 2 +- src/globals/test-extensions.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 6666c429d..ec162461b 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -548,6 +548,11 @@ protected function getStaticAndSharedLibs(): array return [trim($staticLibString), trim($sharedLibString)]; } + protected function getExtraEnv(): array + { + return []; + } + private function getLibraryDependencies(bool $recursive = false): array { $ret = array_filter($this->dependencies, fn ($x) => $x instanceof LibraryBase); @@ -580,9 +585,4 @@ private function getLibraryDependencies(bool $recursive = false): array } return $deps; } - - protected function getExtraEnv(): array - { - return []; - } } diff --git a/src/SPC/builder/extension/pgsql.php b/src/SPC/builder/extension/pgsql.php index 12545fd6d..3ddb5fdca 100644 --- a/src/SPC/builder/extension/pgsql.php +++ b/src/SPC/builder/extension/pgsql.php @@ -61,7 +61,7 @@ public function getWindowsConfigureArg(bool $shared = false): string protected function getExtraEnv(): array { return [ - 'CFLAGS' => '-Wno-int-conversion -Wno-implicit-function-declaration' + 'CFLAGS' => '-Wno-int-conversion -Wno-implicit-function-declaration', ]; } } diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index bcffa5ded..01568c942 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -196,7 +196,7 @@ function quote2(string $param): string $build_cmd .= $upx ? '--with-upx-pack ' : ''; $build_cmd .= $final_libs === '' ? '' : ('--with-libs=' . quote2($final_libs) . ' '); $build_cmd .= str_starts_with($argv[2], 'windows-') ? '' : '--build-fpm '; - $build_cmd .= ''; + $build_cmd .= '--debug '; } echo match ($argv[1]) { From 5a7fd8c24ed11085dd1134b00f50d9cc1ade2ecb Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 09:26:57 +0700 Subject: [PATCH 049/278] we shouldn't need that, need to figure out the cause --- src/SPC/builder/extension/pgsql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/extension/pgsql.php b/src/SPC/builder/extension/pgsql.php index 3ddb5fdca..e1788cfaa 100644 --- a/src/SPC/builder/extension/pgsql.php +++ b/src/SPC/builder/extension/pgsql.php @@ -61,7 +61,7 @@ public function getWindowsConfigureArg(bool $shared = false): string protected function getExtraEnv(): array { return [ - 'CFLAGS' => '-Wno-int-conversion -Wno-implicit-function-declaration', + 'CFLAGS' => '-Wno-int-conversion', ]; } } From 797aaf1ea8279972b6a0ce51c92e28fe80f4c705 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 14:51:36 +0700 Subject: [PATCH 050/278] remove libdir --- src/SPC/store/scripts/zig-cc.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index e9574a16c..a4e5c0550 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash -LIBDIR="$(realpath "$(dirname "$(gcc -print-file-name=libc.so)")")" SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" BUILDROOT_ABS="$(realpath "$SCRIPT_DIR/../../buildroot/include" 2>/dev/null || echo "")" PARSED_ARGS=() @@ -69,7 +68,7 @@ else TARGET="${SPC_TARGET}-${SPC_LIBC}" [ -n "$SPC_LIBC_VERSION" ] && TARGET="${TARGET}.${SPC_LIBC_VERSION}" - output=$(zig cc -target "$TARGET" -L"$LIBDIR" -lstdc++ "${PARSED_ARGS[@]}" 2>&1) + output=$(zig cc -target "$TARGET" -lstdc++ "${PARSED_ARGS[@]}" 2>&1) status=$? filtered_output=$(echo "$output" | grep -v "version '.*' in target triple") @@ -81,7 +80,7 @@ else if echo "$output" | grep -q "version '.*' in target triple"; then TARGET_FALLBACK="${SPC_TARGET}-${SPC_LIBC}" - output=$(zig cc -target "$TARGET_FALLBACK" -L"$LIBDIR" -lstdc++ "${PARSED_ARGS[@]}" 2>&1) + output=$(zig cc -target "$TARGET_FALLBACK" -lstdc++ "${PARSED_ARGS[@]}" 2>&1) status=$? filtered_output=$(echo "$output" | grep -v "version '.*' in target triple") From d2dea83c6391d84c217d330cec20992cfd017889 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 18:21:22 +0700 Subject: [PATCH 051/278] don't check for musl toolkit when running zig, add -static to ncurses --- src/SPC/builder/unix/library/ncurses.php | 4 ++++ src/SPC/doctor/item/LinuxMuslCheck.php | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/SPC/builder/unix/library/ncurses.php b/src/SPC/builder/unix/library/ncurses.php index 14d2a6dc7..0222357a7 100644 --- a/src/SPC/builder/unix/library/ncurses.php +++ b/src/SPC/builder/unix/library/ncurses.php @@ -14,6 +14,9 @@ protected function build(): void $filelist = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true); UnixAutoconfExecutor::create($this) + ->appendEnv([ + 'LDFLAGS' => getenv('SPC_LIBC') === 'musl' ? '-static' : '' + ]) ->configure( '--enable-overwrite', '--with-curses-h', @@ -22,6 +25,7 @@ protected function build(): void '--disable-widec', '--with-normal', '--with-ticlib', + '--with-pthread', '--without-tests', '--without-dlsym', '--without-debug', diff --git a/src/SPC/doctor/item/LinuxMuslCheck.php b/src/SPC/doctor/item/LinuxMuslCheck.php index 155163552..5aad5f75e 100644 --- a/src/SPC/doctor/item/LinuxMuslCheck.php +++ b/src/SPC/doctor/item/LinuxMuslCheck.php @@ -29,6 +29,9 @@ public function checkMusl(): CheckResult if (getenv('SPC_LIBC') === 'glibc') { return CheckResult::ok('Building with glibc, skipped'); } + if (str_contains(getenv('CC'), 'zig')) { + return CheckResult::ok('Building with zig, skipped'); + } $musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m')); if (file_exists($musl_wrapper_lib) && file_exists('/usr/local/musl/lib/libc.a')) { @@ -46,6 +49,9 @@ public function checkMuslCrossMake(): CheckResult if (getenv('SPC_LIBC') === 'glibc') { return CheckResult::ok('Building with glibc, skipped'); } + if (str_contains(getenv('CC'), 'zig')) { + return CheckResult::ok('Building with zig, skipped'); + } $arch = arch2gnu(php_uname('m')); $cross_compile_lib = "/usr/local/musl/{$arch}-linux-musl/lib/libc.a"; From e6bec8eb57fff4d550743ac84ac788d499cc399c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 19:25:29 +0700 Subject: [PATCH 052/278] fix lib extra cflags --- src/SPC/builder/traits/UnixLibraryTrait.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SPC/builder/traits/UnixLibraryTrait.php b/src/SPC/builder/traits/UnixLibraryTrait.php index e98a6f3a8..2f2717791 100644 --- a/src/SPC/builder/traits/UnixLibraryTrait.php +++ b/src/SPC/builder/traits/UnixLibraryTrait.php @@ -119,9 +119,9 @@ public function getLibExtraCFlags(): string { $env = getenv($this->getSnakeCaseName() . '_CFLAGS') ?: ''; if (!str_contains($env, $this->builder->arch_c_flags)) { - $env .= $this->builder->arch_c_flags; + $env .= ' ' .$this->builder->arch_c_flags; } - return $env; + return trim($env); } public function getLibExtraLdFlags(): string @@ -138,8 +138,8 @@ public function getLibExtraCXXFlags(): string { $env = getenv($this->getSnakeCaseName() . '_CXXFLAGS') ?: ''; if (!str_contains($env, $this->builder->arch_cxx_flags)) { - $env .= $this->builder->arch_cxx_flags; + $env .= ' ' . $this->builder->arch_cxx_flags; } - return $env; + return trim($env); } } From 383045d1c0ddff686794998a28dc9dcbdd2d2237 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 19:27:02 +0700 Subject: [PATCH 053/278] cs fix --- src/SPC/builder/traits/UnixLibraryTrait.php | 2 +- src/SPC/builder/unix/library/ncurses.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/traits/UnixLibraryTrait.php b/src/SPC/builder/traits/UnixLibraryTrait.php index 2f2717791..b16886897 100644 --- a/src/SPC/builder/traits/UnixLibraryTrait.php +++ b/src/SPC/builder/traits/UnixLibraryTrait.php @@ -119,7 +119,7 @@ public function getLibExtraCFlags(): string { $env = getenv($this->getSnakeCaseName() . '_CFLAGS') ?: ''; if (!str_contains($env, $this->builder->arch_c_flags)) { - $env .= ' ' .$this->builder->arch_c_flags; + $env .= ' ' . $this->builder->arch_c_flags; } return trim($env); } diff --git a/src/SPC/builder/unix/library/ncurses.php b/src/SPC/builder/unix/library/ncurses.php index 0222357a7..0902174b1 100644 --- a/src/SPC/builder/unix/library/ncurses.php +++ b/src/SPC/builder/unix/library/ncurses.php @@ -15,7 +15,7 @@ protected function build(): void UnixAutoconfExecutor::create($this) ->appendEnv([ - 'LDFLAGS' => getenv('SPC_LIBC') === 'musl' ? '-static' : '' + 'LDFLAGS' => getenv('SPC_LIBC') === 'musl' ? '-static' : '', ]) ->configure( '--enable-overwrite', From e162a0ecd60288b75e0451a9ca6fa5764f6bf874 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 19:37:10 +0700 Subject: [PATCH 054/278] libaom uses different PIC check --- src/SPC/builder/unix/library/libaom.php | 1 + src/SPC/builder/unix/library/ncurses.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/libaom.php b/src/SPC/builder/unix/library/libaom.php index ab5c22b8c..3032b2ab4 100644 --- a/src/SPC/builder/unix/library/libaom.php +++ b/src/SPC/builder/unix/library/libaom.php @@ -16,6 +16,7 @@ trait libaom */ protected function build(): void { + putenv('libaom_CFLAGS=-D__PIE__'); UnixCMakeExecutor::create($this) ->setBuildDir("{$this->source_dir}/builddir") ->addConfigureArgs('-DAOM_TARGET_CPU=generic') diff --git a/src/SPC/builder/unix/library/ncurses.php b/src/SPC/builder/unix/library/ncurses.php index 0902174b1..f1792fa2e 100644 --- a/src/SPC/builder/unix/library/ncurses.php +++ b/src/SPC/builder/unix/library/ncurses.php @@ -25,7 +25,6 @@ protected function build(): void '--disable-widec', '--with-normal', '--with-ticlib', - '--with-pthread', '--without-tests', '--without-dlsym', '--without-debug', From 69e1acd5aec274fc5045262eb478b85a970939a4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 20:28:59 +0700 Subject: [PATCH 055/278] really stupid patch --- src/SPC/builder/unix/library/libaom.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/libaom.php b/src/SPC/builder/unix/library/libaom.php index 3032b2ab4..e4ae12a36 100644 --- a/src/SPC/builder/unix/library/libaom.php +++ b/src/SPC/builder/unix/library/libaom.php @@ -16,11 +16,20 @@ trait libaom */ protected function build(): void { - putenv('libaom_CFLAGS=-D__PIE__'); + $cc = getenv('CC'); + $cxx = getenv('CXX'); + if (str_contains($cc, 'zig') && getenv('SPC_LIBC') === 'musl') { + putenv('CC=' . $cc . ' -D_POSIX_SOURCE'); + putenv('CXX=' . $cxx . ' -D_POSIX_SOURCE'); + } UnixCMakeExecutor::create($this) ->setBuildDir("{$this->source_dir}/builddir") ->addConfigureArgs('-DAOM_TARGET_CPU=generic') ->build(); + if (str_contains($cc, 'zig') && getenv('SPC_LIBC') === 'musl') { + putenv('CC=' . $cc); + putenv('CXX=' . $cxx); + } $this->patchPkgconfPrefix(['aom.pc']); } } From ff95b464cefd04cf1d0d1573aa5b600e3744719b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 21:26:06 +0700 Subject: [PATCH 056/278] really stupid patch for swoole --- src/SPC/builder/extension/swoole.php | 10 ++++++++-- src/globals/patch/swoole_fix_date_time.patch | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/globals/patch/swoole_fix_date_time.patch diff --git a/src/SPC/builder/extension/swoole.php b/src/SPC/builder/extension/swoole.php index 6ce006b97..93d959b73 100644 --- a/src/SPC/builder/extension/swoole.php +++ b/src/SPC/builder/extension/swoole.php @@ -7,6 +7,7 @@ use SPC\builder\Extension; use SPC\builder\macos\MacOSBuilder; use SPC\store\FileSystem; +use SPC\store\SourcePatcher; use SPC\util\CustomExt; #[CustomExt('swoole')] @@ -14,13 +15,18 @@ class swoole extends Extension { public function patchBeforeMake(): bool { + $patched = false; + if (PHP_OS_FAMILY === 'Linux') { + SourcePatcher::patchFile('swoole_fix_date_time.patch', $this->source_dir); + $patched = true; + } if ($this->builder instanceof MacOSBuilder) { // Fix swoole with event extension conflict bug $util_path = shell()->execWithResult('xcrun --show-sdk-path', false)[1][0] . '/usr/include/util.h'; FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/swoole/thirdparty/php/standard/proc_open.cc', 'include ', 'include "' . $util_path . '"'); - return true; + $patched = true; } - return false; + return $patched; } public function getExtVersion(): ?string diff --git a/src/globals/patch/swoole_fix_date_time.patch b/src/globals/patch/swoole_fix_date_time.patch new file mode 100644 index 000000000..b4a056def --- /dev/null +++ b/src/globals/patch/swoole_fix_date_time.patch @@ -0,0 +1,10 @@ +--- a/config.m4 ++++ b/config.m4 +@@ -425,6 +425,7 @@ + AX_CHECK_COMPILE_FLAG(-Wloop-analysis, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wloop-analysis") + AX_CHECK_COMPILE_FLAG(-Wuninitialized, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wuninitialized") + AX_CHECK_COMPILE_FLAG(-Wno-missing-field-initializers, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-missing-field-initializers") ++ AX_CHECK_COMPILE_FLAG(-Wno-date-time, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-date-time") + AX_CHECK_COMPILE_FLAG(-Wno-sign-compare, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-sign-compare") + AX_CHECK_COMPILE_FLAG(-Wno-unused-const-variable, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-unused-const-variable") + AX_CHECK_COMPILE_FLAG(-Wno-unused-parameter, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-unused-parameter") From e92f043cfa845968b4033ecee9694e782928fdd4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 21:38:16 +0700 Subject: [PATCH 057/278] really stupid patch for swoole --- src/globals/patch/swoole_fix_date_time.patch | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/globals/patch/swoole_fix_date_time.patch b/src/globals/patch/swoole_fix_date_time.patch index b4a056def..e94ddd0e5 100644 --- a/src/globals/patch/swoole_fix_date_time.patch +++ b/src/globals/patch/swoole_fix_date_time.patch @@ -1,10 +1,11 @@ --- a/config.m4 +++ b/config.m4 -@@ -425,6 +425,7 @@ - AX_CHECK_COMPILE_FLAG(-Wloop-analysis, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wloop-analysis") - AX_CHECK_COMPILE_FLAG(-Wuninitialized, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wuninitialized") - AX_CHECK_COMPILE_FLAG(-Wno-missing-field-initializers, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-missing-field-initializers") -+ AX_CHECK_COMPILE_FLAG(-Wno-date-time, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-date-time") - AX_CHECK_COMPILE_FLAG(-Wno-sign-compare, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-sign-compare") - AX_CHECK_COMPILE_FLAG(-Wno-unused-const-variable, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-unused-const-variable") - AX_CHECK_COMPILE_FLAG(-Wno-unused-parameter, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-unused-parameter") +@@ -1307,7 +1307,7 @@ + + PHP_REQUIRE_CXX() + +- CXXFLAGS="$CXXFLAGS -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations" ++ CXXFLAGS="$CXXFLAGS -Wall -Wno-date-time -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations" + + if test "$SW_OS" = "CYGWIN" || test "$SW_OS" = "MINGW"; then + CXXFLAGS="$CXXFLAGS -std=gnu++14" From 43dc04b4d062f63ee3bd53a3b6ffccea163d4c3a Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 22:01:37 +0700 Subject: [PATCH 058/278] building shared libphp.so on musl is really pointless and should be an error, since static compilations cannot load it --- src/SPC/builder/linux/LinuxBuilder.php | 6 ++++++ src/SPC/builder/unix/UnixBuilderBase.php | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index a4b35403c..39059201e 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -139,6 +139,9 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void } $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; + if ($embed_type !== 'static' && getenv('SPC_LIBC') === 'musl') { + throw new RuntimeException('Musl libc does not support dynamic linking of PHP embed!'); + } shell()->cd(SOURCE_PATH . '/php-src') ->exec( getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' . @@ -335,6 +338,9 @@ protected function buildEmbed(): void } chdir($cwd); } + if (!$this->getOption('no-strip', false)) { + shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-all php'); + } $this->patchPhpScripts(); } diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 367df0361..cc4536dda 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -327,9 +327,11 @@ protected function buildFrankenphp(): void $debugFlags = $this->getOption('no-strip') ? "'-w -s' " : ''; $extLdFlags = "-extldflags '-pie'"; $muslTags = ''; + $staticFlags = ''; if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') { $extLdFlags = "-extldflags '-static-pie -Wl,-z,stack-size=0x80000'"; $muslTags = 'static_build,'; + $staticFlags = '-static -static-pie'; } $config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list, with_dependencies: true); @@ -337,7 +339,7 @@ protected function buildFrankenphp(): void $env = [ 'CGO_ENABLED' => '1', 'CGO_CFLAGS' => $config['cflags'], - 'CGO_LDFLAGS' => "{$config['ldflags']} {$config['libs']} {$lrt}", + 'CGO_LDFLAGS' => "$staticFlags {$config['ldflags']} {$config['libs']} {$lrt}", 'XCADDY_GO_BUILD_FLAGS' => '-buildmode=pie ' . '-ldflags \"-linkmode=external ' . $extLdFlags . ' ' . $debugFlags . '-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' . From 464c2dca85e8531ecd193d4eb3dc1072d6a882ed Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 22:01:56 +0700 Subject: [PATCH 059/278] cs fix --- src/SPC/builder/unix/UnixBuilderBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index cc4536dda..c55e1bb76 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -339,7 +339,7 @@ protected function buildFrankenphp(): void $env = [ 'CGO_ENABLED' => '1', 'CGO_CFLAGS' => $config['cflags'], - 'CGO_LDFLAGS' => "$staticFlags {$config['ldflags']} {$config['libs']} {$lrt}", + 'CGO_LDFLAGS' => "{$staticFlags} {$config['ldflags']} {$config['libs']} {$lrt}", 'XCADDY_GO_BUILD_FLAGS' => '-buildmode=pie ' . '-ldflags \"-linkmode=external ' . $extLdFlags . ' ' . $debugFlags . '-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' . From 96babd093948a2f5f62d53cab8f779610e4c757f Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 22:06:19 +0700 Subject: [PATCH 060/278] crazy test --- src/globals/test-extensions.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 01568c942..09fa55f01 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -35,10 +35,11 @@ $zig = true; // temporary! if ($zig) { - putenv('SPC_LIBC=glibc'); - putenv('SPC_LIBC_VERSION=2.17'); + putenv('SPC_LIBC=musl'); + // putenv('SPC_LIBC_VERSION=2.17'); putenv('CC=zig-cc'); putenv('CXX=zig-c++'); + exec('ulimit -n 2048'); } // whether enable thread safe @@ -57,7 +58,7 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'apcu,ast,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,iconv,libxml,mbregex,mbstring,opcache,openssl,pcntl,phar,posix,readline,session,simplexml,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter,zip,zlib', + 'Linux', 'Darwin' => 'apcu,ast,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,iconv,libxml,mbregex,mbstring,opcache,openssl,pcntl,phar,posix,readline,session,simplexml,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter,zip,zlib,amqp,brotli,bz2,dio,ds,ev,event,ffi,ftp,gd,gettext,gmp,gmssl,igbinary,imagick,inotify,intl,ldap,lz4,memcache,memcached,mongodb,msgpack,mysqli,mysqlnd,odbc,opentelemetry,parallel,pdo,pdo_mysql,pdo_odbc,pdo_pgsql,pdo_sqlite,pdo_sqlsrv,pgsql,protobuf,rar,redis,rdkafka,shmop,spx,sqlite3,sqlsrv,ssh2,swoole,sysvmsg,sysvsem,sysvshm,tidy,uuid,uv,xhprof,xlswriter,xsl,xz,yac,yaml,zstd', 'Windows' => 'intl', }; From f5281535d9e16af32e845861d08200af82c1fc24 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 22:48:15 +0700 Subject: [PATCH 061/278] strip libphp.so and frankenphp --- src/SPC/builder/linux/LinuxBuilder.php | 7 ++++--- src/SPC/builder/unix/UnixBuilderBase.php | 6 +++++- src/SPC/util/GlobalEnvManager.php | 8 +++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 39059201e..c63a81b09 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -140,7 +140,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; if ($embed_type !== 'static' && getenv('SPC_LIBC') === 'musl') { - throw new RuntimeException('Musl libc does not support dynamic linking of PHP embed!'); + throw new WrongUsageException('Musl libc does not support dynamic linking of PHP embed!'); } shell()->cd(SOURCE_PATH . '/php-src') ->exec( @@ -300,6 +300,7 @@ protected function buildEmbed(): void ->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install"); $ldflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'); + $realLibName = 'libphp.so'; if (preg_match('/-release\s+(\S+)/', $ldflags, $matches)) { $release = $matches[1]; $realLibName = 'libphp-' . $release . '.so'; @@ -338,8 +339,8 @@ protected function buildEmbed(): void } chdir($cwd); } - if (!$this->getOption('no-strip', false)) { - shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-all php'); + if (!$this->getOption('no-strip', false) && file_exists(BUILD_LIB_PATH . '/' . $realLibName)) { + shell()->cd(BUILD_LIB_PATH)->exec("strip --strip-all $realLibName"); } $this->patchPhpScripts(); } diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index c55e1bb76..0e3b6ab62 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -209,7 +209,7 @@ protected function sanityCheck(int $build_target): void if ($ret !== 0) { throw new RuntimeException('embed failed sanity check: build failed. Error message: ' . implode("\n", $out)); } - // if someone changed to --enable-embed=shared, we need to add LD_LIBRARY_PATH + // if someone changed to EMBED_TYPE=shared, we need to add LD_LIBRARY_PATH if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { $ext_path = 'LD_LIBRARY_PATH=' . BUILD_ROOT_PATH . '/lib:$LD_LIBRARY_PATH '; FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.a'); @@ -357,5 +357,9 @@ protected function buildFrankenphp(): void shell()->cd(BUILD_BIN_PATH) ->setEnv($env) ->exec("xcaddy build --output frankenphp {$xcaddyModules}"); + + if (!$this->getOption('no-strip', false) && file_exists(BUILD_BIN_PATH . '/frankenphp')) { + shell()->cd(BUILD_BIN_PATH)->exec('strip --strip-all frankenphp'); + } } } diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index 80f770168..9c4984a90 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -44,7 +44,13 @@ public static function init(): void // Define env vars for linux if (PHP_OS_FAMILY === 'Linux') { $arch = getenv('GNU_ARCH'); - if (SystemUtil::isMuslDist() || getenv('SPC_LIBC') === 'glibc') { + + if (str_contains(getenv('CC'), 'zig')) { + self::putenv('SPC_LINUX_DEFAULT_CC=zig-cc'); + self::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++'); + self::putenv('SPC_LINUX_DEFAULT_AR=ar'); + self::putenv('SPC_LINUX_DEFAULT_LD=ld.lld'); + } elseif (SystemUtil::isMuslDist() || getenv('SPC_LIBC') === 'glibc') { self::putenv('SPC_LINUX_DEFAULT_CC=gcc'); self::putenv('SPC_LINUX_DEFAULT_CXX=g++'); self::putenv('SPC_LINUX_DEFAULT_AR=ar'); From b6240f16fb3e728bdaa090d9e60d58ddb18303ab Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 22:51:53 +0700 Subject: [PATCH 062/278] clean files before compiling because it may try to link the wrong one --- src/SPC/builder/unix/UnixBuilderBase.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 0e3b6ab62..79afdf161 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -205,17 +205,19 @@ protected function sanityCheck(int $build_target): void if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') { $lens .= ' -static'; } - [$ret, $out] = shell()->cd($sample_file_path)->execWithResult(getenv('CC') . ' -o embed embed.c ' . $lens); - if ($ret !== 0) { - throw new RuntimeException('embed failed sanity check: build failed. Error message: ' . implode("\n", $out)); - } // if someone changed to EMBED_TYPE=shared, we need to add LD_LIBRARY_PATH if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { $ext_path = 'LD_LIBRARY_PATH=' . BUILD_ROOT_PATH . '/lib:$LD_LIBRARY_PATH '; FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.a'); } else { $ext_path = ''; - FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.so'); + foreach (glob(BUILD_LIB_PATH . '/libphp*.so') as $file) { + unlink($file); + } + } + [$ret, $out] = shell()->cd($sample_file_path)->execWithResult(getenv('CC') . ' -o embed embed.c ' . $lens); + if ($ret !== 0) { + throw new RuntimeException('embed failed sanity check: build failed. Error message: ' . implode("\n", $out)); } [$ret, $output] = shell()->cd($sample_file_path)->execWithResult($ext_path . './embed'); if ($ret !== 0 || trim(implode('', $output)) !== 'hello') { From 4c8a173213d528d5bc25917021144f2fb251977e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 22:53:04 +0700 Subject: [PATCH 063/278] build_lib_path is better --- src/SPC/builder/linux/LinuxBuilder.php | 2 +- src/SPC/builder/unix/UnixBuilderBase.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index c63a81b09..1de5a41c8 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -340,7 +340,7 @@ protected function buildEmbed(): void chdir($cwd); } if (!$this->getOption('no-strip', false) && file_exists(BUILD_LIB_PATH . '/' . $realLibName)) { - shell()->cd(BUILD_LIB_PATH)->exec("strip --strip-all $realLibName"); + shell()->cd(BUILD_LIB_PATH)->exec("strip --strip-all {$realLibName}"); } $this->patchPhpScripts(); } diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 79afdf161..435f0b9b3 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -207,8 +207,8 @@ protected function sanityCheck(int $build_target): void } // if someone changed to EMBED_TYPE=shared, we need to add LD_LIBRARY_PATH if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { - $ext_path = 'LD_LIBRARY_PATH=' . BUILD_ROOT_PATH . '/lib:$LD_LIBRARY_PATH '; - FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.a'); + $ext_path = 'LD_LIBRARY_PATH=' . BUILD_LIB_PATH . ':$LD_LIBRARY_PATH '; + FileSystem::removeFileIfExists(BUILD_LIB_PATH . '/libphp.a'); } else { $ext_path = ''; foreach (glob(BUILD_LIB_PATH . '/libphp*.so') as $file) { From aff9ff20e80fd328a00131cda93a5f45fa34c407 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 22:55:23 +0700 Subject: [PATCH 064/278] test fix? --- src/globals/test-extensions.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 09fa55f01..3d45fa4a9 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -39,6 +39,8 @@ // putenv('SPC_LIBC_VERSION=2.17'); putenv('CC=zig-cc'); putenv('CXX=zig-c++'); + putenv('AR=ar'); + putenv('LD=ld.lld'); exec('ulimit -n 2048'); } From efb1ff5a9376266bbfda4e2db80261bdec92ea60 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 22:56:49 +0700 Subject: [PATCH 065/278] test fix 2? --- src/SPC/util/GlobalEnvManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index 9c4984a90..06f681c50 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -45,7 +45,7 @@ public static function init(): void if (PHP_OS_FAMILY === 'Linux') { $arch = getenv('GNU_ARCH'); - if (str_contains(getenv('CC'), 'zig')) { + if (str_contains((string) getenv('CC'), 'zig')) { self::putenv('SPC_LINUX_DEFAULT_CC=zig-cc'); self::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++'); self::putenv('SPC_LINUX_DEFAULT_AR=ar'); From aa516522aab9dde2df0b7bde9b662a5e4c1bedc8 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 27 Jun 2025 23:35:04 +0700 Subject: [PATCH 066/278] why isn't this triggered? --- src/SPC/builder/unix/library/libaom.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SPC/builder/unix/library/libaom.php b/src/SPC/builder/unix/library/libaom.php index e4ae12a36..f636f0722 100644 --- a/src/SPC/builder/unix/library/libaom.php +++ b/src/SPC/builder/unix/library/libaom.php @@ -19,16 +19,16 @@ protected function build(): void $cc = getenv('CC'); $cxx = getenv('CXX'); if (str_contains($cc, 'zig') && getenv('SPC_LIBC') === 'musl') { - putenv('CC=' . $cc . ' -D_POSIX_SOURCE'); - putenv('CXX=' . $cxx . ' -D_POSIX_SOURCE'); + f_putenv('CC=' . $cc . ' -D_POSIX_SOURCE'); + f_putenv('CXX=' . $cxx . ' -D_POSIX_SOURCE'); } UnixCMakeExecutor::create($this) ->setBuildDir("{$this->source_dir}/builddir") ->addConfigureArgs('-DAOM_TARGET_CPU=generic') ->build(); if (str_contains($cc, 'zig') && getenv('SPC_LIBC') === 'musl') { - putenv('CC=' . $cc); - putenv('CXX=' . $cxx); + f_putenv('CC=' . $cc); + f_putenv('CXX=' . $cxx); } $this->patchPkgconfPrefix(['aom.pc']); } From 61274cb8650ff6876c7d4f261d170aeec9ab090c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 28 Jun 2025 21:21:29 +0700 Subject: [PATCH 067/278] use extra COMPILER_EXTRA env variable to make sure it's actually passed to compiler --- src/SPC/builder/unix/library/libaom.php | 12 +++--------- src/SPC/store/scripts/zig-cc.sh | 21 ++++++++------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/SPC/builder/unix/library/libaom.php b/src/SPC/builder/unix/library/libaom.php index f636f0722..d0b7c88c9 100644 --- a/src/SPC/builder/unix/library/libaom.php +++ b/src/SPC/builder/unix/library/libaom.php @@ -16,20 +16,14 @@ trait libaom */ protected function build(): void { - $cc = getenv('CC'); - $cxx = getenv('CXX'); - if (str_contains($cc, 'zig') && getenv('SPC_LIBC') === 'musl') { - f_putenv('CC=' . $cc . ' -D_POSIX_SOURCE'); - f_putenv('CXX=' . $cxx . ' -D_POSIX_SOURCE'); + if (getenv('SPC_LIBC') === 'musl' && str_contains(getenv('CC'), 'zig')) { + f_putenv('COMPILER_EXTRA=-D_POSIX_SOURCE'); } UnixCMakeExecutor::create($this) ->setBuildDir("{$this->source_dir}/builddir") ->addConfigureArgs('-DAOM_TARGET_CPU=generic') ->build(); - if (str_contains($cc, 'zig') && getenv('SPC_LIBC') === 'musl') { - f_putenv('CC=' . $cc); - f_putenv('CXX=' . $cxx); - } + f_putenv('COMPILER_EXTRA'); $this->patchPkgconfPrefix(['aom.pc']); } } diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index a4e5c0550..be2a7d1bc 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -61,38 +61,33 @@ if [ "$SPC_LIBC" = "glibc" ]; then fi if [ "$SPC_TARGET_WAS_SET" -eq 0 ] && [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then - exec zig cc "${PARSED_ARGS[@]}" + exec zig cc "${COMPILER_EXTRA}" "${PARSED_ARGS[@]}" elif [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then - exec zig cc -target ${SPC_TARGET} "${PARSED_ARGS[@]}" + exec zig cc -target "${SPC_TARGET}" "${COMPILER_EXTRA}" "${PARSED_ARGS[@]}" else TARGET="${SPC_TARGET}-${SPC_LIBC}" [ -n "$SPC_LIBC_VERSION" ] && TARGET="${TARGET}.${SPC_LIBC_VERSION}" - output=$(zig cc -target "$TARGET" -lstdc++ "${PARSED_ARGS[@]}" 2>&1) + output=$(zig cc -target "$TARGET" -lstdc++ "${COMPILER_EXTRA}" "${PARSED_ARGS[@]}" 2>&1) status=$? - filtered_output=$(echo "$output" | grep -v "version '.*' in target triple") - if [ $status -eq 0 ]; then - echo "$filtered_output" + echo "$output" | grep -v "version '.*' in target triple" exit 0 fi if echo "$output" | grep -q "version '.*' in target triple"; then TARGET_FALLBACK="${SPC_TARGET}-${SPC_LIBC}" - output=$(zig cc -target "$TARGET_FALLBACK" -lstdc++ "${PARSED_ARGS[@]}" 2>&1) + output=$(zig cc -target "$TARGET_FALLBACK" -lstdc++ "${COMPILER_EXTRA}" "${PARSED_ARGS[@]}" 2>&1) status=$? - filtered_output=$(echo "$output" | grep -v "version '.*' in target triple") - if [ $status -eq 0 ]; then - echo "$filtered_output" + echo "$output" exit 0 else - exec zig cc -target "$TARGET_FALLBACK" "${PARSED_ARGS[@]}" + exec zig cc -target "$TARGET_FALLBACK" "${COMPILER_EXTRA}" "${PARSED_ARGS[@]}" fi else - echo "$filtered_output" - exec zig cc -target "$TARGET" "${PARSED_ARGS[@]}" + exec zig cc -target "$TARGET" "${COMPILER_EXTRA}" "${PARSED_ARGS[@]}" fi fi From 4a493f3f6d4771dbd41f08a386d3af97dbab946c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 28 Jun 2025 21:50:57 +0700 Subject: [PATCH 068/278] don't set rpath because on musl it'll fall over with static binaries --- src/SPC/builder/linux/library/libmemcached.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/linux/library/libmemcached.php b/src/SPC/builder/linux/library/libmemcached.php index fb09b52ab..d1e35bfc9 100644 --- a/src/SPC/builder/linux/library/libmemcached.php +++ b/src/SPC/builder/linux/library/libmemcached.php @@ -12,6 +12,8 @@ class libmemcached extends LinuxLibraryBase public function build(): void { - UnixCMakeExecutor::create($this)->build(); + UnixCMakeExecutor::create($this) + ->addConfigureArgs('-DCMAKE_INSTALL_RPATH=""') + ->build(); } } From de3cb2f68686b01f7e28281e312d8de74db666ad Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 28 Jun 2025 21:59:12 +0700 Subject: [PATCH 069/278] no "" --- src/SPC/store/scripts/zig-cc.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index be2a7d1bc..1459a0fc0 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -61,14 +61,14 @@ if [ "$SPC_LIBC" = "glibc" ]; then fi if [ "$SPC_TARGET_WAS_SET" -eq 0 ] && [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then - exec zig cc "${COMPILER_EXTRA}" "${PARSED_ARGS[@]}" + exec zig cc ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" elif [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then - exec zig cc -target "${SPC_TARGET}" "${COMPILER_EXTRA}" "${PARSED_ARGS[@]}" + exec zig cc -target "${SPC_TARGET}" ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" else TARGET="${SPC_TARGET}-${SPC_LIBC}" [ -n "$SPC_LIBC_VERSION" ] && TARGET="${TARGET}.${SPC_LIBC_VERSION}" - output=$(zig cc -target "$TARGET" -lstdc++ "${COMPILER_EXTRA}" "${PARSED_ARGS[@]}" 2>&1) + output=$(zig cc -target "$TARGET" -lstdc++ ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" 2>&1) status=$? if [ $status -eq 0 ]; then @@ -78,16 +78,16 @@ else if echo "$output" | grep -q "version '.*' in target triple"; then TARGET_FALLBACK="${SPC_TARGET}-${SPC_LIBC}" - output=$(zig cc -target "$TARGET_FALLBACK" -lstdc++ "${COMPILER_EXTRA}" "${PARSED_ARGS[@]}" 2>&1) + output=$(zig cc -target "$TARGET_FALLBACK" -lstdc++ ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" 2>&1) status=$? if [ $status -eq 0 ]; then echo "$output" exit 0 else - exec zig cc -target "$TARGET_FALLBACK" "${COMPILER_EXTRA}" "${PARSED_ARGS[@]}" + exec zig cc -target "$TARGET_FALLBACK" ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" fi else - exec zig cc -target "$TARGET" "${COMPILER_EXTRA}" "${PARSED_ARGS[@]}" + exec zig cc -target "$TARGET" ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" fi fi From 9e9474a0266005ae9555dd34a68fc179b52979b9 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 28 Jun 2025 22:09:58 +0700 Subject: [PATCH 070/278] extra patch for swoole for CFLAGS too --- src/globals/patch/swoole_fix_date_time.patch | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/globals/patch/swoole_fix_date_time.patch b/src/globals/patch/swoole_fix_date_time.patch index e94ddd0e5..97c391d16 100644 --- a/src/globals/patch/swoole_fix_date_time.patch +++ b/src/globals/patch/swoole_fix_date_time.patch @@ -1,11 +1,19 @@ --- a/config.m4 +++ b/config.m4 -@@ -1307,7 +1307,7 @@ - +@@ -426,6 +426,7 @@ + AX_CHECK_COMPILE_FLAG(-Wlogical-op-parentheses, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wlogical-op-parentheses") + AX_CHECK_COMPILE_FLAG(-Wloop-analysis, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wloop-analysis") + AX_CHECK_COMPILE_FLAG(-Wuninitialized, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wuninitialized") ++ AX_CHECK_COMPILE_FLAG(-Wno-date-time, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-date-time") + AX_CHECK_COMPILE_FLAG(-Wno-missing-field-initializers, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-missing-field-initializers") + AX_CHECK_COMPILE_FLAG(-Wno-sign-compare, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-sign-compare") + AX_CHECK_COMPILE_FLAG(-Wno-unused-const-variable, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-unused-const-variable") +@@ -1307,7 +1308,7 @@ + PHP_REQUIRE_CXX() - + - CXXFLAGS="$CXXFLAGS -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations" + CXXFLAGS="$CXXFLAGS -Wall -Wno-date-time -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations" - + if test "$SW_OS" = "CYGWIN" || test "$SW_OS" = "MINGW"; then CXXFLAGS="$CXXFLAGS -std=gnu++14" From 02f2837f8600b4c846775c98bc6e859d454a26cb Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 28 Jun 2025 22:55:30 +0700 Subject: [PATCH 071/278] adjust craft command for zig --- src/SPC/command/CraftCommand.php | 11 ++++++++++- src/SPC/store/pkg/Zig.php | 16 ++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/SPC/command/CraftCommand.php b/src/SPC/command/CraftCommand.php index c8003a3e1..7f6f506b6 100644 --- a/src/SPC/command/CraftCommand.php +++ b/src/SPC/command/CraftCommand.php @@ -71,7 +71,16 @@ public function handle(): int $retcode = $this->runCommand('install-pkg', 'go-xcaddy'); if ($retcode !== 0) { $this->output->writeln('craft go-xcaddy failed'); - $this->log("craft go-xcaddy failed with code: {$retcode}", true); + $this->log("craft: spc install-pkg go-xcaddy failed with code: {$retcode}", true); + return static::FAILURE; + } + } + // install zig if requested + if (str_contains(getenv('CC'), 'zig')) { + $retcode = $this->runCommand('install-pkg', 'zig'); + if ($retcode !== 0) { + $this->output->writeln('craft zig failed'); + $this->log("craft: spc install-pkg zig failed with code: {$retcode}", true); return static::FAILURE; } } diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index 7b1f9fcd6..ded551204 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -30,7 +30,11 @@ public function fetch(string $name, bool $force = false, ?array $config = null): default => "{$pkgroot}/{$name}/bin/zig", }; - if (file_exists($zig_exec) && !$force) { + if ($force) { + FileSystem::removeDir($pkgroot . '/' . $name); + } + + if (file_exists($zig_exec)) { return; } @@ -73,13 +77,13 @@ public function fetch(string $name, bool $force = false, ?array $config = null): $url = $download_info['tarball']; $filename = basename($url); - $config = [ + $pkg = [ 'type' => 'url', 'url' => $url, 'filename' => $filename, ]; - Downloader::downloadPackage($name, $config, $force); + Downloader::downloadPackage($name, $pkg, $force); } public function extract(string $name): void @@ -91,11 +95,7 @@ public function extract(string $name): void default => "{$zig_bin_dir}/zig", }; - if (file_exists($zig_exec)) { - if (!file_exists("{$zig_bin_dir}/zig-cc")) { - $this->createZigCcScript($zig_bin_dir); - return; - } + if (file_exists($zig_exec) && file_exists("{$zig_bin_dir}/zig-cc")) { return; } From a7bf1e967663814a6afea1316b272fb7696b0ad9 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 28 Jun 2025 23:33:13 +0700 Subject: [PATCH 072/278] we need to patch swoole early enough --- src/SPC/builder/extension/swoole.php | 5 ---- src/SPC/store/SourcePatcher.php | 34 +++++++++++++++------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/SPC/builder/extension/swoole.php b/src/SPC/builder/extension/swoole.php index 93d959b73..ec32e90dd 100644 --- a/src/SPC/builder/extension/swoole.php +++ b/src/SPC/builder/extension/swoole.php @@ -7,7 +7,6 @@ use SPC\builder\Extension; use SPC\builder\macos\MacOSBuilder; use SPC\store\FileSystem; -use SPC\store\SourcePatcher; use SPC\util\CustomExt; #[CustomExt('swoole')] @@ -16,10 +15,6 @@ class swoole extends Extension public function patchBeforeMake(): bool { $patched = false; - if (PHP_OS_FAMILY === 'Linux') { - SourcePatcher::patchFile('swoole_fix_date_time.patch', $this->source_dir); - $patched = true; - } if ($this->builder instanceof MacOSBuilder) { // Fix swoole with event extension conflict bug $util_path = shell()->execWithResult('xcrun --show-sdk-path', false)[1][0] . '/usr/include/util.h'; diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 69d3a6495..638d394d0 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -16,22 +16,22 @@ class SourcePatcher { public static function init(): void { - // FileSystem::addSourceExtractHook('swow', [SourcePatcher::class, 'patchSwow']); - FileSystem::addSourceExtractHook('micro', [SourcePatcher::class, 'patchMicro']); - FileSystem::addSourceExtractHook('openssl', [SourcePatcher::class, 'patchOpenssl11Darwin']); - FileSystem::addSourceExtractHook('swoole', [SourcePatcher::class, 'patchSwoole']); - FileSystem::addSourceExtractHook('php-src', [SourcePatcher::class, 'patchPhpLibxml212']); - FileSystem::addSourceExtractHook('php-src', [SourcePatcher::class, 'patchGDWin32']); - FileSystem::addSourceExtractHook('php-src', [SourcePatcher::class, 'patchFfiCentos7FixO3strncmp']); - FileSystem::addSourceExtractHook('sqlsrv', [SourcePatcher::class, 'patchSQLSRVWin32']); - FileSystem::addSourceExtractHook('pdo_sqlsrv', [SourcePatcher::class, 'patchSQLSRVWin32']); - FileSystem::addSourceExtractHook('yaml', [SourcePatcher::class, 'patchYamlWin32']); - FileSystem::addSourceExtractHook('libyaml', [SourcePatcher::class, 'patchLibYaml']); - FileSystem::addSourceExtractHook('php-src', [SourcePatcher::class, 'patchImapLicense']); - FileSystem::addSourceExtractHook('ext-imagick', [SourcePatcher::class, 'patchImagickWith84']); - FileSystem::addSourceExtractHook('libaom', [SourcePatcher::class, 'patchLibaomForAlpine']); - FileSystem::addSourceExtractHook('attr', [SourcePatcher::class, 'patchAttrForAlpine']); - FileSystem::addSourceExtractHook('gmssl', [SourcePatcher::class, 'patchGMSSL']); + // FileSystem::addSourceExtractHook('swow', [__CLASS__, 'patchSwow']); + FileSystem::addSourceExtractHook('micro', [__CLASS__, 'patchMicro']); + FileSystem::addSourceExtractHook('openssl', [__CLASS__, 'patchOpenssl11Darwin']); + FileSystem::addSourceExtractHook('swoole', [__CLASS__, 'patchSwoole']); + FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchPhpLibxml212']); + FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchGDWin32']); + FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchFfiCentos7FixO3strncmp']); + FileSystem::addSourceExtractHook('sqlsrv', [__CLASS__, 'patchSQLSRVWin32']); + FileSystem::addSourceExtractHook('pdo_sqlsrv', [__CLASS__, 'patchSQLSRVWin32']); + FileSystem::addSourceExtractHook('yaml', [__CLASS__, 'patchYamlWin32']); + FileSystem::addSourceExtractHook('libyaml', [__CLASS__, 'patchLibYaml']); + FileSystem::addSourceExtractHook('php-src', [__CLASS__, 'patchImapLicense']); + FileSystem::addSourceExtractHook('ext-imagick', [__CLASS__, 'patchImagickWith84']); + FileSystem::addSourceExtractHook('libaom', [__CLASS__, 'patchLibaomForAlpine']); + FileSystem::addSourceExtractHook('attr', [__CLASS__, 'patchAttrForAlpine']); + FileSystem::addSourceExtractHook('gmssl', [__CLASS__, 'patchGMSSL']); } /** @@ -229,6 +229,7 @@ public static function patchSwoole(): bool 'PHP_ADD_INCLUDE([$ext_srcdir])', "PHP_ADD_INCLUDE( [\$ext_srcdir] )\n PHP_ADD_INCLUDE([\$abs_srcdir/ext])" ); + // swoole 5.1.3 build fix // get swoole version first $file = SOURCE_PATH . '/php-src/ext/swoole/include/swoole_version.h'; @@ -242,6 +243,7 @@ public static function patchSwoole(): bool if ($version === '5.1.3') { self::patchFile('spc_fix_swoole_50513.patch', SOURCE_PATH . '/php-src/ext/swoole'); } + self::patchFile('swoole_fix_date_time.patch', SOURCE_PATH . '/php-src/ext/swoole'); return true; } From 19ddddf6186d281dc3990b47161e7c05abf21036 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 28 Jun 2025 23:45:02 +0700 Subject: [PATCH 073/278] self:: instead of SourcePatcher:: --- src/SPC/store/SourcePatcher.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 638d394d0..284d88969 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -73,9 +73,9 @@ public static function patchBeforeBuildconf(BuilderBase $builder): void FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/build/php.m4', 'PKG_CHECK_MODULES(', 'PKG_CHECK_MODULES_STATIC('); if ($builder->getOption('enable-micro-win32')) { - SourcePatcher::patchMicroWin32(); + self::patchMicroWin32(); } else { - SourcePatcher::unpatchMicroWin32(); + self::unpatchMicroWin32(); } } @@ -450,7 +450,7 @@ public static function patchImagickWith84(): bool } $extnum = intval($match[1]); if ($extnum < 30800) { - SourcePatcher::patchFile('imagick_php84_before_30800.patch', SOURCE_PATH . '/php-src/ext/imagick'); + self::patchFile('imagick_php84_before_30800.patch', SOURCE_PATH . '/php-src/ext/imagick'); return true; } return false; @@ -468,14 +468,14 @@ public static function patchFfiCentos7FixO3strncmp(): bool if (preg_match('/PHP_VERSION_ID (\d+)/', $file, $match) !== 0 && intval($match[1]) < 80316) { return false; } - SourcePatcher::patchFile('ffi_centos7_fix_O3_strncmp.patch', SOURCE_PATH . '/php-src'); + self::patchFile('ffi_centos7_fix_O3_strncmp.patch', SOURCE_PATH . '/php-src'); return true; } public static function patchLibaomForAlpine(): bool { if (PHP_OS_FAMILY === 'Linux' && SystemUtil::isMuslDist()) { - SourcePatcher::patchFile('libaom_posix_implict.patch', SOURCE_PATH . '/libaom'); + self::patchFile('libaom_posix_implict.patch', SOURCE_PATH . '/libaom'); return true; } return false; @@ -484,7 +484,7 @@ public static function patchLibaomForAlpine(): bool public static function patchAttrForAlpine(): bool { if (PHP_OS_FAMILY === 'Linux' && SystemUtil::isMuslDist() || PHP_OS_FAMILY === 'Darwin') { - SourcePatcher::patchFile('attr_alpine_gethostname.patch', SOURCE_PATH . '/attr'); + self::patchFile('attr_alpine_gethostname.patch', SOURCE_PATH . '/attr'); return true; } return false; From d588e6e4fd8df910a39603949191d5e7170a219e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 29 Jun 2025 00:06:40 +0700 Subject: [PATCH 074/278] just strip out the error and return the output instead of executing again without version --- src/SPC/store/scripts/zig-cc.sh | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index 1459a0fc0..343fec511 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -72,21 +72,13 @@ else status=$? if [ $status -eq 0 ]; then - echo "$output" | grep -v "version '.*' in target triple" + echo "$output" exit 0 fi if echo "$output" | grep -q "version '.*' in target triple"; then - TARGET_FALLBACK="${SPC_TARGET}-${SPC_LIBC}" - output=$(zig cc -target "$TARGET_FALLBACK" -lstdc++ ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" 2>&1) - status=$? - - if [ $status -eq 0 ]; then - echo "$output" - exit 0 - else - exec zig cc -target "$TARGET_FALLBACK" ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" - fi + echo "$output" | grep -v "version '.*' in target triple" + exit 0 else exec zig cc -target "$TARGET" ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" fi From d6b0912492a453e2e9f96fd95a6769c22dc87044 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 29 Jun 2025 00:40:03 +0700 Subject: [PATCH 075/278] run glibc test with shared extensions against 2.28 this time --- src/globals/test-extensions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 3d45fa4a9..bcfc93667 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -35,8 +35,8 @@ $zig = true; // temporary! if ($zig) { - putenv('SPC_LIBC=musl'); - // putenv('SPC_LIBC_VERSION=2.17'); + putenv('SPC_LIBC=glibc'); + putenv('SPC_LIBC_VERSION=2.28'); putenv('CC=zig-cc'); putenv('CXX=zig-c++'); putenv('AR=ar'); @@ -60,7 +60,7 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'apcu,ast,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,iconv,libxml,mbregex,mbstring,opcache,openssl,pcntl,phar,posix,readline,session,simplexml,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter,zip,zlib,amqp,brotli,bz2,dio,ds,ev,event,ffi,ftp,gd,gettext,gmp,gmssl,igbinary,imagick,inotify,intl,ldap,lz4,memcache,memcached,mongodb,msgpack,mysqli,mysqlnd,odbc,opentelemetry,parallel,pdo,pdo_mysql,pdo_odbc,pdo_pgsql,pdo_sqlite,pdo_sqlsrv,pgsql,protobuf,rar,redis,rdkafka,shmop,spx,sqlite3,sqlsrv,ssh2,swoole,sysvmsg,sysvsem,sysvshm,tidy,uuid,uv,xhprof,xlswriter,xsl,xz,yac,yaml,zstd', + 'Linux', 'Darwin' => 'apcu,ast,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,iconv,libxml,mbregex,mbstring,opcache,openssl,pcntl,phar,posix,readline,session,simplexml,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter,zip,zlib', 'Windows' => 'intl', }; From a44d90671c0e8ffa85c4c971fa76eda65ab8fb5a Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 29 Jun 2025 00:49:39 +0700 Subject: [PATCH 076/278] fix existing check for Zig::fetch --- src/SPC/store/pkg/GoXcaddy.php | 3 +++ src/SPC/store/pkg/Zig.php | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/SPC/store/pkg/GoXcaddy.php b/src/SPC/store/pkg/GoXcaddy.php index c61511a30..ca727ecd9 100644 --- a/src/SPC/store/pkg/GoXcaddy.php +++ b/src/SPC/store/pkg/GoXcaddy.php @@ -26,6 +26,9 @@ public function fetch(string $name, bool $force = false, ?array $config = null): $pkgroot = PKG_ROOT_PATH; $go_exec = "{$pkgroot}/{$name}/bin/go"; $xcaddy_exec = "{$pkgroot}/{$name}/bin/xcaddy"; + if ($force) { + FileSystem::removeDir("{$pkgroot}/{$name}"); + } if (file_exists($go_exec) && file_exists($xcaddy_exec)) { return; } diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index ded551204..aa06922f0 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -26,12 +26,12 @@ public function fetch(string $name, bool $force = false, ?array $config = null): { $pkgroot = PKG_ROOT_PATH; $zig_exec = match (PHP_OS_FAMILY) { - 'Windows' => "{$pkgroot}/{$name}/bin/zig.exe", - default => "{$pkgroot}/{$name}/bin/zig", + 'Windows' => "{$pkgroot}/{$name}/zig.exe", + default => "{$pkgroot}/{$name}/zig", }; if ($force) { - FileSystem::removeDir($pkgroot . '/' . $name); + FileSystem::removeDir("{$pkgroot}/{$name}"); } if (file_exists($zig_exec)) { From 1d29ac228c42531a5f008e480c3cb538e7769e36 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 29 Jun 2025 10:40:48 +0700 Subject: [PATCH 077/278] Revert "just strip out the error and return the output instead of executing again without version" This reverts commit d588e6e4fd8df910a39603949191d5e7170a219e. --- src/SPC/store/scripts/zig-cc.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index 343fec511..1459a0fc0 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -72,13 +72,21 @@ else status=$? if [ $status -eq 0 ]; then - echo "$output" + echo "$output" | grep -v "version '.*' in target triple" exit 0 fi if echo "$output" | grep -q "version '.*' in target triple"; then - echo "$output" | grep -v "version '.*' in target triple" - exit 0 + TARGET_FALLBACK="${SPC_TARGET}-${SPC_LIBC}" + output=$(zig cc -target "$TARGET_FALLBACK" -lstdc++ ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" 2>&1) + status=$? + + if [ $status -eq 0 ]; then + echo "$output" + exit 0 + else + exec zig cc -target "$TARGET_FALLBACK" ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" + fi else exec zig cc -target "$TARGET" ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" fi From 6ed62aa05cf5f050dd4613b37a783d4f6afde110 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 29 Jun 2025 13:31:43 +0700 Subject: [PATCH 078/278] use CC=cc to install xcaddy --- src/SPC/store/pkg/GoXcaddy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/store/pkg/GoXcaddy.php b/src/SPC/store/pkg/GoXcaddy.php index ca727ecd9..fa229cef2 100644 --- a/src/SPC/store/pkg/GoXcaddy.php +++ b/src/SPC/store/pkg/GoXcaddy.php @@ -74,7 +74,7 @@ public function extract(string $name): void 'GOBIN' => "{$pkgroot}/{$name}/bin", 'GOPATH' => "{$pkgroot}/go", ]) - ->exec("{$go_exec} install github.com/caddyserver/xcaddy/cmd/xcaddy@latest"); + ->exec("CC=cc {$go_exec} install github.com/caddyserver/xcaddy/cmd/xcaddy@latest"); } public static function getEnvironment(): array From bd25de15cc35fcd7099ac0b6c534353dbeb1c8b0 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 29 Jun 2025 16:50:19 +0700 Subject: [PATCH 079/278] okay this drove me crazy... --- 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 bcfc93667..a2f25979a 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -40,7 +40,7 @@ putenv('CC=zig-cc'); putenv('CXX=zig-c++'); putenv('AR=ar'); - putenv('LD=ld.lld'); + putenv('LD=ld'); exec('ulimit -n 2048'); } From 2564da2615267ec20755556f2d406632481f3d6d Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 29 Jun 2025 16:56:24 +0700 Subject: [PATCH 080/278] Reapply "just strip out the error and return the output instead of executing again without version" This reverts commit 1d29ac228c42531a5f008e480c3cb538e7769e36. --- src/SPC/store/scripts/zig-cc.sh | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index 1459a0fc0..343fec511 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -72,21 +72,13 @@ else status=$? if [ $status -eq 0 ]; then - echo "$output" | grep -v "version '.*' in target triple" + echo "$output" exit 0 fi if echo "$output" | grep -q "version '.*' in target triple"; then - TARGET_FALLBACK="${SPC_TARGET}-${SPC_LIBC}" - output=$(zig cc -target "$TARGET_FALLBACK" -lstdc++ ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" 2>&1) - status=$? - - if [ $status -eq 0 ]; then - echo "$output" - exit 0 - else - exec zig cc -target "$TARGET_FALLBACK" ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" - fi + echo "$output" | grep -v "version '.*' in target triple" + exit 0 else exec zig cc -target "$TARGET" ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" fi From dbdf10c75a673b0c4eec41f99bbe6db42f4edf5f Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 29 Jun 2025 18:24:25 +0700 Subject: [PATCH 081/278] support for dynamic linking of musl libc --- config/env.ini | 2 ++ src/SPC/builder/linux/LinuxBuilder.php | 2 +- src/SPC/builder/unix/UnixBuilderBase.php | 4 +--- src/SPC/command/BuildPHPCommand.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/env.ini b/config/env.ini index c00aafc35..549961488 100644 --- a/config/env.ini +++ b/config/env.ini @@ -65,6 +65,8 @@ SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime [linux] ; include PATH for musl libc. SPC_LIBC=musl +SPC_LIBC_VERSION= +SPC_LIBC_LINKAGE=-static ; compiler environments CC=${SPC_LINUX_DEFAULT_CC} CXX=${SPC_LINUX_DEFAULT_CXX} diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 1de5a41c8..4e30460cf 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -139,7 +139,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void } $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; - if ($embed_type !== 'static' && getenv('SPC_LIBC') === 'musl') { + if ($embed_type !== 'static' && getenv('SPC_LIBC') === 'musl' && getenv('SPC_LIBC_LINKAGE') === '-static') { throw new WrongUsageException('Musl libc does not support dynamic linking of PHP embed!'); } shell()->cd(SOURCE_PATH . '/php-src') diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 435f0b9b3..7a0ed1399 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -202,9 +202,7 @@ protected function sanityCheck(int $build_target): void $util = new SPCConfigUtil($this); $config = $util->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs')); $lens = "{$config['cflags']} {$config['ldflags']} {$config['libs']}"; - if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') { - $lens .= ' -static'; - } + $lens .= ' ' . getenv('SPC_LIBC_LINKAGE'); // if someone changed to EMBED_TYPE=shared, we need to add LD_LIBRARY_PATH if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { $ext_path = 'LD_LIBRARY_PATH=' . BUILD_LIB_PATH . ':$LD_LIBRARY_PATH '; diff --git a/src/SPC/command/BuildPHPCommand.php b/src/SPC/command/BuildPHPCommand.php index 21a848a5e..63a5ef72e 100644 --- a/src/SPC/command/BuildPHPCommand.php +++ b/src/SPC/command/BuildPHPCommand.php @@ -63,7 +63,7 @@ public function handle(): int // check dynamic extension build env // linux must build with glibc - if (!empty($shared_extensions) && PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') !== 'glibc') { + if (!empty($shared_extensions) && PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') !== 'glibc' && getenv('SPC_LIBC_LINKAGE') === '-static') { $this->output->writeln('Linux does not support dynamic extension loading with musl-libc full-static build, please build with glibc!'); return static::FAILURE; } From 78666ff7de752861d94a44f9d905b29c50cb180b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 29 Jun 2025 18:28:42 +0700 Subject: [PATCH 082/278] support for frankenphp linked dynamically too --- src/SPC/builder/unix/UnixBuilderBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 7a0ed1399..d0d1f6803 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -328,7 +328,7 @@ protected function buildFrankenphp(): void $extLdFlags = "-extldflags '-pie'"; $muslTags = ''; $staticFlags = ''; - if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') { + if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl' && getenv('SPC_LIBC_LINKAGE') === 'static') { $extLdFlags = "-extldflags '-static-pie -Wl,-z,stack-size=0x80000'"; $muslTags = 'static_build,'; $staticFlags = '-static -static-pie'; From 3940f032afd4204de0322f845b9ee78fc10c5611 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 29 Jun 2025 21:09:59 +0700 Subject: [PATCH 083/278] fix tests --- src/SPC/util/GlobalEnvManager.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index 06f681c50..e2c9ed9c8 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -107,6 +107,9 @@ public static function init(): void self::putenv("{$k}={$v}"); } } + if (getenv('SPC_LIBC_LINKAGE') === 'static' && getenv('SPC_LIBC') === 'glibc') { + self::putenv('SPC_LIBC_LINKAGE_FLAG='); + } if (str_contains((string) getenv('CC'), 'zig') || str_contains((string) getenv('CXX'), 'zig')) { $zigEnv = Zig::getEnvironment(); foreach ($zigEnv as $key => $value) { From 320c21d272a252106f0fd005b14bb93286c69361 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 29 Jun 2025 22:26:30 +0700 Subject: [PATCH 084/278] -static, not static --- src/SPC/util/GlobalEnvManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index e2c9ed9c8..814a4b1c9 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -107,7 +107,7 @@ public static function init(): void self::putenv("{$k}={$v}"); } } - if (getenv('SPC_LIBC_LINKAGE') === 'static' && getenv('SPC_LIBC') === 'glibc') { + if (getenv('SPC_LIBC_LINKAGE') === '-static' && getenv('SPC_LIBC') === 'glibc') { self::putenv('SPC_LIBC_LINKAGE_FLAG='); } if (str_contains((string) getenv('CC'), 'zig') || str_contains((string) getenv('CXX'), 'zig')) { From 1839f13149243c9286ba8f93e07d2c9f8e21da05 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 29 Jun 2025 22:57:25 +0700 Subject: [PATCH 085/278] thanks, autocomplete, for the useless flag --- src/SPC/util/GlobalEnvManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index 814a4b1c9..fb7172d92 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -108,7 +108,7 @@ public static function init(): void } } if (getenv('SPC_LIBC_LINKAGE') === '-static' && getenv('SPC_LIBC') === 'glibc') { - self::putenv('SPC_LIBC_LINKAGE_FLAG='); + self::putenv('SPC_LIBC_LINKAGE='); } if (str_contains((string) getenv('CC'), 'zig') || str_contains((string) getenv('CXX'), 'zig')) { $zigEnv = Zig::getEnvironment(); From c43a10027b6b37b91f7a3a109970ab5a60a6a73e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 11:02:20 +0700 Subject: [PATCH 086/278] fix --- src/SPC/builder/unix/library/pkgconfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/pkgconfig.php b/src/SPC/builder/unix/library/pkgconfig.php index b5392f4db..e6f672e59 100644 --- a/src/SPC/builder/unix/library/pkgconfig.php +++ b/src/SPC/builder/unix/library/pkgconfig.php @@ -12,7 +12,7 @@ trait pkgconfig protected function build(): void { UnixAutoconfExecutor::create($this) - ->appendEnv([[ + ->appendEnv([ 'CFLAGS' => '-Wimplicit-function-declaration -Wno-int-conversion', 'LDFLAGS' => SPCTarget::isStatic() ? '--static' : '', ]) From ad8322b6a6fc8de2b9ce55305166d9302b2108cc Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 12:55:32 +0700 Subject: [PATCH 087/278] add zig to libc/static target parsing --- src/SPC/builder/Extension.php | 8 +------- src/SPC/util/SPCTarget.php | 31 ++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index e71376dde..fef4855c0 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -529,8 +529,7 @@ protected function getStaticAndSharedLibs(): array $sharedLibString = ''; $staticLibString = ''; $staticLibs = $this->getLibFilesString(); - $staticLibs = str_replace(BUILD_LIB_PATH . '/lib', '-l', $staticLibs); - $staticLibs = str_replace('.a', '', $staticLibs); + $staticLibs = str_replace([BUILD_LIB_PATH . '/lib', '.a'], ['-l', ''], $staticLibs); $staticLibs = explode('-l', $staticLibs . ' ' . $config['libs']); foreach ($staticLibs as $lib) { $lib = trim($lib); @@ -546,11 +545,6 @@ protected function getStaticAndSharedLibs(): array $sharedLibString .= '-l' . $lib . ' '; } } - // move static libstdc++ to shared if we are on non-full-static build target - if (!SPCTarget::isStatic() && in_array(SPCTarget::getLibc(), SPCTarget::LIBC_LIST)) { - $staticLibString .= ' -lstdc++'; - $sharedLibString = str_replace('-lstdc++', '', $sharedLibString); - } return [trim($staticLibString), trim($sharedLibString)]; } diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index 071f26204..7968c5080 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -19,17 +19,27 @@ class SPCTarget ]; /** - * Returns whether the target is a full-static target. + * Returns whether we link the C runtime in statically. */ public static function isStatic(): bool { - $env = getenv('SPC_TARGET'); $libc = getenv('SPC_LIBC'); // if SPC_LIBC is set, it means the target is static, remove it when 3.0 is released if ($libc === 'musl') { return true; } - // TODO: add zig target parser here + if ($target = getenv('SPC_TARGET')) { + if (str_contains($target, '-macos') || str_contains($target, '-native') && PHP_OS_FAMILY === 'Darwin') { + return false; + } + if (str_contains($target, '-gnu')) { + return false; + } + if (str_contains($target, '-dynamic')) { + return false; + } + return true; + } return false; } @@ -38,12 +48,23 @@ public static function isStatic(): bool */ public static function getLibc(): ?string { - $env = getenv('SPC_TARGET'); $libc = getenv('SPC_LIBC'); if ($libc !== false) { return $libc; } - // TODO: zig target parser + $target = getenv('SPC_TARGET'); + if (str_contains($target, '-gnu')) { + return 'glibc'; + } + if (str_contains($target, '-musl')) { + return 'musl'; + } + if (str_contains($target, '-linux')) { + return 'musl'; + } + if (PHP_OS_FAMILY === 'Linux' && str_contains($target, '-native')) { + return 'musl'; + } return null; } From 7b33ee79dd9e17cc3e6b6dddc98862fb28cab584 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 12:56:51 +0700 Subject: [PATCH 088/278] make sure that $TARGET splits for -dynamic, otherwise it resolves to "-target 'native-native -dynamic'" --- src/SPC/store/scripts/zig-cc.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index 343fec511..96745166d 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -68,7 +68,7 @@ else TARGET="${SPC_TARGET}-${SPC_LIBC}" [ -n "$SPC_LIBC_VERSION" ] && TARGET="${TARGET}.${SPC_LIBC_VERSION}" - output=$(zig cc -target "$TARGET" -lstdc++ ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" 2>&1) + output=$(zig cc -target ${TARGET} -lstdc++ ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" 2>&1) status=$? if [ $status -eq 0 ]; then @@ -80,6 +80,6 @@ else echo "$output" | grep -v "version '.*' in target triple" exit 0 else - exec zig cc -target "$TARGET" ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" + exec zig cc -target ${TARGET} ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" fi fi From df0d5fdbe83408af9018d6d6c695e76a77b64dce Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 13:02:59 +0700 Subject: [PATCH 089/278] merge fix --- src/SPC/builder/Extension.php | 1 - src/SPC/builder/unix/UnixBuilderBase.php | 11 +++++++++++ src/SPC/util/GlobalEnvManager.php | 1 - 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index fef4855c0..def4b5c80 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -11,7 +11,6 @@ use SPC\store\Config; use SPC\store\FileSystem; use SPC\util\SPCConfigUtil; -use SPC\util\SPCTarget; class Extension { diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index b65a9077b..e33640715 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -206,6 +206,16 @@ protected function sanityCheck(int $build_target): void if (SPCTarget::isStatic()) { $lens .= ' -static'; } + // if someone changed to EMBED_TYPE=shared, we need to add LD_LIBRARY_PATH + if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { + $ext_path = 'LD_LIBRARY_PATH=' . BUILD_LIB_PATH . ':$LD_LIBRARY_PATH '; + FileSystem::removeFileIfExists(BUILD_LIB_PATH . '/libphp.a'); + } else { + $ext_path = ''; + foreach (glob(BUILD_LIB_PATH . '/libphp*.so') as $file) { + unlink($file); + } + } [$ret, $out] = shell()->cd($sample_file_path)->execWithResult(getenv('CC') . ' -o embed embed.c ' . $lens); if ($ret !== 0) { throw new RuntimeException('embed failed sanity check: build failed. Error message: ' . implode("\n", $out)); @@ -320,6 +330,7 @@ protected function buildFrankenphp(): void $debugFlags = $this->getOption('no-strip') ? "'-w -s' " : ''; $extLdFlags = "-extldflags '-pie'"; $muslTags = ''; + $staticFlags = ''; if (SPCTarget::isStatic()) { $extLdFlags = "-extldflags '-static-pie -Wl,-z,stack-size=0x80000'"; $muslTags = 'static_build,'; diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index 83131b6d6..23ae242dc 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -6,7 +6,6 @@ use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; -use SPC\store\pkg\Zig; use SPC\toolchain\ToolchainManager; /** From 5370af4a8415fe9dc057e7ed01f887c7e436b7ab Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 13:06:03 +0700 Subject: [PATCH 090/278] don't zig the tests yet --- src/globals/test-extensions.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index c47f358d1..0bed26e69 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -32,18 +32,6 @@ // 'windows-latest', // .\bin\spc.ps1 ]; -$zig = true; -// temporary! -if ($zig) { - putenv('SPC_LIBC=glibc'); - putenv('SPC_LIBC_VERSION=2.28'); - putenv('CC=zig-cc'); - putenv('CXX=zig-c++'); - putenv('AR=ar'); - putenv('LD=ld'); - exec('ulimit -n 2048'); -} - // whether enable thread safe $zts = true; @@ -170,7 +158,7 @@ function quote2(string $param): string break; case 'ubuntu-24.04': case 'ubuntu-24.04-arm': - if (getenv('SPC_LIBC') === 'glibc') { + if (str_contains((string) getenv('SPC_TARGET'), '-gnu')) { $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; } break; From 0a33fba23e1c5dd71545486a998016dd71cdb892 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 14:01:48 +0700 Subject: [PATCH 091/278] zig toolchain stuff --- config/env.ini | 28 +++++------ docs/en/guide/extension-notes.md | 2 +- src/SPC/builder/linux/LinuxBuilder.php | 4 +- src/SPC/builder/unix/library/libxslt.php | 6 +-- src/SPC/doctor/item/ZigCheck.php | 59 ++++++++++++++++++++++++ src/SPC/store/pkg/CustomPackage.php | 2 + src/SPC/store/pkg/Zig.php | 21 +++++++++ src/SPC/toolchain/MuslToolchain.php | 6 +-- src/SPC/toolchain/ToolchainManager.php | 29 ++++++------ src/SPC/toolchain/ZigToolchain.php | 26 ++++++++++- 10 files changed, 147 insertions(+), 36 deletions(-) create mode 100644 src/SPC/doctor/item/ZigCheck.php diff --git a/config/env.ini b/config/env.ini index c49b93345..242887bcf 100644 --- a/config/env.ini +++ b/config/env.ini @@ -65,21 +65,23 @@ UPX_EXEC="${PKG_ROOT_PATH}\bin\upx.exe" SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime140,win32,zend_stream,cli_static [linux] -; Linux can use different build toolchain, but the toolchain can not be changed in this file: -; - musl (default): used for general linux distros, can build `musl-static` target only. -; - zig (WIP): used for general linux distros, can build `musl` and `glibc` targets. -; - musl-native: used for alpine linux, can build `musl-static` and `musl`(WIP) target. -; - gnu-native (assume): used for general linux distros, can build `glibc` target only and have portability issues. +; Linux can use different build toolchains. +; - musl (default, when SPC_LIBC=musl): used for general linux distros, can build `musl` (statically linked) only. +; - zig (will become default): usable on all Linux distros, can build `-musl`, `arch-linux-musl -dynamic` and `arch-linux-gnu` targets. Can specify version such as `x86_64-linux-gnu.2.17`. +; - musl-native: used for alpine linux, can build `musl` and `musl -dynamic` target. +; - gnu-native: used for general linux distros, can build gnu target for the installed glibc version only. -; build target: -; - musl-static (default): pure static linking, using musl-libc, can run on any linux distro. -; - musl: static linking with dynamic linking to musl-libc, can run on musl-based linux distro. -; - glibc: static linking with dynamic linking to glibc, can run on glibc-based linux distro. - -; include PATH for musl libc. +; LEGACY option to specify the target, switch to SPC_TARGET with zig toolchain instead SPC_LIBC=musl -SPC_LIBC_VERSION= -SPC_LIBC_LINKAGE=-static + +; Recommended: specify your target here. Zig toolchain will be used. +; examples: +; `native-native-gnu` - links against glibc, version 2.17 +; `native-native-gnu.2.17` - links against glibc, version 2.17 +; `native-native` - static linking against musl +; `native-native-musl -dynamic` - links against musl libc +; SPC_TARGET= + ; compiler environments CC=${SPC_LINUX_DEFAULT_CC} CXX=${SPC_LINUX_DEFAULT_CXX} diff --git a/docs/en/guide/extension-notes.md b/docs/en/guide/extension-notes.md index 4dad0cfd1..609fda7bb 100644 --- a/docs/en/guide/extension-notes.md +++ b/docs/en/guide/extension-notes.md @@ -82,7 +82,7 @@ and this extension cannot be compiled into php by static linking, so it cannot b ## xdebug -1. Xdebug is only buildable as a shared extension. You need to use a build target other than `musl-static` for SPC_TARGET. +1. Xdebug is only buildable as a shared extension. On Linux, you'll need to use a SPC_TARGET like `native-native -dynamic` or `native-native-gnu`. 2. When using Linux/glibc or macOS, you can compile Xdebug as a shared extension using --build-shared="xdebug". The compiled `./php` binary can be configured and run by specifying the INI, eg `./php -d 'zend_extension=/path/to/xdebug.so' your-code.php`. diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 42636d664..7ff6cff79 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -10,6 +10,8 @@ use SPC\exception\WrongUsageException; use SPC\store\FileSystem; use SPC\store\SourcePatcher; +use SPC\toolchain\ToolchainManager; +use SPC\toolchain\ZigToolchain; use SPC\util\GlobalEnvManager; class LinuxBuilder extends UnixBuilderBase @@ -66,7 +68,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void } // add libstdc++, some extensions or libraries need it $extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lstdc++ ' : ''); - $extra_libs .= (SystemUtil::getCCType() === 'clang' ? ' -lunwind' : ''); + $extra_libs .= (ToolchainManager::getToolchainClass() === ZigToolchain::class ? ' -lunwind' : ''); f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); $cflags = $this->arch_c_flags; f_putenv('CFLAGS=' . $cflags); diff --git a/src/SPC/builder/unix/library/libxslt.php b/src/SPC/builder/unix/library/libxslt.php index aabc277d9..90c63f896 100644 --- a/src/SPC/builder/unix/library/libxslt.php +++ b/src/SPC/builder/unix/library/libxslt.php @@ -33,10 +33,10 @@ protected function build(): void '--without-debugger', "--with-libxml-prefix={$this->getBuildRootPath()}", ); - if (getenv('SPC_LINUX_DEFAULT_LD_LIBRARY_PATH') && getenv('SPC_LINUX_DEFAULT_LIBRARY_PATH')) { + if (getenv('SPC_LD_LIBRARY_PATH') && getenv('SPC_LIBRARY_PATH')) { $ac->appendEnv([ - 'LD_LIBRARY_PATH' => getenv('SPC_LINUX_DEFAULT_LD_LIBRARY_PATH'), - 'LIBRARY_PATH' => getenv('SPC_LINUX_DEFAULT_LIBRARY_PATH'), + 'LD_LIBRARY_PATH' => getenv('SPC_LD_LIBRARY_PATH'), + 'LIBRARY_PATH' => getenv('SPC_LIBRARY_PATH'), ]); } $ac->configure()->make(); diff --git a/src/SPC/doctor/item/ZigCheck.php b/src/SPC/doctor/item/ZigCheck.php new file mode 100644 index 000000000..3848895eb --- /dev/null +++ b/src/SPC/doctor/item/ZigCheck.php @@ -0,0 +1,59 @@ + 'win', + 'Darwin' => 'macos', + 'BSD' => 'freebsd', + default => 'linux', + }; + PackageManager::installPackage("musl-toolchain-{$arch}-{$os}"); + return Zig::isInstalled(); + } +} diff --git a/src/SPC/store/pkg/CustomPackage.php b/src/SPC/store/pkg/CustomPackage.php index bc6f6e46b..0602f8b60 100644 --- a/src/SPC/store/pkg/CustomPackage.php +++ b/src/SPC/store/pkg/CustomPackage.php @@ -13,4 +13,6 @@ abstract public function fetch(string $name, bool $force = false, ?array $config abstract public function extract(string $name): void; abstract public static function getEnvironment(): array; + + abstract public static function isInstalled(): bool; } diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index aa06922f0..e8c5600ce 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -11,6 +11,27 @@ class Zig extends CustomPackage { + private static function getPath(): string + { + $arch = arch2gnu(php_uname('m')); + $os = match (PHP_OS_FAMILY) { + 'Linux' => 'linux', + 'Windows' => 'win', + 'Darwin' => 'macos', + 'BSD' => 'freebsd', + default => 'linux', + }; + + $packageName = "zig-{$arch}-{$os}"; + return PKG_ROOT_PATH . "/{$packageName}"; + } + + public static function isInstalled(): bool + { + $path = self::getPath(); + return file_exists("$path/zig") && file_exists("$path/zig-cc") && file_exists("$path/zig-c++"); + } + public function getSupportName(): array { return [ diff --git a/src/SPC/toolchain/MuslToolchain.php b/src/SPC/toolchain/MuslToolchain.php index dd7955560..e996ef1fa 100644 --- a/src/SPC/toolchain/MuslToolchain.php +++ b/src/SPC/toolchain/MuslToolchain.php @@ -20,8 +20,8 @@ public function initEnv(): void GlobalEnvManager::addPathIfNotExists('/usr/local/musl/bin'); GlobalEnvManager::addPathIfNotExists("/usr/local/musl/{$arch}-linux-musl/bin"); - GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_LD_LIBRARY_PATH=/usr/local/musl/lib:/usr/local/musl/{$arch}-linux-musl/lib"); - GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_LIBRARY_PATH=/usr/local/musl/lib:/usr/local/musl/{$arch}-linux-musl/lib"); + GlobalEnvManager::putenv("SPC_LD_LIBRARY_PATH=/usr/local/musl/lib:/usr/local/musl/{$arch}-linux-musl/lib"); + GlobalEnvManager::putenv("SPC_LIBRARY_PATH=/usr/local/musl/lib:/usr/local/musl/{$arch}-linux-musl/lib"); } public function afterInit(): void @@ -29,7 +29,7 @@ public function afterInit(): void $arch = getenv('GNU_ARCH'); // append LD_LIBRARY_PATH to $configure = getenv('SPC_CMD_PREFIX_PHP_CONFIGURE'); $configure = getenv('SPC_CMD_PREFIX_PHP_CONFIGURE'); - $ld_library_path = getenv('SPC_LINUX_DEFAULT_LD_LIBRARY_PATH'); + $ld_library_path = getenv('SPC_LD_LIBRARY_PATH'); GlobalEnvManager::putenv("SPC_CMD_PREFIX_PHP_CONFIGURE=LD_LIBRARY_PATH=\"{$ld_library_path}\" {$configure}"); if (!file_exists("/usr/local/musl/{$arch}-linux-musl/lib/libc.a")) { diff --git a/src/SPC/toolchain/ToolchainManager.php b/src/SPC/toolchain/ToolchainManager.php index 76807bf22..5d39977ac 100644 --- a/src/SPC/toolchain/ToolchainManager.php +++ b/src/SPC/toolchain/ToolchainManager.php @@ -11,33 +11,36 @@ class ToolchainManager { public const array OS_DEFAULT_TOOLCHAIN = [ - 'Linux' => MuslToolchain::class, // use musl toolchain by default, after zig pr merged, change this to ZigToolchain::class + 'Linux' => ZigToolchain::class, 'Windows' => MSVCToolchain::class, 'Darwin' => ClangNativeToolchain::class, 'BSD' => ClangNativeToolchain::class, ]; - /** - * @throws WrongUsageException - */ - public static function initToolchain(): void + public static function getToolchainClass(): string { $libc = getenv('SPC_LIBC'); if ($libc !== false) { - // uncomment this when zig pr is merged - // logger()->warning('SPC_LIBC is deprecated, please use SPC_TARGET instead.'); - $toolchain = match ($libc) { + logger()->warning('SPC_LIBC is deprecated, please use SPC_TARGET instead.'); + return match ($libc) { 'musl' => SystemUtil::isMuslDist() ? GccNativeToolchain::class : MuslToolchain::class, - 'glibc' => !SystemUtil::isMuslDist() ? GccNativeToolchain::class : throw new WrongUsageException('SPC_TARGET must be musl-static or musl for musl dist.'), + 'glibc' => !SystemUtil::isMuslDist() ? GccNativeToolchain::class : throw new WrongUsageException('SPC_TARGET must be musl for musl dist.'), default => throw new WrongUsageException('Unsupported SPC_LIBC value: ' . $libc), }; - } else { - $toolchain = self::OS_DEFAULT_TOOLCHAIN[PHP_OS_FAMILY]; } - $toolchainClass = $toolchain; + + return self::OS_DEFAULT_TOOLCHAIN[PHP_OS_FAMILY]; + } + + /** + * @throws WrongUsageException + */ + public static function initToolchain(): void + { + $toolchainClass = self::getToolchainClass(); /* @var ToolchainInterface $toolchainClass */ (new $toolchainClass())->initEnv(); - GlobalEnvManager::putenv("SPC_TOOLCHAIN={$toolchain}"); + GlobalEnvManager::putenv("SPC_TOOLCHAIN={$toolchainClass}"); } public static function afterInitToolchain(): void diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index 3922fecbb..d4e5a82db 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -4,9 +4,31 @@ namespace SPC\toolchain; +use SPC\exception\WrongUsageException; +use SPC\store\pkg\Zig; +use SPC\util\GlobalEnvManager; + class ZigToolchain implements ToolchainInterface { - public function initEnv(): void {} + public function initEnv(): void + { + $arch = getenv('GNU_ARCH'); + // Set environment variables for musl toolchain + GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_CC=zig-cc"); + GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_CXX=zig-c++"); + GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_AR=ar"); + GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_LD=ld"); + GlobalEnvManager::addPathIfNotExists('/usr/local/musl/bin'); + GlobalEnvManager::addPathIfNotExists("/usr/local/musl/{$arch}-linux-musl/bin"); + + GlobalEnvManager::putenv("SPC_LD_LIBRARY_PATH=/usr/local/musl/lib:/usr/local/musl/{$arch}-linux-musl/lib"); + GlobalEnvManager::putenv("SPC_LIBRARY_PATH=/usr/local/musl/lib:/usr/local/musl/{$arch}-linux-musl/lib"); + } - public function afterInit(): void {} + public function afterInit(): void + { + if (!is_dir(Zig::getEnvironment()['PATH'])) { + throw new WrongUsageException('You are building with zig, but zig is not installed, please install zig first. (You can use `doctor` command to install it)'); + } + } } From b7e8587608d3b9698468e62a65bc5655c9a62967 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 14:02:10 +0700 Subject: [PATCH 092/278] cs fixes --- src/SPC/doctor/item/ZigCheck.php | 6 ------ src/SPC/store/pkg/Zig.php | 32 +++++++++++++++--------------- src/SPC/toolchain/ZigToolchain.php | 8 ++++---- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/SPC/doctor/item/ZigCheck.php b/src/SPC/doctor/item/ZigCheck.php index 3848895eb..f5983f1d9 100644 --- a/src/SPC/doctor/item/ZigCheck.php +++ b/src/SPC/doctor/item/ZigCheck.php @@ -8,16 +8,10 @@ use SPC\doctor\AsFixItem; use SPC\doctor\CheckResult; use SPC\doctor\OptionalCheck; -use SPC\exception\DownloaderException; use SPC\exception\FileSystemException; -use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; -use SPC\store\Downloader; -use SPC\store\FileSystem; use SPC\store\PackageManager; use SPC\store\pkg\Zig; -use SPC\store\SourcePatcher; -use SPC\toolchain\MuslToolchain; use SPC\toolchain\ZigToolchain; #[OptionalCheck([self::class, 'optionalCheck'])] diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index e8c5600ce..f819da7ac 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -11,25 +11,10 @@ class Zig extends CustomPackage { - private static function getPath(): string - { - $arch = arch2gnu(php_uname('m')); - $os = match (PHP_OS_FAMILY) { - 'Linux' => 'linux', - 'Windows' => 'win', - 'Darwin' => 'macos', - 'BSD' => 'freebsd', - default => 'linux', - }; - - $packageName = "zig-{$arch}-{$os}"; - return PKG_ROOT_PATH . "/{$packageName}"; - } - public static function isInstalled(): bool { $path = self::getPath(); - return file_exists("$path/zig") && file_exists("$path/zig-cc") && file_exists("$path/zig-c++"); + return file_exists("{$path}/zig") && file_exists("{$path}/zig-cc") && file_exists("{$path}/zig-c++"); } public function getSupportName(): array @@ -149,6 +134,21 @@ public static function getEnvironment(): array ]; } + private static function getPath(): string + { + $arch = arch2gnu(php_uname('m')); + $os = match (PHP_OS_FAMILY) { + 'Linux' => 'linux', + 'Windows' => 'win', + 'Darwin' => 'macos', + 'BSD' => 'freebsd', + default => 'linux', + }; + + $packageName = "zig-{$arch}-{$os}"; + return PKG_ROOT_PATH . "/{$packageName}"; + } + private function createZigCcScript(string $bin_dir): void { $script_path = __DIR__ . '/../scripts/zig-cc.sh'; diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index d4e5a82db..493287fc2 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -14,10 +14,10 @@ public function initEnv(): void { $arch = getenv('GNU_ARCH'); // Set environment variables for musl toolchain - GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_CC=zig-cc"); - GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_CXX=zig-c++"); - GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_AR=ar"); - GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_LD=ld"); + GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=zig-cc'); + GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++'); + GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar'); + GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld'); GlobalEnvManager::addPathIfNotExists('/usr/local/musl/bin'); GlobalEnvManager::addPathIfNotExists("/usr/local/musl/{$arch}-linux-musl/bin"); From 9c7e2171f6f1e98546c50ddb57fbc31742729cbf Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 14:07:41 +0700 Subject: [PATCH 093/278] formatting --- config/env.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/env.ini b/config/env.ini index 242887bcf..be4927f8e 100644 --- a/config/env.ini +++ b/config/env.ini @@ -76,9 +76,9 @@ SPC_LIBC=musl ; Recommended: specify your target here. Zig toolchain will be used. ; examples: -; `native-native-gnu` - links against glibc, version 2.17 -; `native-native-gnu.2.17` - links against glibc, version 2.17 -; `native-native` - static linking against musl +; `native-native-gnu` - links against glibc, current OS version +; `native-native-gnu.2.17` - links against glibc, version 2.17 +; `native-native` - static linking against musl ; `native-native-musl -dynamic` - links against musl libc ; SPC_TARGET= From ba7f994a717354eeeb53feaff93291ee802f9eac Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 14:12:51 +0700 Subject: [PATCH 094/278] simplify zig script --- src/SPC/store/scripts/zig-cc.sh | 53 ++++++--------------------------- 1 file changed, 9 insertions(+), 44 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index 96745166d..72900e722 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -34,52 +34,17 @@ while [[ $# -gt 0 ]]; do esac done -SPC_TARGET_WAS_SET=1 -if [ -z "${SPC_TARGET+x}" ]; then - SPC_TARGET_WAS_SET=0 -fi - -UNAME_M="$(uname -m)" -UNAME_S="$(uname -s)" - -case "$UNAME_M" in - x86_64) ARCH="x86_64" ;; - aarch64|arm64) ARCH="aarch64" ;; - *) echo "Unsupported architecture: $UNAME_M" >&2; exit 1 ;; -esac - -case "$UNAME_S" in - Linux) OS="linux" ;; - Darwin) OS="macos" ;; - *) echo "Unsupported OS: $UNAME_S" >&2; exit 1 ;; -esac +output=$(zig cc -target ${SPC_TARGET} -lstdc++ ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" 2>&1) +status=$? -SPC_TARGET="${SPC_TARGET:-$ARCH-$OS}" - -if [ "$SPC_LIBC" = "glibc" ]; then - SPC_LIBC="gnu" +if [ $status -eq 0 ]; then + echo "$output" + exit 0 fi -if [ "$SPC_TARGET_WAS_SET" -eq 0 ] && [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then - exec zig cc ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" -elif [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then - exec zig cc -target "${SPC_TARGET}" ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" +if echo "$output" | grep -q "version '.*' in target triple"; then + echo "$output" | grep -v "version '.*' in target triple" + exit 0 else - TARGET="${SPC_TARGET}-${SPC_LIBC}" - [ -n "$SPC_LIBC_VERSION" ] && TARGET="${TARGET}.${SPC_LIBC_VERSION}" - - output=$(zig cc -target ${TARGET} -lstdc++ ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" 2>&1) - status=$? - - if [ $status -eq 0 ]; then - echo "$output" - exit 0 - fi - - if echo "$output" | grep -q "version '.*' in target triple"; then - echo "$output" | grep -v "version '.*' in target triple" - exit 0 - else - exec zig cc -target ${TARGET} ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" - fi + exec zig cc -target ${SPC_TARGET} ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" fi From bebcb978f61e6e45f09701417b4afd02c5901d9d Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 14:41:14 +0700 Subject: [PATCH 095/278] conflicts with shared tests --- src/SPC/builder/linux/SystemUtil.php | 5 +++-- src/SPC/toolchain/ToolchainManager.php | 4 ++-- src/SPC/util/SPCConfigUtil.php | 5 +++-- src/globals/test-extensions.php | 5 +---- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index 1ccc39dac..419f69fe7 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -6,6 +6,8 @@ use SPC\builder\traits\UnixSystemUtilTrait; use SPC\exception\RuntimeException; +use SPC\toolchain\ToolchainManager; +use SPC\toolchain\ZigToolchain; class SystemUtil { @@ -231,8 +233,7 @@ public static function getLibcVersionIfExists(string $libc): ?string public static function getExtraRuntimeObjects(): string { - $cc = getenv('CC'); - if (!$cc || !str_contains($cc, 'zig')) { + if (ToolchainManager::getToolchainClass() !== ZigToolchain::class) { return ''; } diff --git a/src/SPC/toolchain/ToolchainManager.php b/src/SPC/toolchain/ToolchainManager.php index 5d39977ac..772de18c5 100644 --- a/src/SPC/toolchain/ToolchainManager.php +++ b/src/SPC/toolchain/ToolchainManager.php @@ -20,11 +20,11 @@ class ToolchainManager public static function getToolchainClass(): string { $libc = getenv('SPC_LIBC'); - if ($libc !== false) { + if ($libc !== false && !getenv('SPC_TARGET')) { logger()->warning('SPC_LIBC is deprecated, please use SPC_TARGET instead.'); return match ($libc) { 'musl' => SystemUtil::isMuslDist() ? GccNativeToolchain::class : MuslToolchain::class, - 'glibc' => !SystemUtil::isMuslDist() ? GccNativeToolchain::class : throw new WrongUsageException('SPC_TARGET must be musl for musl dist.'), + 'glibc' => !SystemUtil::isMuslDist() ? GccNativeToolchain::class : throw new WrongUsageException('SPC_LIBC must be musl for musl dist.'), default => throw new WrongUsageException('Unsupported SPC_LIBC value: ' . $libc), }; } diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index 64a546533..3cedf11f6 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -6,12 +6,13 @@ use SPC\builder\BuilderBase; use SPC\builder\BuilderProvider; -use SPC\builder\linux\SystemUtil; use SPC\builder\macos\MacOSBuilder; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\Config; +use SPC\toolchain\ToolchainManager; +use SPC\toolchain\ZigToolchain; use Symfony\Component\Console\Input\ArgvInput; class SPCConfigUtil @@ -71,7 +72,7 @@ public function config(array $extensions = [], array $libraries = [], bool $incl if ($this->builder->hasCpp()) { $libs .= $this->builder instanceof MacOSBuilder ? ' -lc++' : ' -lstdc++'; } - if (SystemUtil::getCCType() === 'clang') { + if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { $libs .= ' -lunwind'; } // mimalloc must come first diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 0bed26e69..0233298b9 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -72,7 +72,7 @@ // You can use `common`, `bulk`, `minimal` or `none`. // note: combination is only available for *nix platform. Windows must use `none` combination $base_combination = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'common', + 'Linux', 'Darwin' => 'minimal', 'Windows' => 'none', }; @@ -214,9 +214,6 @@ function quote2(string $param): string passthru($prefix . $down_cmd, $retcode); break; case 'build_cmd': - if ($zig) { - passthru("{$prefix}install-pkg zig --debug", $retcode); - } passthru($prefix . $build_cmd . ' --build-cli --build-micro', $retcode); break; case 'build_embed_cmd': From a483c4289318a0fd24e2bc1a7e9a6fe13ced8bfc Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 14:45:28 +0700 Subject: [PATCH 096/278] redis check if static or shared --- src/SPC/builder/extension/redis.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/extension/redis.php b/src/SPC/builder/extension/redis.php index 75158ad70..952b004e6 100644 --- a/src/SPC/builder/extension/redis.php +++ b/src/SPC/builder/extension/redis.php @@ -13,8 +13,13 @@ class redis extends Extension public function getUnixConfigureArg(bool $shared = false): string { $arg = '--enable-redis'; - $arg .= $this->builder->getExt('session') ? ' --enable-redis-session' : ' --disable-redis-session'; - $arg .= $this->builder->getExt('igbinary') ? ' --enable-redis-igbinary' : ' --disable-redis-igbinary'; + if ($this->isBuildStatic()) { + $arg .= $this->builder->getExt('session')?->isBuildStatic() ? ' --enable-redis-session' : ' --disable-redis-session'; + $arg .= $this->builder->getExt('igbinary')?->isBuildStatic() ? ' --enable-redis-igbinary' : ' --disable-redis-igbinary'; + } else { + $arg .= $this->builder->getExt('session') ? ' --enable-redis-session' : ' --disable-redis-session'; + $arg .= $this->builder->getExt('igbinary') ? ' --enable-redis-igbinary' : ' --disable-redis-igbinary'; + } if ($this->builder->getLib('zstd')) { $arg .= ' --enable-redis-zstd --with-libzstd="' . BUILD_ROOT_PATH . '"'; } From 292df38c10b53c7dd4fa46aad69c6bca98505354 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 14:59:34 +0700 Subject: [PATCH 097/278] isInstalled for GoXcaddy --- src/SPC/store/pkg/GoXcaddy.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/SPC/store/pkg/GoXcaddy.php b/src/SPC/store/pkg/GoXcaddy.php index 1359192d9..40f5ca258 100644 --- a/src/SPC/store/pkg/GoXcaddy.php +++ b/src/SPC/store/pkg/GoXcaddy.php @@ -10,6 +10,23 @@ class GoXcaddy extends CustomPackage { + public static function isInstalled(): bool + { + $arch = arch2gnu(php_uname('m')); + $os = match (PHP_OS_FAMILY) { + 'Windows' => 'win', + 'Darwin' => 'macos', + 'BSD' => 'freebsd', + default => 'linux', + }; + + $packageName = "go-xcaddy-{$arch}-{$os}"; + $pkgroot = PKG_ROOT_PATH; + $folder = "{$pkgroot}/{$packageName}"; + + return is_dir($folder) && is_file("{$folder}/bin/go") && is_file("{$folder}/bin/xcaddy"); + } + public function getSupportName(): array { return [ From e34eb502dbfcefb007420375f036e7533e1a25bd Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 15:05:44 +0700 Subject: [PATCH 098/278] fix tests failing to deprecation --- src/SPC/toolchain/ToolchainManager.php | 3 ++- src/SPC/util/SPCTarget.php | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SPC/toolchain/ToolchainManager.php b/src/SPC/toolchain/ToolchainManager.php index 772de18c5..72f1d250b 100644 --- a/src/SPC/toolchain/ToolchainManager.php +++ b/src/SPC/toolchain/ToolchainManager.php @@ -21,7 +21,8 @@ public static function getToolchainClass(): string { $libc = getenv('SPC_LIBC'); if ($libc !== false && !getenv('SPC_TARGET')) { - logger()->warning('SPC_LIBC is deprecated, please use SPC_TARGET instead.'); + // TODO: @crazywhalecc this breaks tests + // logger()->warning('SPC_LIBC is deprecated, please use SPC_TARGET instead.'); return match ($libc) { 'musl' => SystemUtil::isMuslDist() ? GccNativeToolchain::class : MuslToolchain::class, 'glibc' => !SystemUtil::isMuslDist() ? GccNativeToolchain::class : throw new WrongUsageException('SPC_LIBC must be musl for musl dist.'), diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index 7968c5080..5288b18b7 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -23,9 +23,8 @@ class SPCTarget */ public static function isStatic(): bool { - $libc = getenv('SPC_LIBC'); // if SPC_LIBC is set, it means the target is static, remove it when 3.0 is released - if ($libc === 'musl') { + if (getenv('SPC_LIBC') === 'musl') { return true; } if ($target = getenv('SPC_TARGET')) { From 55fd7ba8e61dc10693fec6c9ccae50dfe8ce2009 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 15:58:04 +0700 Subject: [PATCH 099/278] bring back static -lstdc++ for rhel 2.17 --- src/SPC/builder/extension/imagick.php | 11 +++++++++++ src/globals/test-extensions.php | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 514e79b32..c1979367d 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -5,6 +5,7 @@ namespace SPC\builder\extension; use SPC\builder\Extension; +use SPC\builder\linux\SystemUtil; use SPC\util\CustomExt; #[CustomExt('imagick')] @@ -15,4 +16,14 @@ public function getUnixConfigureArg(bool $shared = false): string $disable_omp = ' ac_cv_func_omp_pause_resource_all=no'; return '--with-imagick=' . ($shared ? 'shared,' : '') . BUILD_ROOT_PATH . $disable_omp; } + + protected function getStaticAndSharedLibs(): array + { + [$static, $shared] = parent::getStaticAndSharedLibs(); + if (SystemUtil::getLibcVersionIfExists('glibc') && SystemUtil::getLibcVersionIfExists('glibc') <= '2.17') { + $static .= ' -lstdc++'; + $shared = str_replace('-lstdc++', '', $shared); + } + return [$static, $shared]; + } } diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 0233298b9..d99409741 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -24,7 +24,7 @@ // 'macos-13', // bin/spc for x86_64 // 'macos-14', // bin/spc for arm64 'macos-15', // bin/spc for arm64 - 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 + // 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64 'ubuntu-24.04', // bin/spc for x86_64 // 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64 From 408b3b406076e16d1e1cfd978d1b71f2f42c9e51 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 16:21:57 +0700 Subject: [PATCH 100/278] try to test with zig? --- src/SPC/store/scripts/zig-cc.sh | 11 ++++++++--- src/SPC/toolchain/ToolchainManager.php | 2 +- src/globals/test-extensions.php | 5 +++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index 72900e722..fe9e2c837 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -34,7 +34,12 @@ while [[ $# -gt 0 ]]; do esac done -output=$(zig cc -target ${SPC_TARGET} -lstdc++ ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" 2>&1) +TARGET="" +if [ -n "$SPC_TARGET" ]; then + TARGET="-target $SPC_TARGET" +else + +output=$(zig cc $TARGET -lstdc++ $COMPILER_EXTRA "${PARSED_ARGS[@]}" 2>&1) status=$? if [ $status -eq 0 ]; then @@ -43,8 +48,8 @@ if [ $status -eq 0 ]; then fi if echo "$output" | grep -q "version '.*' in target triple"; then - echo "$output" | grep -v "version '.*' in target triple" + echo "$output" | grep -v "version '.*' in target triple" exit 0 else - exec zig cc -target ${SPC_TARGET} ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" + exec zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" fi diff --git a/src/SPC/toolchain/ToolchainManager.php b/src/SPC/toolchain/ToolchainManager.php index 72f1d250b..8192175b2 100644 --- a/src/SPC/toolchain/ToolchainManager.php +++ b/src/SPC/toolchain/ToolchainManager.php @@ -20,7 +20,7 @@ class ToolchainManager public static function getToolchainClass(): string { $libc = getenv('SPC_LIBC'); - if ($libc !== false && !getenv('SPC_TARGET')) { + if ($libc && !getenv('SPC_TARGET')) { // TODO: @crazywhalecc this breaks tests // logger()->warning('SPC_LIBC is deprecated, please use SPC_TARGET instead.'); return match ($libc) { diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index d99409741..f5dd882ff 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -27,8 +27,8 @@ // 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64 'ubuntu-24.04', // bin/spc for x86_64 - // 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64 - // 'ubuntu-24.04-arm', // bin/spc for arm64 + 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64 + 'ubuntu-24.04-arm', // bin/spc for arm64 // 'windows-latest', // .\bin\spc.ps1 ]; @@ -158,6 +158,7 @@ function quote2(string $param): string break; case 'ubuntu-24.04': case 'ubuntu-24.04-arm': + putenv('SPC_TARGET=native-linux-gnu'); if (str_contains((string) getenv('SPC_TARGET'), '-gnu')) { $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; } From f6c6011061c130e8b705940c93db4cda1a660e47 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 16:25:08 +0700 Subject: [PATCH 101/278] err, we need to install zig of course --- src/SPC/builder/unix/library/libaom.php | 6 ++++-- src/SPC/command/CraftCommand.php | 4 +++- src/SPC/doctor/item/ZigCheck.php | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/SPC/builder/unix/library/libaom.php b/src/SPC/builder/unix/library/libaom.php index d0b7c88c9..31c40a0fb 100644 --- a/src/SPC/builder/unix/library/libaom.php +++ b/src/SPC/builder/unix/library/libaom.php @@ -6,6 +6,8 @@ use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\toolchain\ToolchainManager; +use SPC\toolchain\ZigToolchain; use SPC\util\executor\UnixCMakeExecutor; trait libaom @@ -16,8 +18,8 @@ trait libaom */ protected function build(): void { - if (getenv('SPC_LIBC') === 'musl' && str_contains(getenv('CC'), 'zig')) { - f_putenv('COMPILER_EXTRA=-D_POSIX_SOURCE'); + if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { + f_putenv('COMPILER_EXTRA=-D_GNU_SOURCE'); } UnixCMakeExecutor::create($this) ->setBuildDir("{$this->source_dir}/builddir") diff --git a/src/SPC/command/CraftCommand.php b/src/SPC/command/CraftCommand.php index 84080205b..5a40a25d3 100644 --- a/src/SPC/command/CraftCommand.php +++ b/src/SPC/command/CraftCommand.php @@ -5,6 +5,8 @@ namespace SPC\command; use SPC\exception\ValidationException; +use SPC\toolchain\ToolchainManager; +use SPC\toolchain\ZigToolchain; use SPC\util\ConfigValidator; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Process\Process; @@ -76,7 +78,7 @@ public function handle(): int } } // install zig if requested - if (str_contains(getenv('CC'), 'zig')) { + if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { $retcode = $this->runCommand('install-pkg', 'zig'); if ($retcode !== 0) { $this->output->writeln('craft zig failed'); diff --git a/src/SPC/doctor/item/ZigCheck.php b/src/SPC/doctor/item/ZigCheck.php index f5983f1d9..ffd9aca5b 100644 --- a/src/SPC/doctor/item/ZigCheck.php +++ b/src/SPC/doctor/item/ZigCheck.php @@ -47,7 +47,7 @@ public function fixMuslCrossMake(): bool 'BSD' => 'freebsd', default => 'linux', }; - PackageManager::installPackage("musl-toolchain-{$arch}-{$os}"); + PackageManager::installPackage("zig-{$arch}-{$os}"); return Zig::isInstalled(); } } From 27f57cc23a74b62f1d67753a9a5cdc9fa0151c26 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 16:40:12 +0700 Subject: [PATCH 102/278] fix zig runtime --- src/SPC/store/scripts/zig-cc.sh | 2 +- src/SPC/toolchain/ZigToolchain.php | 1 + src/SPC/util/SPCTarget.php | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index fe9e2c837..4b0b70490 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -37,7 +37,7 @@ done TARGET="" if [ -n "$SPC_TARGET" ]; then TARGET="-target $SPC_TARGET" -else +fi output=$(zig cc $TARGET -lstdc++ $COMPILER_EXTRA "${PARSED_ARGS[@]}" 2>&1) status=$? diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index 493287fc2..fce9bb5d2 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -30,5 +30,6 @@ public function afterInit(): void if (!is_dir(Zig::getEnvironment()['PATH'])) { throw new WrongUsageException('You are building with zig, but zig is not installed, please install zig first. (You can use `doctor` command to install it)'); } + GlobalEnvManager::addPathIfNotExists(Zig::getEnvironment()['PATH']); } } diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index 5288b18b7..03f262235 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -96,11 +96,11 @@ public static function getTargetOS(): string if ($target === false) { return PHP_OS_FAMILY; } - // TODO: zig target parser like below? return match (true) { - str_contains($target, 'linux') => 'Linux', - str_contains($target, 'macos') => 'Darwin', - str_contains($target, 'windows') => 'Windows', + str_contains($target, '-linux') => 'Linux', + str_contains($target, '-macos') => 'Darwin', + str_contains($target, '-windows') => 'Windows', + str_contains($target, '-native') => PHP_OS_FAMILY, default => throw new WrongUsageException('Cannot parse target.'), }; } From 88f91728666823b98366054e3f45acb232c30d08 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 16:57:56 +0700 Subject: [PATCH 103/278] bring back opcache jit fix --- .php-cs-fixer.php | 3 ++- src/SPC/builder/linux/LinuxBuilder.php | 11 ++++++++++- src/SPC/builder/unix/library/libaom.php | 12 ++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 47d178665..6e57f1830 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -69,4 +69,5 @@ ]) ->setFinder( PhpCsFixer\Finder::create()->in([__DIR__ . '/src', __DIR__ . '/tests/SPC']) - ); + ) + ->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect()); diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 7ff6cff79..31a9cd5a6 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -13,6 +13,7 @@ use SPC\toolchain\ToolchainManager; use SPC\toolchain\ZigToolchain; use SPC\util\GlobalEnvManager; +use SPC\util\SPCTarget; class LinuxBuilder extends UnixBuilderBase { @@ -92,7 +93,9 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $zts = ''; } $disable_jit = $this->getOption('disable-opcache-jit', false) ? '--disable-opcache-jit ' : ''; - + if (!$disable_jit && $this->getExt('opcache')) { + f_putenv('COMPILER_EXTRA=-fno-sanitize=undefined'); + } $config_file_path = $this->getOption('with-config-file-path', false) ? ('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : ''; $config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ? @@ -123,6 +126,12 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void } $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; + if ($embed_type !== 'static' && SPCTarget::isStatic()) { + throw new WrongUsageException( + 'Linux does not support loading shared libraries when linking libc statically. ' . + 'Change SPC_CMD_VAR_PHP_EMBED_TYPE to static.' + ); + } shell()->cd(SOURCE_PATH . '/php-src') ->exec( getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' . diff --git a/src/SPC/builder/unix/library/libaom.php b/src/SPC/builder/unix/library/libaom.php index 31c40a0fb..9c10079bb 100644 --- a/src/SPC/builder/unix/library/libaom.php +++ b/src/SPC/builder/unix/library/libaom.php @@ -4,28 +4,24 @@ namespace SPC\builder\unix\library; -use SPC\exception\FileSystemException; -use SPC\exception\RuntimeException; use SPC\toolchain\ToolchainManager; use SPC\toolchain\ZigToolchain; use SPC\util\executor\UnixCMakeExecutor; trait libaom { - /** - * @throws RuntimeException - * @throws FileSystemException - */ protected function build(): void { + $extra = getenv('COMPILER_EXTRA'); if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { - f_putenv('COMPILER_EXTRA=-D_GNU_SOURCE'); + $new = trim($extra . ' -D_GNU_SOURCE'); + f_putenv("COMPILER_EXTRA={$new}"); } UnixCMakeExecutor::create($this) ->setBuildDir("{$this->source_dir}/builddir") ->addConfigureArgs('-DAOM_TARGET_CPU=generic') ->build(); - f_putenv('COMPILER_EXTRA'); + f_putenv("COMPILER_EXTRA={$extra}"); $this->patchPkgconfPrefix(['aom.pc']); } } From fd89e837986db0dc8e41a247e9b0218493923848 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 17:08:19 +0700 Subject: [PATCH 104/278] musl paths in zig toolchain are hogwash, of course --- src/SPC/toolchain/ZigToolchain.php | 8 +------- src/SPC/util/SPCTarget.php | 25 +++++++++---------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index fce9bb5d2..779401a06 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -12,17 +12,11 @@ class ZigToolchain implements ToolchainInterface { public function initEnv(): void { - $arch = getenv('GNU_ARCH'); - // Set environment variables for musl toolchain + // Set environment variables for zig toolchain GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=zig-cc'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld'); - GlobalEnvManager::addPathIfNotExists('/usr/local/musl/bin'); - GlobalEnvManager::addPathIfNotExists("/usr/local/musl/{$arch}-linux-musl/bin"); - - GlobalEnvManager::putenv("SPC_LD_LIBRARY_PATH=/usr/local/musl/lib:/usr/local/musl/{$arch}-linux-musl/lib"); - GlobalEnvManager::putenv("SPC_LIBRARY_PATH=/usr/local/musl/lib:/usr/local/musl/{$arch}-linux-musl/lib"); } public function afterInit(): void diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index 03f262235..7298f2c82 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -24,9 +24,6 @@ class SPCTarget public static function isStatic(): bool { // if SPC_LIBC is set, it means the target is static, remove it when 3.0 is released - if (getenv('SPC_LIBC') === 'musl') { - return true; - } if ($target = getenv('SPC_TARGET')) { if (str_contains($target, '-macos') || str_contains($target, '-native') && PHP_OS_FAMILY === 'Darwin') { return false; @@ -39,6 +36,9 @@ public static function isStatic(): bool } return true; } + if (getenv('SPC_LIBC') === 'musl') { + return true; + } return false; } @@ -47,10 +47,6 @@ public static function isStatic(): bool */ public static function getLibc(): ?string { - $libc = getenv('SPC_LIBC'); - if ($libc !== false) { - return $libc; - } $target = getenv('SPC_TARGET'); if (str_contains($target, '-gnu')) { return 'glibc'; @@ -64,6 +60,10 @@ public static function getLibc(): ?string if (PHP_OS_FAMILY === 'Linux' && str_contains($target, '-native')) { return 'musl'; } + $libc = getenv('SPC_LIBC'); + if ($libc !== false) { + return $libc; + } return null; } @@ -72,15 +72,8 @@ public static function getLibc(): ?string */ public static function getLibcVersion(): ?string { - $env = getenv('SPC_TARGET'); - $libc = getenv('SPC_LIBC'); - if ($libc !== false) { - // legacy method: get a version from system - return SystemUtil::getLibcVersionIfExists($libc); - } - // TODO: zig target parser - - return null; + $libc = self::getLibc(); + return SystemUtil::getLibcVersionIfExists($libc); } /** From d275d6cc69f51adf075d4c8d6180382c273037be Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 18:06:18 +0700 Subject: [PATCH 105/278] fix native chain --- src/SPC/util/SPCTarget.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index 7298f2c82..8dd640a06 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -47,18 +47,19 @@ public static function isStatic(): bool */ public static function getLibc(): ?string { - $target = getenv('SPC_TARGET'); - if (str_contains($target, '-gnu')) { - return 'glibc'; - } - if (str_contains($target, '-musl')) { - return 'musl'; - } - if (str_contains($target, '-linux')) { - return 'musl'; - } - if (PHP_OS_FAMILY === 'Linux' && str_contains($target, '-native')) { - return 'musl'; + if ($target = getenv('SPC_TARGET')) { + if (str_contains($target, '-gnu')) { + return 'glibc'; + } + if (str_contains($target, '-musl')) { + return 'musl'; + } + if (str_contains($target, '-linux')) { + return 'musl'; + } + if (PHP_OS_FAMILY === 'Linux' && str_contains($target, '-native')) { + return 'musl'; + } } $libc = getenv('SPC_LIBC'); if ($libc !== false) { From a6d68b9ecfabce03ec6d30dcaa431d227eedeeff Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 18:09:17 +0700 Subject: [PATCH 106/278] fix ncurses --- src/SPC/builder/linux/SystemUtil.php | 2 +- src/SPC/builder/unix/library/ncurses.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index 419f69fe7..6c1037bac 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -194,7 +194,7 @@ public static function getSupportedDistros(): array /** * Get libc version string from ldd */ - public static function getLibcVersionIfExists(string $libc): ?string + public static function getLibcVersionIfExists(?string $libc = null): ?string { if (self::$libc_version !== null) { return self::$libc_version; diff --git a/src/SPC/builder/unix/library/ncurses.php b/src/SPC/builder/unix/library/ncurses.php index f1792fa2e..3899e5597 100644 --- a/src/SPC/builder/unix/library/ncurses.php +++ b/src/SPC/builder/unix/library/ncurses.php @@ -6,6 +6,7 @@ use SPC\store\FileSystem; use SPC\util\executor\UnixAutoconfExecutor; +use SPC\util\SPCTarget; trait ncurses { @@ -15,7 +16,7 @@ protected function build(): void UnixAutoconfExecutor::create($this) ->appendEnv([ - 'LDFLAGS' => getenv('SPC_LIBC') === 'musl' ? '-static' : '', + 'LDFLAGS' => SPCTarget::isStatic() ? '-static' : '', ]) ->configure( '--enable-overwrite', From 8d47e560100348b1385e2e2700a5e4fd426867f6 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 18:22:05 +0700 Subject: [PATCH 107/278] sanity check after toolset init --- src/SPC/builder/linux/SystemUtil.php | 7 +++++-- src/SPC/toolchain/ToolchainManager.php | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index 6c1037bac..0d808f9dd 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -8,6 +8,7 @@ use SPC\exception\RuntimeException; use SPC\toolchain\ToolchainManager; use SPC\toolchain\ZigToolchain; +use SPC\util\SPCTarget; class SystemUtil { @@ -215,10 +216,12 @@ public static function getLibcVersionIfExists(?string $libc = null): ?string return null; } if ($libc === 'musl') { - if (self::isMuslDist()) { + if (SPCTarget::getLibc() === 'musl') { $result = shell()->execWithResult('ldd 2>&1', false); - } else { + } elseif (is_file('/usr/local/musl/lib/libc.so')) { $result = shell()->execWithResult('/usr/local/musl/lib/libc.so 2>&1', false); + } else { + $result = shell()->execWithResult('/lib/ld-musl-x86_64.so.1 2>&1', false); } // Match Version * line // match ldd version: "Version 1.2.3" match 1.2.3 diff --git a/src/SPC/toolchain/ToolchainManager.php b/src/SPC/toolchain/ToolchainManager.php index 8192175b2..bb5fd08e8 100644 --- a/src/SPC/toolchain/ToolchainManager.php +++ b/src/SPC/toolchain/ToolchainManager.php @@ -5,8 +5,10 @@ namespace SPC\toolchain; use SPC\builder\linux\SystemUtil; +use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\util\GlobalEnvManager; +use SPC\util\SPCTarget; class ToolchainManager { @@ -47,7 +49,13 @@ public static function initToolchain(): void public static function afterInitToolchain(): void { if (!getenv('SPC_TOOLCHAIN')) { - throw new WrongUsageException('SPC_TOOLCHAIN not set'); + throw new WrongUsageException('SPC_TOOLCHAIN was not properly set. Please contact the developers.'); + } + if (SPCTarget::getLibc() === 'musl' && !SPCTarget::isStatic() && !file_exists('/lib/ld-musl-x86_64.so.1')) { + throw new RuntimeException('You are linking against musl libc dynamically, but musl libc is not installed. Please install it with `sudo dnf install musl-libc` or `sudo apt install musl`'); + } + if (SPCTarget::getLibc() === 'glibc' && SystemUtil::isMuslDist()) { + throw new RuntimeException('You are linking against glibc libc dynamically, which is only supported on glibc distros.'); } $toolchain = getenv('SPC_TOOLCHAIN'); /* @var ToolchainInterface $toolchain */ From 8b3a22cbe48f66c1b7cac6665938ba6a5ee7ef67 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 18:23:02 +0700 Subject: [PATCH 108/278] better error message --- src/SPC/toolchain/ToolchainManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/toolchain/ToolchainManager.php b/src/SPC/toolchain/ToolchainManager.php index bb5fd08e8..213947f27 100644 --- a/src/SPC/toolchain/ToolchainManager.php +++ b/src/SPC/toolchain/ToolchainManager.php @@ -55,7 +55,7 @@ public static function afterInitToolchain(): void throw new RuntimeException('You are linking against musl libc dynamically, but musl libc is not installed. Please install it with `sudo dnf install musl-libc` or `sudo apt install musl`'); } if (SPCTarget::getLibc() === 'glibc' && SystemUtil::isMuslDist()) { - throw new RuntimeException('You are linking against glibc libc dynamically, which is only supported on glibc distros.'); + throw new RuntimeException('You are linking against glibc dynamically, which is only supported on musl distros.'); } $toolchain = getenv('SPC_TOOLCHAIN'); /* @var ToolchainInterface $toolchain */ From d8ee308a5f0e29fee5d95ce48a6403da92acf050 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 23:01:53 +0700 Subject: [PATCH 109/278] allow explicitly setting toolchain (simplify testing without constantly overriding CC and CXX) --- src/SPC/toolchain/ToolchainManager.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SPC/toolchain/ToolchainManager.php b/src/SPC/toolchain/ToolchainManager.php index 213947f27..d46118ac9 100644 --- a/src/SPC/toolchain/ToolchainManager.php +++ b/src/SPC/toolchain/ToolchainManager.php @@ -21,6 +21,9 @@ class ToolchainManager public static function getToolchainClass(): string { + if ($tc = getenv('SPC_TOOLCHAIN')) { + return $tc; + } $libc = getenv('SPC_LIBC'); if ($libc && !getenv('SPC_TARGET')) { // TODO: @crazywhalecc this breaks tests From 719bde87b77e59316797e1fe62643d3007fbdcfb Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 23:31:54 +0700 Subject: [PATCH 110/278] allow compilation with empty target --- src/SPC/util/SPCTarget.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index 8dd640a06..f7d8372e3 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -86,16 +86,13 @@ public static function getLibcVersion(): ?string */ public static function getTargetOS(): string { - $target = getenv('SPC_TARGET'); - if ($target === false) { - return PHP_OS_FAMILY; - } + $target = (string) getenv('SPC_TARGET'); return match (true) { str_contains($target, '-linux') => 'Linux', str_contains($target, '-macos') => 'Darwin', str_contains($target, '-windows') => 'Windows', str_contains($target, '-native') => PHP_OS_FAMILY, - default => throw new WrongUsageException('Cannot parse target.'), + default => PHP_OS_FAMILY, }; } } From a0564628c45ecaf4f61853fe7a212ff2533284b4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 23:32:55 +0700 Subject: [PATCH 111/278] try removing -lstdc++ (this will likely make a few extensions fail to load with undefined gxx_personality_v0 again, but we can use COMPILER_EXTRA there) --- src/SPC/store/scripts/zig-cc.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index 4b0b70490..7b4b8e233 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -39,7 +39,7 @@ if [ -n "$SPC_TARGET" ]; then TARGET="-target $SPC_TARGET" fi -output=$(zig cc $TARGET -lstdc++ $COMPILER_EXTRA "${PARSED_ARGS[@]}" 2>&1) +output=$(zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" 2>&1) status=$? if [ $status -eq 0 ]; then @@ -51,5 +51,6 @@ if echo "$output" | grep -q "version '.*' in target triple"; then echo "$output" | grep -v "version '.*' in target triple" exit 0 else - exec zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" + echo "$output" + exit $status fi From b16638d813108c1aff497edf2af52cdabe740fed Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 2 Jul 2025 09:23:31 +0700 Subject: [PATCH 112/278] place -lstdc++ in compiler_extra --- src/SPC/builder/Extension.php | 1 + src/SPC/store/scripts/zig-cc.sh | 15 +++++---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index def4b5c80..61070f9dc 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -405,6 +405,7 @@ public function buildUnixShared(): void 'LDFLAGS' => $config['ldflags'], 'LIBS' => $preStatic . $staticLibString . $postStatic . $sharedLibString, 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, + 'COMPILER_EXTRA' => '-lstdc++' ]; if ($this->patchBeforeSharedPhpize()) { diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index 7b4b8e233..9520e6fe7 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -42,15 +42,10 @@ fi output=$(zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" 2>&1) status=$? -if [ $status -eq 0 ]; then - echo "$output" - exit 0 +if [ $status -ne 0 ] && echo "$output" | grep -q "version '.*' in target triple"; then + output=$(echo "$output" | grep -v "version '.*' in target triple") + status=0 fi -if echo "$output" | grep -q "version '.*' in target triple"; then - echo "$output" | grep -v "version '.*' in target triple" - exit 0 -else - echo "$output" - exit $status -fi +echo "$output" +exit $status From b5aa7fc2136ddec3c1c84bdd7e21bf1bac50c952 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 2 Jul 2025 09:26:11 +0700 Subject: [PATCH 113/278] simplify script a bit --- src/SPC/store/scripts/zig-cc.sh | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index 9520e6fe7..975a5a225 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" -BUILDROOT_ABS="$(realpath "$SCRIPT_DIR/../../buildroot/include" 2>/dev/null || echo "")" +BUILDROOT_ABS="$(realpath "$SCRIPT_DIR/../../buildroot/include" 2>/dev/null || true)" PARSED_ARGS=() while [[ $# -gt 0 ]]; do @@ -9,23 +9,15 @@ while [[ $# -gt 0 ]]; do -isystem) shift ARG="$1" - [[ -n "$ARG" ]] && shift || break - ARG_ABS="$(realpath "$ARG" 2>/dev/null || echo "")" - if [[ -n "$ARG_ABS" && "$ARG_ABS" == "$BUILDROOT_ABS" ]]; then - PARSED_ARGS+=("-I$ARG") - else - PARSED_ARGS+=("-isystem" "$ARG") - fi + shift + ARG_ABS="$(realpath "$ARG" 2>/dev/null || true)" + [[ "$ARG_ABS" == "$BUILDROOT_ABS" ]] && PARSED_ARGS+=("-I$ARG") || PARSED_ARGS+=("-isystem" "$ARG") ;; -isystem*) ARG="${1#-isystem}" shift - ARG_ABS="$(realpath "$ARG" 2>/dev/null || echo "")" - if [[ -n "$ARG_ABS" && "$ARG_ABS" == "$BUILDROOT_ABS" ]]; then - PARSED_ARGS+=("-I$ARG") - else - PARSED_ARGS+=("-isystem$ARG") - fi + ARG_ABS="$(realpath "$ARG" 2>/dev/null || true)" + [[ "$ARG_ABS" == "$BUILDROOT_ABS" ]] && PARSED_ARGS+=("-I$ARG") || PARSED_ARGS+=("-isystem$ARG") ;; *) PARSED_ARGS+=("$1") @@ -34,16 +26,13 @@ while [[ $# -gt 0 ]]; do esac done -TARGET="" -if [ -n "$SPC_TARGET" ]; then - TARGET="-target $SPC_TARGET" -fi +[[ -n "$SPC_TARGET" ]] && TARGET="-target $SPC_TARGET" || TARGET="" output=$(zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" 2>&1) status=$? -if [ $status -ne 0 ] && echo "$output" | grep -q "version '.*' in target triple"; then - output=$(echo "$output" | grep -v "version '.*' in target triple") +if [[ $status -ne 0 ]] && grep -q "version '.*' in target triple" <<< "$output"; then + output=$(grep -v "version '.*' in target triple" <<< "$output") status=0 fi From 0695fb93816c80e6ed3a8165ffa92d1685797fc2 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 2 Jul 2025 09:33:33 +0700 Subject: [PATCH 114/278] cs fixer --- src/SPC/builder/Extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 61070f9dc..50d8837aa 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -405,7 +405,7 @@ public function buildUnixShared(): void 'LDFLAGS' => $config['ldflags'], 'LIBS' => $preStatic . $staticLibString . $postStatic . $sharedLibString, 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, - 'COMPILER_EXTRA' => '-lstdc++' + 'COMPILER_EXTRA' => '-lstdc++', ]; if ($this->patchBeforeSharedPhpize()) { From 5577cd0fab770028fb5cad9560ac8750c4c53182 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 2 Jul 2025 11:47:20 +0700 Subject: [PATCH 115/278] add cache file option to autoconf executor by default (if cflags and ldflags match default) --- src/SPC/builder/linux/library/libffi.php | 7 +---- src/SPC/builder/unix/library/gettext.php | 2 +- src/SPC/builder/unix/library/unixodbc.php | 1 + src/SPC/util/UnixShell.php | 5 ++++ .../util/executor/UnixAutoconfExecutor.php | 27 +++++++++++++++---- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/SPC/builder/linux/library/libffi.php b/src/SPC/builder/linux/library/libffi.php index ecb3e1422..9182cf44a 100644 --- a/src/SPC/builder/linux/library/libffi.php +++ b/src/SPC/builder/linux/library/libffi.php @@ -18,13 +18,8 @@ class libffi extends LinuxLibraryBase */ public function build(): void { - $arch = getenv('SPC_ARCH'); UnixAutoconfExecutor::create($this) - ->configure( - "--host={$arch}-unknown-linux", - "--target={$arch}-unknown-linux", - "--libdir={$this->getLibDir()}" - ) + ->configure() ->make(); if (is_file(BUILD_ROOT_PATH . '/lib64/libffi.a')) { diff --git a/src/SPC/builder/unix/library/gettext.php b/src/SPC/builder/unix/library/gettext.php index f0fdae547..fd523dc19 100644 --- a/src/SPC/builder/unix/library/gettext.php +++ b/src/SPC/builder/unix/library/gettext.php @@ -24,7 +24,7 @@ protected function build(): void if ($this->builder->getOption('enable-zts')) { $autoconf->addConfigureArgs('--enable-threads=isoc+posix') ->appendEnv([ - 'CFLAGS' => '-lpthread -D_REENTRANT', + 'CFLAGS' => '-D_REENTRANT', 'LDFLGAS' => '-lpthread', ]); } else { diff --git a/src/SPC/builder/unix/library/unixodbc.php b/src/SPC/builder/unix/library/unixodbc.php index a795d2447..bcd1b776c 100644 --- a/src/SPC/builder/unix/library/unixodbc.php +++ b/src/SPC/builder/unix/library/unixodbc.php @@ -17,6 +17,7 @@ trait unixodbc protected function build(): void { UnixAutoconfExecutor::create($this) + ->removeConfigureArgs('--cache-file') ->configure( '--disable-debug', '--disable-dependency-tracking', diff --git a/src/SPC/util/UnixShell.php b/src/SPC/util/UnixShell.php index ffe18910d..16b079e57 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -129,4 +129,9 @@ private function getExecString(string $cmd): string } return $cmd; } + + public function getEnv(): array + { + return $this->env; + } } diff --git a/src/SPC/util/executor/UnixAutoconfExecutor.php b/src/SPC/util/executor/UnixAutoconfExecutor.php index 1c9f496e2..6884d6d72 100644 --- a/src/SPC/util/executor/UnixAutoconfExecutor.php +++ b/src/SPC/util/executor/UnixAutoconfExecutor.php @@ -32,6 +32,13 @@ public function configure(...$args): static // remove all the ignored args $args = array_merge($args, $this->getDefaultConfigureArgs(), $this->configure_args); $args = array_diff($args, $this->ignore_args); + $args = array_filter( + $args, + fn ($arg) => !array_filter( + $this->ignore_args, + fn ($ignore) => str_starts_with($arg, $ignore . '=') + ) + ); $configure_args = implode(' ', $args); $this->shell->exec("./configure {$configure_args}"); @@ -46,7 +53,7 @@ public function getConfigureArgsString(): string /** * Run make * - * @param string $target Build target + * @param string $target Build target * @throws RuntimeException */ public function make(string $target = '', false|string $with_install = 'install', bool $with_clean = true, array $after_env_vars = []): static @@ -72,9 +79,9 @@ public function exec(string $cmd): static * Add optional library configuration. * This method checks if a library is available and adds the corresponding arguments to the CMake configuration. * - * @param string $name library name to check - * @param \Closure|string $true_args arguments to use if the library is available (allow closure, returns string) - * @param string $false_args arguments to use if the library is not available + * @param string $name library name to check + * @param \Closure|string $true_args arguments to use if the library is available (allow closure, returns string) + * @param string $false_args arguments to use if the library is not available * @return $this */ public function optionalLib(string $name, \Closure|string $true_args, string $false_args = ''): static @@ -119,13 +126,23 @@ public function appendEnv(array $env): static */ private function getDefaultConfigureArgs(): array { - return [ + $args = [ '--disable-shared', '--enable-static', "--prefix={$this->library->getBuildRootPath()}", '--with-pic', '--enable-pic', ]; + + // only add the cache file if CFLAGS and LDFLAGS are defaulted + $env = $this->shell->getEnv(); + $expected_cflags = '-I' . BUILD_INCLUDE_PATH . ' ' . getenv('SPC_DEFAULT_C_FLAGS'); + $expected_ldflags = '-L' . BUILD_LIB_PATH; + + if (($env['CFLAGS'] ?? '') === $expected_cflags && ($env['LDFLAGS'] ?? '') === $expected_ldflags) { + $args[] = '--cache-file=' . BUILD_ROOT_PATH . '/config.cache'; + } + return $args; } /** From abe27598deb861be96e4a85c27a0b439f72d4d85 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 2 Jul 2025 11:47:36 +0700 Subject: [PATCH 116/278] add cache file option to autoconf executor by default (if cflags and ldflags match default) --- src/SPC/util/UnixShell.php | 10 +++++----- src/SPC/util/executor/UnixAutoconfExecutor.php | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/SPC/util/UnixShell.php b/src/SPC/util/UnixShell.php index 16b079e57..95f238102 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -117,6 +117,11 @@ public function getEnvString(): string return trim($str); } + public function getEnv(): array + { + return $this->env; + } + private function getExecString(string $cmd): string { logger()->debug('Executed at: ' . debug_backtrace()[0]['file'] . ':' . debug_backtrace()[0]['line']); @@ -129,9 +134,4 @@ private function getExecString(string $cmd): string } return $cmd; } - - public function getEnv(): array - { - return $this->env; - } } diff --git a/src/SPC/util/executor/UnixAutoconfExecutor.php b/src/SPC/util/executor/UnixAutoconfExecutor.php index 6884d6d72..02f83f59c 100644 --- a/src/SPC/util/executor/UnixAutoconfExecutor.php +++ b/src/SPC/util/executor/UnixAutoconfExecutor.php @@ -53,7 +53,7 @@ public function getConfigureArgsString(): string /** * Run make * - * @param string $target Build target + * @param string $target Build target * @throws RuntimeException */ public function make(string $target = '', false|string $with_install = 'install', bool $with_clean = true, array $after_env_vars = []): static @@ -79,9 +79,9 @@ public function exec(string $cmd): static * Add optional library configuration. * This method checks if a library is available and adds the corresponding arguments to the CMake configuration. * - * @param string $name library name to check - * @param \Closure|string $true_args arguments to use if the library is available (allow closure, returns string) - * @param string $false_args arguments to use if the library is not available + * @param string $name library name to check + * @param \Closure|string $true_args arguments to use if the library is available (allow closure, returns string) + * @param string $false_args arguments to use if the library is not available * @return $this */ public function optionalLib(string $name, \Closure|string $true_args, string $false_args = ''): static From 6f68d7b7f1972b4e6d9e758807226864a8470726 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 2 Jul 2025 12:55:59 +0700 Subject: [PATCH 117/278] Revert "add cache file option to autoconf executor by default (if cflags and ldflags match default)" This reverts commit 5577cd0fab770028fb5cad9560ac8750c4c53182. --- src/SPC/builder/linux/library/libffi.php | 7 ++++++- src/SPC/builder/unix/library/gettext.php | 2 +- src/SPC/builder/unix/library/unixodbc.php | 1 - .../util/executor/UnixAutoconfExecutor.php | 19 +------------------ 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/SPC/builder/linux/library/libffi.php b/src/SPC/builder/linux/library/libffi.php index 9182cf44a..ecb3e1422 100644 --- a/src/SPC/builder/linux/library/libffi.php +++ b/src/SPC/builder/linux/library/libffi.php @@ -18,8 +18,13 @@ class libffi extends LinuxLibraryBase */ public function build(): void { + $arch = getenv('SPC_ARCH'); UnixAutoconfExecutor::create($this) - ->configure() + ->configure( + "--host={$arch}-unknown-linux", + "--target={$arch}-unknown-linux", + "--libdir={$this->getLibDir()}" + ) ->make(); if (is_file(BUILD_ROOT_PATH . '/lib64/libffi.a')) { diff --git a/src/SPC/builder/unix/library/gettext.php b/src/SPC/builder/unix/library/gettext.php index fd523dc19..f0fdae547 100644 --- a/src/SPC/builder/unix/library/gettext.php +++ b/src/SPC/builder/unix/library/gettext.php @@ -24,7 +24,7 @@ protected function build(): void if ($this->builder->getOption('enable-zts')) { $autoconf->addConfigureArgs('--enable-threads=isoc+posix') ->appendEnv([ - 'CFLAGS' => '-D_REENTRANT', + 'CFLAGS' => '-lpthread -D_REENTRANT', 'LDFLGAS' => '-lpthread', ]); } else { diff --git a/src/SPC/builder/unix/library/unixodbc.php b/src/SPC/builder/unix/library/unixodbc.php index bcd1b776c..a795d2447 100644 --- a/src/SPC/builder/unix/library/unixodbc.php +++ b/src/SPC/builder/unix/library/unixodbc.php @@ -17,7 +17,6 @@ trait unixodbc protected function build(): void { UnixAutoconfExecutor::create($this) - ->removeConfigureArgs('--cache-file') ->configure( '--disable-debug', '--disable-dependency-tracking', diff --git a/src/SPC/util/executor/UnixAutoconfExecutor.php b/src/SPC/util/executor/UnixAutoconfExecutor.php index 02f83f59c..1c9f496e2 100644 --- a/src/SPC/util/executor/UnixAutoconfExecutor.php +++ b/src/SPC/util/executor/UnixAutoconfExecutor.php @@ -32,13 +32,6 @@ public function configure(...$args): static // remove all the ignored args $args = array_merge($args, $this->getDefaultConfigureArgs(), $this->configure_args); $args = array_diff($args, $this->ignore_args); - $args = array_filter( - $args, - fn ($arg) => !array_filter( - $this->ignore_args, - fn ($ignore) => str_starts_with($arg, $ignore . '=') - ) - ); $configure_args = implode(' ', $args); $this->shell->exec("./configure {$configure_args}"); @@ -126,23 +119,13 @@ public function appendEnv(array $env): static */ private function getDefaultConfigureArgs(): array { - $args = [ + return [ '--disable-shared', '--enable-static', "--prefix={$this->library->getBuildRootPath()}", '--with-pic', '--enable-pic', ]; - - // only add the cache file if CFLAGS and LDFLAGS are defaulted - $env = $this->shell->getEnv(); - $expected_cflags = '-I' . BUILD_INCLUDE_PATH . ' ' . getenv('SPC_DEFAULT_C_FLAGS'); - $expected_ldflags = '-L' . BUILD_LIB_PATH; - - if (($env['CFLAGS'] ?? '') === $expected_cflags && ($env['LDFLAGS'] ?? '') === $expected_ldflags) { - $args[] = '--cache-file=' . BUILD_ROOT_PATH . '/config.cache'; - } - return $args; } /** From a5a020eef1a220e865cd98e51ee0f1980b5a7f38 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 2 Jul 2025 12:56:11 +0700 Subject: [PATCH 118/278] Revert "add cache file option to autoconf executor by default (if cflags and ldflags match default)" This reverts commit abe27598deb861be96e4a85c27a0b439f72d4d85. --- src/SPC/util/UnixShell.php | 10 +++++----- src/SPC/util/executor/UnixAutoconfExecutor.php | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/SPC/util/UnixShell.php b/src/SPC/util/UnixShell.php index 95f238102..16b079e57 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -117,11 +117,6 @@ public function getEnvString(): string return trim($str); } - public function getEnv(): array - { - return $this->env; - } - private function getExecString(string $cmd): string { logger()->debug('Executed at: ' . debug_backtrace()[0]['file'] . ':' . debug_backtrace()[0]['line']); @@ -134,4 +129,9 @@ private function getExecString(string $cmd): string } return $cmd; } + + public function getEnv(): array + { + return $this->env; + } } diff --git a/src/SPC/util/executor/UnixAutoconfExecutor.php b/src/SPC/util/executor/UnixAutoconfExecutor.php index 1c9f496e2..d0e24a0a5 100644 --- a/src/SPC/util/executor/UnixAutoconfExecutor.php +++ b/src/SPC/util/executor/UnixAutoconfExecutor.php @@ -46,7 +46,7 @@ public function getConfigureArgsString(): string /** * Run make * - * @param string $target Build target + * @param string $target Build target * @throws RuntimeException */ public function make(string $target = '', false|string $with_install = 'install', bool $with_clean = true, array $after_env_vars = []): static @@ -72,9 +72,9 @@ public function exec(string $cmd): static * Add optional library configuration. * This method checks if a library is available and adds the corresponding arguments to the CMake configuration. * - * @param string $name library name to check - * @param \Closure|string $true_args arguments to use if the library is available (allow closure, returns string) - * @param string $false_args arguments to use if the library is not available + * @param string $name library name to check + * @param \Closure|string $true_args arguments to use if the library is available (allow closure, returns string) + * @param string $false_args arguments to use if the library is not available * @return $this */ public function optionalLib(string $name, \Closure|string $true_args, string $false_args = ''): static From cc285ae8d83afc1b7543bd93d54b227c492b8caa Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 2 Jul 2025 12:57:58 +0700 Subject: [PATCH 119/278] cs fix --- src/SPC/util/UnixShell.php | 5 ----- src/SPC/util/executor/UnixAutoconfExecutor.php | 8 ++++---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/SPC/util/UnixShell.php b/src/SPC/util/UnixShell.php index 16b079e57..ffe18910d 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -129,9 +129,4 @@ private function getExecString(string $cmd): string } return $cmd; } - - public function getEnv(): array - { - return $this->env; - } } diff --git a/src/SPC/util/executor/UnixAutoconfExecutor.php b/src/SPC/util/executor/UnixAutoconfExecutor.php index d0e24a0a5..1c9f496e2 100644 --- a/src/SPC/util/executor/UnixAutoconfExecutor.php +++ b/src/SPC/util/executor/UnixAutoconfExecutor.php @@ -46,7 +46,7 @@ public function getConfigureArgsString(): string /** * Run make * - * @param string $target Build target + * @param string $target Build target * @throws RuntimeException */ public function make(string $target = '', false|string $with_install = 'install', bool $with_clean = true, array $after_env_vars = []): static @@ -72,9 +72,9 @@ public function exec(string $cmd): static * Add optional library configuration. * This method checks if a library is available and adds the corresponding arguments to the CMake configuration. * - * @param string $name library name to check - * @param \Closure|string $true_args arguments to use if the library is available (allow closure, returns string) - * @param string $false_args arguments to use if the library is not available + * @param string $name library name to check + * @param \Closure|string $true_args arguments to use if the library is available (allow closure, returns string) + * @param string $false_args arguments to use if the library is not available * @return $this */ public function optionalLib(string $name, \Closure|string $true_args, string $false_args = ''): static From 4b38da76b18bb48e7dbacf71a4fa777d3957e9ff Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 2 Jul 2025 14:01:06 +0700 Subject: [PATCH 120/278] test frankenphp too --- 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 f5dd882ff..a8b542155 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -41,7 +41,7 @@ $upx = false; // whether to test frankenphp build, only available for macos and linux -$frankenphp = false; +$frankenphp = true; // prefer downloading pre-built packages to speed up the build process $prefer_pre_built = true; From 76b36cef3554ee6e5f486b43b589300908597806 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 2 Jul 2025 14:26:15 +0700 Subject: [PATCH 121/278] fix macos test --- src/SPC/builder/unix/UnixBuilderBase.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index e33640715..949738842 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -362,7 +362,11 @@ protected function buildFrankenphp(): void ->exec("xcaddy build --output frankenphp {$xcaddyModules}"); if (!$this->getOption('no-strip', false) && file_exists(BUILD_BIN_PATH . '/frankenphp')) { - shell()->cd(BUILD_BIN_PATH)->exec('strip --strip-all frankenphp'); + if (PHP_OS_FAMILY === 'Linux') { + shell()->cd(BUILD_BIN_PATH)->exec('strip --strip-all frankenphp'); + } else { // macOS doesn't understand strip-all + shell()->cd(BUILD_BIN_PATH)->exec('strip -S frankenphp'); + } } } } From 2ac5438f6b5cbcb7d13e4870a065243f10565450 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 2 Jul 2025 16:11:21 +0700 Subject: [PATCH 122/278] libheif and libde265 report dependency on -lc++ instead of -lstdc++ --- src/SPC/builder/unix/library/libde265.php | 6 ++++++ src/SPC/builder/unix/library/libheif.php | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/SPC/builder/unix/library/libde265.php b/src/SPC/builder/unix/library/libde265.php index eaba0cfcf..dd5810fe7 100644 --- a/src/SPC/builder/unix/library/libde265.php +++ b/src/SPC/builder/unix/library/libde265.php @@ -6,6 +6,7 @@ use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\store\FileSystem; use SPC\util\executor\UnixCMakeExecutor; trait libde265 @@ -19,6 +20,11 @@ protected function build(): void UnixCMakeExecutor::create($this) ->addConfigureArgs('-DENABLE_SDL=OFF') ->build(); + + if (PHP_OS_FAMILY === 'Linux') { + $libheifpc = realpath(BUILD_LIB_PATH . '/pkgconfig/libheif.pc'); + FileSystem::replaceFileStr($libheifpc, '-lc++', '-lstdc++'); + } $this->patchPkgconfPrefix(['libde265.pc']); } } diff --git a/src/SPC/builder/unix/library/libheif.php b/src/SPC/builder/unix/library/libheif.php index 680f33213..ca9c11156 100644 --- a/src/SPC/builder/unix/library/libheif.php +++ b/src/SPC/builder/unix/library/libheif.php @@ -40,6 +40,10 @@ protected function build(): void '-DENABLE_PLUGIN_LOADING=OFF', ) ->build(); + if (PHP_OS_FAMILY === 'Linux') { + $libheifpc = realpath(BUILD_LIB_PATH . '/pkgconfig/libheif.pc'); + FileSystem::replaceFileStr($libheifpc, '-lc++', '-lstdc++'); + } $this->patchPkgconfPrefix(['libheif.pc']); } } From 39ffb8d99d1fa25362e73c9d10453149c921687b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 2 Jul 2025 21:32:24 +0700 Subject: [PATCH 123/278] why does exec work but output=$(...) doesn't? --- src/SPC/store/scripts/zig-cc.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index 975a5a225..1cdad6ee5 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -31,10 +31,14 @@ done output=$(zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" 2>&1) status=$? -if [[ $status -ne 0 ]] && grep -q "version '.*' in target triple" <<< "$output"; then - output=$(grep -v "version '.*' in target triple" <<< "$output") - status=0 -fi +if [[ $status -eq 0 ]]; then + echo "$output" + exit 0 +else + if grep -q "version '.*' in target triple" <<< "$output"; then + output=$(grep -v "version '.*' in target triple" <<< "$output") + status=0 + fi -echo "$output" -exit $status + exec zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" +fi From f6a292b57b4a5168fd542d73970613546f0ed627 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 2 Jul 2025 21:38:58 +0700 Subject: [PATCH 124/278] cleaner --- src/SPC/store/scripts/zig-cc.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index 1cdad6ee5..143622c83 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -34,11 +34,11 @@ status=$? if [[ $status -eq 0 ]]; then echo "$output" exit 0 -else - if grep -q "version '.*' in target triple" <<< "$output"; then - output=$(grep -v "version '.*' in target triple" <<< "$output") - status=0 - fi +fi - exec zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" +if grep -q "version '.*' in target triple" <<< "$output"; then + output=$(grep -v "version '.*' in target triple" <<< "$output") + status=0 fi + +exec zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" From 420fe497a5f14afb3bfa77f5bc4b6de90fdaac90 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 09:23:59 +0700 Subject: [PATCH 125/278] patch correct pc --- src/SPC/builder/unix/library/libde265.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/libde265.php b/src/SPC/builder/unix/library/libde265.php index dd5810fe7..6ab338ca9 100644 --- a/src/SPC/builder/unix/library/libde265.php +++ b/src/SPC/builder/unix/library/libde265.php @@ -22,7 +22,7 @@ protected function build(): void ->build(); if (PHP_OS_FAMILY === 'Linux') { - $libheifpc = realpath(BUILD_LIB_PATH . '/pkgconfig/libheif.pc'); + $libheifpc = realpath(BUILD_LIB_PATH . '/pkgconfig/libde265.pc'); FileSystem::replaceFileStr($libheifpc, '-lc++', '-lstdc++'); } $this->patchPkgconfPrefix(['libde265.pc']); From aff3373b78dc670ad7b778ba9b303f383cda2fd4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 11:11:21 +0700 Subject: [PATCH 126/278] remote -lutil? --- bin/build-static-frankenphp | 2 +- bin/spc-gnu-docker | 2 +- config/env.ini | 4 ++-- src/SPC/builder/extension/swoole.php | 5 ++--- src/SPC/builder/unix/library/ldap.php | 2 +- src/SPC/util/executor/UnixCMakeExecutor.php | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/bin/build-static-frankenphp b/bin/build-static-frankenphp index 10a693a78..150606e35 100755 --- a/bin/build-static-frankenphp +++ b/bin/build-static-frankenphp @@ -148,7 +148,7 @@ echo 'LD=/opt/rh/devtoolset-10/root/usr/bin/ld' >> /tmp/spc-gnu-docker.env echo 'SPC_DEFAULT_C_FLAGS=-fPIE -fPIC' >> /tmp/spc-gnu-docker.env echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env -echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' >> /tmp/spc-gnu-docker.env +echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lrt"' >> /tmp/spc-gnu-docker.env # Run docker # shellcheck disable=SC2068 diff --git a/bin/spc-gnu-docker b/bin/spc-gnu-docker index 20a26389f..51e3513ab 100755 --- a/bin/spc-gnu-docker +++ b/bin/spc-gnu-docker @@ -156,7 +156,7 @@ fi echo 'SPC_DEFAULT_C_FLAGS=-fPIC' > /tmp/spc-gnu-docker.env echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env -echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' >> /tmp/spc-gnu-docker.env +echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lrt"' >> /tmp/spc-gnu-docker.env # Environment variable passthrough ENV_LIST="" diff --git a/config/env.ini b/config/env.ini index be4927f8e..571262c98 100644 --- a/config/env.ini +++ b/config/env.ini @@ -115,11 +115,11 @@ SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}" ; LDFLAGS for configuring php SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" ; LIBS for configuring php -SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil" +SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lrt -lpthread -lm -lresolv" ; EXTRA_CFLAGS for `make` php SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}" ; EXTRA_LIBS for `make` php -SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil" +SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lrt -lpthread -lm -lresolv" ; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS="" ; EXTRA_LDFLAGS_PROGRAM for `make` php diff --git a/src/SPC/builder/extension/swoole.php b/src/SPC/builder/extension/swoole.php index ec32e90dd..6ce006b97 100644 --- a/src/SPC/builder/extension/swoole.php +++ b/src/SPC/builder/extension/swoole.php @@ -14,14 +14,13 @@ class swoole extends Extension { public function patchBeforeMake(): bool { - $patched = false; if ($this->builder instanceof MacOSBuilder) { // Fix swoole with event extension conflict bug $util_path = shell()->execWithResult('xcrun --show-sdk-path', false)[1][0] . '/usr/include/util.h'; FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/swoole/thirdparty/php/standard/proc_open.cc', 'include ', 'include "' . $util_path . '"'); - $patched = true; + return true; } - return $patched; + return false; } public function getExtVersion(): ?string diff --git a/src/SPC/builder/unix/library/ldap.php b/src/SPC/builder/unix/library/ldap.php index 3ff72dcba..0befdb244 100644 --- a/src/SPC/builder/unix/library/ldap.php +++ b/src/SPC/builder/unix/library/ldap.php @@ -12,7 +12,7 @@ trait ldap { public function patchBeforeBuild(): bool { - $extra = SPCTarget::getLibc() === 'glibc' ? '-ldl -lpthread -lm -lresolv -lutil' : ''; + $extra = SPCTarget::getLibc() === 'glibc' ? '-ldl -lpthread -lm -lresolv' : ''; FileSystem::replaceFileStr($this->source_dir . '/configure', '"-lssl -lcrypto', '"-lssl -lcrypto -lz ' . $extra); return true; } diff --git a/src/SPC/util/executor/UnixCMakeExecutor.php b/src/SPC/util/executor/UnixCMakeExecutor.php index b9c7ef589..89bb7fbbe 100644 --- a/src/SPC/util/executor/UnixCMakeExecutor.php +++ b/src/SPC/util/executor/UnixCMakeExecutor.php @@ -200,7 +200,7 @@ private function makeCmakeToolchainFile(): string set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) -set(CMAKE_EXE_LINKER_FLAGS "-ldl -lpthread -lm -lutil") +set(CMAKE_EXE_LINKER_FLAGS "-ldl -lpthread -lm") CMAKE; // Whoops, linux may need CMAKE_AR sometimes if (PHP_OS_FAMILY === 'Linux') { From cebd95b2c77e8ba129e195748ccfdc81b3d40297 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 11:21:24 +0700 Subject: [PATCH 127/278] suggestion --- src/SPC/builder/extension/swoole.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/extension/swoole.php b/src/SPC/builder/extension/swoole.php index 6ce006b97..dee2ddc3a 100644 --- a/src/SPC/builder/extension/swoole.php +++ b/src/SPC/builder/extension/swoole.php @@ -17,7 +17,11 @@ public function patchBeforeMake(): bool if ($this->builder instanceof MacOSBuilder) { // Fix swoole with event extension conflict bug $util_path = shell()->execWithResult('xcrun --show-sdk-path', false)[1][0] . '/usr/include/util.h'; - FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/swoole/thirdparty/php/standard/proc_open.cc', 'include ', 'include "' . $util_path . '"'); + FileSystem::replaceFileStr( + "{$this->source_dir}/thirdparty/php/standard/proc_open.cc", + 'include ', + 'include "' . $util_path . '"', + ); return true; } return false; From c735960ff881d9e0d4b2dc0ddd1966664fb5ec16 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 11:43:05 +0700 Subject: [PATCH 128/278] Revert "remote -lutil?" This reverts commit aff3373b78dc670ad7b778ba9b303f383cda2fd4. --- bin/build-static-frankenphp | 2 +- bin/spc-gnu-docker | 2 +- config/env.ini | 4 ++-- src/SPC/builder/unix/library/ldap.php | 2 +- src/SPC/util/executor/UnixCMakeExecutor.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/build-static-frankenphp b/bin/build-static-frankenphp index 150606e35..10a693a78 100755 --- a/bin/build-static-frankenphp +++ b/bin/build-static-frankenphp @@ -148,7 +148,7 @@ echo 'LD=/opt/rh/devtoolset-10/root/usr/bin/ld' >> /tmp/spc-gnu-docker.env echo 'SPC_DEFAULT_C_FLAGS=-fPIE -fPIC' >> /tmp/spc-gnu-docker.env echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env -echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lrt"' >> /tmp/spc-gnu-docker.env +echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' >> /tmp/spc-gnu-docker.env # Run docker # shellcheck disable=SC2068 diff --git a/bin/spc-gnu-docker b/bin/spc-gnu-docker index 51e3513ab..20a26389f 100755 --- a/bin/spc-gnu-docker +++ b/bin/spc-gnu-docker @@ -156,7 +156,7 @@ fi echo 'SPC_DEFAULT_C_FLAGS=-fPIC' > /tmp/spc-gnu-docker.env echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env -echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lrt"' >> /tmp/spc-gnu-docker.env +echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' >> /tmp/spc-gnu-docker.env # Environment variable passthrough ENV_LIST="" diff --git a/config/env.ini b/config/env.ini index 571262c98..be4927f8e 100644 --- a/config/env.ini +++ b/config/env.ini @@ -115,11 +115,11 @@ SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}" ; LDFLAGS for configuring php SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" ; LIBS for configuring php -SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lrt -lpthread -lm -lresolv" +SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil" ; EXTRA_CFLAGS for `make` php SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}" ; EXTRA_LIBS for `make` php -SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lrt -lpthread -lm -lresolv" +SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil" ; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS="" ; EXTRA_LDFLAGS_PROGRAM for `make` php diff --git a/src/SPC/builder/unix/library/ldap.php b/src/SPC/builder/unix/library/ldap.php index 0befdb244..3ff72dcba 100644 --- a/src/SPC/builder/unix/library/ldap.php +++ b/src/SPC/builder/unix/library/ldap.php @@ -12,7 +12,7 @@ trait ldap { public function patchBeforeBuild(): bool { - $extra = SPCTarget::getLibc() === 'glibc' ? '-ldl -lpthread -lm -lresolv' : ''; + $extra = SPCTarget::getLibc() === 'glibc' ? '-ldl -lpthread -lm -lresolv -lutil' : ''; FileSystem::replaceFileStr($this->source_dir . '/configure', '"-lssl -lcrypto', '"-lssl -lcrypto -lz ' . $extra); return true; } diff --git a/src/SPC/util/executor/UnixCMakeExecutor.php b/src/SPC/util/executor/UnixCMakeExecutor.php index 89bb7fbbe..b9c7ef589 100644 --- a/src/SPC/util/executor/UnixCMakeExecutor.php +++ b/src/SPC/util/executor/UnixCMakeExecutor.php @@ -200,7 +200,7 @@ private function makeCmakeToolchainFile(): string set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) -set(CMAKE_EXE_LINKER_FLAGS "-ldl -lpthread -lm") +set(CMAKE_EXE_LINKER_FLAGS "-ldl -lpthread -lm -lutil") CMAKE; // Whoops, linux may need CMAKE_AR sometimes if (PHP_OS_FAMILY === 'Linux') { From 456d12fb58b3bf2818b1929c6b34417d9920ada8 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 11:59:39 +0700 Subject: [PATCH 129/278] fix error suppression --- src/SPC/store/scripts/zig-cc.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index 143622c83..f0db0bf18 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -36,9 +36,10 @@ if [[ $status -eq 0 ]]; then exit 0 fi -if grep -q "version '.*' in target triple" <<< "$output"; then - output=$(grep -v "version '.*' in target triple" <<< "$output") - status=0 +if echo "$output" | grep -qE "version '.*' in target triple"; then + filtered_output=$(echo "$output" | grep -vE "version '.*' in target triple") + echo "$filtered_output" + exit 0 fi exec zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" From a5a87b975be5667cd5ca747e7711eec36cfc14f8 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 12:20:59 +0700 Subject: [PATCH 130/278] update target declaration to be correct --- config/env.ini | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/env.ini b/config/env.ini index be4927f8e..8f9a7cf9f 100644 --- a/config/env.ini +++ b/config/env.ini @@ -78,8 +78,9 @@ SPC_LIBC=musl ; examples: ; `native-native-gnu` - links against glibc, current OS version ; `native-native-gnu.2.17` - links against glibc, version 2.17 -; `native-native` - static linking against musl -; `native-native-musl -dynamic` - links against musl libc +; `native-native` - links against system libc dynamically +; `native-native-musl` - links against musl libc statically +; `native-native-musl -dynamic` - links against musl libc dynamically ; SPC_TARGET= ; compiler environments From 20c4056561bbfc7f613ce8e0ab8d51eddfdc3a51 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 12:25:36 +0700 Subject: [PATCH 131/278] test native-native in CI --- src/globals/test-extensions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index a8b542155..f9f781829 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -23,7 +23,7 @@ $test_os = [ // 'macos-13', // bin/spc for x86_64 // 'macos-14', // bin/spc for arm64 - 'macos-15', // bin/spc for arm64 + // 'macos-15', // bin/spc for arm64 // 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64 'ubuntu-24.04', // bin/spc for x86_64 @@ -158,8 +158,8 @@ function quote2(string $param): string break; case 'ubuntu-24.04': case 'ubuntu-24.04-arm': - putenv('SPC_TARGET=native-linux-gnu'); - if (str_contains((string) getenv('SPC_TARGET'), '-gnu')) { + putenv('SPC_TARGET=native-native'); + if (!str_contains((string) getenv('SPC_TARGET'), '-musl')) { $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; } break; From 6355a97b47f1d5f5a70ce9625896c046e26f9347 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 12:26:11 +0700 Subject: [PATCH 132/278] don't pass --build-shared when not using zig toolchain --- 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 f9f781829..169c70a67 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -159,7 +159,7 @@ function quote2(string $param): string case 'ubuntu-24.04': case 'ubuntu-24.04-arm': putenv('SPC_TARGET=native-native'); - if (!str_contains((string) getenv('SPC_TARGET'), '-musl')) { + if (getenv('SPC_TARGET') && !str_contains((string) getenv('SPC_TARGET'), '-musl')) { $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; } break; From 4a2b28e88c74da3917882cdcddbdda1f10ff27bd Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 12:33:55 +0700 Subject: [PATCH 133/278] fix isStatic detection for native-native --- src/SPC/util/SPCTarget.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index f7d8372e3..3c4fb8167 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -34,6 +34,12 @@ public static function isStatic(): bool if (str_contains($target, '-dynamic')) { return false; } + if (str_contains($target, '-musl')) { + return false; + } + if (PHP_OS_FAMILY === 'Linux') { + return SystemUtil::isMuslDist(); + } return true; } if (getenv('SPC_LIBC') === 'musl') { From f6a1065cd72faa86973f4ef8f7e003ea5378b8ec Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 12:44:49 +0700 Subject: [PATCH 134/278] fix libc detection too --- src/SPC/util/SPCTarget.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index 3c4fb8167..e739ea1ea 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -60,17 +60,17 @@ public static function getLibc(): ?string if (str_contains($target, '-musl')) { return 'musl'; } - if (str_contains($target, '-linux')) { - return 'musl'; - } - if (PHP_OS_FAMILY === 'Linux' && str_contains($target, '-native')) { - return 'musl'; + if (PHP_OS_FAMILY === 'Linux') { + return SystemUtil::isMuslDist() ? 'musl' : 'glibc'; } } $libc = getenv('SPC_LIBC'); if ($libc !== false) { return $libc; } + if (PHP_OS_FAMILY === 'Linux') { + return SystemUtil::isMuslDist() ? 'musl' : 'glibc'; + } return null; } From 8b37c6408899ddcef65a0879a23354fdd0c13209 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 13:50:06 +0700 Subject: [PATCH 135/278] don't replace -lc++? --- src/SPC/builder/unix/library/libde265.php | 5 ----- src/SPC/builder/unix/library/libheif.php | 4 ---- 2 files changed, 9 deletions(-) diff --git a/src/SPC/builder/unix/library/libde265.php b/src/SPC/builder/unix/library/libde265.php index 6ab338ca9..16ad52121 100644 --- a/src/SPC/builder/unix/library/libde265.php +++ b/src/SPC/builder/unix/library/libde265.php @@ -20,11 +20,6 @@ protected function build(): void UnixCMakeExecutor::create($this) ->addConfigureArgs('-DENABLE_SDL=OFF') ->build(); - - if (PHP_OS_FAMILY === 'Linux') { - $libheifpc = realpath(BUILD_LIB_PATH . '/pkgconfig/libde265.pc'); - FileSystem::replaceFileStr($libheifpc, '-lc++', '-lstdc++'); - } $this->patchPkgconfPrefix(['libde265.pc']); } } diff --git a/src/SPC/builder/unix/library/libheif.php b/src/SPC/builder/unix/library/libheif.php index ca9c11156..680f33213 100644 --- a/src/SPC/builder/unix/library/libheif.php +++ b/src/SPC/builder/unix/library/libheif.php @@ -40,10 +40,6 @@ protected function build(): void '-DENABLE_PLUGIN_LOADING=OFF', ) ->build(); - if (PHP_OS_FAMILY === 'Linux') { - $libheifpc = realpath(BUILD_LIB_PATH . '/pkgconfig/libheif.pc'); - FileSystem::replaceFileStr($libheifpc, '-lc++', '-lstdc++'); - } $this->patchPkgconfPrefix(['libheif.pc']); } } From 3444e308fd113673ee5617015d231f5147364bf6 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 13:51:54 +0700 Subject: [PATCH 136/278] cs fix --- src/SPC/builder/unix/library/libde265.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SPC/builder/unix/library/libde265.php b/src/SPC/builder/unix/library/libde265.php index 16ad52121..eaba0cfcf 100644 --- a/src/SPC/builder/unix/library/libde265.php +++ b/src/SPC/builder/unix/library/libde265.php @@ -6,7 +6,6 @@ use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; -use SPC\store\FileSystem; use SPC\util\executor\UnixCMakeExecutor; trait libde265 From e5c5b77a9a878184a9df8d5646a299ae3f98a702 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 14:46:07 +0700 Subject: [PATCH 137/278] don't run extra logic in zig-cc script if there's no version string in SPC_TARGET --- src/SPC/store/scripts/zig-cc.sh | 22 ++++++++++++---------- src/SPC/store/source/PhpSource.php | 6 ++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index f0db0bf18..4dd0f6c91 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -28,18 +28,20 @@ done [[ -n "$SPC_TARGET" ]] && TARGET="-target $SPC_TARGET" || TARGET="" -output=$(zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" 2>&1) -status=$? +if [[ "$SPC_TARGET" =~ \.[0-9]+\.[0-9]+ ]]; then + output=$(zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" 2>&1) + status=$? -if [[ $status -eq 0 ]]; then - echo "$output" - exit 0 -fi + if [[ $status -eq 0 ]]; then + echo "$output" + exit 0 + fi -if echo "$output" | grep -qE "version '.*' in target triple"; then - filtered_output=$(echo "$output" | grep -vE "version '.*' in target triple") - echo "$filtered_output" - exit 0 + if echo "$output" | grep -qE "version '.*' in target triple"; then + filtered_output=$(echo "$output" | grep -vE "version '.*' in target triple") + echo "$filtered_output" + exit 0 + fi fi exec zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" diff --git a/src/SPC/store/source/PhpSource.php b/src/SPC/store/source/PhpSource.php index 5b4fd0972..d6807cd1c 100644 --- a/src/SPC/store/source/PhpSource.php +++ b/src/SPC/store/source/PhpSource.php @@ -7,6 +7,7 @@ use JetBrains\PhpStorm\ArrayShape; use SPC\exception\DownloaderException; use SPC\exception\FileSystemException; +use SPC\exception\WrongUsageException; use SPC\store\Downloader; class PhpSource extends CustomSourceBase @@ -16,11 +17,12 @@ class PhpSource extends CustomSourceBase /** * @throws DownloaderException * @throws FileSystemException + * @throws WrongUsageException */ public function fetch(bool $force = false, ?array $config = null, int $lock_as = SPC_DOWNLOAD_SOURCE): void { $major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.3'; - Downloader::downloadSource('php-src', self::getLatestPHPInfo($major), $force); + Downloader::downloadSource('php-src', $this->getLatestPHPInfo($major), $force); } /** @@ -34,7 +36,7 @@ public function getLatestPHPInfo(string $major_version): array // 查找最新的小版本号 $info = json_decode(Downloader::curlExec( url: "https://www.php.net/releases/index.php?json&version={$major_version}", - retries: intval(getenv('SPC_DOWNLOAD_RETRIES') ?: 0) + retries: (int) getenv('SPC_DOWNLOAD_RETRIES') ), true); if (!isset($info['version'])) { throw new DownloaderException("Version {$major_version} not found."); From ccdb6a031f742baf48aff8e3bb977701e6d967cc Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 15:42:42 +0700 Subject: [PATCH 138/278] test native-linux-gnu again? --- 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 169c70a67..a17f66dd0 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -158,7 +158,7 @@ function quote2(string $param): string break; case 'ubuntu-24.04': case 'ubuntu-24.04-arm': - putenv('SPC_TARGET=native-native'); + putenv('SPC_TARGET=native-linux-gnu'); if (getenv('SPC_TARGET') && !str_contains((string) getenv('SPC_TARGET'), '-musl')) { $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; } From e019b65ef75e33d495a9b7d1b4f44276d5207e94 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 16:40:04 +0700 Subject: [PATCH 139/278] does this break tests again? --- 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 a17f66dd0..73752c005 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -158,7 +158,7 @@ function quote2(string $param): string break; case 'ubuntu-24.04': case 'ubuntu-24.04-arm': - putenv('SPC_TARGET=native-linux-gnu'); + putenv('SPC_TARGET=native-native-gnu'); if (getenv('SPC_TARGET') && !str_contains((string) getenv('SPC_TARGET'), '-musl')) { $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; } From 3070376fb670e6ee8a4e5c5d512a8409032733c4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 3 Jul 2025 20:37:50 +0700 Subject: [PATCH 140/278] dont use 32 bit objects --- src/SPC/builder/linux/SystemUtil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index 0d808f9dd..443f3ce71 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -251,7 +251,7 @@ public static function getExtraRuntimeObjects(): string foreach ($objects as $obj) { $located = null; foreach ($paths as $base) { - $output = shell_exec("find {$base} -name {$obj} -print -quit 2>/dev/null"); + $output = shell_exec("find {$base} -name {$obj} 2>/dev/null | grep -v '/32/' | head -n 1"); $line = trim((string) $output); if ($line !== '') { $located = $line; From d65d82ff0ab5690574d6624bad3b78b23d39800b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 4 Jul 2025 14:27:48 +0700 Subject: [PATCH 141/278] remove extra libraries for php configure/make, since they're the same and only depend on the target libc --- bin/build-static-frankenphp | 1 - bin/spc-gnu-docker | 1 - config/env.ini | 6 ------ src/SPC/builder/linux/LinuxBuilder.php | 4 ++-- src/SPC/builder/macos/MacOSBuilder.php | 5 +++-- src/SPC/util/SPCConfigUtil.php | 5 ++--- src/SPC/util/SPCTarget.php | 11 +++++++++++ 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/bin/build-static-frankenphp b/bin/build-static-frankenphp index 10a693a78..58d051750 100755 --- a/bin/build-static-frankenphp +++ b/bin/build-static-frankenphp @@ -148,7 +148,6 @@ echo 'LD=/opt/rh/devtoolset-10/root/usr/bin/ld' >> /tmp/spc-gnu-docker.env echo 'SPC_DEFAULT_C_FLAGS=-fPIE -fPIC' >> /tmp/spc-gnu-docker.env echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env -echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' >> /tmp/spc-gnu-docker.env # Run docker # shellcheck disable=SC2068 diff --git a/bin/spc-gnu-docker b/bin/spc-gnu-docker index 20a26389f..2b4f826eb 100755 --- a/bin/spc-gnu-docker +++ b/bin/spc-gnu-docker @@ -156,7 +156,6 @@ fi echo 'SPC_DEFAULT_C_FLAGS=-fPIC' > /tmp/spc-gnu-docker.env echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env -echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' >> /tmp/spc-gnu-docker.env # Environment variable passthrough ENV_LIST="" diff --git a/config/env.ini b/config/env.ini index 8f9a7cf9f..fa5f3030b 100644 --- a/config/env.ini +++ b/config/env.ini @@ -115,12 +115,8 @@ SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -fPIE" SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}" ; LDFLAGS for configuring php SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" -; LIBS for configuring php -SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil" ; EXTRA_CFLAGS for `make` php SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}" -; EXTRA_LIBS for `make` php -SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lrt -lpthread -lm -lresolv -lutil" ; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS="" ; EXTRA_LDFLAGS_PROGRAM for `make` php @@ -158,8 +154,6 @@ SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}" SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" ; EXTRA_CFLAGS for `make` php SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie ${SPC_DEFAULT_C_FLAGS}" -; EXTRA_LIBS for `make` php -SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-lresolv" ; embed type for php, static (libphp.a) or shared (libphp.dylib) SPC_CMD_VAR_PHP_EMBED_TYPE="static" diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 31a9cd5a6..9f9fd0185 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -113,7 +113,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'), 'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'), 'LDFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS'), - 'LIBS' => $mimallocLibs . getenv('SPC_CMD_VAR_PHP_CONFIGURE_LIBS'), + 'LIBS' => $mimallocLibs . SPCTarget::getRuntimeLibs(), ]); // process micro upx patch if micro sapi enabled @@ -336,7 +336,7 @@ private function getMakeExtraVars(): array { return [ 'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'), - 'EXTRA_LIBS' => getenv('SPC_EXTRA_LIBS') . ' ' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS'), + 'EXTRA_LIBS' => getenv('SPC_EXTRA_LIBS') . ' ' . SPCTarget::getRuntimeLibs(), 'EXTRA_LDFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'), 'EXTRA_LDFLAGS_PROGRAM' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM'), ]; diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 362a68fe7..329d09e01 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -12,6 +12,7 @@ use SPC\store\FileSystem; use SPC\store\SourcePatcher; use SPC\util\GlobalEnvManager; +use SPC\util\SPCTarget; class MacOSBuilder extends UnixBuilderBase { @@ -131,7 +132,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'), 'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'), 'LDFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS'), - 'LIBS' => $mimallocLibs . getenv('SPC_CMD_VAR_PHP_CONFIGURE_LIBS'), + 'LIBS' => $mimallocLibs . SPCTarget::getRuntimeLibs(), ]); if ($this->getLib('postgresql')) { @@ -293,7 +294,7 @@ private function getMakeExtraVars(): array { return [ 'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'), - 'EXTRA_LIBS' => getenv('SPC_EXTRA_LIBS') . ' ' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS'), + 'EXTRA_LIBS' => getenv('SPC_EXTRA_LIBS') . ' ' . SPCTarget::getRuntimeLibs(), ]; } } diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index 3cedf11f6..0bf6390c2 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -64,9 +64,8 @@ public function config(array $extensions = [], array $libraries = [], bool $incl // embed $libs = trim("-lphp -lc {$libs}"); - $extra_env = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS'); - if (is_string($extra_env)) { - $libs .= ' ' . trim($extra_env, '"'); + if ($extra_libs = SPCTarget::getRuntimeLibs()) { + $libs .= " {$extra_libs}"; } // c++ if ($this->builder->hasCpp()) { diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index e739ea1ea..96bff7b6c 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -74,6 +74,17 @@ public static function getLibc(): ?string return null; } + public static function getRuntimeLibs(): string + { + if (PHP_OS_FAMILY === 'Linux') { + return self::getLibc() === 'musl' ? 'ldl -lpthread -lm' : '-ldl -lrt -lpthread -lm -lresolv -lutil'; + } + if (PHP_OS_FAMILY === 'Darwin') { + return '-lresolv'; + } + return ''; + } + /** * Returns the libc version if set, for other OS, it will always return null. */ From 94c38df1bac65a518f7df9531f70efeb5a969716 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 4 Jul 2025 14:32:47 +0700 Subject: [PATCH 142/278] remove superfluous build-frankenphp script --- .gitignore | 1 - bin/build-static-frankenphp | 157 ------------------------------------ 2 files changed, 158 deletions(-) delete mode 100755 bin/build-static-frankenphp diff --git a/.gitignore b/.gitignore index a95eeaacd..79ca915a3 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,6 @@ packlib_files.txt !/bin/setup-runtime* !/bin/spc-alpine-docker !/bin/php-cs-fixer-wrapper -!/bin/build-static-frankenphp # exclude windows build tools /php-sdk-binary-tools/ diff --git a/bin/build-static-frankenphp b/bin/build-static-frankenphp deleted file mode 100755 index 58d051750..000000000 --- a/bin/build-static-frankenphp +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/env bash - -# This file is using docker to run commands -set -e - -# Detect docker can run -if ! which docker >/dev/null; then - echo "Docker is not installed, please install docker first !" - exit 1 -fi -DOCKER_EXECUTABLE="docker" -# shellcheck disable=SC2046 -if [ $(id -u) -ne 0 ]; then - if ! docker info > /dev/null 2>&1; then - if [ "$SPC_USE_SUDO" != "yes" ]; then - echo "Docker command requires sudo" - # shellcheck disable=SC2039 - echo -n 'To use sudo to run docker, run "export SPC_USE_SUDO=yes" and run command again' - exit 1 - fi - DOCKER_EXECUTABLE="sudo docker" - fi -fi - - - -# to check if qemu-docker run -if [ "$SPC_USE_ARCH" = "" ]; then - SPC_USE_ARCH=current -fi -case $SPC_USE_ARCH in -current) - BASE_ARCH=$(uname -m) - if [ "$BASE_ARCH" = "arm64" ]; then - BASE_ARCH=aarch64 - GO_ARCH=arm64 - else - GO_ARCH=amd64 - fi - ;; -aarch64) - BASE_ARCH=aarch64 - GO_ARCH=arm64 - # shellcheck disable=SC2039 - echo -e "\e[033m* Using different arch needs to setup qemu-static for docker !\e[0m" - $DOCKER_EXECUTABLE run --rm --privileged multiarch/qemu-user-static:register --reset > /dev/null - ;; -*) - echo "Current arch is not supported to run in docker: $SPC_USE_ARCH" - exit 1 - ;; -esac - -# Detect docker env is setup -if ! $DOCKER_EXECUTABLE images | grep -q cwcc-frankenphp-gnu-$SPC_USE_ARCH; then - echo "Docker container does not exist. Building docker image ..." - $DOCKER_EXECUTABLE build -t cwcc-frankenphp-gnu-$SPC_USE_ARCH -f- . <> /etc/bashrc -RUN source /etc/bashrc - -RUN curl -o cmake.tgz -fsSL https://github.com/Kitware/CMake/releases/download/v3.31.4/cmake-3.31.4-linux-$BASE_ARCH.tar.gz && \ - mkdir /cmake && \ - tar -xzf cmake.tgz -C /cmake --strip-components 1 - -WORKDIR /app -ADD ./src /app/src -COPY ./composer.* /app/ -ADD ./bin/setup-runtime /app/bin/setup-runtime -ADD ./bin/spc /app/bin/spc -RUN /app/bin/setup-runtime -RUN /app/bin/php /app/bin/composer install --no-dev --classmap-authoritative -ENV PATH="/app/bin:/cmake/bin:/usr/local/go/bin:$PATH" -ENV SPC_LIBC=glibc - -ADD ./config/env.ini /app/config/env.ini -RUN bin/spc doctor --auto-fix --debug - -RUN curl -o make.tgz -fsSL https://ftp.gnu.org/gnu/make/make-4.4.tar.gz && \ - tar -zxvf make.tgz && \ - cd make-4.4 && \ - ./configure && \ - make && \ - make install && \ - ln -sf /usr/local/bin/make /usr/bin/make - -RUN curl -o automake.tgz -fsSL https://ftp.gnu.org/gnu/automake/automake-1.17.tar.xz && \ - tar -xvf automake.tgz && \ - cd automake-1.17 && \ - ./configure && \ - make && \ - make install && \ - ln -sf /usr/local/bin/automake /usr/bin/automake - -RUN git clone https://github.com/static-php/gnu-frankenphp --depth=1 /frankenphp -WORKDIR /frankenphp - -RUN curl -o go.tgz -fsSL https://go.dev/dl/go1.24.1.linux-$GO_ARCH.tar.gz && \ - rm -rf /usr/local/go && tar -C /usr/local -xzf go.tgz -EOF -fi - -# Check if in ci (local terminal can execute with -it) -if [ -t 0 ]; then - INTERACT=-it -else - INTERACT='' -fi - -# Mounting volumes -MOUNT_LIST="" -# shellcheck disable=SC2089 -MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/config:/app/config" -MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/src:/app/src" -MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/buildroot:/app/buildroot" -MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/source:/app/source" -MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/dist:/app/dist" -MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/downloads:/app/downloads" -MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot" -MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/frankenphp-dist:/frankenphp/dist" - -# Apply env in temp env file -echo 'CC=/opt/rh/devtoolset-10/root/usr/bin/gcc' > /tmp/spc-gnu-docker.env -echo 'CXX=/opt/rh/devtoolset-10/root/usr/bin/g++' >> /tmp/spc-gnu-docker.env -echo 'AR=/opt/rh/devtoolset-10/root/usr/bin/ar' >> /tmp/spc-gnu-docker.env -echo 'LD=/opt/rh/devtoolset-10/root/usr/bin/ld' >> /tmp/spc-gnu-docker.env -echo 'SPC_DEFAULT_C_FLAGS=-fPIE -fPIC' >> /tmp/spc-gnu-docker.env -echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env -echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env - -# Run docker -# shellcheck disable=SC2068 -# shellcheck disable=SC2086 -# shellcheck disable=SC2090 - -$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-frankenphp-gnu-$SPC_USE_ARCH ./build-static.sh From 013a19e25bd985c9fb2148b92aeadf02586f6537 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 4 Jul 2025 14:39:42 +0700 Subject: [PATCH 143/278] rename COMPILER_EXTRA to SPC_COMPILER_EXTRA --- src/SPC/builder/Extension.php | 2 +- src/SPC/builder/linux/LinuxBuilder.php | 4 ++-- src/SPC/builder/macos/MacOSBuilder.php | 2 +- src/SPC/builder/unix/library/libaom.php | 6 +++--- src/SPC/builder/windows/WindowsBuilder.php | 2 +- src/SPC/store/scripts/zig-cc.sh | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 50d8837aa..ba4ddefe8 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -405,7 +405,7 @@ public function buildUnixShared(): void 'LDFLAGS' => $config['ldflags'], 'LIBS' => $preStatic . $staticLibString . $postStatic . $sharedLibString, 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, - 'COMPILER_EXTRA' => '-lstdc++', + 'SPC_COMPILER_EXTRA' => '-lstdc++', ]; if ($this->patchBeforeSharedPhpize()) { diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 9f9fd0185..be856a656 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -32,7 +32,7 @@ public function __construct(array $options = []) GlobalEnvManager::afterInit(); // concurrency - $this->concurrency = intval(getenv('SPC_CONCURRENCY')); + $this->concurrency = (int) getenv('SPC_CONCURRENCY'); // cflags $this->arch_c_flags = getenv('SPC_DEFAULT_C_FLAGS'); $this->arch_cxx_flags = getenv('SPC_DEFAULT_CXX_FLAGS'); @@ -94,7 +94,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void } $disable_jit = $this->getOption('disable-opcache-jit', false) ? '--disable-opcache-jit ' : ''; if (!$disable_jit && $this->getExt('opcache')) { - f_putenv('COMPILER_EXTRA=-fno-sanitize=undefined'); + f_putenv('SPC_COMPILER_EXTRA=-fno-sanitize=undefined'); } $config_file_path = $this->getOption('with-config-file-path', false) ? ('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : ''; diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 329d09e01..f6e1fb642 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -34,7 +34,7 @@ public function __construct(array $options = []) // ---------- set necessary compile vars ---------- // concurrency - $this->concurrency = intval(getenv('SPC_CONCURRENCY')); + $this->concurrency = (int) getenv('SPC_CONCURRENCY'); // cflags $this->arch_c_flags = getenv('SPC_DEFAULT_C_FLAGS'); $this->arch_cxx_flags = getenv('SPC_DEFAULT_CXX_FLAGS'); diff --git a/src/SPC/builder/unix/library/libaom.php b/src/SPC/builder/unix/library/libaom.php index 9c10079bb..f2f50d85b 100644 --- a/src/SPC/builder/unix/library/libaom.php +++ b/src/SPC/builder/unix/library/libaom.php @@ -12,16 +12,16 @@ trait libaom { protected function build(): void { - $extra = getenv('COMPILER_EXTRA'); + $extra = getenv('SPC_COMPILER_EXTRA'); if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { $new = trim($extra . ' -D_GNU_SOURCE'); - f_putenv("COMPILER_EXTRA={$new}"); + f_putenv("SPC_COMPILER_EXTRA={$new}"); } UnixCMakeExecutor::create($this) ->setBuildDir("{$this->source_dir}/builddir") ->addConfigureArgs('-DAOM_TARGET_CPU=generic') ->build(); - f_putenv("COMPILER_EXTRA={$extra}"); + f_putenv("SPC_COMPILER_EXTRA={$extra}"); $this->patchPkgconfPrefix(['aom.pc']); } } diff --git a/src/SPC/builder/windows/WindowsBuilder.php b/src/SPC/builder/windows/WindowsBuilder.php index 25a503ebf..618d7238d 100644 --- a/src/SPC/builder/windows/WindowsBuilder.php +++ b/src/SPC/builder/windows/WindowsBuilder.php @@ -45,7 +45,7 @@ public function __construct(array $options = []) $this->zts = $this->getOption('enable-zts', false); // set concurrency - $this->concurrency = intval(getenv('SPC_CONCURRENCY')); + $this->concurrency = (int) getenv('SPC_CONCURRENCY'); // make cmake toolchain $this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile(); diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index 4dd0f6c91..d162a3693 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -29,7 +29,7 @@ done [[ -n "$SPC_TARGET" ]] && TARGET="-target $SPC_TARGET" || TARGET="" if [[ "$SPC_TARGET" =~ \.[0-9]+\.[0-9]+ ]]; then - output=$(zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" 2>&1) + output=$(zig cc $TARGET $SPC_COMPILER_EXTRA "${PARSED_ARGS[@]}" 2>&1) status=$? if [[ $status -eq 0 ]]; then @@ -44,4 +44,4 @@ if [[ "$SPC_TARGET" =~ \.[0-9]+\.[0-9]+ ]]; then fi fi -exec zig cc $TARGET $COMPILER_EXTRA "${PARSED_ARGS[@]}" +exec zig cc $TARGET $SPC_COMPILER_EXTRA "${PARSED_ARGS[@]}" From 5f8cd972cd0365cb55cd6adf1889ee248747df88 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 5 Jul 2025 10:48:56 +0800 Subject: [PATCH 144/278] Move extra runtime object to zig toolchain --- src/SPC/builder/Extension.php | 20 ++++---- src/SPC/builder/linux/SystemUtil.php | 71 ---------------------------- src/SPC/toolchain/ZigToolchain.php | 34 +++++++++++++ 3 files changed, 44 insertions(+), 81 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index ba4ddefe8..dc1b2d34c 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -4,12 +4,13 @@ namespace SPC\builder; -use SPC\builder\linux\SystemUtil; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\Config; use SPC\store\FileSystem; +use SPC\toolchain\ToolchainManager; +use SPC\toolchain\ZigToolchain; use SPC\util\SPCConfigUtil; class Extension @@ -216,16 +217,15 @@ public function patchBeforeSharedConfigure(): bool */ public function patchBeforeSharedMake(): bool { - $extra = SystemUtil::getExtraRuntimeObjects(); - if (!$extra) { - return false; + if (ToolchainManager::getToolchainClass() === ZigToolchain::class && ($extra = (new ZigToolchain())->getExtraRuntimeObjects())) { + FileSystem::replaceFileRegex( + $this->source_dir . '/Makefile', + "/^(shared_objects_{$this->getName()}\\s*=.*)$/m", + "$1 {$extra}", + ); + return true; } - FileSystem::replaceFileRegex( - $this->source_dir . '/Makefile', - "/^(shared_objects_{$this->getName()}\\s*=.*)$/m", - "$1 {$extra}", - ); - return true; + return false; } /** diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index 443f3ce71..c9e542559 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -5,9 +5,6 @@ namespace SPC\builder\linux; use SPC\builder\traits\UnixSystemUtilTrait; -use SPC\exception\RuntimeException; -use SPC\toolchain\ToolchainManager; -use SPC\toolchain\ZigToolchain; use SPC\util\SPCTarget; class SystemUtil @@ -16,8 +13,6 @@ class SystemUtil public static ?string $libc_version = null; - private static ?string $extra_runtime_objects = null; - /** @noinspection PhpMissingBreakStatementInspection */ public static function getOSRelease(): array { @@ -80,39 +75,6 @@ public static function getCpuCount(): int return $ncpu; } - /** - * @throws RuntimeException - */ - public static function getCCType(?string $cc = null): string - { - $cc ??= getenv('CC'); - return match (true) { - str_contains($cc, 'zig') => 'clang', - str_ends_with($cc, 'c++'), str_ends_with($cc, 'cc'), str_ends_with($cc, 'g++'), str_ends_with($cc, 'gcc') => 'gcc', - $cc === 'clang++', $cc === 'clang', str_starts_with($cc, 'musl-clang') => 'clang', - default => throw new RuntimeException("unknown cc type: {$cc}"), - }; - } - - /** - * @throws RuntimeException - * @noinspection PhpUnused - */ - public static function getCrossCompilePrefix(string $cc, string $arch): string - { - return match (static::getCCType($cc)) { - // guessing clang toolchains - 'clang' => match ($arch) { - 'x86_64' => 'x86_64-linux-gnu-', - 'arm64', 'aarch64' => 'aarch64-linux-gnu-', - default => throw new RuntimeException('unsupported arch: ' . $arch), - }, - // remove gcc postfix - 'gcc' => str_replace('-cc', '', str_replace('-gcc', '', $cc)) . '-', - default => throw new RuntimeException('unsupported cc'), - }; - } - public static function findStaticLib(string $name): ?array { $paths = getenv('LIBPATH'); @@ -233,37 +195,4 @@ public static function getLibcVersionIfExists(?string $libc = null): ?string } return null; } - - public static function getExtraRuntimeObjects(): string - { - if (ToolchainManager::getToolchainClass() !== ZigToolchain::class) { - return ''; - } - - if (self::$extra_runtime_objects !== null) { - return self::$extra_runtime_objects; - } - - $paths = ['/usr/lib/gcc', '/usr/local/lib/gcc']; - $objects = ['crtbeginS.o', 'crtendS.o']; - $found = []; - - foreach ($objects as $obj) { - $located = null; - foreach ($paths as $base) { - $output = shell_exec("find {$base} -name {$obj} 2>/dev/null | grep -v '/32/' | head -n 1"); - $line = trim((string) $output); - if ($line !== '') { - $located = $line; - break; - } - } - if ($located) { - $found[] = $located; - } - } - - self::$extra_runtime_objects = implode(' ', $found); - return implode(' ', $found); - } } diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index 779401a06..59e974696 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -26,4 +26,38 @@ public function afterInit(): void } GlobalEnvManager::addPathIfNotExists(Zig::getEnvironment()['PATH']); } + + /** + * Get the extra runtime objects needed for zig toolchain. + * This method searches for `crtbeginS.o` and `crtendS.o` in common GCC library paths. + */ + public function getExtraRuntimeObjects(): string + { + static $cache = null; + if ($cache !== null) { + return $cache; + } + + $paths = ['/usr/lib/gcc', '/usr/local/lib/gcc']; + $objects = ['crtbeginS.o', 'crtendS.o']; + $found = []; + + foreach ($objects as $obj) { + $located = null; + foreach ($paths as $base) { + $output = shell_exec("find {$base} -name {$obj} 2>/dev/null | grep -v '/32/' | head -n 1"); + $line = trim((string) $output); + if ($line !== '') { + $located = $line; + break; + } + } + if ($located) { + $found[] = $located; + } + } + + $cache = implode(' ', $found); + return $cache; + } } From d7f3005b6968da90f61ada2ef40004ec904d7915 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 5 Jul 2025 10:49:20 +0800 Subject: [PATCH 145/278] Fix missing dash --- src/SPC/util/SPCTarget.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index 96bff7b6c..de487f4f9 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -13,11 +13,6 @@ */ class SPCTarget { - public const array LIBC_LIST = [ - 'musl', - 'glibc', - ]; - /** * Returns whether we link the C runtime in statically. */ @@ -77,7 +72,7 @@ public static function getLibc(): ?string public static function getRuntimeLibs(): string { if (PHP_OS_FAMILY === 'Linux') { - return self::getLibc() === 'musl' ? 'ldl -lpthread -lm' : '-ldl -lrt -lpthread -lm -lresolv -lutil'; + return self::getLibc() === 'musl' ? '-ldl -lpthread -lm' : '-ldl -lrt -lpthread -lm -lresolv -lutil'; } if (PHP_OS_FAMILY === 'Darwin') { return '-lresolv'; From 59f9143a3c8ad72efcf03c533dde0c206c52ce15 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 5 Jul 2025 10:49:36 +0800 Subject: [PATCH 146/278] Remove redundant postfix in openssl --- src/SPC/builder/linux/library/openssl.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index 76049ccc5..3a4825c8b 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -21,7 +21,6 @@ namespace SPC\builder\linux\library; -use SPC\builder\linux\SystemUtil; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; @@ -62,9 +61,6 @@ public function build(): void $ex_lib = trim($ex_lib); - /* @phpstan-ignore-next-line */ - $clang_postfix = SystemUtil::getCCType() === 'clang' && (GNU_ARCH === 'x86_64' || PHP_OS_FAMILY === 'Darwin') ? '-clang' : ''; - shell()->cd($this->source_dir)->initializeEnv($this) ->exec( "{$env} ./Configure no-shared {$extra} " . @@ -73,7 +69,7 @@ public function build(): void '--openssldir=/etc/ssl ' . "{$zlib_extra}" . 'no-legacy ' . - "linux-{$arch}{$clang_postfix}" + "linux-{$arch}" ) ->exec('make clean') ->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") From c9d33bffc8544eb6f5479e943292e71b5d3b3f69 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 5 Jul 2025 10:49:55 +0800 Subject: [PATCH 147/278] Chore --- src/SPC/builder/extension/imagick.php | 4 ++-- src/SPC/builder/linux/LinuxBuilder.php | 7 ------- tests/SPC/builder/linux/SystemUtilTest.php | 10 ---------- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index c1979367d..4067391a9 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -5,8 +5,8 @@ namespace SPC\builder\extension; use SPC\builder\Extension; -use SPC\builder\linux\SystemUtil; use SPC\util\CustomExt; +use SPC\util\SPCTarget; #[CustomExt('imagick')] class imagick extends Extension @@ -20,7 +20,7 @@ public function getUnixConfigureArg(bool $shared = false): string protected function getStaticAndSharedLibs(): array { [$static, $shared] = parent::getStaticAndSharedLibs(); - if (SystemUtil::getLibcVersionIfExists('glibc') && SystemUtil::getLibcVersionIfExists('glibc') <= '2.17') { + if (SPCTarget::getLibc() === 'glibc' && version_compare(SPCTarget::getLibcVersion(), '2.17', '<=')) { $static .= ' -lstdc++'; $shared = str_replace('-lstdc++', '', $shared); } diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index be856a656..721869498 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -37,13 +37,6 @@ public function __construct(array $options = []) $this->arch_c_flags = getenv('SPC_DEFAULT_C_FLAGS'); $this->arch_cxx_flags = getenv('SPC_DEFAULT_CXX_FLAGS'); - // cross-compiling is not supported yet - /*if (php_uname('m') !== $this->arch) { - $this->cross_compile_prefix = SystemUtil::getCrossCompilePrefix($this->cc, $this->arch); - logger()->info('using cross compile prefix: ' . $this->cross_compile_prefix); - $this->configure_env .= " CROSS_COMPILE='{$this->cross_compile_prefix}'"; - }*/ - // create pkgconfig and include dir (some libs cannot create them automatically) f_mkdir(BUILD_LIB_PATH . '/pkgconfig', recursive: true); f_mkdir(BUILD_INCLUDE_PATH, recursive: true); diff --git a/tests/SPC/builder/linux/SystemUtilTest.php b/tests/SPC/builder/linux/SystemUtilTest.php index 15552bcd3..01d555d81 100644 --- a/tests/SPC/builder/linux/SystemUtilTest.php +++ b/tests/SPC/builder/linux/SystemUtilTest.php @@ -43,16 +43,6 @@ public function testFindHeader() $this->assertIsArray(SystemUtil::findHeader('elf.h')); } - public function testGetCrossCompilePrefix() - { - $this->assertIsString(SystemUtil::getCrossCompilePrefix('gcc', 'x86_64')); - } - - public function testGetCCType() - { - $this->assertEquals('gcc', SystemUtil::getCCType('xjfoiewjfoewof-gcc')); - } - public function testGetSupportedDistros() { $this->assertIsArray(SystemUtil::getSupportedDistros()); From 112f607d6e32dc0b3813b19076f7f6482e9b9cda Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 5 Jul 2025 11:42:00 +0800 Subject: [PATCH 148/278] Add linux-only for extra runtime objects --- src/SPC/builder/Extension.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index dc1b2d34c..ffae2c386 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -217,7 +217,11 @@ public function patchBeforeSharedConfigure(): bool */ public function patchBeforeSharedMake(): bool { - if (ToolchainManager::getToolchainClass() === ZigToolchain::class && ($extra = (new ZigToolchain())->getExtraRuntimeObjects())) { + if ( + PHP_OS_FAMILY === 'Linux' && + ToolchainManager::getToolchainClass() === ZigToolchain::class && + ($extra = (new ZigToolchain())->getExtraRuntimeObjects()) + ) { FileSystem::replaceFileRegex( $this->source_dir . '/Makefile', "/^(shared_objects_{$this->getName()}\\s*=.*)$/m", From 2ac20cf3afb1b43bd2ab1c384fa508d48df8be80 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 10:44:32 +0700 Subject: [PATCH 149/278] remove unnecessary LDFLAGS_PROGRAM env var --- bin/spc-gnu-docker | 1 - config/env.ini | 2 -- src/SPC/builder/linux/LinuxBuilder.php | 2 +- src/SPC/doctor/item/ZigCheck.php | 2 +- 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/bin/spc-gnu-docker b/bin/spc-gnu-docker index 2b4f826eb..f619a82b5 100755 --- a/bin/spc-gnu-docker +++ b/bin/spc-gnu-docker @@ -155,7 +155,6 @@ fi # Apply env in temp env file echo 'SPC_DEFAULT_C_FLAGS=-fPIC' > /tmp/spc-gnu-docker.env echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env -echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env # Environment variable passthrough ENV_LIST="" diff --git a/config/env.ini b/config/env.ini index fa5f3030b..74f4322ce 100644 --- a/config/env.ini +++ b/config/env.ini @@ -119,8 +119,6 @@ SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}" ; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS="" -; EXTRA_LDFLAGS_PROGRAM for `make` php -SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-all-static -pie" [macos] ; build target: macho or macho (possibly we could support macho-universal in the future) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 721869498..258365d16 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -331,7 +331,7 @@ private function getMakeExtraVars(): array 'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'), 'EXTRA_LIBS' => getenv('SPC_EXTRA_LIBS') . ' ' . SPCTarget::getRuntimeLibs(), 'EXTRA_LDFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'), - 'EXTRA_LDFLAGS_PROGRAM' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM'), + 'EXTRA_LDFLAGS_PROGRAM' => SPCTarget::isStatic() ? '-all-static -pie' : '-pie', ]; } diff --git a/src/SPC/doctor/item/ZigCheck.php b/src/SPC/doctor/item/ZigCheck.php index ffd9aca5b..186f43b74 100644 --- a/src/SPC/doctor/item/ZigCheck.php +++ b/src/SPC/doctor/item/ZigCheck.php @@ -38,7 +38,7 @@ public function checkZig(): CheckResult * @throws WrongUsageException */ #[AsFixItem('install-zig')] - public function fixMuslCrossMake(): bool + public function installZig(): bool { $arch = arch2gnu(php_uname('m')); $os = match (PHP_OS_FAMILY) { From 93d6a45a78bc11668b1b3133459c925fe08ab3b2 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 12:01:52 +0700 Subject: [PATCH 150/278] *full* shared extension build linked against musl libc dynamically works! --- src/SPC/builder/linux/LinuxBuilder.php | 12 ++++++------ src/SPC/store/SourcePatcher.php | 19 ++++++++++++++----- src/globals/test-extensions.php | 4 ++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 258365d16..76e6a71d4 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -192,12 +192,12 @@ protected function buildCli(): void ->exec('sed -i "s|//lib|/lib|g" Makefile') ->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} cli"); + if (!$this->getOption('no-strip', false)) { + shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-all php'); + } if ($this->getOption('with-upx-pack')) { shell()->cd(SOURCE_PATH . '/php-src/sapi/cli') - ->exec('strip --strip-all php') ->exec(getenv('UPX_EXEC') . ' --best php'); - } elseif (!$this->getOption('no-strip', false)) { - shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-all php'); } $this->deployBinary(BUILD_TARGET_CLI); @@ -255,12 +255,12 @@ protected function buildFpm(): void ->exec('sed -i "s|//lib|/lib|g" Makefile') ->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} fpm"); + if (!$this->getOption('no-strip', false)) { + shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')->exec('strip --strip-all php-fpm'); + } if ($this->getOption('with-upx-pack')) { shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm') - ->exec('strip --strip-all php-fpm') ->exec(getenv('UPX_EXEC') . ' --best php-fpm'); - } elseif (!$this->getOption('no-strip', false)) { - shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')->exec('strip --strip-all php-fpm'); } $this->deployBinary(BUILD_TARGET_FPM); } diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 08ebdaefb..89c2dc0d9 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -256,14 +256,23 @@ public static function patchSwoole(): bool */ public static function patchBeforeMake(BuilderBase $builder): void { - // Try to fix debian environment build lack HAVE_STRLCAT problem - if ($builder instanceof LinuxBuilder) { - FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/main/php_config.h', '/^#define HAVE_STRLCPY 1$/m', ''); - FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/main/php_config.h', '/^#define HAVE_STRLCAT 1$/m', ''); - } if ($builder instanceof UnixBuilderBase) { FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/Makefile', 'install-micro', ''); } + if (!SPCTarget::isStatic() && SPCTarget::getLibc() === 'musl') { + // we need to patch the symbol to global visibility, otherwise extensions with `initial-exec` TLS model will fail to load + FileSystem::replaceFileStr( + SOURCE_PATH . '/php-src/TSRM/TSRM.h', + '#define TSRMLS_MAIN_CACHE_DEFINE() TSRM_TLS void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL;', + '#define TSRMLS_MAIN_CACHE_DEFINE() TSRM_TLS __attribute__((visibility("default"))) void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL;', + ); + } else { + FileSystem::replaceFileStr( + SOURCE_PATH . '/php-src/TSRM/TSRM.h', + '#define TSRMLS_MAIN_CACHE_DEFINE() TSRM_TLS __attribute__((visibility("default"))) void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL;', + '#define TSRMLS_MAIN_CACHE_DEFINE() TSRM_TLS void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL;', + ); + } // no asan // if (strpos(file_get_contents(SOURCE_PATH . '/php-src/Makefile'), 'CFLAGS_CLEAN = -g') === false) { diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 73752c005..23d3f15da 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -158,8 +158,8 @@ function quote2(string $param): string break; case 'ubuntu-24.04': case 'ubuntu-24.04-arm': - putenv('SPC_TARGET=native-native-gnu'); - if (getenv('SPC_TARGET') && !str_contains((string) getenv('SPC_TARGET'), '-musl')) { + putenv('SPC_TARGET=native-native-musl -dynamic'); + if (getenv('SPC_TARGET') && !str_contains(getenv('SPC_TARGET'), '-musl') || str_contains(getenv('SPC_TARGET'), '-dynamic')) { $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; } break; From 26aca723cba934283f95dce5343fdbfa3d3c2288 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 12:11:48 +0700 Subject: [PATCH 151/278] update php-cs fixer to get rid of PHP_CS_FIXER_IGNORE_ENV variable --- .github/pull_request_template.md | 2 +- .github/workflows/tests.yml | 2 +- .php-cs-fixer.php | 1 + bin/php-cs-fixer-wrapper | 2 +- composer.lock | 359 ++++++++++++++++--------------- src/SPC/store/SourcePatcher.php | 1 - 6 files changed, 189 insertions(+), 178 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 13441a81f..fb78849c7 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -8,7 +8,7 @@ > If a modification is not involved, please skip it directly. - If you modified `*.php` or `*.json`, run them locally to ensure your changes are valid: - - [ ] `PHP_CS_FIXER_IGNORE_ENV=1 composer cs-fix` + - [ ] `composer cs-fix` - [ ] `composer analyse` - [ ] `composer test` - [ ] `bin/spc dev:sort-config` diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5ed6d59dc..c01f78bf1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,7 +39,7 @@ jobs: tools: pecl, composer, php-cs-fixer - name: Run PHP-CS-Fixer fix - run: PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --dry-run --diff --ansi + run: php-cs-fixer fix --dry-run --diff --ansi phpstan: runs-on: ubuntu-latest diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 6e57f1830..d1c30090e 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -4,6 +4,7 @@ return (new PhpCsFixer\Config()) ->setRiskyAllowed(true) + ->setUnsupportedPhpVersionAllowed(true) ->setRules([ '@PSR12' => true, '@Symfony' => true, diff --git a/bin/php-cs-fixer-wrapper b/bin/php-cs-fixer-wrapper index 8a32dbe4c..007b99487 100755 --- a/bin/php-cs-fixer-wrapper +++ b/bin/php-cs-fixer-wrapper @@ -1,4 +1,4 @@ #!/usr/bin/env bash # get parent dir, and run the php-cs-fixer -PHP_CS_FIXER_IGNORE_ENV=1 "$(dirname "$0")/../vendor/bin/php-cs-fixer" "$@" +"$(dirname "$0")/../vendor/bin/php-cs-fixer" "$@" diff --git a/composer.lock b/composer.lock index 3004785e2..2f2912dbd 100644 --- a/composer.lock +++ b/composer.lock @@ -8,7 +8,7 @@ "packages": [ { "name": "illuminate/collections", - "version": "v11.44.4", + "version": "v11.45.1", "source": { "type": "git", "url": "https://github.com/illuminate/collections.git", @@ -64,7 +64,7 @@ }, { "name": "illuminate/conditionable", - "version": "v11.44.4", + "version": "v11.45.1", "source": { "type": "git", "url": "https://github.com/illuminate/conditionable.git", @@ -110,7 +110,7 @@ }, { "name": "illuminate/contracts", - "version": "v11.44.4", + "version": "v11.45.1", "source": { "type": "git", "url": "https://github.com/illuminate/contracts.git", @@ -158,7 +158,7 @@ }, { "name": "illuminate/macroable", - "version": "v11.44.4", + "version": "v11.45.1", "source": { "type": "git", "url": "https://github.com/illuminate/macroable.git", @@ -416,16 +416,16 @@ }, { "name": "symfony/console", - "version": "v6.4.20", + "version": "v6.4.23", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "2e4af9c952617cc3f9559ff706aee420a8464c36" + "reference": "9056771b8eca08d026cd3280deeec3cfd99c4d93" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/2e4af9c952617cc3f9559ff706aee420a8464c36", - "reference": "2e4af9c952617cc3f9559ff706aee420a8464c36", + "url": "https://api.github.com/repos/symfony/console/zipball/9056771b8eca08d026cd3280deeec3cfd99c4d93", + "reference": "9056771b8eca08d026cd3280deeec3cfd99c4d93", "shasum": "" }, "require": { @@ -490,7 +490,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v6.4.20" + "source": "https://github.com/symfony/console/tree/v6.4.23" }, "funding": [ { @@ -506,20 +506,20 @@ "type": "tidelift" } ], - "time": "2025-03-03T17:16:38+00:00" + "time": "2025-06-27T19:37:22+00:00" }, { "name": "symfony/deprecation-contracts", - "version": "v3.5.1", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6" + "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6", - "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62", + "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62", "shasum": "" }, "require": { @@ -532,7 +532,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "3.5-dev" + "dev-main": "3.6-dev" } }, "autoload": { @@ -557,7 +557,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.1" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0" }, "funding": [ { @@ -573,11 +573,11 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:20:29+00:00" + "time": "2024-09-25T14:21:43+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.31.0", + "version": "v1.32.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", @@ -636,7 +636,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.32.0" }, "funding": [ { @@ -656,7 +656,7 @@ }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.31.0", + "version": "v1.32.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", @@ -714,7 +714,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.32.0" }, "funding": [ { @@ -734,7 +734,7 @@ }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.31.0", + "version": "v1.32.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", @@ -795,7 +795,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.32.0" }, "funding": [ { @@ -815,19 +815,20 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.31.0", + "version": "v1.32.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341" + "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/85181ba99b2345b0ef10ce42ecac37612d9fd341", - "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493", + "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493", "shasum": "" }, "require": { + "ext-iconv": "*", "php": ">=7.2" }, "provide": { @@ -875,7 +876,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.32.0" }, "funding": [ { @@ -891,20 +892,20 @@ "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2024-12-23T08:48:59+00:00" }, { "name": "symfony/process", - "version": "v7.2.5", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "87b7c93e57df9d8e39a093d32587702380ff045d" + "reference": "40c295f2deb408d5e9d2d32b8ba1dd61e36f05af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/87b7c93e57df9d8e39a093d32587702380ff045d", - "reference": "87b7c93e57df9d8e39a093d32587702380ff045d", + "url": "https://api.github.com/repos/symfony/process/zipball/40c295f2deb408d5e9d2d32b8ba1dd61e36f05af", + "reference": "40c295f2deb408d5e9d2d32b8ba1dd61e36f05af", "shasum": "" }, "require": { @@ -936,7 +937,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.2.5" + "source": "https://github.com/symfony/process/tree/v7.3.0" }, "funding": [ { @@ -952,20 +953,20 @@ "type": "tidelift" } ], - "time": "2025-03-13T12:21:46+00:00" + "time": "2025-04-17T09:11:12+00:00" }, { "name": "symfony/service-contracts", - "version": "v3.5.1", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "e53260aabf78fb3d63f8d79d69ece59f80d5eda0" + "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/e53260aabf78fb3d63f8d79d69ece59f80d5eda0", - "reference": "e53260aabf78fb3d63f8d79d69ece59f80d5eda0", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f021b05a130d35510bd6b25fe9053c2a8a15d5d4", + "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4", "shasum": "" }, "require": { @@ -983,7 +984,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "3.5-dev" + "dev-main": "3.6-dev" } }, "autoload": { @@ -1019,7 +1020,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.5.1" + "source": "https://github.com/symfony/service-contracts/tree/v3.6.0" }, "funding": [ { @@ -1035,20 +1036,20 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:20:29+00:00" + "time": "2025-04-25T09:37:31+00:00" }, { "name": "symfony/string", - "version": "v7.2.0", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "446e0d146f991dde3e73f45f2c97a9faad773c82" + "reference": "f3570b8c61ca887a9e2938e85cb6458515d2b125" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/446e0d146f991dde3e73f45f2c97a9faad773c82", - "reference": "446e0d146f991dde3e73f45f2c97a9faad773c82", + "url": "https://api.github.com/repos/symfony/string/zipball/f3570b8c61ca887a9e2938e85cb6458515d2b125", + "reference": "f3570b8c61ca887a9e2938e85cb6458515d2b125", "shasum": "" }, "require": { @@ -1106,7 +1107,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.2.0" + "source": "https://github.com/symfony/string/tree/v7.3.0" }, "funding": [ { @@ -1122,20 +1123,20 @@ "type": "tidelift" } ], - "time": "2024-11-13T13:31:26+00:00" + "time": "2025-04-20T20:19:01+00:00" }, { "name": "symfony/yaml", - "version": "v7.2.5", + "version": "v7.3.1", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "4c4b6f4cfcd7e52053f0c8bfad0f7f30fb924912" + "reference": "0c3555045a46ab3cd4cc5a69d161225195230edb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/4c4b6f4cfcd7e52053f0c8bfad0f7f30fb924912", - "reference": "4c4b6f4cfcd7e52053f0c8bfad0f7f30fb924912", + "url": "https://api.github.com/repos/symfony/yaml/zipball/0c3555045a46ab3cd4cc5a69d161225195230edb", + "reference": "0c3555045a46ab3cd4cc5a69d161225195230edb", "shasum": "" }, "require": { @@ -1178,7 +1179,7 @@ "description": "Loads and dumps YAML files", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/yaml/tree/v7.2.5" + "source": "https://github.com/symfony/yaml/tree/v7.3.1" }, "funding": [ { @@ -1194,7 +1195,7 @@ "type": "tidelift" } ], - "time": "2025-03-03T07:12:39+00:00" + "time": "2025-06-03T06:57:57+00:00" }, { "name": "zhamao/logger", @@ -2077,16 +2078,16 @@ }, { "name": "captainhook/captainhook-phar", - "version": "5.25.2", + "version": "5.25.6", "source": { "type": "git", "url": "https://github.com/captainhook-git/captainhook-phar.git", - "reference": "ab47b0561ec7997bf9b88181d090857874f2cf8c" + "reference": "a5dbcd8d20b3dcdb1cbd6948d0d3a058453b3d6a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/captainhook-git/captainhook-phar/zipball/ab47b0561ec7997bf9b88181d090857874f2cf8c", - "reference": "ab47b0561ec7997bf9b88181d090857874f2cf8c", + "url": "https://api.github.com/repos/captainhook-git/captainhook-phar/zipball/a5dbcd8d20b3dcdb1cbd6948d0d3a058453b3d6a", + "reference": "a5dbcd8d20b3dcdb1cbd6948d0d3a058453b3d6a", "shasum": "" }, "require": { @@ -2119,7 +2120,7 @@ } ], "description": "PHP git hook manager", - "homepage": "https://github.com/captainhookphp/captainhook", + "homepage": "https://github.com/captainhook-git/captainhook", "keywords": [ "commit-msg", "git", @@ -2130,8 +2131,8 @@ "prepare-commit-msg" ], "support": { - "issues": "https://github.com/captainhookphp/captainhook/issues", - "source": "https://github.com/captainhook-git/captainhook-phar/tree/5.25.2" + "issues": "https://github.com/captainhook-git/captainhook/issues", + "source": "https://github.com/captainhook-git/captainhook-phar/tree/5.25.6" }, "funding": [ { @@ -2139,7 +2140,7 @@ "type": "github" } ], - "time": "2025-03-30T17:19:44+00:00" + "time": "2025-04-08T07:07:48+00:00" }, { "name": "captainhook/hook-installer", @@ -2832,16 +2833,16 @@ }, { "name": "filp/whoops", - "version": "2.18.0", + "version": "2.18.3", "source": { "type": "git", "url": "https://github.com/filp/whoops.git", - "reference": "a7de6c3c6c3c022f5cfc337f8ede6a14460cf77e" + "reference": "59a123a3d459c5a23055802237cb317f609867e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/a7de6c3c6c3c022f5cfc337f8ede6a14460cf77e", - "reference": "a7de6c3c6c3c022f5cfc337f8ede6a14460cf77e", + "url": "https://api.github.com/repos/filp/whoops/zipball/59a123a3d459c5a23055802237cb317f609867e5", + "reference": "59a123a3d459c5a23055802237cb317f609867e5", "shasum": "" }, "require": { @@ -2891,7 +2892,7 @@ ], "support": { "issues": "https://github.com/filp/whoops/issues", - "source": "https://github.com/filp/whoops/tree/2.18.0" + "source": "https://github.com/filp/whoops/tree/2.18.3" }, "funding": [ { @@ -2899,62 +2900,63 @@ "type": "github" } ], - "time": "2025-03-15T12:00:00+00:00" + "time": "2025-06-16T00:02:10+00:00" }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.75.0", + "version": "v3.76.0", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "399a128ff2fdaf4281e4e79b755693286cdf325c" + "reference": "0e3c484cef0ae9314b0f85986a36296087432c40" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/399a128ff2fdaf4281e4e79b755693286cdf325c", - "reference": "399a128ff2fdaf4281e4e79b755693286cdf325c", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/0e3c484cef0ae9314b0f85986a36296087432c40", + "reference": "0e3c484cef0ae9314b0f85986a36296087432c40", "shasum": "" }, "require": { "clue/ndjson-react": "^1.0", "composer/semver": "^3.4", - "composer/xdebug-handler": "^3.0.3", + "composer/xdebug-handler": "^3.0.5", "ext-filter": "*", "ext-hash": "*", "ext-json": "*", "ext-tokenizer": "*", "fidry/cpu-core-counter": "^1.2", "php": "^7.4 || ^8.0", - "react/child-process": "^0.6.5", + "react/child-process": "^0.6.6", "react/event-loop": "^1.0", - "react/promise": "^2.0 || ^3.0", + "react/promise": "^2.11 || ^3.0", "react/socket": "^1.0", "react/stream": "^1.0", - "sebastian/diff": "^4.0 || ^5.1 || ^6.0 || ^7.0", - "symfony/console": "^5.4 || ^6.4 || ^7.0", - "symfony/event-dispatcher": "^5.4 || ^6.4 || ^7.0", - "symfony/filesystem": "^5.4 || ^6.4 || ^7.0", - "symfony/finder": "^5.4 || ^6.4 || ^7.0", - "symfony/options-resolver": "^5.4 || ^6.4 || ^7.0", - "symfony/polyfill-mbstring": "^1.31", - "symfony/polyfill-php80": "^1.31", - "symfony/polyfill-php81": "^1.31", - "symfony/process": "^5.4 || ^6.4 || ^7.2", - "symfony/stopwatch": "^5.4 || ^6.4 || ^7.0" + "sebastian/diff": "^4.0.6 || ^5.1.1 || ^6.0.2 || ^7.0", + "symfony/console": "^5.4.45 || ^6.4.13 || ^7.0", + "symfony/event-dispatcher": "^5.4.45 || ^6.4.13 || ^7.0", + "symfony/filesystem": "^5.4.45 || ^6.4.13 || ^7.0", + "symfony/finder": "^5.4.45 || ^6.4.17 || ^7.0", + "symfony/options-resolver": "^5.4.45 || ^6.4.16 || ^7.0", + "symfony/polyfill-mbstring": "^1.32", + "symfony/polyfill-php80": "^1.32", + "symfony/polyfill-php81": "^1.32", + "symfony/process": "^5.4.47 || ^6.4.20 || ^7.2", + "symfony/stopwatch": "^5.4.45 || ^6.4.19 || ^7.0" }, "require-dev": { "facile-it/paraunit": "^1.3.1 || ^2.6", "infection/infection": "^0.29.14", - "justinrainbow/json-schema": "^5.3 || ^6.2", - "keradus/cli-executor": "^2.1", + "justinrainbow/json-schema": "^5.3 || ^6.4", + "keradus/cli-executor": "^2.2", "mikey179/vfsstream": "^1.6.12", - "php-coveralls/php-coveralls": "^2.7", + "php-coveralls/php-coveralls": "^2.8", "php-cs-fixer/accessible-object": "^1.1", "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.6", "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.6", - "phpunit/phpunit": "^9.6.22 || ^10.5.45 || ^11.5.12", - "symfony/var-dumper": "^5.4.48 || ^6.4.18 || ^7.2.3", - "symfony/yaml": "^5.4.45 || ^6.4.18 || ^7.2.3" + "phpunit/phpunit": "^9.6.23 || ^10.5.47 || ^11.5.25", + "symfony/polyfill-php84": "^1.32", + "symfony/var-dumper": "^5.4.48 || ^6.4.23 || ^7.3.1", + "symfony/yaml": "^5.4.45 || ^6.4.23 || ^7.3.1" }, "suggest": { "ext-dom": "For handling output formats in XML", @@ -2995,7 +2997,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.75.0" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.76.0" }, "funding": [ { @@ -3003,7 +3005,7 @@ "type": "github" } ], - "time": "2025-03-31T18:40:42+00:00" + "time": "2025-06-30T14:15:06+00:00" }, { "name": "humbug/box", @@ -3546,16 +3548,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.13.0", + "version": "1.13.2", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "024473a478be9df5fdaca2c793f2232fe788e414" + "reference": "d25e62e636b0a9b01e3bdebb7823b474876dd829" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/024473a478be9df5fdaca2c793f2232fe788e414", - "reference": "024473a478be9df5fdaca2c793f2232fe788e414", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/d25e62e636b0a9b01e3bdebb7823b474876dd829", + "reference": "d25e62e636b0a9b01e3bdebb7823b474876dd829", "shasum": "" }, "require": { @@ -3594,7 +3596,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.13.0" + "source": "https://github.com/myclabs/DeepCopy/tree/1.13.2" }, "funding": [ { @@ -3602,7 +3604,7 @@ "type": "tidelift" } ], - "time": "2025-02-12T12:17:51+00:00" + "time": "2025-07-04T14:07:32+00:00" }, { "name": "nikic/iter", @@ -3658,16 +3660,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.4.0", + "version": "v5.5.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "447a020a1f875a434d62f2a401f53b82a396e494" + "reference": "ae59794362fe85e051a58ad36b289443f57be7a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/447a020a1f875a434d62f2a401f53b82a396e494", - "reference": "447a020a1f875a434d62f2a401f53b82a396e494", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/ae59794362fe85e051a58ad36b289443f57be7a9", + "reference": "ae59794362fe85e051a58ad36b289443f57be7a9", "shasum": "" }, "require": { @@ -3710,9 +3712,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.4.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.5.0" }, - "time": "2024-12-30T11:07:19+00:00" + "time": "2025-05-31T08:24:38+00:00" }, { "name": "nunomaduro/collision", @@ -4451,16 +4453,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.24", + "version": "1.12.27", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "338b92068f58d9f8035b76aed6cf2b9e5624c025" + "reference": "3a6e423c076ab39dfedc307e2ac627ef579db162" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/338b92068f58d9f8035b76aed6cf2b9e5624c025", - "reference": "338b92068f58d9f8035b76aed6cf2b9e5624c025", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/3a6e423c076ab39dfedc307e2ac627ef579db162", + "reference": "3a6e423c076ab39dfedc307e2ac627ef579db162", "shasum": "" }, "require": { @@ -4505,7 +4507,7 @@ "type": "github" } ], - "time": "2025-04-16T13:01:53+00:00" + "time": "2025-05-21T20:51:45+00:00" }, { "name": "phpunit/php-code-coverage", @@ -4830,16 +4832,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.5.45", + "version": "10.5.47", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "bd68a781d8e30348bc297449f5234b3458267ae8" + "reference": "3637b3e50d32ab3a0d1a33b3b6177169ec3d95a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/bd68a781d8e30348bc297449f5234b3458267ae8", - "reference": "bd68a781d8e30348bc297449f5234b3458267ae8", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3637b3e50d32ab3a0d1a33b3b6177169ec3d95a3", + "reference": "3637b3e50d32ab3a0d1a33b3b6177169ec3d95a3", "shasum": "" }, "require": { @@ -4849,7 +4851,7 @@ "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.12.1", + "myclabs/deep-copy": "^1.13.1", "phar-io/manifest": "^2.0.4", "phar-io/version": "^3.2.1", "php": ">=8.1", @@ -4911,7 +4913,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.45" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.47" }, "funding": [ { @@ -4922,12 +4924,20 @@ "url": "https://github.com/sebastianbergmann", "type": "github" }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, { "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", "type": "tidelift" } ], - "time": "2025-02-06T16:08:12+00:00" + "time": "2025-06-20T11:29:11+00:00" }, { "name": "psr/event-dispatcher", @@ -6715,16 +6725,16 @@ }, { "name": "symfony/event-dispatcher", - "version": "v7.2.0", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "910c5db85a5356d0fea57680defec4e99eb9c8c1" + "reference": "497f73ac996a598c92409b44ac43b6690c4f666d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/910c5db85a5356d0fea57680defec4e99eb9c8c1", - "reference": "910c5db85a5356d0fea57680defec4e99eb9c8c1", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/497f73ac996a598c92409b44ac43b6690c4f666d", + "reference": "497f73ac996a598c92409b44ac43b6690c4f666d", "shasum": "" }, "require": { @@ -6775,7 +6785,7 @@ "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/event-dispatcher/tree/v7.2.0" + "source": "https://github.com/symfony/event-dispatcher/tree/v7.3.0" }, "funding": [ { @@ -6791,20 +6801,20 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:21:43+00:00" + "time": "2025-04-22T09:11:45+00:00" }, { "name": "symfony/event-dispatcher-contracts", - "version": "v3.5.1", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "7642f5e970b672283b7823222ae8ef8bbc160b9f" + "reference": "59eb412e93815df44f05f342958efa9f46b1e586" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/7642f5e970b672283b7823222ae8ef8bbc160b9f", - "reference": "7642f5e970b672283b7823222ae8ef8bbc160b9f", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/59eb412e93815df44f05f342958efa9f46b1e586", + "reference": "59eb412e93815df44f05f342958efa9f46b1e586", "shasum": "" }, "require": { @@ -6818,7 +6828,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "3.5-dev" + "dev-main": "3.6-dev" } }, "autoload": { @@ -6851,7 +6861,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.5.1" + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.6.0" }, "funding": [ { @@ -6867,11 +6877,11 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:20:29+00:00" + "time": "2024-09-25T14:21:43+00:00" }, { "name": "symfony/filesystem", - "version": "v7.2.0", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", @@ -6917,7 +6927,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v7.2.0" + "source": "https://github.com/symfony/filesystem/tree/v7.3.0" }, "funding": [ { @@ -6937,16 +6947,16 @@ }, { "name": "symfony/finder", - "version": "v7.2.2", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "87a71856f2f56e4100373e92529eed3171695cfb" + "reference": "ec2344cf77a48253bbca6939aa3d2477773ea63d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/87a71856f2f56e4100373e92529eed3171695cfb", - "reference": "87a71856f2f56e4100373e92529eed3171695cfb", + "url": "https://api.github.com/repos/symfony/finder/zipball/ec2344cf77a48253bbca6939aa3d2477773ea63d", + "reference": "ec2344cf77a48253bbca6939aa3d2477773ea63d", "shasum": "" }, "require": { @@ -6981,7 +6991,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.2.2" + "source": "https://github.com/symfony/finder/tree/v7.3.0" }, "funding": [ { @@ -6997,20 +7007,20 @@ "type": "tidelift" } ], - "time": "2024-12-30T19:00:17+00:00" + "time": "2024-12-30T19:00:26+00:00" }, { "name": "symfony/options-resolver", - "version": "v7.2.0", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "7da8fbac9dcfef75ffc212235d76b2754ce0cf50" + "reference": "afb9a8038025e5dbc657378bfab9198d75f10fca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/7da8fbac9dcfef75ffc212235d76b2754ce0cf50", - "reference": "7da8fbac9dcfef75ffc212235d76b2754ce0cf50", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/afb9a8038025e5dbc657378bfab9198d75f10fca", + "reference": "afb9a8038025e5dbc657378bfab9198d75f10fca", "shasum": "" }, "require": { @@ -7048,7 +7058,7 @@ "options" ], "support": { - "source": "https://github.com/symfony/options-resolver/tree/v7.2.0" + "source": "https://github.com/symfony/options-resolver/tree/v7.3.0" }, "funding": [ { @@ -7064,20 +7074,20 @@ "type": "tidelift" } ], - "time": "2024-11-20T11:17:29+00:00" + "time": "2025-04-04T13:12:05+00:00" }, { "name": "symfony/polyfill-iconv", - "version": "v1.31.0", + "version": "v1.32.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-iconv.git", - "reference": "48becf00c920479ca2e910c22a5a39e5d47ca956" + "reference": "5f3b930437ae03ae5dff61269024d8ea1b3774aa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/48becf00c920479ca2e910c22a5a39e5d47ca956", - "reference": "48becf00c920479ca2e910c22a5a39e5d47ca956", + "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/5f3b930437ae03ae5dff61269024d8ea1b3774aa", + "reference": "5f3b930437ae03ae5dff61269024d8ea1b3774aa", "shasum": "" }, "require": { @@ -7128,7 +7138,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-iconv/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-iconv/tree/v1.32.0" }, "funding": [ { @@ -7144,20 +7154,20 @@ "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2024-09-17T14:58:18+00:00" }, { "name": "symfony/polyfill-php84", - "version": "v1.31.0", + "version": "v1.32.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php84.git", - "reference": "e5493eb51311ab0b1cc2243416613f06ed8f18bd" + "reference": "000df7860439609837bbe28670b0be15783b7fbf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php84/zipball/e5493eb51311ab0b1cc2243416613f06ed8f18bd", - "reference": "e5493eb51311ab0b1cc2243416613f06ed8f18bd", + "url": "https://api.github.com/repos/symfony/polyfill-php84/zipball/000df7860439609837bbe28670b0be15783b7fbf", + "reference": "000df7860439609837bbe28670b0be15783b7fbf", "shasum": "" }, "require": { @@ -7204,7 +7214,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php84/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-php84/tree/v1.32.0" }, "funding": [ { @@ -7220,11 +7230,11 @@ "type": "tidelift" } ], - "time": "2024-09-09T12:04:04+00:00" + "time": "2025-02-20T12:04:08+00:00" }, { "name": "symfony/stopwatch", - "version": "v7.2.4", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", @@ -7266,7 +7276,7 @@ "description": "Provides a way to profile code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/stopwatch/tree/v7.2.4" + "source": "https://github.com/symfony/stopwatch/tree/v7.3.0" }, "funding": [ { @@ -7286,20 +7296,21 @@ }, { "name": "symfony/var-dumper", - "version": "v7.2.3", + "version": "v7.3.1", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "82b478c69745d8878eb60f9a049a4d584996f73a" + "reference": "6e209fbe5f5a7b6043baba46fe5735a4b85d0d42" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/82b478c69745d8878eb60f9a049a4d584996f73a", - "reference": "82b478c69745d8878eb60f9a049a4d584996f73a", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/6e209fbe5f5a7b6043baba46fe5735a4b85d0d42", + "reference": "6e209fbe5f5a7b6043baba46fe5735a4b85d0d42", "shasum": "" }, "require": { "php": ">=8.2", + "symfony/deprecation-contracts": "^2.5|^3", "symfony/polyfill-mbstring": "~1.0" }, "conflict": { @@ -7349,7 +7360,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v7.2.3" + "source": "https://github.com/symfony/var-dumper/tree/v7.3.1" }, "funding": [ { @@ -7365,20 +7376,20 @@ "type": "tidelift" } ], - "time": "2025-01-17T11:39:41+00:00" + "time": "2025-06-27T19:55:54+00:00" }, { "name": "thecodingmachine/safe", - "version": "v3.1.0", + "version": "v3.3.0", "source": { "type": "git", "url": "https://github.com/thecodingmachine/safe.git", - "reference": "e14ac96126e6c19ea9d1f4029abb51487f4cf2cf" + "reference": "2cdd579eeaa2e78e51c7509b50cc9fb89a956236" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thecodingmachine/safe/zipball/e14ac96126e6c19ea9d1f4029abb51487f4cf2cf", - "reference": "e14ac96126e6c19ea9d1f4029abb51487f4cf2cf", + "url": "https://api.github.com/repos/thecodingmachine/safe/zipball/2cdd579eeaa2e78e51c7509b50cc9fb89a956236", + "reference": "2cdd579eeaa2e78e51c7509b50cc9fb89a956236", "shasum": "" }, "require": { @@ -7488,7 +7499,7 @@ "description": "PHP core functions that throw exceptions instead of returning FALSE on error", "support": { "issues": "https://github.com/thecodingmachine/safe/issues", - "source": "https://github.com/thecodingmachine/safe/tree/v3.1.0" + "source": "https://github.com/thecodingmachine/safe/tree/v3.3.0" }, "funding": [ { @@ -7504,7 +7515,7 @@ "type": "github" } ], - "time": "2025-04-12T06:41:26+00:00" + "time": "2025-05-14T06:15:44+00:00" }, { "name": "theseer/tokenizer", @@ -7617,7 +7628,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -7625,6 +7636,6 @@ "ext-mbstring": "*", "ext-zlib": "*" }, - "platform-dev": {}, - "plugin-api-version": "2.6.0" + "platform-dev": [], + "plugin-api-version": "2.3.0" } diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 89c2dc0d9..6bff5d539 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -5,7 +5,6 @@ namespace SPC\store; use SPC\builder\BuilderBase; -use SPC\builder\linux\LinuxBuilder; use SPC\builder\linux\SystemUtil; use SPC\builder\unix\UnixBuilderBase; use SPC\exception\FileSystemException; From 47cbdf555f1020fdcf15221dec167df9501bccb6 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 12:13:02 +0700 Subject: [PATCH 152/278] oops, needs musl --- src/globals/test-extensions.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 23d3f15da..5f687683f 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -160,6 +160,7 @@ function quote2(string $param): string case 'ubuntu-24.04-arm': putenv('SPC_TARGET=native-native-musl -dynamic'); if (getenv('SPC_TARGET') && !str_contains(getenv('SPC_TARGET'), '-musl') || str_contains(getenv('SPC_TARGET'), '-dynamic')) { + exec('sudo apt install musl -y'); $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; } break; From e31e228d10ff1a58c2f27781f8cc9ad4cb2f18f3 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 12:19:26 +0700 Subject: [PATCH 153/278] don't hardcode architecture --- src/SPC/toolchain/ToolchainManager.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SPC/toolchain/ToolchainManager.php b/src/SPC/toolchain/ToolchainManager.php index d46118ac9..3264b14f1 100644 --- a/src/SPC/toolchain/ToolchainManager.php +++ b/src/SPC/toolchain/ToolchainManager.php @@ -54,7 +54,8 @@ public static function afterInitToolchain(): void if (!getenv('SPC_TOOLCHAIN')) { throw new WrongUsageException('SPC_TOOLCHAIN was not properly set. Please contact the developers.'); } - if (SPCTarget::getLibc() === 'musl' && !SPCTarget::isStatic() && !file_exists('/lib/ld-musl-x86_64.so.1')) { + $musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m')); + if (SPCTarget::getLibc() === 'musl' && !SPCTarget::isStatic() && !file_exists($musl_wrapper_lib)) { throw new RuntimeException('You are linking against musl libc dynamically, but musl libc is not installed. Please install it with `sudo dnf install musl-libc` or `sudo apt install musl`'); } if (SPCTarget::getLibc() === 'glibc' && SystemUtil::isMuslDist()) { From a191c136dc2a806e150063d6ecb2cbf869f60003 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 13:52:47 +0700 Subject: [PATCH 154/278] strip all may strip things needed for relocation on musl --- src/SPC/builder/freebsd/BSDBuilder.php | 2 +- src/SPC/builder/linux/LinuxBuilder.php | 73 ++++++++++++++++-------- src/SPC/builder/unix/UnixBuilderBase.php | 4 +- 3 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/SPC/builder/freebsd/BSDBuilder.php b/src/SPC/builder/freebsd/BSDBuilder.php index 65ebea571..b51e7b2c9 100644 --- a/src/SPC/builder/freebsd/BSDBuilder.php +++ b/src/SPC/builder/freebsd/BSDBuilder.php @@ -210,7 +210,7 @@ protected function buildMicro(): void ->exec("make -j{$this->concurrency} {$vars} micro"); if (!$this->getOption('no-strip', false)) { - shell()->cd(SOURCE_PATH . '/php-src/sapi/micro')->exec('strip --strip-all micro.sfx'); + shell()->cd(SOURCE_PATH . '/php-src/sapi/micro')->exec('strip --strip-unneeded micro.sfx'); } $this->deployBinary(BUILD_TARGET_MICRO); diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 76e6a71d4..f0914b21c 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -193,7 +193,7 @@ protected function buildCli(): void ->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} cli"); if (!$this->getOption('no-strip', false)) { - shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-all php'); + shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-unneeded php'); } if ($this->getOption('with-upx-pack')) { shell()->cd(SOURCE_PATH . '/php-src/sapi/cli') @@ -256,7 +256,7 @@ protected function buildFpm(): void ->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} fpm"); if (!$this->getOption('no-strip', false)) { - shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')->exec('strip --strip-all php-fpm'); + shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')->exec('strip --strip-unneeded php-fpm'); } if ($this->getOption('with-upx-pack')) { shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm') @@ -280,25 +280,32 @@ protected function buildEmbed(): void ->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install"); $ldflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'); + $libDir = BUILD_LIB_PATH; + $modulesDir = BUILD_MODULES_PATH; + $libphpSo = "{$libDir}/libphp.so"; $realLibName = 'libphp.so'; + if (preg_match('/-release\s+(\S+)/', $ldflags, $matches)) { $release = $matches[1]; - $realLibName = 'libphp-' . $release . '.so'; - $cwd = getcwd(); - $libphpPath = BUILD_LIB_PATH . '/libphp.so'; - $libphpRelease = BUILD_LIB_PATH . '/' . $realLibName; - if (!file_exists($libphpRelease) && file_exists($libphpPath)) { - rename($libphpPath, $libphpRelease); + $realLibName = "libphp-{$release}.so"; + $libphpRelease = "{$libDir}/{$realLibName}"; + if (!file_exists($libphpRelease) && file_exists($libphpSo)) { + rename($libphpSo, $libphpRelease); } if (file_exists($libphpRelease)) { - chdir(BUILD_LIB_PATH); - if (file_exists($libphpPath)) { - unlink($libphpPath); + chdir($libDir); + if (file_exists($libphpSo)) { + unlink($libphpSo); } symlink($realLibName, 'libphp.so'); + shell()->exec(sprintf( + 'patchelf --set-soname %s %s', + escapeshellarg($realLibName), + escapeshellarg($libphpRelease) + )); } - if (is_dir(BUILD_MODULES_PATH)) { - chdir(BUILD_MODULES_PATH); + if (is_dir($modulesDir)) { + chdir($modulesDir); foreach ($this->getExts() as $ext) { if (!$ext->isBuildShared()) { continue; @@ -306,21 +313,39 @@ protected function buildEmbed(): void $name = $ext->getName(); $versioned = "{$name}-{$release}.so"; $unversioned = "{$name}.so"; - if (is_file(BUILD_MODULES_PATH . "/{$versioned}")) { - rename(BUILD_MODULES_PATH . "/{$versioned}", BUILD_MODULES_PATH . "/{$unversioned}"); - shell()->cd(BUILD_MODULES_PATH) - ->exec(sprintf( - 'patchelf --set-soname %s %s', - escapeshellarg($unversioned), - escapeshellarg($unversioned) - )); + $src = "{$modulesDir}/{$versioned}"; + $dst = "{$modulesDir}/{$unversioned}"; + if (is_file($src)) { + rename($src, $dst); + shell()->exec(sprintf( + 'patchelf --set-soname %s %s', + escapeshellarg($unversioned), + escapeshellarg($dst) + )); } } } - chdir($cwd); + chdir(getcwd()); + } + + $target = "{$libDir}/{$realLibName}"; + if (file_exists($target)) { + [, $output] = shell()->execWithResult("readelf -d " . escapeshellarg($target)); + $output = join("\n", $output); + if (preg_match('/SONAME.*\[(.+)\]/', $output, $sonameMatch)) { + $currentSoname = $sonameMatch[1]; + if ($currentSoname !== basename($target)) { + shell()->exec(sprintf( + 'patchelf --set-soname %s %s', + escapeshellarg(basename($target)), + escapeshellarg($target) + )); + } + } } + if (!$this->getOption('no-strip', false) && file_exists(BUILD_LIB_PATH . '/' . $realLibName)) { - shell()->cd(BUILD_LIB_PATH)->exec("strip --strip-all {$realLibName}"); + shell()->cd(BUILD_LIB_PATH)->exec("strip --strip-unneeded {$realLibName}"); } $this->patchPhpScripts(); } @@ -382,7 +407,7 @@ private function processMicroUPXLegacy(): void private function processMicroUPX(): void { if (version_compare($this->getMicroVersion(), '0.2.0') >= 0 && !$this->getOption('no-strip', false)) { - shell()->exec('strip --strip-all ' . SOURCE_PATH . '/php-src/sapi/micro/micro.sfx'); + shell()->exec('strip --strip-unneeded ' . SOURCE_PATH . '/php-src/sapi/micro/micro.sfx'); if ($this->getOption('with-upx-pack')) { // strip first diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 949738842..d63cedf9e 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -363,8 +363,8 @@ protected function buildFrankenphp(): void if (!$this->getOption('no-strip', false) && file_exists(BUILD_BIN_PATH . '/frankenphp')) { if (PHP_OS_FAMILY === 'Linux') { - shell()->cd(BUILD_BIN_PATH)->exec('strip --strip-all frankenphp'); - } else { // macOS doesn't understand strip-all + shell()->cd(BUILD_BIN_PATH)->exec('strip --strip-unneeded frankenphp'); + } else { // macOS doesn't understand strip-unneeded shell()->cd(BUILD_BIN_PATH)->exec('strip -S frankenphp'); } } From 05f3abe9440259d3b2b8080eda172b8da71c7b44 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 13:53:12 +0700 Subject: [PATCH 155/278] cs fix --- 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 f0914b21c..a2078e9d9 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -330,7 +330,7 @@ protected function buildEmbed(): void $target = "{$libDir}/{$realLibName}"; if (file_exists($target)) { - [, $output] = shell()->execWithResult("readelf -d " . escapeshellarg($target)); + [, $output] = shell()->execWithResult('readelf -d ' . escapeshellarg($target)); $output = join("\n", $output); if (preg_match('/SONAME.*\[(.+)\]/', $output, $sonameMatch)) { $currentSoname = $sonameMatch[1]; From b0cfb4b2c4dabf15e3e3440bd16fd9b58e4e852f Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 14:00:43 +0700 Subject: [PATCH 156/278] don't clog our build CI when cs fix, phpstan or phpunit fail --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c01f78bf1..0d1c48af6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -134,7 +134,7 @@ jobs: build: name: "Build PHP Test (PHP ${{ matrix.php }} ${{ matrix.os }})" runs-on: ${{ matrix.os }} - needs: define-matrix + needs: [define-matrix, php-cs-fixer, phpstan, phpunit] timeout-minutes: 120 strategy: matrix: From a097484a5185aef616037bc9af54968d9d47965e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 14:26:04 +0700 Subject: [PATCH 157/278] update isStatic check to ignore SPC_LIBC if using Gcc/Clang/Musl toolchain --- src/SPC/util/SPCTarget.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index de487f4f9..1ea0c1fc5 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -6,6 +6,11 @@ use SPC\builder\linux\SystemUtil; use SPC\exception\WrongUsageException; +use SPC\toolchain\ClangNativeToolchain; +use SPC\toolchain\GccNativeToolchain; +use SPC\toolchain\MuslToolchain; +use SPC\toolchain\ToolchainManager; +use SPC\toolchain\ZigToolchain; /** * SPC build target constants and toolchain initialization. @@ -18,6 +23,15 @@ class SPCTarget */ public static function isStatic(): bool { + if (ToolchainManager::getToolchainClass() === MuslToolchain::class) { + return true; + } + if (ToolchainManager::getToolchainClass() === GccNativeToolchain::class) { + return PHP_OS_FAMILY === 'Linux' && SystemUtil::isMuslDist(); + } + if (ToolchainManager::getToolchainClass() === ClangNativeToolchain::class) { + return PHP_OS_FAMILY === 'Linux' && SystemUtil::isMuslDist(); + } // if SPC_LIBC is set, it means the target is static, remove it when 3.0 is released if ($target = getenv('SPC_TARGET')) { if (str_contains($target, '-macos') || str_contains($target, '-native') && PHP_OS_FAMILY === 'Darwin') { From 4024f9d6ddff24175addf78d4bb7bde1bd08db33 Mon Sep 17 00:00:00 2001 From: Marc Date: Sat, 5 Jul 2025 14:47:27 +0700 Subject: [PATCH 158/278] Update SPCTarget.php --- src/SPC/util/SPCTarget.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index 1ea0c1fc5..e87368d03 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -10,7 +10,6 @@ use SPC\toolchain\GccNativeToolchain; use SPC\toolchain\MuslToolchain; use SPC\toolchain\ToolchainManager; -use SPC\toolchain\ZigToolchain; /** * SPC build target constants and toolchain initialization. From 9935eba336cbbf11a27c7c651c7ab8785a98443e Mon Sep 17 00:00:00 2001 From: Marc Date: Sat, 5 Jul 2025 15:56:36 +0700 Subject: [PATCH 159/278] Update test-extensions.php --- 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 5f687683f..2577827e3 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -44,7 +44,7 @@ $frankenphp = true; // prefer downloading pre-built packages to speed up the build process -$prefer_pre_built = true; +$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) { From 939b9eb8a84e7b0acd1505082daad82d61c2f131 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 18:41:50 +0700 Subject: [PATCH 160/278] fix debug flags --- src/SPC/builder/unix/UnixBuilderBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index d63cedf9e..41213c30e 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -327,7 +327,7 @@ protected function buildFrankenphp(): void if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { $libphpVersion = preg_replace('/\.\d$/', '', $libphpVersion); } - $debugFlags = $this->getOption('no-strip') ? "'-w -s' " : ''; + $debugFlags = $this->getOption('no-strip') ? "-w -s " : ''; $extLdFlags = "-extldflags '-pie'"; $muslTags = ''; $staticFlags = ''; From 3ff8c504f8437bd7d2037ce7177716c2378582fc Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 19:19:17 +0700 Subject: [PATCH 161/278] cs fix, enable action-tmate --- .github/workflows/build-unix.yml | 6 +++--- src/SPC/builder/unix/UnixBuilderBase.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-unix.yml b/.github/workflows/build-unix.yml index e0b516148..b58afb399 100644 --- a/.github/workflows/build-unix.yml +++ b/.github/workflows/build-unix.yml @@ -198,9 +198,9 @@ jobs: run: ${{ needs.define-build.outputs.download }} - name: "Build PHP" run: ${{ needs.define-build.outputs.build }} - #- name: Setup tmate session - # if: ${{ failure() }} - # uses: mxschmitt/action-tmate@v3 + - name: Setup tmate session + if: ${{ failure() }} + uses: mxschmitt/action-tmate@v3 # Upload cli executable - if: ${{ inputs.build-cli == true }} diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 41213c30e..a82be71c6 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -327,7 +327,7 @@ protected function buildFrankenphp(): void if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { $libphpVersion = preg_replace('/\.\d$/', '', $libphpVersion); } - $debugFlags = $this->getOption('no-strip') ? "-w -s " : ''; + $debugFlags = $this->getOption('no-strip') ? '-w -s ' : ''; $extLdFlags = "-extldflags '-pie'"; $muslTags = ''; $staticFlags = ''; From b12cb3350fe5589bad251c22253c9e988fddd24c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 20:00:55 +0700 Subject: [PATCH 162/278] move tmate session thingy --- .github/workflows/build-unix.yml | 6 +++--- .github/workflows/tests.yml | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-unix.yml b/.github/workflows/build-unix.yml index b58afb399..7a7450484 100644 --- a/.github/workflows/build-unix.yml +++ b/.github/workflows/build-unix.yml @@ -198,9 +198,9 @@ jobs: run: ${{ needs.define-build.outputs.download }} - name: "Build PHP" run: ${{ needs.define-build.outputs.build }} - - name: Setup tmate session - if: ${{ failure() }} - uses: mxschmitt/action-tmate@v3 +# - name: Setup tmate session +# if: ${{ failure() }} +# uses: mxschmitt/action-tmate@v3 # Upload cli executable - if: ${{ inputs.build-cli == true }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0d1c48af6..624ca7429 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -198,3 +198,7 @@ jobs: - name: "Run Build Tests (build - embed for non-windows)" if: ${{ !startsWith(matrix.os, 'windows-') }} run: php src/globals/test-extensions.php build_embed_cmd ${{ matrix.os }} ${{ matrix.php }} + + - name: Setup tmate session + if: ${{ failure() }} + uses: mxschmitt/action-tmate@v3 From 67277ccc21508ca15e9a5cdf950a9145b04f42f7 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 21:54:36 +0700 Subject: [PATCH 163/278] explicitly state libphp we built? --- src/SPC/builder/unix/UnixBuilderBase.php | 2 ++ src/SPC/util/SPCTarget.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index a82be71c6..dba5ca11d 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -338,6 +338,8 @@ protected function buildFrankenphp(): void } $config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list, with_dependencies: true); + $libphp = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared' ? 'libphp.so' : 'libphp.a'; + $config['libs'] = str_replace('-lphp', BUILD_LIB_PATH . '/' . $libphp, $config['libs']); $env = [ 'CGO_ENABLED' => '1', diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index e87368d03..583fa757d 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -43,7 +43,7 @@ public static function isStatic(): bool return false; } if (str_contains($target, '-musl')) { - return false; + return true; } if (PHP_OS_FAMILY === 'Linux') { return SystemUtil::isMuslDist(); From 01517f82b816efd8fdbaf8a9f564e016c5766d10 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 22:22:51 +0700 Subject: [PATCH 164/278] disable tmate --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 624ca7429..63cb8a256 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -199,6 +199,6 @@ jobs: if: ${{ !startsWith(matrix.os, 'windows-') }} run: php src/globals/test-extensions.php build_embed_cmd ${{ matrix.os }} ${{ matrix.php }} - - name: Setup tmate session - if: ${{ failure() }} - uses: mxschmitt/action-tmate@v3 +# - name: Setup tmate session +# if: ${{ failure() }} +# uses: mxschmitt/action-tmate@v3 From 10c8fe1f2638af27aaa829367b8262db2c837b45 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 5 Jul 2025 22:51:57 +0700 Subject: [PATCH 165/278] make it fail again (so we can later enable tmate) --- .github/workflows/tests.yml | 2 ++ src/SPC/builder/unix/UnixBuilderBase.php | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 63cb8a256..ad6c308a3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -55,6 +55,8 @@ jobs: extensions: curl, openssl, mbstring ini-values: memory_limit=-1 tools: composer + env: + phpts: zts - name: "Cache Composer packages" id: composer-cache diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index dba5ca11d..a82be71c6 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -338,8 +338,6 @@ protected function buildFrankenphp(): void } $config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list, with_dependencies: true); - $libphp = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared' ? 'libphp.so' : 'libphp.a'; - $config['libs'] = str_replace('-lphp', BUILD_LIB_PATH . '/' . $libphp, $config['libs']); $env = [ 'CGO_ENABLED' => '1', From 9bf65ffe83a6fb5b6ee9eea0f1910dfa27b89f85 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 6 Jul 2025 08:34:01 +0700 Subject: [PATCH 166/278] figure out what libphp it pulls in and why --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ad6c308a3..c647cdfaa 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -201,6 +201,6 @@ jobs: if: ${{ !startsWith(matrix.os, 'windows-') }} run: php src/globals/test-extensions.php build_embed_cmd ${{ matrix.os }} ${{ matrix.php }} -# - name: Setup tmate session -# if: ${{ failure() }} -# uses: mxschmitt/action-tmate@v3 + - name: Setup tmate session + if: ${{ failure() }} + uses: mxschmitt/action-tmate@v3 From 5ab5908ef571242282c7b9cc50e134b387768d36 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 6 Jul 2025 09:51:12 +0700 Subject: [PATCH 167/278] comment it out again --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c647cdfaa..ad6c308a3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -201,6 +201,6 @@ jobs: if: ${{ !startsWith(matrix.os, 'windows-') }} run: php src/globals/test-extensions.php build_embed_cmd ${{ matrix.os }} ${{ matrix.php }} - - name: Setup tmate session - if: ${{ failure() }} - uses: mxschmitt/action-tmate@v3 +# - name: Setup tmate session +# if: ${{ failure() }} +# uses: mxschmitt/action-tmate@v3 From 04cbba3f4e805968ed3e828865fde63903c3550f Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 7 Jul 2025 21:09:39 +0700 Subject: [PATCH 168/278] enable-pie for openssl --- src/SPC/builder/linux/library/openssl.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index 3a4825c8b..625af810c 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -68,6 +68,7 @@ public function build(): void '--libdir=lib ' . '--openssldir=/etc/ssl ' . "{$zlib_extra}" . + 'enable-pie ' . 'no-legacy ' . "linux-{$arch}" ) From 385a46b96f1b52f6a93d55b004b92e999043fb00 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 7 Jul 2025 21:19:57 +0700 Subject: [PATCH 169/278] update notes for argon2 --- docs/en/guide/extension-notes.md | 4 ++-- docs/zh/guide/extension-notes.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/en/guide/extension-notes.md b/docs/en/guide/extension-notes.md index 609fda7bb..1fa65d0e0 100644 --- a/docs/en/guide/extension-notes.md +++ b/docs/en/guide/extension-notes.md @@ -122,8 +122,8 @@ For details on the solution, see [FAQ - Unable to use ssl](../faq/#unable-to-use ## password-argon2 -1. password-argon2 is not a standard extension, it is an additional algorithm for the `password_hash` function. -2. On Linux systems, `password-argon2` dependency `libargon2` conflicts with the `libsodium` library. +1. password-argon2 is not a standard extension. The algorithm `PASSWORD_ARGON2ID` for the `password_hash` function needs libsodium or libargon2 to work. +2. using password-argon2 enables multithread support for this. ## ffi diff --git a/docs/zh/guide/extension-notes.md b/docs/zh/guide/extension-notes.md index 8313439a6..40744ffaf 100644 --- a/docs/zh/guide/extension-notes.md +++ b/docs/zh/guide/extension-notes.md @@ -114,8 +114,8 @@ pgsql 16.2 修复了这个 Bug,现在正常工作了。 ## password-argon2 -1. password-argon2不是一个标准的扩展,它是 `password_hash` 函数的额外算法。 -2. 在Linux系统,password-argon2 的依赖库 `libargon2` 与 `libsodium` 库冲突。 +1. password-argon2不是一个标准的扩展。`password_hash` 函数的 `PASSWORD_ARGON2ID` 算法需要 libsodium 或 libargon2 才能工作。 +2. 使用 password-argon2 可以为此启用多线程支持。 ## ffi From 9cd17fca1c6640111217660c8a95d3f6e3a724f8 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 7 Jul 2025 22:44:07 +0700 Subject: [PATCH 170/278] make sure that libargon2 is always linked in before libsodium --- src/SPC/builder/extension/password_argon2.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/SPC/builder/extension/password_argon2.php b/src/SPC/builder/extension/password_argon2.php index fd45ca7e8..51d2afff7 100644 --- a/src/SPC/builder/extension/password_argon2.php +++ b/src/SPC/builder/extension/password_argon2.php @@ -23,4 +23,21 @@ public function runCliCheckUnix(): void throw new RuntimeException('extension ' . $this->getName() . ' failed sanity check'); } } + + public function patchBeforeMake(): bool + { + if ($this->builder->getLib('libsodium') !== null) { + $extraLibs = getenv('SPC_EXTRA_LIBS'); + if ($extraLibs !== false) { + $extraLibs = str_replace( + [BUILD_LIB_PATH . '/libargon2.a', BUILD_LIB_PATH . '/libsodium.a'], + ['', BUILD_LIB_PATH . '/libargon2.a' . ' ' . BUILD_LIB_PATH . '/libsodium.a'], + $extraLibs, + ); + $extraLibs = trim(preg_replace('/\s+/', ' ', $extraLibs)); // normalize spacing + f_putenv('SPC_EXTRA_LIBS=' . $extraLibs); + } + } + return false; + } } From 7b5f4e9dd0190c5adaa2eb526d12cbc8d27734a6 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 8 Jul 2025 11:25:44 +0700 Subject: [PATCH 171/278] cs fix --- src/SPC/builder/extension/password_argon2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/extension/password_argon2.php b/src/SPC/builder/extension/password_argon2.php index 51d2afff7..fc30288a3 100644 --- a/src/SPC/builder/extension/password_argon2.php +++ b/src/SPC/builder/extension/password_argon2.php @@ -31,7 +31,7 @@ public function patchBeforeMake(): bool if ($extraLibs !== false) { $extraLibs = str_replace( [BUILD_LIB_PATH . '/libargon2.a', BUILD_LIB_PATH . '/libsodium.a'], - ['', BUILD_LIB_PATH . '/libargon2.a' . ' ' . BUILD_LIB_PATH . '/libsodium.a'], + ['', BUILD_LIB_PATH . '/libargon2.a ' . BUILD_LIB_PATH . '/libsodium.a'], $extraLibs, ); $extraLibs = trim(preg_replace('/\s+/', ' ', $extraLibs)); // normalize spacing From dd6c1d960740885594aed21fee5e29c0b4a6ae9e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 8 Jul 2025 22:56:36 +0700 Subject: [PATCH 172/278] patch pkgconf prefix to BUILD_ROOT_PATH instead of /../.. --- src/SPC/builder/traits/UnixLibraryTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/traits/UnixLibraryTrait.php b/src/SPC/builder/traits/UnixLibraryTrait.php index b16886897..f924157d9 100644 --- a/src/SPC/builder/traits/UnixLibraryTrait.php +++ b/src/SPC/builder/traits/UnixLibraryTrait.php @@ -75,7 +75,7 @@ public function patchPkgconfPrefix(array $files, int $patch_option = PKGCONF_PAT logger()->debug('Patching ' . $realpath); // replace prefix $file = FileSystem::readFile($realpath); - $file = ($patch_option & PKGCONF_PATCH_PREFIX) === PKGCONF_PATCH_PREFIX ? preg_replace('/^prefix\s*=.*$/m', 'prefix=${pcfiledir}/../..', $file) : $file; + $file = ($patch_option & PKGCONF_PATCH_PREFIX) === PKGCONF_PATCH_PREFIX ? preg_replace('/^prefix\s*=.*$/m', 'prefix=' . BUILD_ROOT_PATH, $file) : $file; $file = ($patch_option & PKGCONF_PATCH_EXEC_PREFIX) === PKGCONF_PATCH_EXEC_PREFIX ? preg_replace('/^exec_prefix\s*=.*$/m', 'exec_prefix=${prefix}', $file) : $file; $file = ($patch_option & PKGCONF_PATCH_LIBDIR) === PKGCONF_PATCH_LIBDIR ? preg_replace('/^libdir\s*=.*$/m', 'libdir=${prefix}/lib', $file) : $file; $file = ($patch_option & PKGCONF_PATCH_INCLUDEDIR) === PKGCONF_PATCH_INCLUDEDIR ? preg_replace('/^includedir\s*=.*$/m', 'includedir=${prefix}/include', $file) : $file; From 4f4e1ca80dbe8c47aaf369e40c4b67658d3132f3 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 9 Jul 2025 09:50:58 +0700 Subject: [PATCH 173/278] revert --- src/SPC/builder/traits/UnixLibraryTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/traits/UnixLibraryTrait.php b/src/SPC/builder/traits/UnixLibraryTrait.php index f924157d9..b16886897 100644 --- a/src/SPC/builder/traits/UnixLibraryTrait.php +++ b/src/SPC/builder/traits/UnixLibraryTrait.php @@ -75,7 +75,7 @@ public function patchPkgconfPrefix(array $files, int $patch_option = PKGCONF_PAT logger()->debug('Patching ' . $realpath); // replace prefix $file = FileSystem::readFile($realpath); - $file = ($patch_option & PKGCONF_PATCH_PREFIX) === PKGCONF_PATCH_PREFIX ? preg_replace('/^prefix\s*=.*$/m', 'prefix=' . BUILD_ROOT_PATH, $file) : $file; + $file = ($patch_option & PKGCONF_PATCH_PREFIX) === PKGCONF_PATCH_PREFIX ? preg_replace('/^prefix\s*=.*$/m', 'prefix=${pcfiledir}/../..', $file) : $file; $file = ($patch_option & PKGCONF_PATCH_EXEC_PREFIX) === PKGCONF_PATCH_EXEC_PREFIX ? preg_replace('/^exec_prefix\s*=.*$/m', 'exec_prefix=${prefix}', $file) : $file; $file = ($patch_option & PKGCONF_PATCH_LIBDIR) === PKGCONF_PATCH_LIBDIR ? preg_replace('/^libdir\s*=.*$/m', 'libdir=${prefix}/lib', $file) : $file; $file = ($patch_option & PKGCONF_PATCH_INCLUDEDIR) === PKGCONF_PATCH_INCLUDEDIR ? preg_replace('/^includedir\s*=.*$/m', 'includedir=${prefix}/include', $file) : $file; From df4d66ad4bbcf45324b287da67957c849d2508b4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 15 Jul 2025 23:29:20 +0700 Subject: [PATCH 174/278] disable jbig for imagemagick --- src/SPC/builder/unix/library/imagemagick.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SPC/builder/unix/library/imagemagick.php b/src/SPC/builder/unix/library/imagemagick.php index d7cfa8876..1c1aaf007 100644 --- a/src/SPC/builder/unix/library/imagemagick.php +++ b/src/SPC/builder/unix/library/imagemagick.php @@ -34,6 +34,7 @@ protected function build(): void ->optionalLib('bzip2', ...ac_with_args('bzlib')) ->addConfigureArgs( '--disable-openmp', + '--without-jbig', '--without-jxl', '--without-x', ); From 64776e3868911838a399980eec2b41175b92b44a Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 16 Jul 2025 12:28:22 +0700 Subject: [PATCH 175/278] don't do host shenanigans with libffi --- src/SPC/builder/linux/library/libffi.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/SPC/builder/linux/library/libffi.php b/src/SPC/builder/linux/library/libffi.php index ecb3e1422..e47d3d232 100644 --- a/src/SPC/builder/linux/library/libffi.php +++ b/src/SPC/builder/linux/library/libffi.php @@ -18,14 +18,8 @@ class libffi extends LinuxLibraryBase */ public function build(): void { - $arch = getenv('SPC_ARCH'); UnixAutoconfExecutor::create($this) - ->configure( - "--host={$arch}-unknown-linux", - "--target={$arch}-unknown-linux", - "--libdir={$this->getLibDir()}" - ) - ->make(); + ->configure()->make(); if (is_file(BUILD_ROOT_PATH . '/lib64/libffi.a')) { copy(BUILD_ROOT_PATH . '/lib64/libffi.a', BUILD_ROOT_PATH . '/lib/libffi.a'); From b3c665907bfcf7748688956db6b3481bfe4daef2 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 16 Jul 2025 12:34:30 +0700 Subject: [PATCH 176/278] always dump error when extension sanity test fails --- src/SPC/builder/Extension.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index ffae2c386..511be12fc 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -306,9 +306,7 @@ public function runCliCheckUnix(): void [$ret, $out] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n' . $sharedExtensions . ' -r "' . trim($test) . '"'); if ($ret !== 0) { - if ($this->builder->getOption('debug')) { - var_dump($out); - } + var_dump($out); throw new RuntimeException('extension ' . $this->getName() . ' failed sanity check'); } } From b05002ee9bbad93a8fc45886647d143e140f0f11 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 16 Jul 2025 17:50:39 +0700 Subject: [PATCH 177/278] manual compilation doesn't respect CFLAGS, so pass them directly --- src/SPC/builder/unix/library/watcher.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/unix/library/watcher.php b/src/SPC/builder/unix/library/watcher.php index 19f881b79..84f8140e8 100644 --- a/src/SPC/builder/unix/library/watcher.php +++ b/src/SPC/builder/unix/library/watcher.php @@ -16,9 +16,13 @@ trait watcher */ protected function build(): void { + $cflags = $this->getLibExtraCXXFlags(); + if (stripos($cflags, '-fpic') === false) { + $cflags .= ' -fPIC'; + } + $ldflags = $this->getLibExtraLdFlags() ? ' ' . $this->getLibExtraLdFlags() : ''; shell()->cd($this->source_dir . '/watcher-c') - ->initializeEnv($this) - ->exec(getenv('CXX') . ' -c -o libwatcher-c.o ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -Wall -Wextra -fPIC') + ->exec(getenv('CXX') . " -c -o libwatcher-c.o ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -Wall -Wextra {$cflags}{$ldflags}") ->exec(getenv('AR') . ' rcs libwatcher-c.a libwatcher-c.o'); copy($this->source_dir . '/watcher-c/libwatcher-c.a', BUILD_LIB_PATH . '/libwatcher-c.a'); From e675af9a18fce23568ea911f72e1f4b47e2bff09 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 16 Jul 2025 18:58:08 +0700 Subject: [PATCH 178/278] use zts of course... --- src/globals/test-extensions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 4dbef91cb..8d07be344 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -25,15 +25,15 @@ // 'macos-14', // bin/spc for arm64 // 'macos-15', // bin/spc for arm64 // 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 - 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64 + // 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64 'ubuntu-24.04', // bin/spc for x86_64 - 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64 + // 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64 'ubuntu-24.04-arm', // bin/spc for arm64 // 'windows-latest', // .\bin\spc.ps1 ]; // whether enable thread safe -$zts = false; +$zts = true; $no_strip = false; From 33d974bb3d3a3630be0d6af3916618b1f6b444a3 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 18 Jul 2025 11:53:36 +0700 Subject: [PATCH 179/278] use stable sources for swoole and swow --- config/source.json | 16 +++++----------- src/SPC/builder/Extension.php | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/config/source.json b/config/source.json index b3c9cd621..46781d78a 100644 --- a/config/source.json +++ b/config/source.json @@ -957,24 +957,18 @@ }, "swoole": { "path": "php-src/ext/swoole", - "type": "git", - "rev": "master", - "url": "https://github.com/swoole/swoole-src.git", + "type": "ghtar", + "repo": "swoole/swoole-src", + "prefer-stable": true, "license": { "type": "file", "path": "LICENSE" - }, - "alt": { - "type": "ghtar", - "repo": "swoole/swoole-src", - "prefer-stable": true } }, "swow": { - "type": "git", "path": "php-src/ext/swow-src", - "rev": "ci", - "url": "https://github.com/swow/swow", + "type": "ghtar", + "repo": "swoole/swoole-src", "license": { "type": "file", "path": "LICENSE" diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 511be12fc..84450bbd7 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -263,7 +263,7 @@ public function getSharedExtensionLoadString(): string $ret = ''; foreach ($order as $ext) { - if ($ext instanceof Extension && $ext->isBuildShared()) { + if ($ext instanceof self && $ext->isBuildShared()) { if (Config::getExt($ext->getName(), 'zend-extension', false) === true) { $ret .= " -d \"zend_extension={$ext->getName()}\""; } else { From 991e2dee5a33cba373cd886a3bb856abb92185ba Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 18 Jul 2025 11:53:57 +0700 Subject: [PATCH 180/278] stable --- config/source.json | 1 + 1 file changed, 1 insertion(+) diff --git a/config/source.json b/config/source.json index 46781d78a..299519ee0 100644 --- a/config/source.json +++ b/config/source.json @@ -969,6 +969,7 @@ "path": "php-src/ext/swow-src", "type": "ghtar", "repo": "swoole/swoole-src", + "prefer-stable": true, "license": { "type": "file", "path": "LICENSE" From c752f4d4b524a585832dcfdb4d8d59e424b92621 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 18 Jul 2025 11:56:29 +0700 Subject: [PATCH 181/278] tidy too --- config/source.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/source.json b/config/source.json index 299519ee0..7d6cdfdbb 100644 --- a/config/source.json +++ b/config/source.json @@ -976,9 +976,9 @@ } }, "tidy": { - "type": "url", - "url": "https://github.com/htacg/tidy-html5/archive/refs/tags/5.8.0.tar.gz", - "filename": "tidy-html5.tgz", + "type": "ghtar", + "repo": "htacg/tidy-html5", + "prefer-stable": true, "license": { "type": "file", "path": "README/LICENSE.md" From fff23649cf9320450d2cc9291ad092935bb22f1b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 18 Jul 2025 20:45:46 +0700 Subject: [PATCH 182/278] only comment out that line temporarily --- src/SPC/builder/BuilderBase.php | 2 ++ src/SPC/builder/unix/UnixBuilderBase.php | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 184d88dc5..48e72b118 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -260,6 +260,7 @@ public function buildSharedExts(): void } } file_put_contents(BUILD_BIN_PATH . '/php-config', implode('', $lines)); + FileSystem::replaceFileStr(BUILD_LIB_PATH . '/php/build/phpize.m4', 'test "[$]$1" = "no" && $1=yes', '# test "[$]$1" = "no" && $1=yes'); FileSystem::createDir(BUILD_MODULES_PATH); try { foreach ($this->getExts() as $ext) { @@ -273,6 +274,7 @@ public function buildSharedExts(): void throw $e; } FileSystem::replaceFileLineContainsString(BUILD_BIN_PATH . '/php-config', 'extension_dir=', $extension_dir_line); + FileSystem::replaceFileStr(BUILD_LIB_PATH . '/php/build/phpize.m4', '# test "[$]$1" = "no" && $1=yes', 'test "[$]$1" = "no" && $1=yes'); } /** diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 6bcd6dcca..3488dc8e0 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -285,7 +285,6 @@ protected function patchPhpScripts(): void logger()->debug('Patching phpize prefix'); FileSystem::replaceFileStr(BUILD_BIN_PATH . '/phpize', "prefix=''", "prefix='" . BUILD_ROOT_PATH . "'"); FileSystem::replaceFileStr(BUILD_BIN_PATH . '/phpize', 's##', 's#/usr/local#'); - FileSystem::replaceFileStr(BUILD_LIB_PATH . '/php/build/phpize.m4', 'test "[$]$1" = "no" && $1=yes', '# test "[$]$1" = "no" && $1=yes'); } // patch php-config if (file_exists(BUILD_BIN_PATH . '/php-config')) { From 01887d652cb6dbe69c3818cd7db4e63aa452b70e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 19 Jul 2025 15:10:42 +0700 Subject: [PATCH 183/278] add extra runtime objects for shared libraries built directly by php make too --- config/ext.json | 1 + src/SPC/builder/Extension.php | 14 ++++++++++++++ src/SPC/builder/extension/amqp.php | 3 ++- src/SPC/builder/extension/curl.php | 3 ++- src/SPC/builder/extension/event.php | 4 +++- src/SPC/builder/extension/grpc.php | 1 + src/SPC/builder/extension/imap.php | 3 ++- src/SPC/builder/extension/openssl.php | 3 ++- src/SPC/builder/extension/opentelemetry.php | 1 + src/SPC/builder/extension/password_argon2.php | 4 +++- src/SPC/builder/extension/rdkafka.php | 1 + src/SPC/builder/extension/swoole.php | 3 ++- src/SPC/builder/extension/xlswriter.php | 3 ++- 13 files changed, 36 insertions(+), 8 deletions(-) diff --git a/config/ext.json b/config/ext.json index a5eca9f46..a98ed3e34 100644 --- a/config/ext.json +++ b/config/ext.json @@ -495,6 +495,7 @@ "type": "builtin", "arg-type": "custom", "arg-type-windows": "with", + "build-with-php": true, "lib-depends": [ "openssl", "zlib" diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 84450bbd7..ad208d404 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -12,6 +12,7 @@ use SPC\toolchain\ToolchainManager; use SPC\toolchain\ZigToolchain; use SPC\util\SPCConfigUtil; +use SPC\util\SPCTarget; class Extension { @@ -187,6 +188,19 @@ public function patchBeforeConfigure(): bool */ public function patchBeforeMake(): bool { + if ( + PHP_OS_FAMILY === 'Linux' && + $this->isBuildShared() && + ToolchainManager::getToolchainClass() === ZigToolchain::class && + ($extra = (new ZigToolchain())->getExtraRuntimeObjects()) + ) { + FileSystem::replaceFileRegex( + $this->source_dir . '/Makefile', + "/^(shared_objects_{$this->getName()}\\s*=.*)$/m", + "$1 {$extra}", + ); + return true; + } return false; } diff --git a/src/SPC/builder/extension/amqp.php b/src/SPC/builder/extension/amqp.php index 7e0ea2dec..d4df55044 100644 --- a/src/SPC/builder/extension/amqp.php +++ b/src/SPC/builder/extension/amqp.php @@ -13,6 +13,7 @@ class amqp extends Extension { public function patchBeforeMake(): bool { + $patched = parent::patchBeforeMake(); if (PHP_OS_FAMILY === 'Windows') { FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp.h', '/^#warning.*/m', ''); FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp_framing.h', '/^#warning.*/m', ''); @@ -20,7 +21,7 @@ public function patchBeforeMake(): bool FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp_tcp_socket.h', '/^#warning.*/m', ''); return true; } - return false; + return $patched; } public function getUnixConfigureArg(bool $shared = false): string diff --git a/src/SPC/builder/extension/curl.php b/src/SPC/builder/extension/curl.php index 9ac3fd9b5..a9079830d 100644 --- a/src/SPC/builder/extension/curl.php +++ b/src/SPC/builder/extension/curl.php @@ -60,13 +60,14 @@ public function patchBeforeConfigure(): bool public function patchBeforeMake(): bool { + $patched = parent::patchBeforeMake(); $extra_libs = getenv('SPC_EXTRA_LIBS'); if ($this->builder instanceof WindowsBuilder && !str_contains($extra_libs, 'secur32.lib')) { $extra_libs .= ' secur32.lib'; putenv('SPC_EXTRA_LIBS=' . trim($extra_libs)); return true; } - return false; + return $patched; } public function patchBeforeSharedConfigure(): bool diff --git a/src/SPC/builder/extension/event.php b/src/SPC/builder/extension/event.php index 95d9aba60..d2d063b22 100644 --- a/src/SPC/builder/extension/event.php +++ b/src/SPC/builder/extension/event.php @@ -41,10 +41,12 @@ public function patchBeforeConfigure(): bool */ public function patchBeforeMake(): bool { + $patched = parent::patchBeforeMake(); // Prevent event extension compile error on macOS if ($this->builder instanceof MacOSBuilder) { FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/main/php_config.h', '/^#define HAVE_OPENPTY 1$/m', ''); + return true; } - return true; + return $patched; } } diff --git a/src/SPC/builder/extension/grpc.php b/src/SPC/builder/extension/grpc.php index 852f2933e..53eae210c 100644 --- a/src/SPC/builder/extension/grpc.php +++ b/src/SPC/builder/extension/grpc.php @@ -39,6 +39,7 @@ public function patchBeforeBuildconf(): bool public function patchBeforeMake(): bool { + parent::patchBeforeMake(); // add -Wno-strict-prototypes GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -Wno-strict-prototypes'); return true; diff --git a/src/SPC/builder/extension/imap.php b/src/SPC/builder/extension/imap.php index f36ffb1e3..81bb31648 100644 --- a/src/SPC/builder/extension/imap.php +++ b/src/SPC/builder/extension/imap.php @@ -45,8 +45,9 @@ public function getUnixConfigureArg(bool $shared = false): string public function patchBeforeMake(): bool { + $patched = parent::patchBeforeMake(); if (PHP_OS_FAMILY !== 'Linux' || SystemUtil::isMuslDist()) { - return false; + return $patched; } $extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -lcrypt'); f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); diff --git a/src/SPC/builder/extension/openssl.php b/src/SPC/builder/extension/openssl.php index fc4831f30..3ef4998f2 100644 --- a/src/SPC/builder/extension/openssl.php +++ b/src/SPC/builder/extension/openssl.php @@ -12,6 +12,7 @@ class openssl extends Extension { public function patchBeforeMake(): bool { + $patched = parent::patchBeforeMake(); // patch openssl3 with php8.0 bug if ($this->builder->getPHPVersionID() < 80100) { $openssl_c = file_get_contents(SOURCE_PATH . '/php-src/ext/openssl/openssl.c'); @@ -20,7 +21,7 @@ public function patchBeforeMake(): bool return true; } - return false; + return $patched; } public function getUnixConfigureArg(bool $shared = false): string diff --git a/src/SPC/builder/extension/opentelemetry.php b/src/SPC/builder/extension/opentelemetry.php index 4b0829e01..4b3c5aaaf 100644 --- a/src/SPC/builder/extension/opentelemetry.php +++ b/src/SPC/builder/extension/opentelemetry.php @@ -34,6 +34,7 @@ public function patchBeforeBuildconf(): bool public function patchBeforeMake(): bool { + parent::patchBeforeMake(); // add -Wno-strict-prototypes GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -Wno-strict-prototypes'); return true; diff --git a/src/SPC/builder/extension/password_argon2.php b/src/SPC/builder/extension/password_argon2.php index fc30288a3..4a7fd9d07 100644 --- a/src/SPC/builder/extension/password_argon2.php +++ b/src/SPC/builder/extension/password_argon2.php @@ -26,6 +26,7 @@ public function runCliCheckUnix(): void public function patchBeforeMake(): bool { + $patched = parent::patchBeforeMake(); if ($this->builder->getLib('libsodium') !== null) { $extraLibs = getenv('SPC_EXTRA_LIBS'); if ($extraLibs !== false) { @@ -36,8 +37,9 @@ public function patchBeforeMake(): bool ); $extraLibs = trim(preg_replace('/\s+/', ' ', $extraLibs)); // normalize spacing f_putenv('SPC_EXTRA_LIBS=' . $extraLibs); + return true; } } - return false; + return $patched; } } diff --git a/src/SPC/builder/extension/rdkafka.php b/src/SPC/builder/extension/rdkafka.php index cb1792c5f..575ab3092 100644 --- a/src/SPC/builder/extension/rdkafka.php +++ b/src/SPC/builder/extension/rdkafka.php @@ -20,6 +20,7 @@ public function patchBeforeBuildconf(): bool public function patchBeforeMake(): bool { + parent::patchBeforeMake(); // when compiling rdkafka with inline builds, it shows some errors, I don't know why. FileSystem::replaceFileStr( SOURCE_PATH . '/php-src/ext/rdkafka/rdkafka.c', diff --git a/src/SPC/builder/extension/swoole.php b/src/SPC/builder/extension/swoole.php index dee2ddc3a..00085e8bf 100644 --- a/src/SPC/builder/extension/swoole.php +++ b/src/SPC/builder/extension/swoole.php @@ -14,6 +14,7 @@ class swoole extends Extension { public function patchBeforeMake(): bool { + $patched = parent::patchBeforeMake(); if ($this->builder instanceof MacOSBuilder) { // Fix swoole with event extension conflict bug $util_path = shell()->execWithResult('xcrun --show-sdk-path', false)[1][0] . '/usr/include/util.h'; @@ -24,7 +25,7 @@ public function patchBeforeMake(): bool ); return true; } - return false; + return $patched; } public function getExtVersion(): ?string diff --git a/src/SPC/builder/extension/xlswriter.php b/src/SPC/builder/extension/xlswriter.php index 878168adf..56b1988c5 100644 --- a/src/SPC/builder/extension/xlswriter.php +++ b/src/SPC/builder/extension/xlswriter.php @@ -27,6 +27,7 @@ public function getWindowsConfigureArg(bool $shared = false): string public function patchBeforeMake(): bool { + $patched = parent::patchBeforeMake(); if (PHP_OS_FAMILY === 'Windows') { // fix windows build with openssl extension duplicate symbol bug SourcePatcher::patchFile('spc_fix_xlswriter_win32.patch', $this->source_dir); @@ -37,6 +38,6 @@ public function patchBeforeMake(): bool } return true; } - return false; + return $patched; } } From ada203c00cb275aacf7c4bb3eb7f8ace4392d359 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 19 Jul 2025 15:11:22 +0700 Subject: [PATCH 184/278] str_starts_with --- src/SPC/builder/extension/xlswriter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/extension/xlswriter.php b/src/SPC/builder/extension/xlswriter.php index 56b1988c5..24d32d947 100644 --- a/src/SPC/builder/extension/xlswriter.php +++ b/src/SPC/builder/extension/xlswriter.php @@ -33,7 +33,7 @@ public function patchBeforeMake(): bool SourcePatcher::patchFile('spc_fix_xlswriter_win32.patch', $this->source_dir); $content = file_get_contents($this->source_dir . '/library/libxlsxwriter/src/theme.c'); $bom = pack('CCC', 0xEF, 0xBB, 0xBF); - if (substr($content, 0, 3) !== $bom) { + if (!str_starts_with($content, $bom)) { file_put_contents($this->source_dir . '/library/libxlsxwriter/src/theme.c', $bom . $content); } return true; From 683461d918f255b8ebf648a8c1cdd1cd714756e4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 19 Jul 2025 15:12:15 +0700 Subject: [PATCH 185/278] actually path php makefile --- src/SPC/builder/Extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index ad208d404..171d4096d 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -195,7 +195,7 @@ public function patchBeforeMake(): bool ($extra = (new ZigToolchain())->getExtraRuntimeObjects()) ) { FileSystem::replaceFileRegex( - $this->source_dir . '/Makefile', + SOURCE_PATH . '/php-src/Makefile', "/^(shared_objects_{$this->getName()}\\s*=.*)$/m", "$1 {$extra}", ); From 6f9a45b54a44e3f47782f28f8f3d5b88de8a0554 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 19 Jul 2025 15:17:44 +0700 Subject: [PATCH 186/278] shared extensions may also need to patch --- src/SPC/store/SourcePatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 6bff5d539..02a64624b 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -279,7 +279,7 @@ public static function patchBeforeMake(BuilderBase $builder): void // } // call extension patch before make - foreach ($builder->getExts(false) as $ext) { + foreach ($builder->getExts() as $ext) { if ($ext->patchBeforeMake() === true) { logger()->info("Extension [{$ext->getName()}] patched before make"); } From 9b72f574630ed9c3c416c0e4934ea005bfe55b5e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 19 Jul 2025 15:22:23 +0700 Subject: [PATCH 187/278] use www.example.com --- src/globals/ext-tests/curl.php | 2 +- src/globals/ext-tests/openssl.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/globals/ext-tests/curl.php b/src/globals/ext-tests/curl.php index a890a8cf9..eaf4b82ef 100644 --- a/src/globals/ext-tests/curl.php +++ b/src/globals/ext-tests/curl.php @@ -9,7 +9,7 @@ $curl_version = curl_version(); if (stripos($curl_version['ssl_version'], 'schannel') !== false) { $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, 'https://example.com/'); + curl_setopt($curl, CURLOPT_URL, 'https://www.example.com/'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HEADER, 0); $data = curl_exec($curl); diff --git a/src/globals/ext-tests/openssl.php b/src/globals/ext-tests/openssl.php index 3b3452b3e..87862e872 100644 --- a/src/globals/ext-tests/openssl.php +++ b/src/globals/ext-tests/openssl.php @@ -5,5 +5,5 @@ assert(function_exists('openssl_digest')); assert(openssl_digest('123456', 'md5') === 'e10adc3949ba59abbe56e057f20f883e'); if (file_exists('/etc/ssl/openssl.cnf')) { - assert(file_get_contents('https://example.com/') !== false); + assert(file_get_contents('https://www.example.com/') !== false); } From b79b1f5750e160062f9a85f90a6d42c8e163791d Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 19 Jul 2025 15:23:18 +0700 Subject: [PATCH 188/278] cs fix --- src/SPC/builder/Extension.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 171d4096d..6f6fe15bb 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -12,7 +12,6 @@ use SPC\toolchain\ToolchainManager; use SPC\toolchain\ZigToolchain; use SPC\util\SPCConfigUtil; -use SPC\util\SPCTarget; class Extension { From bce363e5431b0bc0f120152b67438992470abbf6 Mon Sep 17 00:00:00 2001 From: Marc Date: Mon, 21 Jul 2025 18:32:57 +0700 Subject: [PATCH 189/278] make sure we didn't break any other OS --- src/globals/test-extensions.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 8d07be344..beff0161d 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -13,7 +13,7 @@ // test php version (8.1 ~ 8.4 available, multiple for matrix) $test_php_version = [ - // '8.1', + '8.1', // '8.2', // '8.3', '8.4', @@ -21,15 +21,15 @@ // test os (macos-13, macos-14, macos-15, ubuntu-latest, windows-latest are available) $test_os = [ - // 'macos-13', // bin/spc for x86_64 + 'macos-13', // bin/spc for x86_64 // 'macos-14', // bin/spc for arm64 - // 'macos-15', // bin/spc for arm64 - // 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 - // 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64 + 'macos-15', // bin/spc for arm64 + 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 + 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64 'ubuntu-24.04', // bin/spc for x86_64 - // 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64 + 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64 'ubuntu-24.04-arm', // bin/spc for arm64 - // 'windows-latest', // .\bin\spc.ps1 + 'windows-latest', // .\bin\spc.ps1 ]; // whether enable thread safe From 711d61d1202d42368381e2556aadebf8361b3a95 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 21 Jul 2025 19:00:53 +0700 Subject: [PATCH 190/278] testing frankenphp with php 8.1 makes no sense --- src/globals/test-extensions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index beff0161d..80fb80de3 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -13,8 +13,8 @@ // test php version (8.1 ~ 8.4 available, multiple for matrix) $test_php_version = [ - '8.1', - // '8.2', + // '8.1', + '8.2', // '8.3', '8.4', ]; From 828f51500db65dd2ec7a3cfe971151ebfcecec2d Mon Sep 17 00:00:00 2001 From: Marc Date: Mon, 21 Jul 2025 21:01:39 +0700 Subject: [PATCH 191/278] disable ubuntu latest (jit error until php-src fixes it) --- 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 80fb80de3..092552bed 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -24,7 +24,7 @@ 'macos-13', // bin/spc for x86_64 // 'macos-14', // bin/spc for arm64 'macos-15', // bin/spc for arm64 - 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 + // 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64 'ubuntu-24.04', // bin/spc for x86_64 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64 From ff30e0f99a4d84c71b68413944e641eac0808bf1 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 22 Jul 2025 12:24:48 +0800 Subject: [PATCH 192/278] Use https instead of http for gnu docker --- bin/spc-gnu-docker | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/spc-gnu-docker b/bin/spc-gnu-docker index f619a82b5..164697f16 100755 --- a/bin/spc-gnu-docker +++ b/bin/spc-gnu-docker @@ -83,7 +83,8 @@ RUN if [ "$SPC_USE_ARCH" = "aarch64" ]; then \ sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo ; \ fi RUN sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/*.repo && \ - sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo + sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo && \ + sed -i 's|http://|https://|g' /etc/yum.repos.d/*.repo RUN yum update -y && \ yum install -y devtoolset-10-gcc-* From 4fc081fcc60141e466ee0b23d2d350e648298cc3 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 22 Jul 2025 12:25:43 +0800 Subject: [PATCH 193/278] Correct chdir to original dir --- src/SPC/builder/linux/LinuxBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index a2078e9d9..863fb1e49 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -284,6 +284,7 @@ protected function buildEmbed(): void $modulesDir = BUILD_MODULES_PATH; $libphpSo = "{$libDir}/libphp.so"; $realLibName = 'libphp.so'; + $cwd = getcwd(); if (preg_match('/-release\s+(\S+)/', $ldflags, $matches)) { $release = $matches[1]; @@ -325,7 +326,7 @@ protected function buildEmbed(): void } } } - chdir(getcwd()); + chdir($cwd); } $target = "{$libDir}/{$realLibName}"; From 86e3e51b5a49697cd227a282dee40a07514f1c66 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 22 Jul 2025 12:29:41 +0800 Subject: [PATCH 194/278] Drop legacy phpmicro support --- src/SPC/builder/linux/LinuxBuilder.php | 56 +++----------------------- 1 file changed, 5 insertions(+), 51 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 863fb1e49..9c4b6d42c 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -109,15 +109,6 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void 'LIBS' => $mimallocLibs . SPCTarget::getRuntimeLibs(), ]); - // process micro upx patch if micro sapi enabled - if ($enableMicro) { - if (version_compare($this->getMicroVersion(), '0.2.0') < 0) { - // for phpmicro 0.1.x - $this->processMicroUPXLegacy(); - } - // micro latest needs do strip and upx pack later (strip, upx, cut binary manually supported) - } - $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; if ($embed_type !== 'static' && SPCTarget::isStatic()) { throw new WrongUsageException( @@ -333,7 +324,7 @@ protected function buildEmbed(): void if (file_exists($target)) { [, $output] = shell()->execWithResult('readelf -d ' . escapeshellarg($target)); $output = join("\n", $output); - if (preg_match('/SONAME.*\[(.+)\]/', $output, $sonameMatch)) { + if (preg_match('/SONAME.*\[(.+)]/', $output, $sonameMatch)) { $currentSoname = $sonameMatch[1]; if ($currentSoname !== basename($target)) { shell()->exec(sprintf( @@ -362,49 +353,12 @@ private function getMakeExtraVars(): array } /** - * Apply option --no-strip and --with-upx-pack for micro sapi (only for phpmicro 0.1.x) + * Strip micro.sfx for Linux. + * The micro.sfx does not support UPX directly, but we can remove UPX-info segment to adapt. + * This will also make micro.sfx with upx-packed more like a malware fore antivirus :( * - * @throws FileSystemException + * @throws RuntimeException */ - private function processMicroUPXLegacy(): void - { - // upx pack and strip for micro - // but always restore Makefile.frag.bak first - if (file_exists(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag.bak')) { - copy(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag.bak', SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag'); - } - if ($this->getOption('with-upx-pack', false)) { - // judge $(MAKE) micro_2s_objs SFX_FILESIZE=`$(STAT_SIZE) $(SAPI_MICRO_PATH)` count - // if 2, replace src/globals/extra/micro-triple-Makefile.frag file content - if (substr_count(FileSystem::readFile(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag'), '$(MAKE) micro_2s_objs SFX_FILESIZE=`$(STAT_SIZE) $(SAPI_MICRO_PATH)`') === 2) { - // bak first - copy(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag', SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag.bak'); - // replace Makefile.frag content - FileSystem::writeFile(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag', FileSystem::readFile(ROOT_DIR . '/src/globals/extra/micro-triple-Makefile.frag')); - } - // with upx pack always need strip - FileSystem::replaceFileRegex( - SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag', - '/POST_MICRO_BUILD_COMMANDS=.*/', - 'POST_MICRO_BUILD_COMMANDS=\$(STRIP) \$(MICRO_STRIP_FLAGS) \$(SAPI_MICRO_PATH) && ' . getenv('UPX_EXEC') . ' --best \$(SAPI_MICRO_PATH)', - ); - } elseif (!$this->getOption('no-strip', false)) { - // not-no-strip means strip (default behavior) - FileSystem::replaceFileRegex( - SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag', - '/POST_MICRO_BUILD_COMMANDS=.*/', - 'POST_MICRO_BUILD_COMMANDS=\$(STRIP) \$(MICRO_STRIP_FLAGS) \$(SAPI_MICRO_PATH)', - ); - } else { - // just no strip - FileSystem::replaceFileRegex( - SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag', - '/POST_MICRO_BUILD_COMMANDS=.*/', - 'POST_MICRO_BUILD_COMMANDS=true', - ); - } - } - private function processMicroUPX(): void { if (version_compare($this->getMicroVersion(), '0.2.0') >= 0 && !$this->getOption('no-strip', false)) { From d5cd42b0e7dbc3f4cf2506c03249e41a0378f9d5 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 22 Jul 2025 11:38:42 +0700 Subject: [PATCH 195/278] delete cs fixer wrapper --- .gitignore | 1 - bin/php-cs-fixer-wrapper | 4 ---- 2 files changed, 5 deletions(-) delete mode 100755 bin/php-cs-fixer-wrapper diff --git a/.gitignore b/.gitignore index 79ca915a3..159c28520 100644 --- a/.gitignore +++ b/.gitignore @@ -35,7 +35,6 @@ packlib_files.txt !/bin/spc* !/bin/setup-runtime* !/bin/spc-alpine-docker -!/bin/php-cs-fixer-wrapper # exclude windows build tools /php-sdk-binary-tools/ diff --git a/bin/php-cs-fixer-wrapper b/bin/php-cs-fixer-wrapper deleted file mode 100755 index 007b99487..000000000 --- a/bin/php-cs-fixer-wrapper +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -# get parent dir, and run the php-cs-fixer -"$(dirname "$0")/../vendor/bin/php-cs-fixer" "$@" From a0f474db208ad0740fe3e4db6890410e496da18b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 22 Jul 2025 11:39:07 +0700 Subject: [PATCH 196/278] redundant --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 159c28520..ccdb7866f 100644 --- a/.gitignore +++ b/.gitignore @@ -34,7 +34,6 @@ packlib_files.txt /bin/* !/bin/spc* !/bin/setup-runtime* -!/bin/spc-alpine-docker # exclude windows build tools /php-sdk-binary-tools/ From f69f8d1e4ab73bed9a26fe33055a08f7771c536d Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 22 Jul 2025 13:16:26 +0800 Subject: [PATCH 197/278] Move zig-toolchain-only things to zig toolchain class --- src/SPC/builder/Extension.php | 20 ++++--------- src/SPC/builder/linux/LinuxBuilder.php | 3 -- src/SPC/store/pkg/Zig.php | 15 ++++++---- src/SPC/toolchain/ZigToolchain.php | 41 ++++++++++++-------------- src/SPC/util/SPCConfigUtil.php | 6 +--- 5 files changed, 34 insertions(+), 51 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 6f6fe15bb..6a7024164 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -9,9 +9,8 @@ use SPC\exception\WrongUsageException; use SPC\store\Config; use SPC\store\FileSystem; -use SPC\toolchain\ToolchainManager; -use SPC\toolchain\ZigToolchain; use SPC\util\SPCConfigUtil; +use SPC\util\SPCTarget; class Extension { @@ -187,16 +186,11 @@ public function patchBeforeConfigure(): bool */ public function patchBeforeMake(): bool { - if ( - PHP_OS_FAMILY === 'Linux' && - $this->isBuildShared() && - ToolchainManager::getToolchainClass() === ZigToolchain::class && - ($extra = (new ZigToolchain())->getExtraRuntimeObjects()) - ) { + if (SPCTarget::getTargetOS() === 'Linux' && $this->isBuildShared() && ($objs = getenv('SPC_EXTRA_RUNTIME_OBJECTS'))) { FileSystem::replaceFileRegex( SOURCE_PATH . '/php-src/Makefile', "/^(shared_objects_{$this->getName()}\\s*=.*)$/m", - "$1 {$extra}", + "$1 {$objs}", ); return true; } @@ -230,15 +224,11 @@ public function patchBeforeSharedConfigure(): bool */ public function patchBeforeSharedMake(): bool { - if ( - PHP_OS_FAMILY === 'Linux' && - ToolchainManager::getToolchainClass() === ZigToolchain::class && - ($extra = (new ZigToolchain())->getExtraRuntimeObjects()) - ) { + if (SPCTarget::getTargetOS() === 'Linux' && ($objs = getenv('SPC_EXTRA_RUNTIME_OBJECTS'))) { FileSystem::replaceFileRegex( $this->source_dir . '/Makefile', "/^(shared_objects_{$this->getName()}\\s*=.*)$/m", - "$1 {$extra}", + "$1 {$objs}", ); return true; } diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 9c4b6d42c..8983cab7b 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -10,8 +10,6 @@ use SPC\exception\WrongUsageException; use SPC\store\FileSystem; use SPC\store\SourcePatcher; -use SPC\toolchain\ToolchainManager; -use SPC\toolchain\ZigToolchain; use SPC\util\GlobalEnvManager; use SPC\util\SPCTarget; @@ -62,7 +60,6 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void } // add libstdc++, some extensions or libraries need it $extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lstdc++ ' : ''); - $extra_libs .= (ToolchainManager::getToolchainClass() === ZigToolchain::class ? ' -lunwind' : ''); f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); $cflags = $this->arch_c_flags; f_putenv('CFLAGS=' . $cflags); diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index f819da7ac..6f823405f 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -4,6 +4,8 @@ namespace SPC\store\pkg; +use SPC\exception\RuntimeException; +use SPC\exception\WrongUsageException; use SPC\store\CurlHook; use SPC\store\Downloader; use SPC\store\FileSystem; @@ -50,14 +52,14 @@ public function fetch(string $name, bool $force = false, ?array $config = null): $zig_arch = match ($arch) { 'x86_64', 'aarch64' => $arch, - default => throw new \InvalidArgumentException('Unsupported architecture: ' . $arch), + default => throw new WrongUsageException('Unsupported architecture: ' . $arch), }; $zig_os = match ($os) { 'linux' => 'linux', 'macos' => 'macos', 'win' => 'windows', - default => throw new \InvalidArgumentException('Unsupported OS: ' . $os), + default => throw new WrongUsageException('Unsupported OS: ' . $os), }; $index_json = json_decode(Downloader::curlExec('https://ziglang.org/download/index.json', hooks: [[CurlHook::class, 'setupGithubToken']]), true); @@ -69,14 +71,14 @@ public function fetch(string $name, bool $force = false, ?array $config = null): } if (!$latest_version) { - throw new \RuntimeException('Could not determine latest Zig version'); + throw new RuntimeException('Could not determine latest Zig version'); } logger()->info("Installing Zig version {$latest_version}"); $platform_key = "{$zig_arch}-{$zig_os}"; if (!isset($index_json[$latest_version][$platform_key])) { - throw new \RuntimeException("No download available for {$platform_key} in Zig version {$latest_version}"); + throw new RuntimeException("No download available for {$platform_key} in Zig version {$latest_version}"); } $download_info = $index_json[$latest_version][$platform_key]; @@ -119,7 +121,6 @@ public static function getEnvironment(): array { $arch = arch2gnu(php_uname('m')); $os = match (PHP_OS_FAMILY) { - 'Linux' => 'linux', 'Windows' => 'win', 'Darwin' => 'macos', 'BSD' => 'freebsd', @@ -134,11 +135,13 @@ public static function getEnvironment(): array ]; } + /** + * @throws WrongUsageException + */ private static function getPath(): string { $arch = arch2gnu(php_uname('m')); $os = match (PHP_OS_FAMILY) { - 'Linux' => 'linux', 'Windows' => 'win', 'Darwin' => 'macos', 'BSD' => 'freebsd', diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index 59e974696..1447956f5 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -17,27 +17,8 @@ public function initEnv(): void GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld'); - } - - public function afterInit(): void - { - if (!is_dir(Zig::getEnvironment()['PATH'])) { - throw new WrongUsageException('You are building with zig, but zig is not installed, please install zig first. (You can use `doctor` command to install it)'); - } - GlobalEnvManager::addPathIfNotExists(Zig::getEnvironment()['PATH']); - } - - /** - * Get the extra runtime objects needed for zig toolchain. - * This method searches for `crtbeginS.o` and `crtendS.o` in common GCC library paths. - */ - public function getExtraRuntimeObjects(): string - { - static $cache = null; - if ($cache !== null) { - return $cache; - } + // Generate additional object needed for zig toolchain $paths = ['/usr/lib/gcc', '/usr/local/lib/gcc']; $objects = ['crtbeginS.o', 'crtendS.o']; $found = []; @@ -56,8 +37,24 @@ public function getExtraRuntimeObjects(): string $found[] = $located; } } + GlobalEnvManager::putenv('SPC_EXTRA_RUNTIME_OBJECTS=' . implode(' ', $found)); + + $extra_libs = getenv('SPC_EXTRA_LIBS') ?: ''; + if (!str_contains($extra_libs, '-lunwind')) { + // Add unwind library if not already present + $extra_libs = trim($extra_libs . ' -lunwind'); + GlobalEnvManager::putenv("SPC_EXTRA_LIBS={$extra_libs}"); + } + } - $cache = implode(' ', $found); - return $cache; + /** + * @throws WrongUsageException + */ + public function afterInit(): void + { + if (!is_dir(Zig::getEnvironment()['PATH'])) { + throw new WrongUsageException('You are building with zig, but zig is not installed, please install zig first. (You can use `doctor` command to install it)'); + } + GlobalEnvManager::addPathIfNotExists(Zig::getEnvironment()['PATH']); } } diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index 83b76b2c3..d7ecd368b 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -11,8 +11,6 @@ use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\Config; -use SPC\toolchain\ToolchainManager; -use SPC\toolchain\ZigToolchain; use Symfony\Component\Console\Input\ArgvInput; class SPCConfigUtil @@ -71,9 +69,7 @@ public function config(array $extensions = [], array $libraries = [], bool $incl if ($this->builder->hasCpp()) { $libs .= $this->builder instanceof MacOSBuilder ? ' -lc++' : ' -lstdc++'; } - if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { - $libs .= ' -lunwind'; - } + $libs .= ' ' . (getenv('SPC_EXTRA_LIBS') ?: ''); // mimalloc must come first if (str_contains($libs, BUILD_LIB_PATH . '/mimalloc.o')) { $libs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace(BUILD_LIB_PATH . '/mimalloc.o', '', $libs); From a8dcfce99ec79777d2f5db595c44f8061d62d919 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 22 Jul 2025 13:16:34 +0800 Subject: [PATCH 198/278] chore --- src/SPC/toolchain/ClangNativeToolchain.php | 6 ++++++ src/SPC/util/GlobalEnvManager.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/SPC/toolchain/ClangNativeToolchain.php b/src/SPC/toolchain/ClangNativeToolchain.php index fb0bea464..aef844d7d 100644 --- a/src/SPC/toolchain/ClangNativeToolchain.php +++ b/src/SPC/toolchain/ClangNativeToolchain.php @@ -10,6 +10,9 @@ use SPC\exception\WrongUsageException; use SPC\util\GlobalEnvManager; +/** + * Toolchain implementation for system clang compiler. + */ class ClangNativeToolchain implements ToolchainInterface { public function initEnv(): void @@ -20,6 +23,9 @@ public function initEnv(): void GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld'); } + /** + * @throws WrongUsageException + */ public function afterInit(): void { foreach (['CC', 'CXX', 'AR', 'LD'] as $env) { diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index 23ae242dc..f5dafea25 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -15,6 +15,8 @@ class GlobalEnvManager { private static array $env_cache = []; + private static bool $initialized = false; + public static function getInitializedEnv(): array { return self::$env_cache; @@ -28,6 +30,9 @@ public static function getInitializedEnv(): array */ public static function init(): void { + if (self::$initialized) { + return; + } // Check pre-defined env vars exists if (getenv('BUILD_ROOT_PATH') === false) { throw new RuntimeException('You must include src/globals/internal-env.php before using GlobalEnvManager'); @@ -85,6 +90,7 @@ public static function init(): void self::putenv("{$k}={$v}"); } } + self::$initialized = true; } public static function putenv(string $val): void From b746e502337f764854e85eea4d2e838a82b34ced Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 22 Jul 2025 13:21:18 +0800 Subject: [PATCH 199/278] Make IANA happier than apple --- src/globals/ext-tests/curl.php | 2 +- src/globals/ext-tests/openssl.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/globals/ext-tests/curl.php b/src/globals/ext-tests/curl.php index eaf4b82ef..7c3eecf79 100644 --- a/src/globals/ext-tests/curl.php +++ b/src/globals/ext-tests/curl.php @@ -9,7 +9,7 @@ $curl_version = curl_version(); if (stripos($curl_version['ssl_version'], 'schannel') !== false) { $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, 'https://www.example.com/'); + curl_setopt($curl, CURLOPT_URL, 'https://captive.apple.com/'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HEADER, 0); $data = curl_exec($curl); diff --git a/src/globals/ext-tests/openssl.php b/src/globals/ext-tests/openssl.php index 87862e872..0453101a6 100644 --- a/src/globals/ext-tests/openssl.php +++ b/src/globals/ext-tests/openssl.php @@ -5,5 +5,5 @@ assert(function_exists('openssl_digest')); assert(openssl_digest('123456', 'md5') === 'e10adc3949ba59abbe56e057f20f883e'); if (file_exists('/etc/ssl/openssl.cnf')) { - assert(file_get_contents('https://www.example.com/') !== false); + assert(file_get_contents('https://captive.apple.com/') !== false); } From 206bc95ee2f2cee3f3230a4eb8cdb6e7a56912f1 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 22 Jul 2025 12:42:45 +0700 Subject: [PATCH 200/278] use correct musl lib --- src/SPC/builder/linux/SystemUtil.php | 3 ++- src/globals/common-tests/embed.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index c9e542559..e4fbc3f52 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -183,7 +183,8 @@ public static function getLibcVersionIfExists(?string $libc = null): ?string } elseif (is_file('/usr/local/musl/lib/libc.so')) { $result = shell()->execWithResult('/usr/local/musl/lib/libc.so 2>&1', false); } else { - $result = shell()->execWithResult('/lib/ld-musl-x86_64.so.1 2>&1', false); + $arch = php_uname('m'); + $result = shell()->execWithResult("/lib/ld-musl-{$arch}.so.1 2>&1", false); } // Match Version * line // match ldd version: "Version 1.2.3" match 1.2.3 diff --git a/src/globals/common-tests/embed.c b/src/globals/common-tests/embed.c index 85c299219..38d8f39fc 100644 --- a/src/globals/common-tests/embed.c +++ b/src/globals/common-tests/embed.c @@ -8,10 +8,10 @@ int main(int argc,char **argv){ zend_stream_init_filename(&file_handle,"embed.php"); - if(php_execute_script(&file_handle) == FAILURE){ + if(!php_execute_script(&file_handle)){ php_printf("Failed to execute PHP script.\n"); } PHP_EMBED_END_BLOCK() return 0; -} \ No newline at end of file +} From 9ba9b874056637d395aad17e8c819e609d49b5b9 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 22 Jul 2025 12:44:51 +0700 Subject: [PATCH 201/278] makes more sense --- src/SPC/builder/linux/SystemUtil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index e4fbc3f52..bde67226c 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -178,7 +178,7 @@ public static function getLibcVersionIfExists(?string $libc = null): ?string return null; } if ($libc === 'musl') { - if (SPCTarget::getLibc() === 'musl') { + if (self::isMuslDist()) { $result = shell()->execWithResult('ldd 2>&1', false); } elseif (is_file('/usr/local/musl/lib/libc.so')) { $result = shell()->execWithResult('/usr/local/musl/lib/libc.so 2>&1', false); From 1300919c44108753f989d321836fb1e12572b756 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 22 Jul 2025 12:50:04 +0700 Subject: [PATCH 202/278] cs fix --- src/SPC/builder/linux/SystemUtil.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index bde67226c..056af090d 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -5,7 +5,6 @@ namespace SPC\builder\linux; use SPC\builder\traits\UnixSystemUtilTrait; -use SPC\util\SPCTarget; class SystemUtil { From aa366d42132c65a61d765b4ccd6a25a7e2269745 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 22 Jul 2025 13:06:48 +0700 Subject: [PATCH 203/278] remove linux target os --- src/SPC/builder/Extension.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index e321b0a88..8efd45691 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -10,6 +10,7 @@ use SPC\store\Config; use SPC\store\FileSystem; use SPC\util\SPCConfigUtil; +use SPC\util\SPCTarget; class Extension { @@ -223,7 +224,7 @@ public function patchBeforeSharedConfigure(): bool */ public function patchBeforeSharedMake(): bool { - if (SPCTarget::getTargetOS() === 'Linux' && ($objs = getenv('SPC_EXTRA_RUNTIME_OBJECTS'))) { + if ($objs = getenv('SPC_EXTRA_RUNTIME_OBJECTS')) { FileSystem::replaceFileRegex( $this->source_dir . '/Makefile', "/^(shared_objects_{$this->getName()}\\s*=.*)$/m", From 8f8a493b20015da03712365f9c4621f7d639cd31 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 22 Jul 2025 17:04:56 +0700 Subject: [PATCH 204/278] trigger deprecation again --- src/SPC/toolchain/ToolchainManager.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SPC/toolchain/ToolchainManager.php b/src/SPC/toolchain/ToolchainManager.php index 3264b14f1..f3fbdf28e 100644 --- a/src/SPC/toolchain/ToolchainManager.php +++ b/src/SPC/toolchain/ToolchainManager.php @@ -26,8 +26,7 @@ public static function getToolchainClass(): string } $libc = getenv('SPC_LIBC'); if ($libc && !getenv('SPC_TARGET')) { - // TODO: @crazywhalecc this breaks tests - // logger()->warning('SPC_LIBC is deprecated, please use SPC_TARGET instead.'); + trigger_error('Setting SPC_LIBC is deprecated, please use SPC_TARGET instead.', E_USER_DEPRECATED); return match ($libc) { 'musl' => SystemUtil::isMuslDist() ? GccNativeToolchain::class : MuslToolchain::class, 'glibc' => !SystemUtil::isMuslDist() ? GccNativeToolchain::class : throw new WrongUsageException('SPC_LIBC must be musl for musl dist.'), From b3f1103143db1376c1a9a075bead45710e64de7b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 14:28:34 +0700 Subject: [PATCH 205/278] well shit, zig cannot build libjxl --- src/SPC/builder/unix/library/libjxl.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/SPC/builder/unix/library/libjxl.php b/src/SPC/builder/unix/library/libjxl.php index 871477b99..3646134fb 100644 --- a/src/SPC/builder/unix/library/libjxl.php +++ b/src/SPC/builder/unix/library/libjxl.php @@ -12,17 +12,19 @@ trait libjxl protected function build(): void { UnixCMakeExecutor::create($this) - ->addConfigureArgs('-DJPEGXL_ENABLE_TOOLS=OFF') - ->addConfigureArgs('-DJPEGXL_ENABLE_EXAMPLES=OFF') - ->addConfigureArgs('-DJPEGXL_ENABLE_MANPAGES=OFF') - ->addConfigureArgs('-DJPEGXL_ENABLE_BENCHMARK=OFF') - ->addConfigureArgs('-DJPEGXL_ENABLE_PLUGINS=OFF') - ->addConfigureArgs('-DJPEGXL_ENABLE_SJPOEG=ON') - ->addConfigureArgs('-DJPEGXL_ENABLE_JNI=OFF') - ->addConfigureArgs('-DJPEGXL_ENABLE_TRANSCODE_JPEG=ON') - ->addConfigureArgs('-DJPEGXL_STATIC=' . (SPCTarget::isStatic() ? 'ON' : 'OFF')) - ->addConfigureArgs('-DJPEGXL_FORCE_SYSTEM_BROTLI=ON') - ->addConfigureArgs('-DBUILD_TESTING=OFF') + ->addConfigureArgs( + '-DJPEGXL_ENABLE_TOOLS=OFF', + '-DJPEGXL_ENABLE_EXAMPLES=OFF', + '-DJPEGXL_ENABLE_MANPAGES=OFF', + '-DJPEGXL_ENABLE_BENCHMARK=OFF', + '-DJPEGXL_ENABLE_PLUGINS=OFF', + '-DJPEGXL_ENABLE_SJPOEG=ON', + '-DJPEGXL_ENABLE_JNI=OFF', + '-DJPEGXL_ENABLE_TRANSCODE_JPEG=ON', + '-DJPEGXL_STATIC=' . (SPCTarget::isStatic() ? 'ON' : 'OFF'), + '-DJPEGXL_FORCE_SYSTEM_BROTLI=ON', + '-DBUILD_TESTING=OFF' + ) ->build(); } } From 8c8800f156bdf264d1e6bdd8450f4fb98085954c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 14:32:47 +0700 Subject: [PATCH 206/278] work around it for -target without version... --- src/SPC/builder/unix/library/libjxl.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/SPC/builder/unix/library/libjxl.php b/src/SPC/builder/unix/library/libjxl.php index 3646134fb..52784053c 100644 --- a/src/SPC/builder/unix/library/libjxl.php +++ b/src/SPC/builder/unix/library/libjxl.php @@ -4,6 +4,8 @@ namespace SPC\builder\unix\library; +use SPC\toolchain\ToolchainManager; +use SPC\toolchain\ZigToolchain; use SPC\util\executor\UnixCMakeExecutor; use SPC\util\SPCTarget; @@ -11,6 +13,13 @@ trait libjxl { protected function build(): void { + if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { + if (str_contains(getenv('SPC_TARGET'), '.2.')) { + throw new \RuntimeException('Zig toolchain does not support libjxl with target version.'); + } + putenv('CC=gcc'); + putenv('CXX=g++'); + } UnixCMakeExecutor::create($this) ->addConfigureArgs( '-DJPEGXL_ENABLE_TOOLS=OFF', @@ -26,5 +35,9 @@ protected function build(): void '-DBUILD_TESTING=OFF' ) ->build(); + if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { + putenv('CC=zig-cc'); + putenv('CXX=zig-c++'); + } } } From 6c76187f5db988bdead53fd795c6670d8f35d7c8 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 14:59:47 +0700 Subject: [PATCH 207/278] remove old code --- src/SPC/builder/macos/MacOSBuilder.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index bcf9e750b..50efa0135 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -89,21 +89,6 @@ public function getFrameworks(bool $asString = false): array|string */ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void { - $extra_libs = getenv('SPC_EXTRA_LIBS') ?: ''; - // ---------- Update extra-libs ---------- - // add macOS frameworks - $extra_libs .= (empty($extra_libs) ? '' : ' ') . $this->getFrameworks(true); - // add libc++, some extensions or libraries need it (C++ cannot be linked statically) - $extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lc++ ' : ''); - // bloat means force-load all static libraries, even if they are not used - if (!$this->getOption('bloat', false)) { - $extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles()); - } else { - logger()->info('bloat linking'); - $extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', array_map(fn ($x) => "-Wl,-force_load,{$x}", array_filter($this->getAllStaticLibFiles()))); - } - f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); - $this->emitPatchPoint('before-php-buildconf'); SourcePatcher::patchBeforeBuildconf($this); From 407f6d46719ae2be7be835f83a2433159ec1737b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 15:03:33 +0700 Subject: [PATCH 208/278] remove zig specifics --- src/SPC/builder/unix/library/libjxl.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/SPC/builder/unix/library/libjxl.php b/src/SPC/builder/unix/library/libjxl.php index 52784053c..3646134fb 100644 --- a/src/SPC/builder/unix/library/libjxl.php +++ b/src/SPC/builder/unix/library/libjxl.php @@ -4,8 +4,6 @@ namespace SPC\builder\unix\library; -use SPC\toolchain\ToolchainManager; -use SPC\toolchain\ZigToolchain; use SPC\util\executor\UnixCMakeExecutor; use SPC\util\SPCTarget; @@ -13,13 +11,6 @@ trait libjxl { protected function build(): void { - if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { - if (str_contains(getenv('SPC_TARGET'), '.2.')) { - throw new \RuntimeException('Zig toolchain does not support libjxl with target version.'); - } - putenv('CC=gcc'); - putenv('CXX=g++'); - } UnixCMakeExecutor::create($this) ->addConfigureArgs( '-DJPEGXL_ENABLE_TOOLS=OFF', @@ -35,9 +26,5 @@ protected function build(): void '-DBUILD_TESTING=OFF' ) ->build(); - if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { - putenv('CC=zig-cc'); - putenv('CXX=zig-c++'); - } } } From 6da3f78df69698154c7ad8a7138eab58ed6a102c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 15:12:11 +0700 Subject: [PATCH 209/278] force disable AVX512 for zig --- src/SPC/builder/unix/library/libjxl.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/unix/library/libjxl.php b/src/SPC/builder/unix/library/libjxl.php index 3646134fb..cfeea65c9 100644 --- a/src/SPC/builder/unix/library/libjxl.php +++ b/src/SPC/builder/unix/library/libjxl.php @@ -4,6 +4,8 @@ namespace SPC\builder\unix\library; +use SPC\toolchain\ToolchainManager; +use SPC\toolchain\ZigToolchain; use SPC\util\executor\UnixCMakeExecutor; use SPC\util\SPCTarget; @@ -11,7 +13,8 @@ trait libjxl { protected function build(): void { - UnixCMakeExecutor::create($this) + + $cmake = UnixCMakeExecutor::create($this) ->addConfigureArgs( '-DJPEGXL_ENABLE_TOOLS=OFF', '-DJPEGXL_ENABLE_EXAMPLES=OFF', @@ -24,7 +27,18 @@ protected function build(): void '-DJPEGXL_STATIC=' . (SPCTarget::isStatic() ? 'ON' : 'OFF'), '-DJPEGXL_FORCE_SYSTEM_BROTLI=ON', '-DBUILD_TESTING=OFF' - ) - ->build(); + ); + + if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { + $cmake->addConfigureArgs( + '-DCXX_MAVX512F_SUPPORTED:BOOL=FALSE', + '-DCXX_MAVX512DQ_SUPPORTED:BOOL=FALSE', + '-DCXX_MAVX512CD_SUPPORTED:BOOL=FALSE', + '-DCXX_MAVX512BW_SUPPORTED:BOOL=FALSE', + '-DCXX_MAVX512VL_SUPPORTED:BOOL=FALSE' + ); + } + + $cmake->build(); } } From 41bb3e731969c152376ad0f5d1052e0785b60c57 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 15:51:08 +0700 Subject: [PATCH 210/278] move -Wno-date-time to ZigToolchain instead of env.ini --- config/env.ini | 2 -- src/SPC/toolchain/ZigToolchain.php | 22 +++++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/config/env.ini b/config/env.ini index f52c13f86..f81189ee1 100644 --- a/config/env.ini +++ b/config/env.ini @@ -63,8 +63,6 @@ PHP_SDK_PATH="${WORKING_DIR}\php-sdk-binary-tools" UPX_EXEC="${PKG_ROOT_PATH}\bin\upx.exe" ; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime140,win32,zend_stream,cli_static -; Windows static linking system libs -SPC_EXTRA_LIBS="" [linux] ; Linux can use different build toolchains. diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index 1447956f5..77601294a 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -38,13 +38,6 @@ public function initEnv(): void } } GlobalEnvManager::putenv('SPC_EXTRA_RUNTIME_OBJECTS=' . implode(' ', $found)); - - $extra_libs = getenv('SPC_EXTRA_LIBS') ?: ''; - if (!str_contains($extra_libs, '-lunwind')) { - // Add unwind library if not already present - $extra_libs = trim($extra_libs . ' -lunwind'); - GlobalEnvManager::putenv("SPC_EXTRA_LIBS={$extra_libs}"); - } } /** @@ -56,5 +49,20 @@ public function afterInit(): void throw new WrongUsageException('You are building with zig, but zig is not installed, please install zig first. (You can use `doctor` command to install it)'); } GlobalEnvManager::addPathIfNotExists(Zig::getEnvironment()['PATH']); + $cflags = getenv('SPC_DEFAULT_C_FLAGS') ?: ''; + $cxxflags = getenv('SPC_DEFAULT_CXX_FLAGS') ?: ''; + $extraCflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') ?: ''; + $cflags = trim($cflags . ' -Wno-date-time'); + $cxxflags = trim($cxxflags . ' -Wno-date-time'); + $extraCflags = trim($extraCflags . ' -Wno-date-time'); + GlobalEnvManager::putenv("SPC_EXTRA_CFLAGS={$cflags}"); + GlobalEnvManager::putenv("SPC_EXTRA_CXXFLAGS={$cxxflags}"); + GlobalEnvManager::putenv("SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS={$extraCflags}"); + $extra_libs = getenv('SPC_EXTRA_LIBS') ?: ''; + if (!str_contains($extra_libs, '-lunwind')) { + // Add unwind library if not already present + $extra_libs = trim($extra_libs . ' -lunwind'); + GlobalEnvManager::putenv("SPC_EXTRA_LIBS={$extra_libs}"); + } } } From 1d6b2bd0025dc1be1ee9a37a1566cb511f799a27 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 15:51:50 +0700 Subject: [PATCH 211/278] cs fix --- src/SPC/builder/unix/library/libjxl.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SPC/builder/unix/library/libjxl.php b/src/SPC/builder/unix/library/libjxl.php index cfeea65c9..a5147f60f 100644 --- a/src/SPC/builder/unix/library/libjxl.php +++ b/src/SPC/builder/unix/library/libjxl.php @@ -13,7 +13,6 @@ trait libjxl { protected function build(): void { - $cmake = UnixCMakeExecutor::create($this) ->addConfigureArgs( '-DJPEGXL_ENABLE_TOOLS=OFF', From c86360c9c426e91628dd5666171ee1e7c6ded484 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 16:43:36 +0700 Subject: [PATCH 212/278] typo --- src/SPC/builder/unix/library/libjxl.php | 2 +- src/globals/test-extensions.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/unix/library/libjxl.php b/src/SPC/builder/unix/library/libjxl.php index a5147f60f..13f8481b1 100644 --- a/src/SPC/builder/unix/library/libjxl.php +++ b/src/SPC/builder/unix/library/libjxl.php @@ -20,7 +20,7 @@ protected function build(): void '-DJPEGXL_ENABLE_MANPAGES=OFF', '-DJPEGXL_ENABLE_BENCHMARK=OFF', '-DJPEGXL_ENABLE_PLUGINS=OFF', - '-DJPEGXL_ENABLE_SJPOEG=ON', + '-DJPEGXL_ENABLE_SJPEG=ON', '-DJPEGXL_ENABLE_JNI=OFF', '-DJPEGXL_ENABLE_TRANSCODE_JPEG=ON', '-DJPEGXL_STATIC=' . (SPCTarget::isStatic() ? 'ON' : 'OFF'), diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 945a204dd..f3d591909 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -14,7 +14,7 @@ // test php version (8.1 ~ 8.4 available, multiple for matrix) $test_php_version = [ // '8.1', - '8.2', + // '8.2', // '8.3', '8.4', ]; From eb898a8867016a887973a3ab37327e4363760a36 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 17:14:20 +0700 Subject: [PATCH 213/278] add ulimit -n for zigtoolchain --- src/SPC/toolchain/ZigToolchain.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index 77601294a..6f000f349 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -49,6 +49,7 @@ public function afterInit(): void throw new WrongUsageException('You are building with zig, but zig is not installed, please install zig first. (You can use `doctor` command to install it)'); } GlobalEnvManager::addPathIfNotExists(Zig::getEnvironment()['PATH']); + exec('ulimit -n 2048'); // zig opens extra file descriptors, so when a lot of extensions are built statically, 1024 is not enough $cflags = getenv('SPC_DEFAULT_C_FLAGS') ?: ''; $cxxflags = getenv('SPC_DEFAULT_CXX_FLAGS') ?: ''; $extraCflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') ?: ''; From 7b07137b5be209d20d02ec4ccd546b4f2df10cc5 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 18:43:10 +0700 Subject: [PATCH 214/278] typo --- src/SPC/toolchain/ZigToolchain.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index 6f000f349..227e972ce 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -56,8 +56,8 @@ public function afterInit(): void $cflags = trim($cflags . ' -Wno-date-time'); $cxxflags = trim($cxxflags . ' -Wno-date-time'); $extraCflags = trim($extraCflags . ' -Wno-date-time'); - GlobalEnvManager::putenv("SPC_EXTRA_CFLAGS={$cflags}"); - GlobalEnvManager::putenv("SPC_EXTRA_CXXFLAGS={$cxxflags}"); + GlobalEnvManager::putenv("SPC_DEFAULT_C_FLAGS={$cflags}"); + GlobalEnvManager::putenv("SPC_DEFAULT_CXX_FLAGS={$cxxflags}"); GlobalEnvManager::putenv("SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS={$extraCflags}"); $extra_libs = getenv('SPC_EXTRA_LIBS') ?: ''; if (!str_contains($extra_libs, '-lunwind')) { From 5c9a3e236bc8a04cd66e6ea379c6143cd01f7743 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 21:29:34 +0700 Subject: [PATCH 215/278] array_reverse again --- config/lib.json | 4 ++-- src/SPC/util/SPCConfigUtil.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/lib.json b/config/lib.json index 13f886ca5..77d032a4e 100644 --- a/config/lib.json +++ b/config/lib.json @@ -738,8 +738,8 @@ "openssl": { "source": "openssl", "static-libs-unix": [ - "libcrypto.a", - "libssl.a" + "libssl.a", + "libcrypto.a" ], "static-libs-windows": [ "libssl.lib", diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index ea69cefbf..918aac927 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -183,7 +183,7 @@ private function getLibsString(array $libraries, bool $use_short_libs = true): s $lib_names = [...$lib_names, ...$pc_libs]; } // convert all static-libs to short names - $libs = Config::getLib($library, 'static-libs', []); + $libs = array_reverse(Config::getLib($library, 'static-libs', [])); foreach ($libs as $lib) { // check file existence if (!file_exists(BUILD_LIB_PATH . "/{$lib}")) { From dd99f258c18ff9a9fd0c5c75c56f6396d8384b22 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 21:32:14 +0700 Subject: [PATCH 216/278] do not pull it symbols from libpq during conftests... --- src/SPC/builder/linux/LinuxBuilder.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index cf38474fd..2b79d0f78 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -89,6 +89,10 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void // prepare build php envs $config = (new SPCConfigUtil($this, ['libs_only_deps' => true]))->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs')); + if (str_contains($config['libs'], ' -lpgport') && !$this->getExt('pgsql')?->isBuildStatic()) { + // -lpgport defines many glibc functions if they are missing, which leads to feature tests succeeding that aren't meant to succeed + $config['libs'] = str_replace(' -lpgport', '', $config['libs']); + } $envs_build_php = SystemUtil::makeEnvVarString([ 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'), 'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'), From eca7a43a013bdcbe2356acf771f67c8daffd1bcb Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 21:42:31 +0700 Subject: [PATCH 217/278] get rid of extra logic for shared and static libraries, rely on SPCConfigUtil --- src/SPC/builder/Extension.php | 42 +-------------------------- src/SPC/builder/extension/imagick.php | 11 ------- src/SPC/util/SPCConfigUtil.php | 8 ++++- src/globals/test-extensions.php | 4 +-- 4 files changed, 10 insertions(+), 55 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 79aed284d..02193f587 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -400,17 +400,12 @@ public function buildShared(): void public function buildUnixShared(): void { $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], with_dependencies: true); - [$staticLibString, $sharedLibString] = $this->getStaticAndSharedLibs(); - // macOS ld64 doesn't understand these, while Linux and BSD do - // use them to make sure that all symbols are picked up, even if a library has already been visited before - $preStatic = PHP_OS_FAMILY !== 'Darwin' ? '-Wl,--start-group ' : ''; - $postStatic = PHP_OS_FAMILY !== 'Darwin' ? ' -Wl,--end-group ' : ' '; $env = [ 'CFLAGS' => $config['cflags'], 'CXXFLAGS' => $config['cflags'], 'LDFLAGS' => $config['ldflags'], - 'LIBS' => $preStatic . $staticLibString . $postStatic . $sharedLibString, + 'LIBS' => $config['libs'], 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, 'SPC_COMPILER_EXTRA' => '-lstdc++', ]; @@ -525,41 +520,6 @@ protected function addExtensionDependency(string $name, bool $optional = false): } } - /** - * Get required static and shared libraries as a pair of strings in format -l{libname} -l{libname2} - * - * @return array [staticLibString, sharedLibString] - */ - protected function getStaticAndSharedLibs(): array - { - $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], with_dependencies: true); - $sharedLibString = ''; - $staticLibString = ''; - $staticLibs = $this->getLibFilesString(); - $staticLibs = str_replace([BUILD_LIB_PATH . '/lib', '.a'], ['-l', ''], $staticLibs); - $staticLibs = explode('-l', $staticLibs . ' ' . $config['libs']); - foreach ($staticLibs as $lib) { - $lib = trim($lib); - if ($lib === '') { - continue; - } - $static_lib = 'lib' . $lib . '.a'; - if (file_exists(BUILD_LIB_PATH . '/' . $static_lib) && !str_contains($static_lib, 'libphp')) { - if (!str_contains($staticLibString, '-l' . $lib . ' ')) { - $staticLibString .= '-l' . $lib . ' '; - } - } elseif (!str_contains($sharedLibString, '-l' . $lib . ' ')) { - $sharedLibString .= '-l' . $lib . ' '; - } - } - // move -lstdc++ to static libraries because centos 7 the shared libstdc++ is incomplete - if (str_contains((string) getenv('PATH'), 'rh/devtoolset-10')) { - $staticLibString .= ' -lstdc++'; - $sharedLibString = str_replace('-lstdc++', '', $sharedLibString); - } - return [trim($staticLibString), trim($sharedLibString)]; - } - protected function getExtraEnv(): array { return []; diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 4067391a9..514e79b32 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -6,7 +6,6 @@ use SPC\builder\Extension; use SPC\util\CustomExt; -use SPC\util\SPCTarget; #[CustomExt('imagick')] class imagick extends Extension @@ -16,14 +15,4 @@ public function getUnixConfigureArg(bool $shared = false): string $disable_omp = ' ac_cv_func_omp_pause_resource_all=no'; return '--with-imagick=' . ($shared ? 'shared,' : '') . BUILD_ROOT_PATH . $disable_omp; } - - protected function getStaticAndSharedLibs(): array - { - [$static, $shared] = parent::getStaticAndSharedLibs(); - if (SPCTarget::getLibc() === 'glibc' && version_compare(SPCTarget::getLibcVersion(), '2.17', '<=')) { - $static .= ' -lstdc++'; - $shared = str_replace('-lstdc++', '', $shared); - } - return [$static, $shared]; - } } diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index 918aac927..31242cc54 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -86,7 +86,13 @@ public function config(array $extensions = [], array $libraries = [], bool $incl $libs .= " {$this->getFrameworksString($extensions)}"; } if ($this->builder->hasCpp()) { - $libs .= SPCTarget::getTargetOS() === 'Darwin' ? ' -lc++' : ' -lstdc++'; + $libcpp = SPCTarget::getTargetOS() === 'Darwin' ? '-lc++' : '-lstdc++'; + if (!str_contains($libs, $libcpp)) { + $libs .= " {$libcpp}"; + } + if (str_contains(getenv('OATH'), 'rh/devtoolset-10')) { + str_replace('-lstdc++', '-l:stdc++.a', $libs); + } } if ($this->libs_only_deps) { diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index f3d591909..d91817d6a 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -21,9 +21,9 @@ // test os (macos-13, macos-14, macos-15, ubuntu-latest, windows-latest are available) $test_os = [ - 'macos-13', // bin/spc for x86_64 + // 'macos-13', // bin/spc for x86_64 // 'macos-14', // bin/spc for arm64 - 'macos-15', // bin/spc for arm64 + // 'macos-15', // bin/spc for arm64 // 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64 'ubuntu-24.04', // bin/spc for x86_64 From 7177afd7f82276418c4aaf4dd5fb7fd6a80cf3bb Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 21:57:56 +0700 Subject: [PATCH 218/278] phpstan fix --- src/SPC/builder/Extension.php | 20 ++++++++++++++++---- src/SPC/util/SPCConfigUtil.php | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 02193f587..6c18222d7 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -9,6 +9,8 @@ use SPC\exception\WrongUsageException; use SPC\store\Config; use SPC\store\FileSystem; +use SPC\toolchain\ToolchainManager; +use SPC\toolchain\ZigToolchain; use SPC\util\SPCConfigUtil; use SPC\util\SPCTarget; @@ -399,16 +401,17 @@ public function buildShared(): void */ public function buildUnixShared(): void { - $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], with_dependencies: true); - + $config = (new SPCConfigUtil($this->builder))->config([$this->getName()]); $env = [ 'CFLAGS' => $config['cflags'], 'CXXFLAGS' => $config['cflags'], 'LDFLAGS' => $config['ldflags'], 'LIBS' => $config['libs'], 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, - 'SPC_COMPILER_EXTRA' => '-lstdc++', ]; + if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { + $env['SPC_COMPILER_EXTRA'] = '-lstdc++'; + } if ($this->patchBeforeSharedPhpize()) { logger()->info("Extension [{$this->getName()}] patched before shared phpize"); @@ -433,11 +436,20 @@ public function buildUnixShared(): void '--enable-shared --disable-static' ); + $staticLibString = ''; + $libs = explode(' ', $config['libs']); + foreach ($libs as $lib) { + $staticLib = BUILD_LIB_PATH . '/' . str_replace('-l', '', $lib) . '.a'; + if (file_exists($staticLib)) { + $staticLibString .= " {$lib}"; + } + } + // some extensions don't define their dependencies well, this patch is only needed for a few FileSystem::replaceFileRegex( $this->source_dir . '/Makefile', '/^(.*_SHARED_LIBADD\s*=.*)$/m', - '$1 ' . $staticLibString + '$1 ' . trim($staticLibString) ); if ($this->patchBeforeSharedMake()) { diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index 31242cc54..83c33fa71 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -57,7 +57,7 @@ public function __construct(?BuilderBase $builder = null, array $options = []) * @throws WrongUsageException * @throws \Throwable */ - public function config(array $extensions = [], array $libraries = [], bool $include_suggest_ext = false, bool $include_suggest_lib = false, bool $with_dependencies = false): array + public function config(array $extensions = [], array $libraries = [], bool $include_suggest_ext = false, bool $include_suggest_lib = false): array { [$extensions, $libraries] = DependencyUtil::getExtsAndLibs($extensions, $libraries, $include_suggest_ext, $include_suggest_lib); @@ -90,7 +90,7 @@ public function config(array $extensions = [], array $libraries = [], bool $incl if (!str_contains($libs, $libcpp)) { $libs .= " {$libcpp}"; } - if (str_contains(getenv('OATH'), 'rh/devtoolset-10')) { + if (str_contains(getenv('PATH'), 'rh/devtoolset-10')) { str_replace('-lstdc++', '-l:stdc++.a', $libs); } } From 155e22a9f926d309bcaba21ceb66d3ebb1a9faf2 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 22:01:32 +0700 Subject: [PATCH 219/278] with_dependencies was removed --- src/SPC/builder/unix/UnixBuilderBase.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 930fb7145..7f38dc881 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -260,8 +260,7 @@ protected function buildFrankenphp(): void $staticFlags = '-static -static-pie'; } - $config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list, with_dependencies: true); - + $config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list); $env = [ 'CGO_ENABLED' => '1', 'CGO_CFLAGS' => $config['cflags'], From 8c5dc91895402c70fc1962da2092273ce648313c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 24 Jul 2025 22:52:58 +0700 Subject: [PATCH 220/278] test gnu (test musl again later, jxl fails with avx shit again) --- src/SPC/builder/Extension.php | 30 +++++++++++++++++++----------- src/globals/test-extensions.php | 6 ++++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 6c18222d7..2dacdae8a 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -402,11 +402,12 @@ public function buildShared(): void public function buildUnixShared(): void { $config = (new SPCConfigUtil($this->builder))->config([$this->getName()]); + [$staticLibs, $sharedLibs] = $this->getStaticAndSharedLibs($config['libs']); $env = [ 'CFLAGS' => $config['cflags'], 'CXXFLAGS' => $config['cflags'], 'LDFLAGS' => $config['ldflags'], - 'LIBS' => $config['libs'], + 'LIBS' => "-Wl,--start-group {$staticLibs} -Wl,--end-group {$sharedLibs}", 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, ]; if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { @@ -436,20 +437,11 @@ public function buildUnixShared(): void '--enable-shared --disable-static' ); - $staticLibString = ''; - $libs = explode(' ', $config['libs']); - foreach ($libs as $lib) { - $staticLib = BUILD_LIB_PATH . '/' . str_replace('-l', '', $lib) . '.a'; - if (file_exists($staticLib)) { - $staticLibString .= " {$lib}"; - } - } - // some extensions don't define their dependencies well, this patch is only needed for a few FileSystem::replaceFileRegex( $this->source_dir . '/Makefile', '/^(.*_SHARED_LIBADD\s*=.*)$/m', - '$1 ' . trim($staticLibString) + '$1 ' . trim($staticLibs) ); if ($this->patchBeforeSharedMake()) { @@ -537,6 +529,22 @@ protected function getExtraEnv(): array return []; } + private function getStaticAndSharedLibs(string $allLibs): array + { + $staticLibString = ''; + $sharedLibString = ''; + $libs = explode(' ', $allLibs); + foreach ($libs as $lib) { + $staticLib = BUILD_LIB_PATH . '/lib' . str_replace('-l', '', $lib) . '.a'; + if (file_exists($staticLib)) { + $staticLibString .= " {$lib}"; + } else { + $sharedLibString .= " {$lib}"; + } + } + return [$staticLibString, $sharedLibString]; + } + private function getLibraryDependencies(bool $recursive = false): array { $ret = array_filter($this->dependencies, fn ($x) => $x instanceof LibraryBase); diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index d91817d6a..1c279e2f5 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -158,9 +158,11 @@ function quote2(string $param): string break; case 'ubuntu-24.04': case 'ubuntu-24.04-arm': - putenv('SPC_TARGET=native-native-musl -dynamic'); - if (getenv('SPC_TARGET') && !str_contains(getenv('SPC_TARGET'), '-musl') || str_contains(getenv('SPC_TARGET'), '-dynamic')) { + putenv('SPC_TARGET=native-native-gnu'); + if (getenv('SPC_TARGET') && !str_contains(getenv('SPC_TARGET'), '-musl')) { exec('sudo apt install musl -y'); + } + if (getenv('SPC_TARGET')) { $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; } break; From 8ff52e2e36936cd2552230d53b679d4e06b276a1 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 24 Jul 2025 23:47:01 +0700 Subject: [PATCH 221/278] -lphp shared not static --- src/SPC/builder/Extension.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 2dacdae8a..b035412c3 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -536,13 +536,13 @@ private function getStaticAndSharedLibs(string $allLibs): array $libs = explode(' ', $allLibs); foreach ($libs as $lib) { $staticLib = BUILD_LIB_PATH . '/lib' . str_replace('-l', '', $lib) . '.a'; - if (file_exists($staticLib)) { - $staticLibString .= " {$lib}"; - } else { + if (!file_exists($staticLib) || $lib === '-lphp') { $sharedLibString .= " {$lib}"; + } else { + $staticLibString .= " {$lib}"; } } - return [$staticLibString, $sharedLibString]; + return [trim($staticLibString), trim($sharedLibString)]; } private function getLibraryDependencies(bool $recursive = false): array From 7eb5fb4520747c9426fad033fd70fbf0ae05a367 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 09:30:15 +0700 Subject: [PATCH 222/278] l:libstdc++.a --- src/SPC/util/SPCConfigUtil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index 83c33fa71..59dfb36fc 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -91,7 +91,7 @@ public function config(array $extensions = [], array $libraries = [], bool $incl $libs .= " {$libcpp}"; } if (str_contains(getenv('PATH'), 'rh/devtoolset-10')) { - str_replace('-lstdc++', '-l:stdc++.a', $libs); + str_replace('-lstdc++', '-l:libstdc++.a', $libs); } } From 00e78dd84fbde9581ce3eb1074d59fb8c2525c66 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 09:59:24 +0700 Subject: [PATCH 223/278] fix imagick problem, for some reason it must be in the --start-group --end-group --- src/SPC/builder/Extension.php | 2 +- src/SPC/builder/extension/imagick.php | 10 ++++++++++ src/SPC/builder/linux/LinuxBuilder.php | 2 +- src/SPC/util/SPCConfigUtil.php | 15 ++++++--------- src/globals/functions.php | 9 +++++++++ 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index b035412c3..e83f9dcdd 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -529,7 +529,7 @@ protected function getExtraEnv(): array return []; } - private function getStaticAndSharedLibs(string $allLibs): array + protected function getStaticAndSharedLibs(string $allLibs): array { $staticLibString = ''; $sharedLibString = ''; diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 514e79b32..3c940289f 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -15,4 +15,14 @@ public function getUnixConfigureArg(bool $shared = false): string $disable_omp = ' ac_cv_func_omp_pause_resource_all=no'; return '--with-imagick=' . ($shared ? 'shared,' : '') . BUILD_ROOT_PATH . $disable_omp; } + + protected function getStaticAndSharedLibs(string $allLibs): array + { + [$static, $shared] = parent::getStaticAndSharedLibs($allLibs); + if (str_contains(getenv('PATH'), 'rh/devtoolset-10')) { + $static .= ' -l:libstdc++.a'; + $shared = str_replace('-lstdc++', '', $shared); + } + return [deduplicate_spaces($static), deduplicate_spaces($shared)]; + } } diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 2b79d0f78..d24458920 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -338,7 +338,7 @@ private function getMakeExtraVars(): array $config = (new SPCConfigUtil($this, ['libs_only_deps' => true, 'absolute_libs' => true]))->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs')); return [ 'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'), - 'EXTRA_LIBS' => $config['libs'] . ' ' . SPCTarget::getRuntimeLibs(), + 'EXTRA_LIBS' => $config['libs'], 'EXTRA_LDFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'), 'EXTRA_LDFLAGS_PROGRAM' => SPCTarget::isStatic() ? '-all-static -pie' : '-pie', ]; diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index 59dfb36fc..cf2b4ce4e 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -90,9 +90,6 @@ public function config(array $extensions = [], array $libraries = [], bool $incl if (!str_contains($libs, $libcpp)) { $libs .= " {$libcpp}"; } - if (str_contains(getenv('PATH'), 'rh/devtoolset-10')) { - str_replace('-lstdc++', '-l:libstdc++.a', $libs); - } } if ($this->libs_only_deps) { @@ -101,9 +98,9 @@ public function config(array $extensions = [], array $libraries = [], bool $incl $libs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace(BUILD_LIB_PATH . '/mimalloc.o', '', $libs); } return [ - 'cflags' => trim(getenv('CFLAGS') . ' ' . $cflags), - 'ldflags' => trim(getenv('LDFLAGS') . ' ' . $ldflags), - 'libs' => trim(getenv('LIBS') . ' ' . $libs), + 'cflags' => deduplicate_spaces(getenv('CFLAGS') . ' ' . $cflags), + 'ldflags' => deduplicate_spaces(getenv('LDFLAGS') . ' ' . $ldflags), + 'libs' => deduplicate_spaces(getenv('LIBS') . ' ' . $libs), ]; } @@ -120,9 +117,9 @@ public function config(array $extensions = [], array $libraries = [], bool $incl } return [ - 'cflags' => trim(getenv('CFLAGS') . ' ' . $cflags), - 'ldflags' => trim(getenv('LDFLAGS') . ' ' . $ldflags), - 'libs' => trim($allLibs), + 'cflags' => deduplicate_spaces(getenv('CFLAGS') . ' ' . $cflags), + 'ldflags' => deduplicate_spaces(getenv('LDFLAGS') . ' ' . $ldflags), + 'libs' => deduplicate_spaces($allLibs), ]; } diff --git a/src/globals/functions.php b/src/globals/functions.php index b45d8c5ee..1ad115fc0 100644 --- a/src/globals/functions.php +++ b/src/globals/functions.php @@ -242,3 +242,12 @@ function get_pack_replace(): array BUILD_ROOT_PATH => '@build_root_path@', ]; } + +/** + * @param $string + * @return string without double spaces + */ +function deduplicate_spaces($string): string +{ + return trim(preg_replace('/\s+/', ' ', $string)); +} From ea56e460d0b74967dcb9acf5066f2e9b98a2c350 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 10:00:49 +0700 Subject: [PATCH 224/278] zig script --- src/SPC/store/scripts/zig-cc.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/SPC/store/scripts/zig-cc.sh b/src/SPC/store/scripts/zig-cc.sh index d162a3693..388a3655c 100644 --- a/src/SPC/store/scripts/zig-cc.sh +++ b/src/SPC/store/scripts/zig-cc.sh @@ -19,6 +19,13 @@ while [[ $# -gt 0 ]]; do ARG_ABS="$(realpath "$ARG" 2>/dev/null || true)" [[ "$ARG_ABS" == "$BUILDROOT_ABS" ]] && PARSED_ARGS+=("-I$ARG") || PARSED_ARGS+=("-isystem$ARG") ;; + -march=*|-mcpu=*) # replace -march=x86-64 with -march=x86_64 + OPT_NAME="${1%%=*}" + OPT_VALUE="${1#*=}" + OPT_VALUE="${OPT_VALUE//-/_}" + PARSED_ARGS+=("${OPT_NAME}=${OPT_VALUE}") + shift + ;; *) PARSED_ARGS+=("$1") shift From 27a4d5af545ad28786d13ce8b73168343f82e1da Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 10:04:06 +0700 Subject: [PATCH 225/278] better description of function --- src/SPC/builder/extension/imagick.php | 2 +- src/SPC/util/SPCConfigUtil.php | 12 ++++++------ src/globals/functions.php | 8 +++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 3c940289f..0471dd659 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -23,6 +23,6 @@ protected function getStaticAndSharedLibs(string $allLibs): array $static .= ' -l:libstdc++.a'; $shared = str_replace('-lstdc++', '', $shared); } - return [deduplicate_spaces($static), deduplicate_spaces($shared)]; + return [clean_spaces($static), clean_spaces($shared)]; } } diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index cf2b4ce4e..c3bb83cc2 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -98,9 +98,9 @@ public function config(array $extensions = [], array $libraries = [], bool $incl $libs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace(BUILD_LIB_PATH . '/mimalloc.o', '', $libs); } return [ - 'cflags' => deduplicate_spaces(getenv('CFLAGS') . ' ' . $cflags), - 'ldflags' => deduplicate_spaces(getenv('LDFLAGS') . ' ' . $ldflags), - 'libs' => deduplicate_spaces(getenv('LIBS') . ' ' . $libs), + 'cflags' => clean_spaces(getenv('CFLAGS') . ' ' . $cflags), + 'ldflags' => clean_spaces(getenv('LDFLAGS') . ' ' . $ldflags), + 'libs' => clean_spaces(getenv('LIBS') . ' ' . $libs), ]; } @@ -117,9 +117,9 @@ public function config(array $extensions = [], array $libraries = [], bool $incl } return [ - 'cflags' => deduplicate_spaces(getenv('CFLAGS') . ' ' . $cflags), - 'ldflags' => deduplicate_spaces(getenv('LDFLAGS') . ' ' . $ldflags), - 'libs' => deduplicate_spaces($allLibs), + 'cflags' => clean_spaces(getenv('CFLAGS') . ' ' . $cflags), + 'ldflags' => clean_spaces(getenv('LDFLAGS') . ' ' . $ldflags), + 'libs' => clean_spaces($allLibs), ]; } diff --git a/src/globals/functions.php b/src/globals/functions.php index 1ad115fc0..2fef0d7f7 100644 --- a/src/globals/functions.php +++ b/src/globals/functions.php @@ -244,10 +244,12 @@ function get_pack_replace(): array } /** - * @param $string - * @return string without double spaces + * Remove duplicate spaces from a string. + * + * @param string $string Input string that may contain unnecessary spaces (e.g., " -la -lb"). + * @return string The trimmed string with only single spaces (e.g., "-la -lb"). */ -function deduplicate_spaces($string): string +function clean_spaces(string $string): string { return trim(preg_replace('/\s+/', ' ', $string)); } From 0acf238c74b45ceb4033cd92a91379f69f2b1655 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 11:02:01 +0700 Subject: [PATCH 226/278] suggested are required too --- src/SPC/builder/Extension.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index e83f9dcdd..9ea5c8b34 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -228,15 +228,21 @@ public function patchBeforeSharedConfigure(): bool */ public function patchBeforeSharedMake(): bool { + $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], $this->builder->getOption('with-suggested-exts'), $this->builder->getOption('with-suggested-libs')); + [$staticLibs] = $this->getStaticAndSharedLibs($config['libs']); + FileSystem::replaceFileRegex( + $this->source_dir . '/Makefile', + '/^(.*_SHARED_LIBADD\s*=.*)$/m', + '$1 ' . trim($staticLibs) + ); if ($objs = getenv('SPC_EXTRA_RUNTIME_OBJECTS')) { FileSystem::replaceFileRegex( $this->source_dir . '/Makefile', "/^(shared_objects_{$this->getName()}\\s*=.*)$/m", "$1 {$objs}", ); - return true; } - return false; + return true; } /** @@ -401,7 +407,7 @@ public function buildShared(): void */ public function buildUnixShared(): void { - $config = (new SPCConfigUtil($this->builder))->config([$this->getName()]); + $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], $this->builder->getOption('with-suggested-exts'), $this->builder->getOption('with-suggested-libs')); [$staticLibs, $sharedLibs] = $this->getStaticAndSharedLibs($config['libs']); $env = [ 'CFLAGS' => $config['cflags'], @@ -437,13 +443,6 @@ public function buildUnixShared(): void '--enable-shared --disable-static' ); - // some extensions don't define their dependencies well, this patch is only needed for a few - FileSystem::replaceFileRegex( - $this->source_dir . '/Makefile', - '/^(.*_SHARED_LIBADD\s*=.*)$/m', - '$1 ' . trim($staticLibs) - ); - if ($this->patchBeforeSharedMake()) { logger()->info("Extension [{$this->getName()}] patched before shared make"); } From 029f2db6204535d5ee269fbe20bb36d630ecef9a Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 11:12:49 +0700 Subject: [PATCH 227/278] oh dear god what am I doing --- src/SPC/builder/Extension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 9ea5c8b34..43ff000a7 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -228,7 +228,7 @@ public function patchBeforeSharedConfigure(): bool */ public function patchBeforeSharedMake(): bool { - $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], $this->builder->getOption('with-suggested-exts'), $this->builder->getOption('with-suggested-libs')); + $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], array_map(fn ($l) => $l->getName(), $this->builder->getLibs())); [$staticLibs] = $this->getStaticAndSharedLibs($config['libs']); FileSystem::replaceFileRegex( $this->source_dir . '/Makefile', @@ -407,7 +407,7 @@ public function buildShared(): void */ public function buildUnixShared(): void { - $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], $this->builder->getOption('with-suggested-exts'), $this->builder->getOption('with-suggested-libs')); + $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], array_map(fn ($l) => $l->getName(), $this->builder->getLibs())); [$staticLibs, $sharedLibs] = $this->getStaticAndSharedLibs($config['libs']); $env = [ 'CFLAGS' => $config['cflags'], From 51fcc6b2317fd4c3128e33a2f4bc45268ed9baf7 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 12:32:49 +0700 Subject: [PATCH 228/278] test musl again (succeeds locally :) --- 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 1c279e2f5..56489d845 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -158,7 +158,7 @@ function quote2(string $param): string break; case 'ubuntu-24.04': case 'ubuntu-24.04-arm': - putenv('SPC_TARGET=native-native-gnu'); + putenv('SPC_TARGET=native-native-musl -dynamic'); if (getenv('SPC_TARGET') && !str_contains(getenv('SPC_TARGET'), '-musl')) { exec('sudo apt install musl -y'); } From 37a453b3cda451526b3c7bf7b2968f37a30bbc7b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 12:57:40 +0700 Subject: [PATCH 229/278] of course x) --- 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 56489d845..1bba2f9ad 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -159,7 +159,7 @@ function quote2(string $param): string case 'ubuntu-24.04': case 'ubuntu-24.04-arm': putenv('SPC_TARGET=native-native-musl -dynamic'); - if (getenv('SPC_TARGET') && !str_contains(getenv('SPC_TARGET'), '-musl')) { + if (getenv('SPC_TARGET') && str_contains(getenv('SPC_TARGET'), '-musl')) { exec('sudo apt install musl -y'); } if (getenv('SPC_TARGET')) { From b4392aded7ea24badb9be72088dd7a7710bda4b6 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 16:11:11 +0700 Subject: [PATCH 230/278] always install musl libc (to be able to compile dynamic with zig) --- src/SPC/doctor/item/LinuxToolCheckList.php | 6 +++--- src/globals/test-extensions.php | 10 ---------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 51e191bfa..5586bb005 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -31,7 +31,7 @@ class LinuxToolCheckList 'tar', 'unzip', 'gzip', 'bzip2', 'cmake', 'patch', 'xz', 'libtoolize', 'which', - 'patchelf', + 'patchelf', 'musl' ]; public const TOOLS_RHEL = [ @@ -40,7 +40,7 @@ class LinuxToolCheckList 'tar', 'unzip', 'gzip', 'gcc', 'bzip2', 'cmake', 'patch', 'which', 'xz', 'libtool', 'gettext-devel', - 'perl', 'patchelf', + 'perl', 'patchelf', 'musl-libc' ]; public const TOOLS_ARCH = [ @@ -69,7 +69,7 @@ public function checkCliTools(): ?CheckResult }; $missing = []; foreach ($required as $package) { - if ($this->findCommand(self::PROVIDED_COMMAND[$package] ?? $package) === null) { + if (self::findCommand(self::PROVIDED_COMMAND[$package] ?? $package) === null) { $missing[] = $package; } } diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 1bba2f9ad..f66f7ceea 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -156,16 +156,6 @@ function quote2(string $param): string case 'ubuntu-22.04-arm': $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; break; - case 'ubuntu-24.04': - case 'ubuntu-24.04-arm': - putenv('SPC_TARGET=native-native-musl -dynamic'); - if (getenv('SPC_TARGET') && str_contains(getenv('SPC_TARGET'), '-musl')) { - exec('sudo apt install musl -y'); - } - if (getenv('SPC_TARGET')) { - $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; - } - break; case 'macos-13': case 'macos-14': case 'macos-15': From a8be88d7715b8b632ded55b7017db7b60ad736ac Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 16:13:48 +0700 Subject: [PATCH 231/278] fix swow --- config/source.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/source.json b/config/source.json index c6343683f..0fc9bca75 100644 --- a/config/source.json +++ b/config/source.json @@ -1007,7 +1007,7 @@ "swow": { "path": "php-src/ext/swow-src", "type": "ghtar", - "repo": "swoole/swoole-src", + "repo": "swow/swow", "prefer-stable": true, "license": { "type": "file", From 821411cfd6a0d318f73a2a1c5362b2e81af7d53c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 16:17:13 +0700 Subject: [PATCH 232/278] only -lstdc++ on linux --- src/SPC/builder/Extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 43ff000a7..d8db6d07f 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -416,7 +416,7 @@ public function buildUnixShared(): void 'LIBS' => "-Wl,--start-group {$staticLibs} -Wl,--end-group {$sharedLibs}", 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, ]; - if (ToolchainManager::getToolchainClass() === ZigToolchain::class) { + if (ToolchainManager::getToolchainClass() === ZigToolchain::class && SPCTarget::getTargetOS() === 'Linux') { $env['SPC_COMPILER_EXTRA'] = '-lstdc++'; } From a9fab862693d350bcfa1a81e45d77083765efbd4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 16:18:04 +0700 Subject: [PATCH 233/278] rename getStaticAndSharedLibs --- src/SPC/builder/Extension.php | 6 +++--- src/SPC/builder/extension/imagick.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index d8db6d07f..8a3759fea 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -229,7 +229,7 @@ public function patchBeforeSharedConfigure(): bool public function patchBeforeSharedMake(): bool { $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], array_map(fn ($l) => $l->getName(), $this->builder->getLibs())); - [$staticLibs] = $this->getStaticAndSharedLibs($config['libs']); + [$staticLibs] = $this->splitLibsIntoStaticAndShared($config['libs']); FileSystem::replaceFileRegex( $this->source_dir . '/Makefile', '/^(.*_SHARED_LIBADD\s*=.*)$/m', @@ -408,7 +408,7 @@ public function buildShared(): void public function buildUnixShared(): void { $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], array_map(fn ($l) => $l->getName(), $this->builder->getLibs())); - [$staticLibs, $sharedLibs] = $this->getStaticAndSharedLibs($config['libs']); + [$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']); $env = [ 'CFLAGS' => $config['cflags'], 'CXXFLAGS' => $config['cflags'], @@ -528,7 +528,7 @@ protected function getExtraEnv(): array return []; } - protected function getStaticAndSharedLibs(string $allLibs): array + protected function splitLibsIntoStaticAndShared(string $allLibs): array { $staticLibString = ''; $sharedLibString = ''; diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 0471dd659..cd5542cf4 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -16,9 +16,9 @@ public function getUnixConfigureArg(bool $shared = false): string return '--with-imagick=' . ($shared ? 'shared,' : '') . BUILD_ROOT_PATH . $disable_omp; } - protected function getStaticAndSharedLibs(string $allLibs): array + protected function splitLibsIntoStaticAndShared(string $allLibs): array { - [$static, $shared] = parent::getStaticAndSharedLibs($allLibs); + [$static, $shared] = parent::splitLibsIntoStaticAndShared($allLibs); if (str_contains(getenv('PATH'), 'rh/devtoolset-10')) { $static .= ' -l:libstdc++.a'; $shared = str_replace('-lstdc++', '', $shared); From a0edca5e5b7561bad39d70b072af1930f6d592ec Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 16:22:42 +0700 Subject: [PATCH 234/278] docs for function --- src/SPC/builder/Extension.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 8a3759fea..f3bf9ccf5 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -528,6 +528,14 @@ protected function getExtraEnv(): array return []; } + /** + * Splits a given string of library flags into static and shared libraries. + * + * @param string $allLibs A space-separated string of library flags (e.g., -lxyz). + * @return array An array containing two elements: the first is a space-separated string + * of static library flags, and the second is a space-separated string + * of shared library flags. + */ protected function splitLibsIntoStaticAndShared(string $allLibs): array { $staticLibString = ''; @@ -535,7 +543,7 @@ protected function splitLibsIntoStaticAndShared(string $allLibs): array $libs = explode(' ', $allLibs); foreach ($libs as $lib) { $staticLib = BUILD_LIB_PATH . '/lib' . str_replace('-l', '', $lib) . '.a'; - if (!file_exists($staticLib) || $lib === '-lphp') { + if ($lib === '-lphp' || !file_exists($staticLib)) { $sharedLibString .= " {$lib}"; } else { $staticLibString .= " {$lib}"; From af63723794da83f474f7ec878de2dd1fdf2a84ce Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 16:24:22 +0700 Subject: [PATCH 235/278] revert DYLD_LIBRARY_PATH --- src/SPC/builder/unix/UnixBuilderBase.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 7f38dc881..f4b97be52 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -126,7 +126,11 @@ protected function sanityCheck(int $build_target): void } // if someone changed to EMBED_TYPE=shared, we need to add LD_LIBRARY_PATH if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { - $ext_path = 'LD_LIBRARY_PATH=' . BUILD_LIB_PATH . ':$LD_LIBRARY_PATH '; + if (PHP_OS_FAMILY === 'Darwin') { + $ext_path = 'DYLD_LIBRARY_PATH=' . BUILD_LIB_PATH . ':$DYLD_LIBRARY_PATH '; + } else { + $ext_path = 'LD_LIBRARY_PATH=' . BUILD_LIB_PATH . ':$LD_LIBRARY_PATH '; + } FileSystem::removeFileIfExists(BUILD_LIB_PATH . '/libphp.a'); } else { $ext_path = ''; From ed3a78b56dbfb91a8bcc639acd71cb7fb753a1f4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 16:26:02 +0700 Subject: [PATCH 236/278] revert macos mistake --- src/SPC/builder/unix/UnixBuilderBase.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index f4b97be52..d4afbc93e 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -134,7 +134,8 @@ protected function sanityCheck(int $build_target): void FileSystem::removeFileIfExists(BUILD_LIB_PATH . '/libphp.a'); } else { $ext_path = ''; - foreach (glob(BUILD_LIB_PATH . '/libphp*.so') as $file) { + $suffix = PHP_OS_FAMILY === 'Darwin' ? 'dylib' : 'so'; + foreach (glob(BUILD_LIB_PATH . "/libphp*.{$suffix}") as $file) { unlink($file); } } From a3efe86cac490d16a2bd44c87af447d2d2cc9b4e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 16:26:07 +0700 Subject: [PATCH 237/278] logging --- src/SPC/toolchain/ZigToolchain.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index 227e972ce..e9ce220c3 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -49,7 +49,7 @@ public function afterInit(): void throw new WrongUsageException('You are building with zig, but zig is not installed, please install zig first. (You can use `doctor` command to install it)'); } GlobalEnvManager::addPathIfNotExists(Zig::getEnvironment()['PATH']); - exec('ulimit -n 2048'); // zig opens extra file descriptors, so when a lot of extensions are built statically, 1024 is not enough + f_passthru('ulimit -n 2048'); // zig opens extra file descriptors, so when a lot of extensions are built statically, 1024 is not enough $cflags = getenv('SPC_DEFAULT_C_FLAGS') ?: ''; $cxxflags = getenv('SPC_DEFAULT_CXX_FLAGS') ?: ''; $extraCflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') ?: ''; From 18a5215da9f9a4ed35b65c4300dace1c8e7cc7ee Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 16:26:34 +0700 Subject: [PATCH 238/278] cs fix --- src/SPC/builder/Extension.php | 8 ++++---- src/SPC/doctor/item/LinuxToolCheckList.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index f3bf9ccf5..4672ca78d 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -531,10 +531,10 @@ protected function getExtraEnv(): array /** * Splits a given string of library flags into static and shared libraries. * - * @param string $allLibs A space-separated string of library flags (e.g., -lxyz). - * @return array An array containing two elements: the first is a space-separated string - * of static library flags, and the second is a space-separated string - * of shared library flags. + * @param string $allLibs A space-separated string of library flags (e.g., -lxyz). + * @return array an array containing two elements: the first is a space-separated string + * of static library flags, and the second is a space-separated string + * of shared library flags */ protected function splitLibsIntoStaticAndShared(string $allLibs): array { diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 5586bb005..5b43f38fe 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -31,7 +31,7 @@ class LinuxToolCheckList 'tar', 'unzip', 'gzip', 'bzip2', 'cmake', 'patch', 'xz', 'libtoolize', 'which', - 'patchelf', 'musl' + 'patchelf', 'musl', ]; public const TOOLS_RHEL = [ @@ -40,7 +40,7 @@ class LinuxToolCheckList 'tar', 'unzip', 'gzip', 'gcc', 'bzip2', 'cmake', 'patch', 'which', 'xz', 'libtool', 'gettext-devel', - 'perl', 'patchelf', 'musl-libc' + 'perl', 'patchelf', 'musl-libc', ]; public const TOOLS_ARCH = [ From 5482f130ba0be5680b5eafb8d6b93f174f8e4838 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 16:55:16 +0700 Subject: [PATCH 239/278] make sure we don't use musl ld --- src/SPC/store/pkg/GoXcaddy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/store/pkg/GoXcaddy.php b/src/SPC/store/pkg/GoXcaddy.php index 40f5ca258..e071e9343 100644 --- a/src/SPC/store/pkg/GoXcaddy.php +++ b/src/SPC/store/pkg/GoXcaddy.php @@ -89,7 +89,7 @@ public function extract(string $name): void 'GOBIN' => "{$pkgroot}/{$name}/bin", 'GOPATH' => "{$pkgroot}/go", ]) - ->exec("CC=cc {$go_exec} install github.com/caddyserver/xcaddy/cmd/xcaddy@latest"); + ->exec("CC=cc CXX=c++ LD=ld AR=ar {$go_exec} install github.com/caddyserver/xcaddy/cmd/xcaddy@latest"); } public static function getEnvironment(): array From a355e4d0e7c7314e02de1a73bed9c0bc5b5a5565 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 16:55:51 +0700 Subject: [PATCH 240/278] run macos tests again --- src/globals/test-extensions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index f66f7ceea..a9fb682b5 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -21,9 +21,9 @@ // test os (macos-13, macos-14, macos-15, ubuntu-latest, windows-latest are available) $test_os = [ - // 'macos-13', // bin/spc for x86_64 + 'macos-13', // bin/spc for x86_64 // 'macos-14', // bin/spc for arm64 - // 'macos-15', // bin/spc for arm64 + 'macos-15', // bin/spc for arm64 // 'ubuntu-latest', // bin/spc-alpine-docker for x86_64 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64 'ubuntu-24.04', // bin/spc for x86_64 From da8c38575edcb585cd244b0b05a109f653f61fb2 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 17:16:35 +0700 Subject: [PATCH 241/278] please...? --- src/SPC/store/pkg/GoXcaddy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/store/pkg/GoXcaddy.php b/src/SPC/store/pkg/GoXcaddy.php index e071e9343..b672e878f 100644 --- a/src/SPC/store/pkg/GoXcaddy.php +++ b/src/SPC/store/pkg/GoXcaddy.php @@ -89,7 +89,7 @@ public function extract(string $name): void 'GOBIN' => "{$pkgroot}/{$name}/bin", 'GOPATH' => "{$pkgroot}/go", ]) - ->exec("CC=cc CXX=c++ LD=ld AR=ar {$go_exec} install github.com/caddyserver/xcaddy/cmd/xcaddy@latest"); + ->exec("CC=/usr/bin/cc CXX=/usr/bin/c++ LD=/usr/bin/ld AR=/usr/bin/ar {$go_exec} install github.com/caddyserver/xcaddy/cmd/xcaddy@latest"); } public static function getEnvironment(): array From d62736313220de587f23eee5f899ac45bd88744e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 17:52:33 +0700 Subject: [PATCH 242/278] please please...? --- src/SPC/store/pkg/GoXcaddy.php | 15 +++++++++++---- src/globals/test-extensions.php | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/SPC/store/pkg/GoXcaddy.php b/src/SPC/store/pkg/GoXcaddy.php index b672e878f..13041a6f2 100644 --- a/src/SPC/store/pkg/GoXcaddy.php +++ b/src/SPC/store/pkg/GoXcaddy.php @@ -4,6 +4,7 @@ namespace SPC\store\pkg; +use SPC\builder\linux\SystemUtil; use SPC\store\Downloader; use SPC\store\FileSystem; use SPC\store\LockFile; @@ -77,19 +78,25 @@ public function extract(string $name): void $lock = json_decode(FileSystem::readFile(LockFile::LOCK_FILE), true); $source_type = $lock[$name]['source_type']; $filename = DOWNLOAD_PATH . '/' . ($lock[$name]['filename'] ?? $lock[$name]['dirname']); - $extract = $lock[$name]['move_path'] === null ? "{$pkgroot}/{$name}" : $lock[$name]['move_path']; + $extract = $lock[$name]['move_path'] ?? "{$pkgroot}/{$name}"; FileSystem::extractPackage($name, $source_type, $filename, $extract); - // install xcaddy + $sanitizedPath = getenv('PATH'); + if (PHP_OS_FAMILY === 'Linux' && !SystemUtil::isMuslDist()) { + $sanitizedPath = preg_replace('#(:?/?[^:]*musl[^:]*)#', '', $sanitizedPath); + $sanitizedPath = preg_replace('#^:|:$|::#', ':', $sanitizedPath); // clean up colons + } + + // install xcaddy without using musl tools, xcaddy build requires dynamic linking shell() ->appendEnv([ - 'PATH' => "{$pkgroot}/{$name}/bin:" . getenv('PATH'), + 'PATH' => "{$pkgroot}/{$name}/bin:" . $sanitizedPath, 'GOROOT' => "{$pkgroot}/{$name}", 'GOBIN' => "{$pkgroot}/{$name}/bin", 'GOPATH' => "{$pkgroot}/go", ]) - ->exec("CC=/usr/bin/cc CXX=/usr/bin/c++ LD=/usr/bin/ld AR=/usr/bin/ar {$go_exec} install github.com/caddyserver/xcaddy/cmd/xcaddy@latest"); + ->exec('CC=cc go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest'); } public static function getEnvironment(): array diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index a9fb682b5..3784f9089 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -205,6 +205,7 @@ function quote2(string $param): string switch ($argv[1] ?? null) { case 'download_cmd': + passthru("{$prefix}install-pkg go-xcaddy --debug", $retcode); # test passthru($prefix . $down_cmd, $retcode); break; case 'build_cmd': From 753c7207162e217bb5b23c7f62a0c580220fd827 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 17:56:42 +0700 Subject: [PATCH 243/278] remove test, seems like removing musl from paths was successful --- src/globals/test-extensions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 3784f9089..a9fb682b5 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -205,7 +205,6 @@ function quote2(string $param): string switch ($argv[1] ?? null) { case 'download_cmd': - passthru("{$prefix}install-pkg go-xcaddy --debug", $retcode); # test passthru($prefix . $down_cmd, $retcode); break; case 'build_cmd': From 3cbd52c1f9ee1dccb064902e8efa6e305ccbe414 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 18:44:30 +0700 Subject: [PATCH 244/278] test with zig-cc instead --- src/globals/test-extensions.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index a9fb682b5..8558e9b74 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -156,6 +156,13 @@ function quote2(string $param): string case 'ubuntu-22.04-arm': $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; break; + case 'ubuntu-24.04': + putenv('SPC_TARGET=native-native-musl -dynamic'); + $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; + break; + case 'ubuntu-24.04-arm': + putenv('SPC_TARGET=native-native-musl'); + break; case 'macos-13': case 'macos-14': case 'macos-15': From 70a9ffe4a2b5e01ccf639eae156f3f1595a9cee0 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 25 Jul 2025 20:00:46 +0700 Subject: [PATCH 245/278] now test gnu again --- src/globals/test-extensions.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 8558e9b74..8795d0a68 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -157,11 +157,12 @@ function quote2(string $param): string $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; break; case 'ubuntu-24.04': - putenv('SPC_TARGET=native-native-musl -dynamic'); + putenv('SPC_TARGET=native-native-gnu.2.17'); $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; break; case 'ubuntu-24.04-arm': - putenv('SPC_TARGET=native-native-musl'); + putenv('SPC_TARGET=native-native-gnu.2.28'); + $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; break; case 'macos-13': case 'macos-14': From 2cb1a95132af6d1c9ee96a6f31d65c59be881d33 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 11:13:29 +0700 Subject: [PATCH 246/278] change dependency tracking --- config/env.ini | 10 ---------- src/SPC/builder/Extension.php | 7 ++++++- src/SPC/builder/linux/LinuxBuilder.php | 14 +++++--------- src/SPC/builder/macos/MacOSBuilder.php | 2 +- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/config/env.ini b/config/env.ini index 521d1e914..1565f6221 100644 --- a/config/env.ini +++ b/config/env.ini @@ -108,10 +108,6 @@ SPC_CMD_PREFIX_PHP_MAKE="make -j${SPC_CONCURRENCY}" SPC_CMD_VAR_PHP_EMBED_TYPE="static" ; CFLAGS for configuring php SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -fPIE" -; CPPFLAGS for configuring php -SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}" -; LDFLAGS for configuring php -SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" ; EXTRA_CFLAGS for `make` php SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}" ; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so @@ -143,14 +139,8 @@ SPC_CMD_PREFIX_PHP_MAKE="make -j${SPC_CONCURRENCY}" SPC_CMD_VAR_PHP_EMBED_TYPE="static" ; CFLAGS for configuring php SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -Werror=unknown-warning-option" -; CPPFLAGS for configuring php -SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}" -; LDFLAGS for configuring php -SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" ; EXTRA_CFLAGS for `make` php SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie ${SPC_DEFAULT_C_FLAGS}" -; embed type for php, static (libphp.a) or shared (libphp.dylib) -SPC_CMD_VAR_PHP_EMBED_TYPE="static" [freebsd] ; compiler environments diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 4672ca78d..234f80b01 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -407,7 +407,12 @@ public function buildShared(): void */ public function buildUnixShared(): void { - $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], array_map(fn ($l) => $l->getName(), $this->builder->getLibs())); + $config = (new SPCConfigUtil($this->builder))->config( + [$this->getName()], + array_map(fn ($l) => $l->getName(), $this->getLibraryDependencies(recursive: true)), + $this->builder->getOption('with-suggested-exts'), + $this->builder->getOption('with-suggested-libs'), + ); [$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']); $env = [ 'CFLAGS' => $config['cflags'], diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 03158c1ea..e185560a8 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -88,16 +88,12 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $enableFrankenphp = ($build_target & BUILD_TARGET_FRANKENPHP) === BUILD_TARGET_FRANKENPHP; // prepare build php envs - $config = (new SPCConfigUtil($this, ['libs_only_deps' => true]))->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs')); - if (str_contains($config['libs'], ' -lpgport') && !$this->getExt('pgsql')?->isBuildStatic()) { - // -lpgport defines many glibc functions if they are missing, which leads to feature tests succeeding that aren't meant to succeed - $config['libs'] = str_replace(' -lpgport', '', $config['libs']); - } - $envs_build_php = SystemUtil::makeEnvVarString([ + $mimallocLibs = $this->getLib('mimalloc') !== null ? BUILD_LIB_PATH . '/mimalloc.o ' : ''; + $php_configure_env = SystemUtil::makeEnvVarString([ 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'), - 'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'), + 'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, 'LDFLAGS' => '-L' . BUILD_LIB_PATH, - 'LIBS' => $config['libs'], + 'LIBS' => $mimallocLibs . SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions! ]); $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; @@ -121,7 +117,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $zts . $maxExecutionTimers . $this->makeStaticExtensionArgs() . - ' ' . $envs_build_php . ' ' + ' ' . $php_configure_env . ' ' ); $this->emitPatchPoint('before-php-make'); diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 9b131b9d6..b8a8d8141 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -115,7 +115,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $mimallocLibs = $this->getLib('mimalloc') !== null ? BUILD_LIB_PATH . '/mimalloc.o ' : ''; $envs_build_php = SystemUtil::makeEnvVarString([ 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'), - 'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'), + 'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, 'LDFLAGS' => '-L' . BUILD_LIB_PATH, 'LIBS' => $mimallocLibs . getenv('SPC_CMD_VAR_PHP_CONFIGURE_LIBS'), ]); From 6e74dabc1c8e7bf78fd6aea55f3a36a00066f078 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 13:48:22 +0700 Subject: [PATCH 247/278] reduce libphp.a size by stripping .a archives inside it as well --- src/SPC/builder/linux/LinuxBuilder.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index e185560a8..3bd74ead7 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -323,6 +323,10 @@ protected function buildEmbed(): void } } + if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'static') { + f_passthru('ar -t ' . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 ar d " . BUILD_LIB_PATH . '/libphp.a'); + } + if (!$this->getOption('no-strip', false) && file_exists(BUILD_LIB_PATH . '/' . $realLibName)) { shell()->cd(BUILD_LIB_PATH)->exec("strip --strip-unneeded {$realLibName}"); } From c2b3b7884672749cf0ff5487aa6d6f3f7706c69d Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 13:51:34 +0700 Subject: [PATCH 248/278] switch to libmimalloc.a because go linker is sometimes doing unpredictable things --- config/lib.json | 2 +- src/SPC/builder/Extension.php | 3 +++ src/SPC/builder/linux/LinuxBuilder.php | 3 +-- src/SPC/builder/macos/MacOSBuilder.php | 5 +---- src/SPC/builder/unix/library/mimalloc.php | 1 + src/SPC/util/SPCConfigUtil.php | 8 ++++---- tests/SPC/util/SPCConfigUtilTest.php | 16 ++++++++-------- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/config/lib.json b/config/lib.json index 77d032a4e..d12950744 100644 --- a/config/lib.json +++ b/config/lib.json @@ -655,7 +655,7 @@ "mimalloc": { "source": "mimalloc", "static-libs-unix": [ - "mimalloc.o" + "libmimalloc.a" ] }, "ncurses": { diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 234f80b01..721d1f429 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -548,6 +548,9 @@ protected function splitLibsIntoStaticAndShared(string $allLibs): array $libs = explode(' ', $allLibs); foreach ($libs as $lib) { $staticLib = BUILD_LIB_PATH . '/lib' . str_replace('-l', '', $lib) . '.a'; + if (str_starts_with($lib, BUILD_LIB_PATH . '/lib') && str_ends_with($lib, '.a')) { + $staticLib = $lib; + } if ($lib === '-lphp' || !file_exists($staticLib)) { $sharedLibString .= " {$lib}"; } else { diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 3bd74ead7..2d42f9313 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -88,12 +88,11 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $enableFrankenphp = ($build_target & BUILD_TARGET_FRANKENPHP) === BUILD_TARGET_FRANKENPHP; // prepare build php envs - $mimallocLibs = $this->getLib('mimalloc') !== null ? BUILD_LIB_PATH . '/mimalloc.o ' : ''; $php_configure_env = SystemUtil::makeEnvVarString([ 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'), 'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, 'LDFLAGS' => '-L' . BUILD_LIB_PATH, - 'LIBS' => $mimallocLibs . SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions! + 'LIBS' => SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions! ]); $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index b8a8d8141..3530de1b0 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -112,12 +112,10 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $enableFrankenphp = ($build_target & BUILD_TARGET_FRANKENPHP) === BUILD_TARGET_FRANKENPHP; // prepare build php envs - $mimallocLibs = $this->getLib('mimalloc') !== null ? BUILD_LIB_PATH . '/mimalloc.o ' : ''; $envs_build_php = SystemUtil::makeEnvVarString([ 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'), 'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, 'LDFLAGS' => '-L' . BUILD_LIB_PATH, - 'LIBS' => $mimallocLibs . getenv('SPC_CMD_VAR_PHP_CONFIGURE_LIBS'), ]); if ($this->getLib('postgresql')) { @@ -269,8 +267,7 @@ protected function buildEmbed(): void ->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install"); if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'static') { - shell()->cd(SOURCE_PATH . '/php-src') - ->exec('ar -t ' . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 ar d " . BUILD_LIB_PATH . '/libphp.a'); + f_passthru('ar -t ' . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 ar d " . BUILD_LIB_PATH . '/libphp.a'); } $this->patchPhpScripts(); } diff --git a/src/SPC/builder/unix/library/mimalloc.php b/src/SPC/builder/unix/library/mimalloc.php index 6d89e6dfc..d483ed397 100644 --- a/src/SPC/builder/unix/library/mimalloc.php +++ b/src/SPC/builder/unix/library/mimalloc.php @@ -14,6 +14,7 @@ protected function build(): void $cmake = UnixCMakeExecutor::create($this) ->addConfigureArgs( '-DMI_BUILD_SHARED=OFF', + '-DMI_BUILD_OBJECT=OFF', '-DMI_INSTALL_TOPLEVEL=ON', ); if (SPCTarget::getLibc() === 'musl') { diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index c3bb83cc2..08570008e 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -94,8 +94,8 @@ public function config(array $extensions = [], array $libraries = [], bool $incl if ($this->libs_only_deps) { // mimalloc must come first - if (str_contains($libs, BUILD_LIB_PATH . '/mimalloc.o')) { - $libs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace(BUILD_LIB_PATH . '/mimalloc.o', '', $libs); + if ($this->builder->getLib('mimalloc') && file_exists(BUILD_LIB_PATH . '/libmimalloc.a')) { + $libs = BUILD_LIB_PATH . '/libmimalloc.a ' . str_replace([BUILD_LIB_PATH . '/libmimalloc.a', '-lmimalloc'], ['', ''], $libs); } return [ 'cflags' => clean_spaces(getenv('CFLAGS') . ' ' . $cflags), @@ -112,8 +112,8 @@ public function config(array $extensions = [], array $libraries = [], bool $incl $allLibs = getenv('LIBS') . ' ' . $libs; // mimalloc must come first - if (str_contains($libs, BUILD_LIB_PATH . '/mimalloc.o')) { - $allLibs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace(BUILD_LIB_PATH . '/mimalloc.o', '', $allLibs); + if ($this->builder->getLib('mimalloc') && file_exists(BUILD_LIB_PATH . '/libmimalloc.a')) { + $allLibs = BUILD_LIB_PATH . '/libmimalloc.a ' . str_replace([BUILD_LIB_PATH . '/libmimalloc.a', '-lmimalloc'], ['', ''], $allLibs); } return [ diff --git a/tests/SPC/util/SPCConfigUtilTest.php b/tests/SPC/util/SPCConfigUtilTest.php index c37f01f38..7b8baa6c5 100644 --- a/tests/SPC/util/SPCConfigUtilTest.php +++ b/tests/SPC/util/SPCConfigUtilTest.php @@ -57,18 +57,18 @@ public function testConfig(): void $result = (new SPCConfigUtil())->config(['rar']); $this->assertStringContainsString(PHP_OS_FAMILY === 'Darwin' ? '-lc++' : '-lstdc++', $result['libs']); - // has mimalloc.o in lib dir + // has libmimalloc.a in lib dir // backup first - if (file_exists(BUILD_LIB_PATH . '/mimalloc.o')) { - $bak = file_get_contents(BUILD_LIB_PATH . '/mimalloc.o'); - @unlink(BUILD_LIB_PATH . '/mimalloc.o'); + if (file_exists(BUILD_LIB_PATH . '/libmimalloc.a')) { + $bak = file_get_contents(BUILD_LIB_PATH . '/libmimalloc.a'); + @unlink(BUILD_LIB_PATH . '/libmimalloc.a'); } - file_put_contents(BUILD_LIB_PATH . '/mimalloc.o', ''); + file_put_contents(BUILD_LIB_PATH . '/libmimalloc.a', ''); $result = (new SPCConfigUtil())->config(['bcmath'], ['mimalloc']); - $this->assertStringStartsWith(BUILD_LIB_PATH . '/mimalloc.o', $result['libs']); - @unlink(BUILD_LIB_PATH . '/mimalloc.o'); + $this->assertStringStartsWith(BUILD_LIB_PATH . '/libmimalloc.a', $result['libs']); + @unlink(BUILD_LIB_PATH . '/libmimalloc.a'); if (isset($bak)) { - file_put_contents(BUILD_LIB_PATH . '/mimalloc.o', $bak); + file_put_contents(BUILD_LIB_PATH . '/libmimalloc.a', $bak); } } } From 630f861c629104d2890f2bdf5332020cfb9ab204 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 15:17:37 +0700 Subject: [PATCH 249/278] move musl check so it doesn't keep prompting for install --- src/SPC/doctor/item/LinuxMuslCheck.php | 10 ++++++++-- src/SPC/doctor/item/LinuxToolCheckList.php | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/SPC/doctor/item/LinuxMuslCheck.php b/src/SPC/doctor/item/LinuxMuslCheck.php index a4e57eba2..48b33fedb 100644 --- a/src/SPC/doctor/item/LinuxMuslCheck.php +++ b/src/SPC/doctor/item/LinuxMuslCheck.php @@ -4,6 +4,7 @@ namespace SPC\doctor\item; +use SPC\builder\linux\SystemUtil; use SPC\doctor\AsCheckItem; use SPC\doctor\AsFixItem; use SPC\doctor\CheckResult; @@ -17,13 +18,15 @@ use SPC\store\PackageManager; use SPC\store\SourcePatcher; use SPC\toolchain\MuslToolchain; +use SPC\toolchain\ZigToolchain; #[OptionalCheck([self::class, 'optionalCheck'])] class LinuxMuslCheck { public static function optionalCheck(): bool { - return getenv('SPC_TOOLCHAIN') === MuslToolchain::class; + return getenv('SPC_TOOLCHAIN') === MuslToolchain::class || + (getenv('SPC_TOOLCHAIN') === ZigToolchain::class && !SystemUtil::isMuslDist()); } /** @noinspection PhpUnused */ @@ -31,7 +34,7 @@ public static function optionalCheck(): bool public function checkMusl(): CheckResult { $musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m')); - if (file_exists($musl_wrapper_lib) && file_exists('/usr/local/musl/lib/libc.a')) { + if (file_exists($musl_wrapper_lib) && (file_exists('/usr/local/musl/lib/libc.a') || getenv('SPC_TOOLCHAIN') === ZigToolchain::class)) { return CheckResult::ok(); } return CheckResult::fail('musl-wrapper is not installed on your system', 'fix-musl-wrapper'); @@ -40,6 +43,9 @@ public function checkMusl(): CheckResult #[AsCheckItem('if musl-cross-make is installed', limit_os: 'Linux', level: 799)] public function checkMuslCrossMake(): CheckResult { + if (getenv('SPC_TOOLCHAIN') === ZigToolchain::class && !SystemUtil::isMuslDist()) { + return CheckResult::ok(); + } $arch = arch2gnu(php_uname('m')); $cross_compile_lib = "/usr/local/musl/{$arch}-linux-musl/lib/libc.a"; $cross_compile_gcc = "/usr/local/musl/bin/{$arch}-linux-musl-gcc"; diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 5b43f38fe..b5c9cb034 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -31,7 +31,7 @@ class LinuxToolCheckList 'tar', 'unzip', 'gzip', 'bzip2', 'cmake', 'patch', 'xz', 'libtoolize', 'which', - 'patchelf', 'musl', + 'patchelf', ]; public const TOOLS_RHEL = [ @@ -40,7 +40,7 @@ class LinuxToolCheckList 'tar', 'unzip', 'gzip', 'gcc', 'bzip2', 'cmake', 'patch', 'which', 'xz', 'libtool', 'gettext-devel', - 'perl', 'patchelf', 'musl-libc', + 'perl', 'patchelf', ]; public const TOOLS_ARCH = [ From fb62a0e3382d7efdba3f2771c1e489edd8e2fc97 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 20:12:18 +0700 Subject: [PATCH 250/278] small adjustments --- src/SPC/toolchain/ZigToolchain.php | 4 ++-- src/SPC/util/UnixShell.php | 2 +- src/SPC/util/executor/UnixAutoconfExecutor.php | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index e9ce220c3..a379164cf 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -15,8 +15,8 @@ public function initEnv(): void // Set environment variables for zig toolchain GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=zig-cc'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++'); - GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar'); - GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld'); + GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=zig ar'); + GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=zig-cc'); // Generate additional object needed for zig toolchain $paths = ['/usr/lib/gcc', '/usr/local/lib/gcc']; diff --git a/src/SPC/util/UnixShell.php b/src/SPC/util/UnixShell.php index ffe18910d..3e96e4bde 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -61,9 +61,9 @@ public function initializeEnv(BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $ { $this->setEnv([ 'CFLAGS' => $library->getLibExtraCFlags(), + 'CXXFLAGS' => $library->getLibExtraCXXFlags(), 'LDFLAGS' => $library->getLibExtraLdFlags(), 'LIBS' => $library->getLibExtraLibs(), - 'CXXFLAGS' => $library->getLibExtraCXXFlags(), ]); return $this; } diff --git a/src/SPC/util/executor/UnixAutoconfExecutor.php b/src/SPC/util/executor/UnixAutoconfExecutor.php index 8f923b1f1..4543bd7bc 100644 --- a/src/SPC/util/executor/UnixAutoconfExecutor.php +++ b/src/SPC/util/executor/UnixAutoconfExecutor.php @@ -135,6 +135,7 @@ private function initShell(): void { $this->shell = shell()->cd($this->library->getSourceDir())->initializeEnv($this->library)->appendEnv([ 'CFLAGS' => "-I{$this->library->getIncludeDir()}", + 'CXXFLAGS' => "-I{$this->library->getIncludeDir()}", 'LDFLAGS' => "-L{$this->library->getLibDir()}", ]); } From 978552136cb9a4f50dc8b13049800a839e4805bb Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 21:44:01 +0700 Subject: [PATCH 251/278] try to make everything -flto=thin compatible (librdkafka fails for some reason) --- src/SPC/builder/linux/LinuxBuilder.php | 8 ++++---- src/SPC/builder/unix/library/librdkafka.php | 11 +++++++++++ src/SPC/builder/unix/library/unixodbc.php | 11 +++++++++++ src/SPC/store/pkg/Zig.php | 6 ++++++ src/SPC/toolchain/ZigToolchain.php | 6 ++++-- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 2d42f9313..aeadea5e8 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -92,7 +92,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'), 'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, 'LDFLAGS' => '-L' . BUILD_LIB_PATH, - 'LIBS' => SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions! + //'LIBS' => SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions! ]); $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; @@ -103,7 +103,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void ); } shell()->cd(SOURCE_PATH . '/php-src') - ->exec( + ->exec($php_configure_env . ' ' . getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' . ($enableCli ? '--enable-cli ' : '--disable-cli ') . ($enableFpm ? '--enable-fpm ' . ($this->getLib('libacl') !== null ? '--with-fpm-acl ' : '') : '--disable-fpm ') . @@ -115,8 +115,8 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $json_74 . $zts . $maxExecutionTimers . - $this->makeStaticExtensionArgs() . - ' ' . $php_configure_env . ' ' + $this->makeStaticExtensionArgs() . ' ' + //'ac_cv_lib_readline_rl_pending_input=yes' ); $this->emitPatchPoint('before-php-make'); diff --git a/src/SPC/builder/unix/library/librdkafka.php b/src/SPC/builder/unix/library/librdkafka.php index 3df7a931a..81bd93642 100644 --- a/src/SPC/builder/unix/library/librdkafka.php +++ b/src/SPC/builder/unix/library/librdkafka.php @@ -17,6 +17,14 @@ trait librdkafka */ protected function build(): void { + $cflags = $this->builder->arch_c_flags; + $cxxflags = $this->builder->arch_cxx_flags; + $patched_cflags = preg_replace('/\s*-flto(=\S*)?\s*/', ' ', $cflags); + $patched_cxxflags = preg_replace('/\s*-flto(=\S*)?\s*/', ' ', $cxxflags); + + $this->builder->arch_c_flags = $patched_cflags; + $this->builder->arch_cxx_flags = $patched_cxxflags; + FileSystem::replaceFileStr( $this->source_dir . '/lds-gen.py', "funcs.append('rd_ut_coverage_check')", @@ -56,5 +64,8 @@ function ($lib) { ->exec("rm -rf {$this->getLibDir()}/*.so.*") ->exec("rm -rf {$this->getLibDir()}/*.so") ->exec("rm -rf {$this->getLibDir()}/*.dylib"); + + $this->builder->arch_c_flags = $cflags; + $this->builder->arch_cxx_flags = $cxxflags; } } diff --git a/src/SPC/builder/unix/library/unixodbc.php b/src/SPC/builder/unix/library/unixodbc.php index a795d2447..842b9d933 100644 --- a/src/SPC/builder/unix/library/unixodbc.php +++ b/src/SPC/builder/unix/library/unixodbc.php @@ -16,6 +16,14 @@ trait unixodbc */ protected function build(): void { + $cflags = $this->builder->arch_c_flags; + $cxxflags = $this->builder->arch_cxx_flags; + $patched_cflags = preg_replace('/\s*-flto(=\S*)?\s*/', ' ', $cflags); + $patched_cxxflags = preg_replace('/\s*-flto(=\S*)?\s*/', ' ', $cxxflags); + + $this->builder->arch_c_flags = $patched_cflags; + $this->builder->arch_cxx_flags = $patched_cxxflags; + UnixAutoconfExecutor::create($this) ->configure( '--disable-debug', @@ -27,5 +35,8 @@ protected function build(): void ->make(); $this->patchPkgconfPrefix(['odbc.pc', 'odbccr.pc', 'odbcinst.pc']); $this->patchLaDependencyPrefix(); + + $this->builder->arch_c_flags = $cflags; + $this->builder->arch_cxx_flags = $cxxflags; } } diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index 6f823405f..f6025b576 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -162,6 +162,12 @@ private function createZigCcScript(string $bin_dir): void $script_content = str_replace('zig cc', 'zig c++', $script_content); file_put_contents("{$bin_dir}/zig-c++", $script_content); + file_put_contents("{$bin_dir}/zig-ar", "#!/usr/bin/env bash\nexec zig ar $@"); + file_put_contents("{$bin_dir}/zig-ranlib", "#!/usr/bin/env bash\nexec zig ranlib $@"); + file_put_contents("{$bin_dir}/zig-objcopy", "#!/usr/bin/env bash\nexec zig objcopy $@"); chmod("{$bin_dir}/zig-c++", 0755); + chmod("{$bin_dir}/zig-ar", 0755); + chmod("{$bin_dir}/zig-ranlib", 0755); + chmod("{$bin_dir}/zig-objcopy", 0755); } } diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index a379164cf..3ededcbc2 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -15,10 +15,12 @@ public function initEnv(): void // Set environment variables for zig toolchain GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=zig-cc'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++'); - GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=zig ar'); + GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=zig-ar'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=zig-cc'); + GlobalEnvManager::putenv('RANLIB=zig-ranlib'); + GlobalEnvManager::putenv('OBJCOPY=zig-objcopy'); - // Generate additional object needed for zig toolchain + // Generate additional objects needed for zig toolchain $paths = ['/usr/lib/gcc', '/usr/local/lib/gcc']; $objects = ['crtbeginS.o', 'crtendS.o']; $found = []; From 05053b5cd67beff94bcc2da67845c15820277ee2 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 21:45:48 +0700 Subject: [PATCH 252/278] cs fix --- src/SPC/builder/linux/LinuxBuilder.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index aeadea5e8..9065a3bee 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -92,7 +92,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'), 'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, 'LDFLAGS' => '-L' . BUILD_LIB_PATH, - //'LIBS' => SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions! + 'LIBS' => SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions! ]); $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; @@ -103,7 +103,8 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void ); } shell()->cd(SOURCE_PATH . '/php-src') - ->exec($php_configure_env . ' ' . + ->exec( + $php_configure_env . ' ' . getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' . ($enableCli ? '--enable-cli ' : '--disable-cli ') . ($enableFpm ? '--enable-fpm ' . ($this->getLib('libacl') !== null ? '--with-fpm-acl ' : '') : '--disable-fpm ') . @@ -116,7 +117,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $zts . $maxExecutionTimers . $this->makeStaticExtensionArgs() . ' ' - //'ac_cv_lib_readline_rl_pending_input=yes' + // 'ac_cv_lib_readline_rl_pending_input=yes' ); $this->emitPatchPoint('before-php-make'); From d0d51ccf827cdd1fcce3494e2fc1d442aa348ae1 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 22:23:00 +0700 Subject: [PATCH 253/278] trigger CI again after clearing cache --- 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 9065a3bee..74ffb93f5 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -92,7 +92,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'), 'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, 'LDFLAGS' => '-L' . BUILD_LIB_PATH, - 'LIBS' => SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions! + // 'LIBS' => SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions! ]); $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; From e1edaa24cc751155e0b858aa27c3a4b7777ecd9e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 23:14:29 +0700 Subject: [PATCH 254/278] "zig-cc" cannot create shared objects according to conftests... --- src/SPC/store/pkg/Zig.php | 8 +++++++- src/SPC/toolchain/ZigToolchain.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index f6025b576..eb56fdc46 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -16,7 +16,13 @@ class Zig extends CustomPackage public static function isInstalled(): bool { $path = self::getPath(); - return file_exists("{$path}/zig") && file_exists("{$path}/zig-cc") && file_exists("{$path}/zig-c++"); + $files = ['zig', 'zig-cc', 'zig-c++', 'zig-ar', 'zig-ranlib', 'zig-objcopy']; + foreach ($files as $file) { + if (!file_exists("{$path}/{$file}")) { + return false; + } + } + return true; } public function getSupportName(): array diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index 3ededcbc2..1d3900d62 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -16,7 +16,7 @@ public function initEnv(): void GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=zig-cc'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=zig-ar'); - GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=zig-cc'); + GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld'); GlobalEnvManager::putenv('RANLIB=zig-ranlib'); GlobalEnvManager::putenv('OBJCOPY=zig-objcopy'); From 76094fd30572b911940493b07244c0d6ecf77aa3 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 23:20:27 +0700 Subject: [PATCH 255/278] hello? --- src/globals/test-extensions.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 8795d0a68..0fc910c66 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -228,6 +228,7 @@ function quote2(string $param): string passthru($prefix . $build_cmd . (str_starts_with($argv[2], 'windows-') ? ' --build-cli' : (' --build-embed' . ($frankenphp ? ' --build-frankenphp' : ''))), $retcode); break; case 'doctor_cmd': + passthru($prefix . 'install-pkg zig', $retcode); passthru($prefix . $doctor_cmd, $retcode); break; case 'install_upx_cmd': From bd3092ae90a036ac2a5873f6426af61636a8d5cf Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 23:24:59 +0700 Subject: [PATCH 256/278] wtf? --- .github/workflows/tests.yml | 11 ++++++++--- src/globals/test-extensions.php | 1 - 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a360e54a8..673db692d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -192,6 +192,11 @@ jobs: php src/globals/test-extensions.php install_upx_cmd ${{ matrix.os }} ${{ matrix.php }} echo "UPX_CMD=$(php src/globals/test-extensions.php upx)" >> $GITHUB_ENV + - name: "Prepare Zig for Linux" + if: ${{ startsWith(matrix.os, 'ubuntu-24') }} + run: | + php bin/spc install-pkg zig + - name: "Run Build Tests (download)" run: php src/globals/test-extensions.php download_cmd ${{ matrix.os }} ${{ matrix.php }} @@ -202,6 +207,6 @@ jobs: if: ${{ !startsWith(matrix.os, 'windows-') }} run: php src/globals/test-extensions.php build_embed_cmd ${{ matrix.os }} ${{ matrix.php }} -# - name: Setup tmate session -# if: ${{ failure() }} -# uses: mxschmitt/action-tmate@v3 + - name: Setup tmate session + if: ${{ failure() }} + uses: mxschmitt/action-tmate@v3 diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 0fc910c66..8795d0a68 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -228,7 +228,6 @@ function quote2(string $param): string passthru($prefix . $build_cmd . (str_starts_with($argv[2], 'windows-') ? ' --build-cli' : (' --build-embed' . ($frankenphp ? ' --build-frankenphp' : ''))), $retcode); break; case 'doctor_cmd': - passthru($prefix . 'install-pkg zig', $retcode); passthru($prefix . $doctor_cmd, $retcode); break; case 'install_upx_cmd': From 5a4da8ed5d03cde068e8634cd7a4cb63b590fadc Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 23:28:17 +0700 Subject: [PATCH 257/278] install zig before doctor --- .github/workflows/tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 673db692d..15347e314 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -177,6 +177,11 @@ jobs: - name: "Install Dependencies" run: composer update -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + - name: "Prepare Zig for Linux" + if: ${{ startsWith(matrix.os, 'ubuntu-24') }} + run: | + php bin/spc install-pkg zig + - name: "Run Build Tests (doctor)" run: php src/globals/test-extensions.php doctor_cmd ${{ matrix.os }} ${{ matrix.php }} @@ -192,11 +197,6 @@ jobs: php src/globals/test-extensions.php install_upx_cmd ${{ matrix.os }} ${{ matrix.php }} echo "UPX_CMD=$(php src/globals/test-extensions.php upx)" >> $GITHUB_ENV - - name: "Prepare Zig for Linux" - if: ${{ startsWith(matrix.os, 'ubuntu-24') }} - run: | - php bin/spc install-pkg zig - - name: "Run Build Tests (download)" run: php src/globals/test-extensions.php download_cmd ${{ matrix.os }} ${{ matrix.php }} From cf529adc79acc98fbb8b7ef5e6918bc08a8f5ee9 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 23:35:38 +0700 Subject: [PATCH 258/278] uh, oh, we forgot to do post init --- src/SPC/command/BaseCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SPC/command/BaseCommand.php b/src/SPC/command/BaseCommand.php index 9c07b074e..870ac6de6 100644 --- a/src/SPC/command/BaseCommand.php +++ b/src/SPC/command/BaseCommand.php @@ -99,6 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int // init GlobalEnv if (!$this instanceof BuildCommand) { GlobalEnvManager::init(); + GlobalEnvManager::afterInit(); f_putenv('SPC_SKIP_TOOLCHAIN_CHECK=yes'); } if ($this->shouldExecute()) { From 5beb083c5502ba3f1c15672daf751d5930dbc0ca Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 23:39:32 +0700 Subject: [PATCH 259/278] no musl check? --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 15347e314..a00e2fdf4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -180,7 +180,7 @@ jobs: - name: "Prepare Zig for Linux" if: ${{ startsWith(matrix.os, 'ubuntu-24') }} run: | - php bin/spc install-pkg zig + SPC_TARGET=native-native php bin/spc install-pkg zig - name: "Run Build Tests (doctor)" run: php src/globals/test-extensions.php doctor_cmd ${{ matrix.os }} ${{ matrix.php }} From 42b42729657fb4b4f65f837dbd7ec90599c7098b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sat, 26 Jul 2025 23:46:36 +0700 Subject: [PATCH 260/278] idk --- .github/workflows/tests.yml | 11 +++-------- src/SPC/command/BaseCommand.php | 1 - src/SPC/toolchain/ZigToolchain.php | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a00e2fdf4..a360e54a8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -177,11 +177,6 @@ jobs: - name: "Install Dependencies" run: composer update -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - - name: "Prepare Zig for Linux" - if: ${{ startsWith(matrix.os, 'ubuntu-24') }} - run: | - SPC_TARGET=native-native php bin/spc install-pkg zig - - name: "Run Build Tests (doctor)" run: php src/globals/test-extensions.php doctor_cmd ${{ matrix.os }} ${{ matrix.php }} @@ -207,6 +202,6 @@ jobs: if: ${{ !startsWith(matrix.os, 'windows-') }} run: php src/globals/test-extensions.php build_embed_cmd ${{ matrix.os }} ${{ matrix.php }} - - name: Setup tmate session - if: ${{ failure() }} - uses: mxschmitt/action-tmate@v3 +# - name: Setup tmate session +# if: ${{ failure() }} +# uses: mxschmitt/action-tmate@v3 diff --git a/src/SPC/command/BaseCommand.php b/src/SPC/command/BaseCommand.php index 870ac6de6..9c07b074e 100644 --- a/src/SPC/command/BaseCommand.php +++ b/src/SPC/command/BaseCommand.php @@ -99,7 +99,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int // init GlobalEnv if (!$this instanceof BuildCommand) { GlobalEnvManager::init(); - GlobalEnvManager::afterInit(); f_putenv('SPC_SKIP_TOOLCHAIN_CHECK=yes'); } if ($this->shouldExecute()) { diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index 1d3900d62..b8061b0d9 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -17,8 +17,6 @@ public function initEnv(): void GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=zig-ar'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld'); - GlobalEnvManager::putenv('RANLIB=zig-ranlib'); - GlobalEnvManager::putenv('OBJCOPY=zig-objcopy'); // Generate additional objects needed for zig toolchain $paths = ['/usr/lib/gcc', '/usr/local/lib/gcc']; @@ -61,6 +59,8 @@ public function afterInit(): void GlobalEnvManager::putenv("SPC_DEFAULT_C_FLAGS={$cflags}"); GlobalEnvManager::putenv("SPC_DEFAULT_CXX_FLAGS={$cxxflags}"); GlobalEnvManager::putenv("SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS={$extraCflags}"); + GlobalEnvManager::putenv('RANLIB=zig-ranlib'); + GlobalEnvManager::putenv('OBJCOPY=zig-objcopy'); $extra_libs = getenv('SPC_EXTRA_LIBS') ?: ''; if (!str_contains($extra_libs, '-lunwind')) { // Add unwind library if not already present From b6f673cd682cb32c464a01896283ccaaf91f6b3b Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 27 Jul 2025 00:59:32 +0700 Subject: [PATCH 261/278] Use $AR instead of `ar`. Compatibility with -flto(=thin). --- src/SPC/builder/linux/LinuxBuilder.php | 12 +++++++++--- src/SPC/builder/macos/MacOSBuilder.php | 3 ++- src/SPC/builder/unix/library/libxslt.php | 5 +++-- src/SPC/builder/unix/library/ngtcp2.php | 3 ++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 74ffb93f5..33db12d33 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -102,6 +102,11 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void 'Change SPC_CMD_VAR_PHP_EMBED_TYPE to static.' ); } + + $extra = ''; + if ($this->getPHPVersionID() < 84000 && $this->getExt('readline') && $this->getLib('libreadline') !== null) { + $extra = 'ac_cv_lib_readline_rl_pending_input=yes'; + } shell()->cd(SOURCE_PATH . '/php-src') ->exec( $php_configure_env . ' ' . @@ -116,8 +121,8 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $json_74 . $zts . $maxExecutionTimers . - $this->makeStaticExtensionArgs() . ' ' - // 'ac_cv_lib_readline_rl_pending_input=yes' + $this->makeStaticExtensionArgs() . ' ' . + $extra ); $this->emitPatchPoint('before-php-make'); @@ -324,7 +329,8 @@ protected function buildEmbed(): void } if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'static') { - f_passthru('ar -t ' . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 ar d " . BUILD_LIB_PATH . '/libphp.a'); + $AR = getenv('AR') ?: 'ar'; + f_passthru("{$AR} -t " . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 ar d " . BUILD_LIB_PATH . '/libphp.a'); } if (!$this->getOption('no-strip', false) && file_exists(BUILD_LIB_PATH . '/' . $realLibName)) { diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 3530de1b0..b8d59098c 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -267,7 +267,8 @@ protected function buildEmbed(): void ->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install"); if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'static') { - f_passthru('ar -t ' . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 ar d " . BUILD_LIB_PATH . '/libphp.a'); + $AR = getenv('AR') ?: 'ar'; + f_passthru("{$AR} -t " . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 ar d " . BUILD_LIB_PATH . '/libphp.a'); } $this->patchPhpScripts(); } diff --git a/src/SPC/builder/unix/library/libxslt.php b/src/SPC/builder/unix/library/libxslt.php index 238997dae..c5315cbf2 100644 --- a/src/SPC/builder/unix/library/libxslt.php +++ b/src/SPC/builder/unix/library/libxslt.php @@ -45,8 +45,9 @@ protected function build(): void $this->patchPkgconfPrefix(['libexslt.pc', 'libxslt.pc']); $this->patchLaDependencyPrefix(); + $AR = getenv('AR') ?: 'ar'; shell()->cd(BUILD_LIB_PATH) - ->exec("ar -t libxslt.a | grep '\\.a$' | xargs -n1 ar d libxslt.a") - ->exec("ar -t libexslt.a | grep '\\.a$' | xargs -n1 ar d libexslt.a"); + ->exec("{$AR} -t libxslt.a | grep '\\.a$' | xargs -n1 ar d libxslt.a") + ->exec("{$AR} -t libexslt.a | grep '\\.a$' | xargs -n1 ar d libexslt.a"); } } diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php index 9c9919d8a..bb993d42d 100644 --- a/src/SPC/builder/unix/library/ngtcp2.php +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -48,6 +48,7 @@ protected function build(): void // on macOS, the static library may contain other static libraries? // ld: archive member 'libssl.a' not a mach-o file in libngtcp2_crypto_ossl.a - shell()->cd(BUILD_LIB_PATH)->exec("ar -t libngtcp2_crypto_ossl.a | grep '\\.a$' | xargs -n1 ar d libngtcp2_crypto_ossl.a"); + $AR = getenv('AR') ?: 'ar'; + shell()->cd(BUILD_LIB_PATH)->exec("{$AR} -t libngtcp2_crypto_ossl.a | grep '\\.a$' | xargs -n1 ar d libngtcp2_crypto_ossl.a"); } } From a8492f06bb9de4d1a71c9f86407558a0a1c3e542 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 27 Jul 2025 01:07:54 +0700 Subject: [PATCH 262/278] use zig's linker too (ends up getting used automatically in most cases, anyway, but better be explicit) --- src/SPC/store/pkg/Zig.php | 3 ++- src/SPC/toolchain/ZigToolchain.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index eb56fdc46..14b444d81 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -16,7 +16,7 @@ class Zig extends CustomPackage public static function isInstalled(): bool { $path = self::getPath(); - $files = ['zig', 'zig-cc', 'zig-c++', 'zig-ar', 'zig-ranlib', 'zig-objcopy']; + $files = ['zig', 'zig-cc', 'zig-c++', 'zig-ar', 'zig-ld.lld', 'zig-ranlib', 'zig-objcopy']; foreach ($files as $file) { if (!file_exists("{$path}/{$file}")) { return false; @@ -169,6 +169,7 @@ private function createZigCcScript(string $bin_dir): void $script_content = str_replace('zig cc', 'zig c++', $script_content); file_put_contents("{$bin_dir}/zig-c++", $script_content); file_put_contents("{$bin_dir}/zig-ar", "#!/usr/bin/env bash\nexec zig ar $@"); + file_put_contents("{$bin_dir}/zig-ld.lld", "#!/usr/bin/env bash\nexec zig ld.lld $@"); file_put_contents("{$bin_dir}/zig-ranlib", "#!/usr/bin/env bash\nexec zig ranlib $@"); file_put_contents("{$bin_dir}/zig-objcopy", "#!/usr/bin/env bash\nexec zig objcopy $@"); chmod("{$bin_dir}/zig-c++", 0755); diff --git a/src/SPC/toolchain/ZigToolchain.php b/src/SPC/toolchain/ZigToolchain.php index b8061b0d9..613c0f979 100644 --- a/src/SPC/toolchain/ZigToolchain.php +++ b/src/SPC/toolchain/ZigToolchain.php @@ -16,7 +16,7 @@ public function initEnv(): void GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=zig-cc'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=zig-ar'); - GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld'); + GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=zig-ld.lld'); // Generate additional objects needed for zig toolchain $paths = ['/usr/lib/gcc', '/usr/local/lib/gcc']; From 5b4cbbb669ea43f65dc4cac78e771f4174a8a8f9 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 27 Jul 2025 01:08:34 +0700 Subject: [PATCH 263/278] set permissions --- src/SPC/store/pkg/Zig.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index 14b444d81..659417039 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -174,6 +174,7 @@ private function createZigCcScript(string $bin_dir): void file_put_contents("{$bin_dir}/zig-objcopy", "#!/usr/bin/env bash\nexec zig objcopy $@"); chmod("{$bin_dir}/zig-c++", 0755); chmod("{$bin_dir}/zig-ar", 0755); + chmod("{$bin_dir}/zig-ld.lld", 0755); chmod("{$bin_dir}/zig-ranlib", 0755); chmod("{$bin_dir}/zig-objcopy", 0755); } From 944cca709f9e987e190d2adf89e0997b51e342f9 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 27 Jul 2025 01:10:21 +0700 Subject: [PATCH 264/278] use $AR in second part of command too --- src/SPC/builder/linux/LinuxBuilder.php | 2 +- src/SPC/builder/macos/MacOSBuilder.php | 2 +- src/SPC/builder/unix/library/libxslt.php | 4 ++-- src/SPC/builder/unix/library/ngtcp2.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 33db12d33..88e0a71d1 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -330,7 +330,7 @@ protected function buildEmbed(): void if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'static') { $AR = getenv('AR') ?: 'ar'; - f_passthru("{$AR} -t " . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 ar d " . BUILD_LIB_PATH . '/libphp.a'); + f_passthru("{$AR} -t " . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 {$AR} d " . BUILD_LIB_PATH . '/libphp.a'); } if (!$this->getOption('no-strip', false) && file_exists(BUILD_LIB_PATH . '/' . $realLibName)) { diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index b8d59098c..a74b6f14f 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -268,7 +268,7 @@ protected function buildEmbed(): void if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'static') { $AR = getenv('AR') ?: 'ar'; - f_passthru("{$AR} -t " . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 ar d " . BUILD_LIB_PATH . '/libphp.a'); + f_passthru("{$AR} -t " . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 {$AR} d " . BUILD_LIB_PATH . '/libphp.a'); } $this->patchPhpScripts(); } diff --git a/src/SPC/builder/unix/library/libxslt.php b/src/SPC/builder/unix/library/libxslt.php index c5315cbf2..1c584be20 100644 --- a/src/SPC/builder/unix/library/libxslt.php +++ b/src/SPC/builder/unix/library/libxslt.php @@ -47,7 +47,7 @@ protected function build(): void $this->patchLaDependencyPrefix(); $AR = getenv('AR') ?: 'ar'; shell()->cd(BUILD_LIB_PATH) - ->exec("{$AR} -t libxslt.a | grep '\\.a$' | xargs -n1 ar d libxslt.a") - ->exec("{$AR} -t libexslt.a | grep '\\.a$' | xargs -n1 ar d libexslt.a"); + ->exec("{$AR} -t libxslt.a | grep '\\.a$' | xargs -n1 {$AR} d libxslt.a") + ->exec("{$AR} -t libexslt.a | grep '\\.a$' | xargs -n1 {$AR} d libexslt.a"); } } diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php index bb993d42d..e2c4ed099 100644 --- a/src/SPC/builder/unix/library/ngtcp2.php +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -49,6 +49,6 @@ protected function build(): void // on macOS, the static library may contain other static libraries? // ld: archive member 'libssl.a' not a mach-o file in libngtcp2_crypto_ossl.a $AR = getenv('AR') ?: 'ar'; - shell()->cd(BUILD_LIB_PATH)->exec("{$AR} -t libngtcp2_crypto_ossl.a | grep '\\.a$' | xargs -n1 ar d libngtcp2_crypto_ossl.a"); + shell()->cd(BUILD_LIB_PATH)->exec("{$AR} -t libngtcp2_crypto_ossl.a | grep '\\.a$' | xargs -n1 {$AR} d libngtcp2_crypto_ossl.a"); } } From fb2d676293cac18cb61d48895bc0b70d266eafc0 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 27 Jul 2025 01:22:11 +0700 Subject: [PATCH 265/278] zig doesn't support windows (php doesn't support mingw, zig can only compile mingw) --- src/SPC/store/pkg/Zig.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/SPC/store/pkg/Zig.php b/src/SPC/store/pkg/Zig.php index 659417039..a28460891 100644 --- a/src/SPC/store/pkg/Zig.php +++ b/src/SPC/store/pkg/Zig.php @@ -104,12 +104,16 @@ public function extract(string $name): void { $pkgroot = PKG_ROOT_PATH; $zig_bin_dir = "{$pkgroot}/{$name}"; - $zig_exec = match (PHP_OS_FAMILY) { - 'Windows' => "{$zig_bin_dir}/zig.exe", - default => "{$zig_bin_dir}/zig", - }; - if (file_exists($zig_exec) && file_exists("{$zig_bin_dir}/zig-cc")) { + $files = ['zig', 'zig-cc', 'zig-c++', 'zig-ar', 'zig-ld.lld', 'zig-ranlib', 'zig-objcopy']; + $all_exist = true; + foreach ($files as $file) { + if (!file_exists("{$zig_bin_dir}/{$file}")) { + $all_exist = false; + break; + } + } + if ($all_exist) { return; } From 3087dc86f8193c33e869d9c927e545a423250b39 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 28 Jul 2025 14:51:13 +0700 Subject: [PATCH 266/278] https://www.phoronix.com/news/GNU-Binutils-2.44 ld.gold is deprecated don't deprecate libc usage yet, we don't want people to switch to gcc/clang yet --- src/SPC/toolchain/GccNativeToolchain.php | 2 +- src/SPC/toolchain/ToolchainManager.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/toolchain/GccNativeToolchain.php b/src/SPC/toolchain/GccNativeToolchain.php index 1e97b50e4..1ada28b54 100644 --- a/src/SPC/toolchain/GccNativeToolchain.php +++ b/src/SPC/toolchain/GccNativeToolchain.php @@ -17,7 +17,7 @@ public function initEnv(): void GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=gcc'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=g++'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar'); - GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld.gold'); + GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld'); } public function afterInit(): void diff --git a/src/SPC/toolchain/ToolchainManager.php b/src/SPC/toolchain/ToolchainManager.php index f3fbdf28e..ad40b61d7 100644 --- a/src/SPC/toolchain/ToolchainManager.php +++ b/src/SPC/toolchain/ToolchainManager.php @@ -26,7 +26,7 @@ public static function getToolchainClass(): string } $libc = getenv('SPC_LIBC'); if ($libc && !getenv('SPC_TARGET')) { - trigger_error('Setting SPC_LIBC is deprecated, please use SPC_TARGET instead.', E_USER_DEPRECATED); + // trigger_error('Setting SPC_LIBC is deprecated, please use SPC_TARGET instead.', E_USER_DEPRECATED); return match ($libc) { 'musl' => SystemUtil::isMuslDist() ? GccNativeToolchain::class : MuslToolchain::class, 'glibc' => !SystemUtil::isMuslDist() ? GccNativeToolchain::class : throw new WrongUsageException('SPC_LIBC must be musl for musl dist.'), From 342192fd671ddb97fb48af32c413e320cb8685c6 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 28 Jul 2025 19:43:01 +0700 Subject: [PATCH 267/278] remove lto related stuff again, not worth using --- config/env.ini | 1 + src/SPC/builder/linux/LinuxBuilder.php | 1 + src/SPC/builder/macos/MacOSBuilder.php | 1 + src/SPC/builder/traits/UnixLibraryTrait.php | 24 ++++++++++++--------- src/SPC/builder/unix/UnixBuilderBase.php | 3 +++ src/SPC/builder/unix/library/librdkafka.php | 11 ---------- src/SPC/builder/unix/library/unixodbc.php | 11 ---------- 7 files changed, 20 insertions(+), 32 deletions(-) diff --git a/config/env.ini b/config/env.ini index 1565f6221..cc4ec13e1 100644 --- a/config/env.ini +++ b/config/env.ini @@ -90,6 +90,7 @@ LD=${SPC_LINUX_DEFAULT_LD} ; default compiler flags, used in CMake toolchain file, openssl and pkg-config build SPC_DEFAULT_C_FLAGS="-fPIC -Os" SPC_DEFAULT_CXX_FLAGS="-fPIC -Os" +SPC_DEFAULT_LD_FLAGS="" ; upx executable path UPX_EXEC=${PKG_ROOT_PATH}/bin/upx ; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 88e0a71d1..d62cc7a99 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -35,6 +35,7 @@ public function __construct(array $options = []) // cflags $this->arch_c_flags = getenv('SPC_DEFAULT_C_FLAGS'); $this->arch_cxx_flags = getenv('SPC_DEFAULT_CXX_FLAGS'); + $this->arch_ld_flags = getenv('SPC_DEFAULT_LD_FLAGS'); // create pkgconfig and include dir (some libs cannot create them automatically) f_mkdir(BUILD_LIB_PATH . '/pkgconfig', recursive: true); diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index a74b6f14f..bd152cb7d 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -38,6 +38,7 @@ public function __construct(array $options = []) // cflags $this->arch_c_flags = getenv('SPC_DEFAULT_C_FLAGS'); $this->arch_cxx_flags = getenv('SPC_DEFAULT_CXX_FLAGS'); + $this->arch_ld_flags = getenv('SPC_DEFAULT_LD_FLAGS'); // create pkgconfig and include dir (some libs cannot create them automatically) f_mkdir(BUILD_LIB_PATH . '/pkgconfig', recursive: true); diff --git a/src/SPC/builder/traits/UnixLibraryTrait.php b/src/SPC/builder/traits/UnixLibraryTrait.php index 151ace1be..c45d45b22 100644 --- a/src/SPC/builder/traits/UnixLibraryTrait.php +++ b/src/SPC/builder/traits/UnixLibraryTrait.php @@ -97,16 +97,6 @@ public function getLibExtraCFlags(): string return trim($env); } - public function getLibExtraLdFlags(): string - { - return getenv($this->getSnakeCaseName() . '_LDFLAGS') ?: ''; - } - - public function getLibExtraLibs(): string - { - return getenv($this->getSnakeCaseName() . '_LIBS') ?: ''; - } - public function getLibExtraCXXFlags(): string { $env = getenv($this->getSnakeCaseName() . '_CXXFLAGS') ?: ''; @@ -115,4 +105,18 @@ public function getLibExtraCXXFlags(): string } return trim($env); } + + public function getLibExtraLdFlags(): string + { + $env = getenv($this->getSnakeCaseName() . '_LDFLAGS') ?: ''; + if (!str_contains($env, $this->builder->arch_ld_flags)) { + $env .= ' ' . $this->builder->arch_ld_flags; + } + return trim($env); + } + + public function getLibExtraLibs(): string + { + return getenv($this->getSnakeCaseName() . '_LIBS') ?: ''; + } } diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index d4afbc93e..98567a6bf 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -26,6 +26,9 @@ abstract class UnixBuilderBase extends BuilderBase /** @var string C++ flags */ public string $arch_cxx_flags; + /** @var string LD flags */ + public string $arch_ld_flags; + public function proveLibs(array $sorted_libraries): void { // search all supported libs diff --git a/src/SPC/builder/unix/library/librdkafka.php b/src/SPC/builder/unix/library/librdkafka.php index 81bd93642..3df7a931a 100644 --- a/src/SPC/builder/unix/library/librdkafka.php +++ b/src/SPC/builder/unix/library/librdkafka.php @@ -17,14 +17,6 @@ trait librdkafka */ protected function build(): void { - $cflags = $this->builder->arch_c_flags; - $cxxflags = $this->builder->arch_cxx_flags; - $patched_cflags = preg_replace('/\s*-flto(=\S*)?\s*/', ' ', $cflags); - $patched_cxxflags = preg_replace('/\s*-flto(=\S*)?\s*/', ' ', $cxxflags); - - $this->builder->arch_c_flags = $patched_cflags; - $this->builder->arch_cxx_flags = $patched_cxxflags; - FileSystem::replaceFileStr( $this->source_dir . '/lds-gen.py', "funcs.append('rd_ut_coverage_check')", @@ -64,8 +56,5 @@ function ($lib) { ->exec("rm -rf {$this->getLibDir()}/*.so.*") ->exec("rm -rf {$this->getLibDir()}/*.so") ->exec("rm -rf {$this->getLibDir()}/*.dylib"); - - $this->builder->arch_c_flags = $cflags; - $this->builder->arch_cxx_flags = $cxxflags; } } diff --git a/src/SPC/builder/unix/library/unixodbc.php b/src/SPC/builder/unix/library/unixodbc.php index 842b9d933..a795d2447 100644 --- a/src/SPC/builder/unix/library/unixodbc.php +++ b/src/SPC/builder/unix/library/unixodbc.php @@ -16,14 +16,6 @@ trait unixodbc */ protected function build(): void { - $cflags = $this->builder->arch_c_flags; - $cxxflags = $this->builder->arch_cxx_flags; - $patched_cflags = preg_replace('/\s*-flto(=\S*)?\s*/', ' ', $cflags); - $patched_cxxflags = preg_replace('/\s*-flto(=\S*)?\s*/', ' ', $cxxflags); - - $this->builder->arch_c_flags = $patched_cflags; - $this->builder->arch_cxx_flags = $patched_cxxflags; - UnixAutoconfExecutor::create($this) ->configure( '--disable-debug', @@ -35,8 +27,5 @@ protected function build(): void ->make(); $this->patchPkgconfPrefix(['odbc.pc', 'odbccr.pc', 'odbcinst.pc']); $this->patchLaDependencyPrefix(); - - $this->builder->arch_c_flags = $cflags; - $this->builder->arch_cxx_flags = $cxxflags; } } From feaff0a08c61e2089aec7dcd134013eb7ac0afc6 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 29 Jul 2025 09:20:33 +0700 Subject: [PATCH 268/278] fix macos --- config/env.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/config/env.ini b/config/env.ini index cc4ec13e1..465f72d5b 100644 --- a/config/env.ini +++ b/config/env.ini @@ -124,6 +124,7 @@ CXX=clang++ ; default compiler flags, used in CMake toolchain file, openssl and pkg-config build SPC_DEFAULT_C_FLAGS="--target=${MAC_ARCH}-apple-darwin -Os" SPC_DEFAULT_CXX_FLAGS="--target=${MAC_ARCH}-apple-darwin -Os" +SPC_DEFAULT_LD_FLAGS="" ; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches SPC_MICRO_PATCHES=cli_checks,macos_iconv From a968b19be0d68a4a42386621434aebacd29acca2 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 29 Jul 2025 10:02:21 +0700 Subject: [PATCH 269/278] remove zig stuff from tests for now, since we need to keep gcc default --- src/globals/test-extensions.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 8795d0a68..f2fe1029d 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -54,7 +54,7 @@ // If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`). $shared_extensions = match (PHP_OS_FAMILY) { - 'Linux' => 'amqp,brotli,bz2,dio,ds,ev,event,ffi,ftp,gd,gettext,gmp,gmssl,igbinary,imagick,inotify,intl,ldap,lz4,memcache,memcached,mongodb,msgpack,mysqli,mysqlnd,odbc,opentelemetry,parallel,pdo,pdo_mysql,pdo_odbc,pdo_pgsql,pdo_sqlite,pdo_sqlsrv,pgsql,protobuf,rar,redis,rdkafka,shmop,spx,sqlite3,sqlsrv,ssh2,swoole,sysvmsg,sysvsem,sysvshm,tidy,uuid,uv,xdebug,xhprof,xlswriter,xsl,xz,yac,yaml,zstd', + 'Linux' => '', 'Darwin' => '', 'Windows' => '', }; @@ -157,12 +157,7 @@ function quote2(string $param): string $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; break; case 'ubuntu-24.04': - putenv('SPC_TARGET=native-native-gnu.2.17'); - $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; - break; case 'ubuntu-24.04-arm': - putenv('SPC_TARGET=native-native-gnu.2.28'); - $shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' '; break; case 'macos-13': case 'macos-14': From 72abd63b6969bc733f88b9ef5991b9bba3cc686f Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 29 Jul 2025 10:23:46 +0700 Subject: [PATCH 270/278] cs fix --- src/SPC/store/pkg/CustomPackage.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/SPC/store/pkg/CustomPackage.php b/src/SPC/store/pkg/CustomPackage.php index 9c7eead93..093f65d02 100644 --- a/src/SPC/store/pkg/CustomPackage.php +++ b/src/SPC/store/pkg/CustomPackage.php @@ -31,16 +31,15 @@ abstract public function fetch(string $name, bool $force = false, ?array $config /** * Get the environment variables this package needs to be usable. * PATH needs to be appended, rather than replaced. - * - * @return array */ abstract public static function getEnvironment(): array; abstract public static function isInstalled(): bool; + /** * Extract the downloaded package * - * @param string $name Package name + * @param string $name Package name */ abstract public function extract(string $name): void; } From 81f359dbcf8599eb38ab1816f4cc25bb61bf6512 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 29 Jul 2025 10:39:21 +0700 Subject: [PATCH 271/278] fix tests --- src/SPC/util/SPCTarget.php | 3 ++- tests/SPC/util/SPCTargetTest.php | 28 +++------------------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index 583fa757d..fac548aaf 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -17,6 +17,8 @@ */ class SPCTarget { + const array LIBC_LIST = ['musl', 'glibc']; + /** * Returns whether we link the C runtime in statically. */ @@ -107,7 +109,6 @@ public static function getLibcVersion(): ?string * Currently, we only support native building. * * @return 'BSD'|'Darwin'|'Linux'|'Windows' - * @throws WrongUsageException */ public static function getTargetOS(): string { diff --git a/tests/SPC/util/SPCTargetTest.php b/tests/SPC/util/SPCTargetTest.php index dc003932a..f14f0e6c4 100644 --- a/tests/SPC/util/SPCTargetTest.php +++ b/tests/SPC/util/SPCTargetTest.php @@ -85,19 +85,6 @@ public function testGetTargetOS(string $target, string $expected): void $this->assertEquals($expected, $result); } - /** - * @dataProvider invalidTargetProvider - */ - public function testGetTargetOSWithInvalidTarget(string $target): void - { - putenv("SPC_TARGET={$target}"); - - $this->expectException(WrongUsageException::class); - $this->expectExceptionMessage('Cannot parse target.'); - - SPCTarget::getTargetOS(); - } - public function testLibcListConstant(): void { $this->assertIsArray(SPCTarget::LIBC_LIST); @@ -117,22 +104,13 @@ public function libcProvider(): array public function targetOSProvider(): array { return [ - 'linux-target' => ['linux-x86_64', 'Linux'], - 'macos-target' => ['macos-x86_64', 'Darwin'], - 'windows-target' => ['windows-x86_64', 'Windows'], + 'linux-target' => ['native-linux', 'Linux'], + 'macos-target' => ['native-macos', 'Darwin'], + 'windows-target' => ['native-windows', 'Windows'], 'empty-target' => ['', PHP_OS_FAMILY], ]; } - public function invalidTargetProvider(): array - { - return [ - 'invalid-target' => ['invalid-target'], - 'unknown-target' => ['unknown-target'], - 'mixed-target' => ['mixed-target'], - ]; - } - private function assertIsStringOrNull($value): void { $this->assertTrue(is_string($value) || is_null($value), 'Value must be string or null'); From 430364aacdda4d2b4ec923709312203d143496d3 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 29 Jul 2025 10:40:46 +0700 Subject: [PATCH 272/278] quicker tests --- 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 f2fe1029d..f47340a03 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -48,7 +48,7 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'apcu,ast,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,iconv,libxml,mbregex,mbstring,opcache,openssl,pcntl,phar,posix,readline,session,simplexml,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter,zip,zlib', + 'Linux', 'Darwin' => 'ast,bcmath,calendar,ctype,dba,dom,exif,fileinfo,filter,libxml,mbregex,mbstring,pcntl,phar,posix,session,simplexml,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter,zlib', 'Windows' => 'intl', }; From 83dae09208d348dd8de122f2c08e285cb5a11681 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 29 Jul 2025 10:49:08 +0700 Subject: [PATCH 273/278] cs fix --- src/SPC/util/SPCTarget.php | 3 +-- tests/SPC/util/SPCTargetTest.php | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index fac548aaf..d4164ceb6 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -5,7 +5,6 @@ namespace SPC\util; use SPC\builder\linux\SystemUtil; -use SPC\exception\WrongUsageException; use SPC\toolchain\ClangNativeToolchain; use SPC\toolchain\GccNativeToolchain; use SPC\toolchain\MuslToolchain; @@ -17,7 +16,7 @@ */ class SPCTarget { - const array LIBC_LIST = ['musl', 'glibc']; + public const array LIBC_LIST = ['musl', 'glibc']; /** * Returns whether we link the C runtime in statically. diff --git a/tests/SPC/util/SPCTargetTest.php b/tests/SPC/util/SPCTargetTest.php index f14f0e6c4..05d95e08c 100644 --- a/tests/SPC/util/SPCTargetTest.php +++ b/tests/SPC/util/SPCTargetTest.php @@ -4,7 +4,6 @@ namespace SPC\Tests\util; -use SPC\exception\WrongUsageException; use SPC\util\SPCTarget; /** From df76ecb60ffbd9f5db91294520a726e0d683deeb Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 29 Jul 2025 12:14:31 +0800 Subject: [PATCH 274/278] Fix PHPUnit test, remove unneeded test (function is dynamic) --- tests/SPC/util/GlobalEnvManagerTest.php | 8 ++++++++ tests/SPC/util/SPCTargetTest.php | 11 ----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/SPC/util/GlobalEnvManagerTest.php b/tests/SPC/util/GlobalEnvManagerTest.php index 28d60d34d..1caeaa19b 100644 --- a/tests/SPC/util/GlobalEnvManagerTest.php +++ b/tests/SPC/util/GlobalEnvManagerTest.php @@ -23,6 +23,10 @@ protected function setUp(): void 'SPC_TARGET' => getenv('SPC_TARGET'), 'SPC_LIBC' => getenv('SPC_LIBC'), ]; + // Temporarily set private GlobalEnvManager::$initialized to false (use reflection) + $reflection = new \ReflectionClass(GlobalEnvManager::class); + $property = $reflection->getProperty('initialized'); + $property->setValue(null, false); } protected function tearDown(): void @@ -35,6 +39,10 @@ protected function tearDown(): void putenv("{$key}={$value}"); } } + // Temporarily set private GlobalEnvManager::$initialized to false (use reflection) + $reflection = new \ReflectionClass(GlobalEnvManager::class); + $property = $reflection->getProperty('initialized'); + $property->setValue(null, true); } public function testGetInitializedEnv(): void diff --git a/tests/SPC/util/SPCTargetTest.php b/tests/SPC/util/SPCTargetTest.php index 05d95e08c..665b4045b 100644 --- a/tests/SPC/util/SPCTargetTest.php +++ b/tests/SPC/util/SPCTargetTest.php @@ -34,17 +34,6 @@ protected function tearDown(): void } } - /** - * @dataProvider libcProvider - */ - public function testIsStatic(string $libc, bool $expected): void - { - putenv("SPC_LIBC={$libc}"); - - $result = SPCTarget::isStatic(); - $this->assertEquals($expected, $result); - } - /** * @dataProvider libcProvider */ From 76d17ebef063d977b48d6bfb7a8303aee614b4f7 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 29 Jul 2025 13:34:01 +0700 Subject: [PATCH 275/278] -static was too much --- src/SPC/builder/unix/UnixBuilderBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 98567a6bf..b69aba2eb 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -265,7 +265,7 @@ protected function buildFrankenphp(): void if (SPCTarget::isStatic()) { $extLdFlags = "-extldflags '-static-pie -Wl,-z,stack-size=0x80000'"; $muslTags = 'static_build,'; - $staticFlags = '-static -static-pie'; + $staticFlags = '-static-pie'; } $config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list); From fda637bb03027a9b3abd5b6f9cf6e8e5a4c47d08 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 30 Jul 2025 10:24:21 +0700 Subject: [PATCH 276/278] suggestions --- src/SPC/builder/extension/readline.php | 7 ++++++- src/SPC/builder/linux/LinuxBuilder.php | 7 +------ src/SPC/builder/unix/library/librdkafka.php | 15 ++++++++++----- src/SPC/toolchain/ToolchainManager.php | 5 ++--- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/SPC/builder/extension/readline.php b/src/SPC/builder/extension/readline.php index dc4d15f7c..939484daf 100644 --- a/src/SPC/builder/extension/readline.php +++ b/src/SPC/builder/extension/readline.php @@ -27,7 +27,12 @@ public function patchBeforeConfigure(): bool public function getUnixConfigureArg(bool $shared = false): string { - return '--without-libedit --with-readline=' . BUILD_ROOT_PATH; + $enable = '--without-libedit --with-readline=' . BUILD_ROOT_PATH; + if ($this->builder->getPHPVersionID() < 84000) { + // the check uses `char rl_pending_input()` instead of `extern int rl_pending_input`, which makes LTO fail + $enable .= ' ac_cv_lib_readline_rl_pending_input=yes'; + } + return $enable; } public function buildUnixShared(): void diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index da3e12fb4..28edeb223 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -104,10 +104,6 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void ); } - $extra = ''; - if ($this->getPHPVersionID() < 84000 && $this->getExt('readline') && $this->getLib('libreadline') !== null) { - $extra = 'ac_cv_lib_readline_rl_pending_input=yes'; - } shell()->cd(SOURCE_PATH . '/php-src') ->exec( $php_configure_env . ' ' . @@ -122,8 +118,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $json_74 . $zts . $maxExecutionTimers . - $this->makeStaticExtensionArgs() . ' ' . - $extra + $this->makeStaticExtensionArgs() . ' ' ); $this->emitPatchPoint('before-php-make'); diff --git a/src/SPC/builder/unix/library/librdkafka.php b/src/SPC/builder/unix/library/librdkafka.php index 3df7a931a..e2c3b46e9 100644 --- a/src/SPC/builder/unix/library/librdkafka.php +++ b/src/SPC/builder/unix/library/librdkafka.php @@ -11,11 +11,7 @@ trait librdkafka { - /** - * @throws FileSystemException - * @throws RuntimeException - */ - protected function build(): void + public function patchBeforeBuild(): bool { FileSystem::replaceFileStr( $this->source_dir . '/lds-gen.py', @@ -27,6 +23,15 @@ protected function build(): void '#error "IOV_MAX not defined"', "#define IOV_MAX 1024\n#define __GNU__" ); + return true; + } + + /** + * @throws FileSystemException + * @throws RuntimeException + */ + protected function build(): void + { UnixAutoconfExecutor::create($this) ->appendEnv(['CFLAGS' => '-Wno-int-conversion -Wno-unused-but-set-variable -Wno-unused-variable']) ->optionalLib( diff --git a/src/SPC/toolchain/ToolchainManager.php b/src/SPC/toolchain/ToolchainManager.php index ad40b61d7..0c92c58a9 100644 --- a/src/SPC/toolchain/ToolchainManager.php +++ b/src/SPC/toolchain/ToolchainManager.php @@ -5,7 +5,6 @@ namespace SPC\toolchain; use SPC\builder\linux\SystemUtil; -use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\util\GlobalEnvManager; use SPC\util\SPCTarget; @@ -55,10 +54,10 @@ public static function afterInitToolchain(): void } $musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m')); if (SPCTarget::getLibc() === 'musl' && !SPCTarget::isStatic() && !file_exists($musl_wrapper_lib)) { - throw new RuntimeException('You are linking against musl libc dynamically, but musl libc is not installed. Please install it with `sudo dnf install musl-libc` or `sudo apt install musl`'); + throw new WrongUsageException('You are linking against musl libc dynamically, but musl libc is not installed. Please use `bin/spc doctor` to install it.'); } if (SPCTarget::getLibc() === 'glibc' && SystemUtil::isMuslDist()) { - throw new RuntimeException('You are linking against glibc dynamically, which is only supported on musl distros.'); + throw new WrongUsageException('You are linking against glibc dynamically, which is only supported on glibc distros.'); } $toolchain = getenv('SPC_TOOLCHAIN'); /* @var ToolchainInterface $toolchain */ From ecaa31f38da00ed574acff798400fd3b2bba4c57 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 31 Jul 2025 21:11:15 +0700 Subject: [PATCH 277/278] no start group for macos --- src/SPC/builder/Extension.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 721d1f429..90f2e27e0 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -414,11 +414,13 @@ public function buildUnixShared(): void $this->builder->getOption('with-suggested-libs'), ); [$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']); + $preStatic = PHP_OS_FAMILY === 'Darwin' ? '' : '-Wl,--start-group '; + $postStatic = PHP_OS_FAMILY === 'Darwin' ? '' : ' -Wl,--end-group '; $env = [ 'CFLAGS' => $config['cflags'], 'CXXFLAGS' => $config['cflags'], 'LDFLAGS' => $config['ldflags'], - 'LIBS' => "-Wl,--start-group {$staticLibs} -Wl,--end-group {$sharedLibs}", + 'LIBS' => clean_spaces("{$preStatic} {$staticLibs} {$postStatic} {$sharedLibs}"), 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, ]; if (ToolchainManager::getToolchainClass() === ZigToolchain::class && SPCTarget::getTargetOS() === 'Linux') { From c58bc038f4ed50d87e0add34d70ee263903707db Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 31 Jul 2025 21:11:42 +0700 Subject: [PATCH 278/278] version 2.7.0 --- src/SPC/ConsoleApplication.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/ConsoleApplication.php b/src/SPC/ConsoleApplication.php index a24eada9a..43c838eae 100644 --- a/src/SPC/ConsoleApplication.php +++ b/src/SPC/ConsoleApplication.php @@ -34,7 +34,7 @@ */ final class ConsoleApplication extends Application { - public const VERSION = '2.6.1'; + public const VERSION = '2.7.0'; public function __construct() {