From 460699c48cb9e323708738a509bfe82273e9f1c1 Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Wed, 5 Mar 2025 11:35:03 +0100 Subject: [PATCH 01/23] add (lib)attr and libacl as optional libraries when libacl is built and --enable-fpm is used, also enable --with-fpm-acl --- config/lib.json | 15 ++++++++++++ config/source.json | 20 ++++++++++++++++ src/SPC/builder/linux/LinuxBuilder.php | 11 +++++++-- src/SPC/builder/linux/library/attr.php | 12 ++++++++++ src/SPC/builder/linux/library/libacl.php | 12 ++++++++++ src/SPC/builder/unix/library/attr.php | 26 ++++++++++++++++++++ src/SPC/builder/unix/library/libacl.php | 30 ++++++++++++++++++++++++ 7 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 src/SPC/builder/linux/library/attr.php create mode 100644 src/SPC/builder/linux/library/libacl.php create mode 100644 src/SPC/builder/unix/library/attr.php create mode 100644 src/SPC/builder/unix/library/libacl.php diff --git a/config/lib.json b/config/lib.json index cfe41927..32d9a770 100644 --- a/config/lib.json +++ b/config/lib.json @@ -24,6 +24,12 @@ "pkg-config" ] }, + "attr": { + "source": "attr", + "static-libs-unix": [ + "libattr.a" + ] + }, "brotli": { "source": "brotli", "static-libs-unix": [ @@ -234,6 +240,15 @@ "libsodium" ] }, + "libacl": { + "source": "libacl", + "static-libs-unix": [ + "libacl.a" + ], + "lib-depends": [ + "attr" + ] + }, "libaom": { "source": "libaom", "static-libs-unix": [ diff --git a/config/source.json b/config/source.json index b97ab139..81204229 100644 --- a/config/source.json +++ b/config/source.json @@ -36,6 +36,16 @@ "path": "LICENSE" } }, + "attr": { + "type": "git", + "rev": "v2.5.2", + "url": "https://git.savannah.nongnu.org/git/attr.git", + "provide-pre-built": false, + "license": { + "type": "file", + "path": "doc/COPYING" + } + }, "brotli": { "type": "ghtar", "repo": "google/brotli", @@ -323,6 +333,16 @@ "path": "LICENSE" } }, + "libacl": { + "type": "git", + "rev": "v2.3.2", + "url": "https://git.savannah.nongnu.org/git/acl.git", + "provide-pre-built": false, + "license": { + "type": "file", + "path": "doc/COPYING" + } + }, "libaom": { "type": "git", "rev": "main", diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index b809a005..2012ae3a 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -174,7 +174,7 @@ class LinuxBuilder extends UnixBuilderBase ->exec( getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' . ($enable_cli ? '--enable-cli ' : '--disable-cli ') . - ($enable_fpm ? '--enable-fpm ' : '--disable-fpm ') . + ($enable_fpm ? '--enable-fpm ' . ($this->getLib('libacl') !== null ? '--with-fpm-acl ' : '') : '--disable-fpm ') . ($enable_embed ? "--enable-embed={$embed_type} " : '--disable-embed ') . ($enable_micro ? '--enable-micro=all-static ' : '--disable-micro ') . $config_file_path . @@ -287,7 +287,14 @@ class LinuxBuilder extends UnixBuilderBase */ protected function buildFpm(): void { - $vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars()); + $vars = $this->getMakeExtraVars(); + if ($this->getLib('libacl') !== null) { + $ldflags_program = $vars['EXTRA_LDFLAGS_PROGRAM'] ?? ''; + if (!str_contains($ldflags_program, '-L' . BUILD_LIB_PATH)) { + $vars['EXTRA_LDFLAGS_PROGRAM'] = trim('-L' . BUILD_LIB_PATH . ' ' . $ldflags_program); + } + } + $vars = $this->getEnvString($vars); shell()->cd(SOURCE_PATH . '/php-src') ->exec('sed -i "s|//lib|/lib|g" Makefile') ->exec("\$SPC_CMD_PREFIX_PHP_MAKE {$vars} fpm"); diff --git a/src/SPC/builder/linux/library/attr.php b/src/SPC/builder/linux/library/attr.php new file mode 100644 index 00000000..da29d48f --- /dev/null +++ b/src/SPC/builder/linux/library/attr.php @@ -0,0 +1,12 @@ +cd($this->source_dir) + ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) + ->execWithEnv('./autogen.sh') + ->execWithEnv('./configure --prefix= --enable-static --disable-shared --disable-tests') + ->execWithEnv("make -j {$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + + $this->patchPkgconfPrefix(['libattr.pc'], PKGCONF_PATCH_PREFIX); + $this->cleanLaFiles(); + } +} diff --git a/src/SPC/builder/unix/library/libacl.php b/src/SPC/builder/unix/library/libacl.php new file mode 100644 index 00000000..9d6ebc82 --- /dev/null +++ b/src/SPC/builder/unix/library/libacl.php @@ -0,0 +1,30 @@ +cd($this->source_dir) + ->setEnv([ + 'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags()), + 'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags()), + 'LIBS' => $this->getLibExtraLibs(), + ]) + ->execWithEnv('./autogen.sh') + ->execWithEnv('./configure --prefix= --enable-static --disable-shared --disable-tests --disable-nls') + ->execWithEnv("make -j {$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + + $this->patchPkgconfPrefix(['libacl.pc'], PKGCONF_PATCH_PREFIX); + $this->cleanLaFiles(); + } +} From 4bc4c2ff052cda557a1691a8d8df7e64f726b60d Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Wed, 5 Mar 2025 11:59:30 +0100 Subject: [PATCH 02/23] revert EXTRA_LDFLAGS_PROGRAM patch, TODO: patchBeforeMake and remove -lacl from the libtool command --- src/SPC/builder/linux/LinuxBuilder.php | 9 +-------- src/SPC/builder/unix/library/attr.php | 1 - src/SPC/builder/unix/library/libacl.php | 1 - 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 2012ae3a..f12316ec 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -287,14 +287,7 @@ class LinuxBuilder extends UnixBuilderBase */ protected function buildFpm(): void { - $vars = $this->getMakeExtraVars(); - if ($this->getLib('libacl') !== null) { - $ldflags_program = $vars['EXTRA_LDFLAGS_PROGRAM'] ?? ''; - if (!str_contains($ldflags_program, '-L' . BUILD_LIB_PATH)) { - $vars['EXTRA_LDFLAGS_PROGRAM'] = trim('-L' . BUILD_LIB_PATH . ' ' . $ldflags_program); - } - } - $vars = $this->getEnvString($vars); + $vars = $this->getEnvString($this->getMakeExtraVars()); shell()->cd(SOURCE_PATH . '/php-src') ->exec('sed -i "s|//lib|/lib|g" Makefile') ->exec("\$SPC_CMD_PREFIX_PHP_MAKE {$vars} fpm"); diff --git a/src/SPC/builder/unix/library/attr.php b/src/SPC/builder/unix/library/attr.php index 66aa71c6..d82d12f6 100644 --- a/src/SPC/builder/unix/library/attr.php +++ b/src/SPC/builder/unix/library/attr.php @@ -21,6 +21,5 @@ trait attr ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libattr.pc'], PKGCONF_PATCH_PREFIX); - $this->cleanLaFiles(); } } diff --git a/src/SPC/builder/unix/library/libacl.php b/src/SPC/builder/unix/library/libacl.php index 9d6ebc82..27aa802b 100644 --- a/src/SPC/builder/unix/library/libacl.php +++ b/src/SPC/builder/unix/library/libacl.php @@ -25,6 +25,5 @@ trait libacl ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libacl.pc'], PKGCONF_PATCH_PREFIX); - $this->cleanLaFiles(); } } From 29a0f2facb94453fb9b314f98a615549e587f53b Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Fri, 7 Mar 2025 10:00:10 +0100 Subject: [PATCH 03/23] revert to SystemUtils::makeEnvVarString --- 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 f12316ec..58281bf4 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -287,7 +287,7 @@ class LinuxBuilder extends UnixBuilderBase */ protected function buildFpm(): void { - $vars = $this->getEnvString($this->getMakeExtraVars()); + $vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars()); shell()->cd(SOURCE_PATH . '/php-src') ->exec('sed -i "s|//lib|/lib|g" Makefile') ->exec("\$SPC_CMD_PREFIX_PHP_MAKE {$vars} fpm"); From bed40c3d0511be60c9d978cf07ab44332c4c9708 Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Mon, 10 Mar 2025 06:57:04 +0100 Subject: [PATCH 04/23] add libacl to php requirements --- config/lib.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/lib.json b/config/lib.json index 32d9a770..b2e205ae 100644 --- a/config/lib.json +++ b/config/lib.json @@ -11,6 +11,9 @@ "lib-depends": [ "micro", "lib-base" + ], + "lib-depends-unix": [ + "libacl" ] }, "micro": { From 53f82d286c007626bb94a7992c37375649fbaa3a Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Mon, 10 Mar 2025 07:30:17 +0100 Subject: [PATCH 05/23] split requirements into unix and windows --- config/lib.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/lib.json b/config/lib.json index b2e205ae..4ebe8548 100644 --- a/config/lib.json +++ b/config/lib.json @@ -8,12 +8,14 @@ "php": { "type": "root", "source": "php-src", - "lib-depends": [ + "lib-depends-windows": [ "micro", "lib-base" ], "lib-depends-unix": [ - "libacl" + "libacl", + "micro", + "lib-base" ] }, "micro": { From 77bbc7fcaa734e70bd8d3763c6c5fe96aa6f224a Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Mon, 10 Mar 2025 07:50:11 +0100 Subject: [PATCH 06/23] add libacl and attr to macos, not sure if they build --- src/SPC/builder/macos/library/attr.php | 12 ++++++++++++ src/SPC/builder/macos/library/libacl.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/SPC/builder/macos/library/attr.php create mode 100644 src/SPC/builder/macos/library/libacl.php diff --git a/src/SPC/builder/macos/library/attr.php b/src/SPC/builder/macos/library/attr.php new file mode 100644 index 00000000..028deb26 --- /dev/null +++ b/src/SPC/builder/macos/library/attr.php @@ -0,0 +1,12 @@ + Date: Mon, 10 Mar 2025 09:01:54 +0100 Subject: [PATCH 07/23] add required packages for autopoint to spc doctor --- .github/workflows/build-unix.yml | 2 +- src/SPC/doctor/item/LinuxToolCheckList.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-unix.yml b/.github/workflows/build-unix.yml index bfcf098e..0ec63e24 100644 --- a/.github/workflows/build-unix.yml +++ b/.github/workflows/build-unix.yml @@ -15,7 +15,7 @@ on: php-version: required: true description: PHP version to compile - default: '8.3' + default: '8.4' type: choice options: - '8.4' diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 0e4b236a..810614be 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -17,7 +17,7 @@ class LinuxToolCheckList public const TOOLS_ALPINE = [ 'make', 'bison', 'flex', - 'git', 'autoconf', 'automake', + 'git', 'autoconf', 'automake', 'gettext-dev', 'tar', 'unzip', 'gzip', 'bzip2', 'cmake', 'gcc', 'g++', 'patch', 'binutils-gold', @@ -26,7 +26,7 @@ class LinuxToolCheckList public const TOOLS_DEBIAN = [ 'make', 'bison', 'flex', - 'git', 'autoconf', 'automake', + 'git', 'autoconf', 'automake', 'autopoint', 'tar', 'unzip', 'gzip', 'bzip2', 'cmake', 'patch', 'xz', 'libtoolize', From c6552f6800e23f879707d0c60136f94e1c489188 Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Mon, 10 Mar 2025 09:46:20 +0100 Subject: [PATCH 08/23] add patch for attr on alpine --- src/SPC/builder/unix/library/attr.php | 2 +- src/SPC/store/SourcePatcher.php | 10 ++++++++++ src/globals/patch/attr_alpine_gethostname.patch | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/globals/patch/attr_alpine_gethostname.patch diff --git a/src/SPC/builder/unix/library/attr.php b/src/SPC/builder/unix/library/attr.php index d82d12f6..542fd807 100644 --- a/src/SPC/builder/unix/library/attr.php +++ b/src/SPC/builder/unix/library/attr.php @@ -16,7 +16,7 @@ trait attr shell()->cd($this->source_dir) ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->execWithEnv('./autogen.sh') - ->execWithEnv('./configure --prefix= --enable-static --disable-shared --disable-tests') + ->execWithEnv('./configure --prefix= --enable-static --disable-shared') ->execWithEnv("make -j {$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 5c7db38f..93703ce2 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -29,6 +29,7 @@ class SourcePatcher 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']); } /** @@ -407,6 +408,15 @@ class SourcePatcher return false; } + public static function patchAttrForAlpine(): bool + { + if (PHP_OS_FAMILY === 'Linux' && SystemUtil::isMuslDist()) { + SourcePatcher::patchFile('attr_alpine_gethostname.patch', SOURCE_PATH . '/attr'); + return true; + } + return false; + } + /** * Patch cli SAPI Makefile for Windows. * diff --git a/src/globals/patch/attr_alpine_gethostname.patch b/src/globals/patch/attr_alpine_gethostname.patch new file mode 100644 index 00000000..ee6e4bdd --- /dev/null +++ b/src/globals/patch/attr_alpine_gethostname.patch @@ -0,0 +1,11 @@ +diff --git a/tools/attr.c b/tools/attr.c +index 312aef1..8e82810 100644 +--- a/tools/attr.c ++++ b/tools/attr.c +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + + #include \ No newline at end of file From 4e32ff47df0792184212d8b8c43af548f0c7e27e Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Mon, 10 Mar 2025 10:25:35 +0100 Subject: [PATCH 09/23] patch libacl WIP --- src/SPC/builder/LibraryBase.php | 5 +++++ src/SPC/builder/unix/library/libacl.php | 14 ++++++++++++-- src/SPC/store/SourcePatcher.php | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index e0500cbe..4cb62811 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -294,6 +294,11 @@ abstract class LibraryBase // do something before pack, default do nothing. overwrite this method to do something (e.g. modify pkg-config file) } + public function patchBeforeConfigure(): bool + { + return false; + } + /** * Build this library. * diff --git a/src/SPC/builder/unix/library/libacl.php b/src/SPC/builder/unix/library/libacl.php index 27aa802b..8fbe1610 100644 --- a/src/SPC/builder/unix/library/libacl.php +++ b/src/SPC/builder/unix/library/libacl.php @@ -4,19 +4,29 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\linux\library\LinuxLibraryBase; use SPC\exception\RuntimeException; +use SPC\store\FileSystem; trait libacl { + public function patchBeforeConfigure(): bool + { + FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/sapi/fpm/config.m4', '[AS_VAR_APPEND([FPM_EXTRA_LIBS],', ','); + return true; + } + /** * @throws RuntimeException */ protected function build(): void { + $cflags = PHP_OS_FAMILY !== 'Linux' ? '-Wimplicit-function-declaration -Wno-int-conversion' : ''; + $ldflags = !($this instanceof LinuxLibraryBase) ? '' : '--static'; shell()->cd($this->source_dir) ->setEnv([ - 'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags()), - 'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags()), + 'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags() . ' ' . $cflags), + 'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags() . ' ' . $ldflags), 'LIBS' => $this->getLibExtraLibs(), ]) ->execWithEnv('./autogen.sh') diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 93703ce2..047c33cf 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -85,6 +85,11 @@ class SourcePatcher logger()->info('Extension [' . $ext->getName() . '] patched before configure'); } } + foreach ($builder->getLibs() as $lib) { + if ($lib->patchBeforeConfigure() === true) { + logger()->info('Library [' . $lib->getName() . '] patched before configure'); + } + } // patch capstone FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/configure', '/have_capstone="yes"/', 'have_capstone="no"'); if ($builder instanceof LinuxBuilder && $builder->libc === 'glibc') { From be3d68cebe76d385aad8c21641ff2ce91c21c470 Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Mon, 10 Mar 2025 11:25:38 +0100 Subject: [PATCH 10/23] patch the makefile before make (remove -lacl from FPM_EXTRA_LIBS) --- src/SPC/builder/LibraryBase.php | 5 +++++ src/SPC/builder/unix/library/libacl.php | 13 +++++++++++-- src/SPC/store/SourcePatcher.php | 7 ++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index 4cb62811..08ff3d84 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -299,6 +299,11 @@ abstract class LibraryBase return false; } + public function patchBeforeMake(): bool + { + return false; + } + /** * Build this library. * diff --git a/src/SPC/builder/unix/library/libacl.php b/src/SPC/builder/unix/library/libacl.php index 8fbe1610..9727e17c 100644 --- a/src/SPC/builder/unix/library/libacl.php +++ b/src/SPC/builder/unix/library/libacl.php @@ -5,14 +5,23 @@ declare(strict_types=1); namespace SPC\builder\unix\library; use SPC\builder\linux\library\LinuxLibraryBase; +use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\store\FileSystem; trait libacl { - public function patchBeforeConfigure(): bool + /** + * @throws FileSystemException + */ + public function patchBeforeMake(): bool { - FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/sapi/fpm/config.m4', '[AS_VAR_APPEND([FPM_EXTRA_LIBS],', ','); + $file_path = SOURCE_PATH . '/php-src/Makefile'; + $file_content = FileSystem::readFile($file_path); + if (!preg_match('/FPM_EXTRA_LIBS =(.*)-lacl/', $file_content)) { + return false; + } + FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/Makefile', '/FPM_EXTRA_LIBS =(.*)-lacl ?(.*)/', 'FPM_EXTRA_LIBS =$1$2'); return true; } diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 047c33cf..3c90e3ec 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -252,6 +252,11 @@ class SourcePatcher logger()->info('Extension [' . $ext->getName() . '] patched before make'); } } + foreach ($builder->getLibs() as $lib) { + if ($lib->patchBeforeMake() === true) { + logger()->info('Library [' . $lib->getName() . '] patched before make'); + } + } } /** @@ -415,7 +420,7 @@ class SourcePatcher public static function patchAttrForAlpine(): bool { - if (PHP_OS_FAMILY === 'Linux' && SystemUtil::isMuslDist()) { + if (PHP_OS_FAMILY === 'Linux' && SystemUtil::isMuslDist() || PHP_OS_FAMILY === 'Darwin') { SourcePatcher::patchFile('attr_alpine_gethostname.patch', SOURCE_PATH . '/attr'); return true; } From 40ea306008e0650647eb9cc9f32a4cd74082dfa0 Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Mon, 10 Mar 2025 11:42:44 +0100 Subject: [PATCH 11/23] try something with static --- src/SPC/builder/unix/library/attr.php | 9 +++++++-- src/SPC/builder/unix/library/libacl.php | 3 +-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/SPC/builder/unix/library/attr.php b/src/SPC/builder/unix/library/attr.php index 542fd807..edfa89ab 100644 --- a/src/SPC/builder/unix/library/attr.php +++ b/src/SPC/builder/unix/library/attr.php @@ -13,9 +13,14 @@ trait attr */ protected function build(): void { + $cflags = PHP_OS_FAMILY !== 'Linux' ? '-Wimplicit-function-declaration -Wno-int-conversion' : ''; + $ldflags = PHP_OS_FAMILY !== 'Linux' ? '' : '--static'; shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv('./autogen.sh') + ->setEnv([ + 'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags() . ' ' . $cflags), + 'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags() . ' ' . $ldflags), + 'LIBS' => $this->getLibExtraLibs(), + ])->execWithEnv('./autogen.sh') ->execWithEnv('./configure --prefix= --enable-static --disable-shared') ->execWithEnv("make -j {$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); diff --git a/src/SPC/builder/unix/library/libacl.php b/src/SPC/builder/unix/library/libacl.php index 9727e17c..2068d8e8 100644 --- a/src/SPC/builder/unix/library/libacl.php +++ b/src/SPC/builder/unix/library/libacl.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\linux\library\LinuxLibraryBase; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\store\FileSystem; @@ -31,7 +30,7 @@ trait libacl protected function build(): void { $cflags = PHP_OS_FAMILY !== 'Linux' ? '-Wimplicit-function-declaration -Wno-int-conversion' : ''; - $ldflags = !($this instanceof LinuxLibraryBase) ? '' : '--static'; + $ldflags = '--static'; shell()->cd($this->source_dir) ->setEnv([ 'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags() . ' ' . $cflags), From c52ab62fa6a5a974813073b44df811cf7ae7fca3 Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Mon, 10 Mar 2025 11:46:53 +0100 Subject: [PATCH 12/23] arch c flags --- src/SPC/builder/unix/library/attr.php | 2 +- src/SPC/builder/unix/library/libacl.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/unix/library/attr.php b/src/SPC/builder/unix/library/attr.php index edfa89ab..d4fb4ac6 100644 --- a/src/SPC/builder/unix/library/attr.php +++ b/src/SPC/builder/unix/library/attr.php @@ -13,7 +13,7 @@ trait attr */ protected function build(): void { - $cflags = PHP_OS_FAMILY !== 'Linux' ? '-Wimplicit-function-declaration -Wno-int-conversion' : ''; + $cflags = PHP_OS_FAMILY !== 'Linux' ? "{$this->builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion" : ''; $ldflags = PHP_OS_FAMILY !== 'Linux' ? '' : '--static'; shell()->cd($this->source_dir) ->setEnv([ diff --git a/src/SPC/builder/unix/library/libacl.php b/src/SPC/builder/unix/library/libacl.php index 2068d8e8..7d84d9ec 100644 --- a/src/SPC/builder/unix/library/libacl.php +++ b/src/SPC/builder/unix/library/libacl.php @@ -29,7 +29,7 @@ trait libacl */ protected function build(): void { - $cflags = PHP_OS_FAMILY !== 'Linux' ? '-Wimplicit-function-declaration -Wno-int-conversion' : ''; + $cflags = PHP_OS_FAMILY !== 'Linux' ? "{$this->builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion" : ''; $ldflags = '--static'; shell()->cd($this->source_dir) ->setEnv([ From 878e17ddb4a0426889daa603529851849e04dc87 Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Tue, 11 Mar 2025 05:39:38 +0100 Subject: [PATCH 13/23] remove attr and libacl from macos --- config/lib.json | 12 ++++++------ src/SPC/builder/LibraryBase.php | 2 +- src/SPC/builder/macos/library/attr.php | 12 ------------ src/SPC/builder/macos/library/libacl.php | 12 ------------ src/SPC/builder/unix/library/attr.php | 6 ++---- src/SPC/builder/unix/library/libacl.php | 6 ++---- 6 files changed, 11 insertions(+), 39 deletions(-) delete mode 100644 src/SPC/builder/macos/library/attr.php delete mode 100644 src/SPC/builder/macos/library/libacl.php diff --git a/config/lib.json b/config/lib.json index 4ebe8548..53c26d2c 100644 --- a/config/lib.json +++ b/config/lib.json @@ -8,14 +8,14 @@ "php": { "type": "root", "source": "php-src", - "lib-depends-windows": [ - "micro", - "lib-base" + "lib-depends": [ + "lib-base", + "micro" ], - "lib-depends-unix": [ + "lib-depends-linux": [ + "lib-base", "libacl", - "micro", - "lib-base" + "micro" ] }, "micro": { diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index 08ff3d84..deb7c45f 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -113,7 +113,7 @@ abstract class LibraryBase /* Rules: If it is a Windows system, try the following dependencies in order: lib-depends-windows, lib-depends-win, lib-depends. - If it is a macOS system, try the following dependencies in order: lib-depends-darwin, lib-depends-unix, lib-depends. + If it is a macOS system, try the following dependencies in order: lib-depends-macos, lib-depends-unix, lib-depends. If it is a Linux system, try the following dependencies in order: lib-depends-linux, lib-depends-unix, lib-depends. */ foreach (Config::getLib(static::NAME, 'lib-depends', []) as $dep_name) { diff --git a/src/SPC/builder/macos/library/attr.php b/src/SPC/builder/macos/library/attr.php deleted file mode 100644 index 028deb26..00000000 --- a/src/SPC/builder/macos/library/attr.php +++ /dev/null @@ -1,12 +0,0 @@ -builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion" : ''; - $ldflags = PHP_OS_FAMILY !== 'Linux' ? '' : '--static'; shell()->cd($this->source_dir) ->setEnv([ - 'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags() . ' ' . $cflags), - 'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags() . ' ' . $ldflags), + 'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags()), + 'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags()), 'LIBS' => $this->getLibExtraLibs(), ])->execWithEnv('./autogen.sh') ->execWithEnv('./configure --prefix= --enable-static --disable-shared') diff --git a/src/SPC/builder/unix/library/libacl.php b/src/SPC/builder/unix/library/libacl.php index 7d84d9ec..e43cc2fc 100644 --- a/src/SPC/builder/unix/library/libacl.php +++ b/src/SPC/builder/unix/library/libacl.php @@ -29,12 +29,10 @@ trait libacl */ protected function build(): void { - $cflags = PHP_OS_FAMILY !== 'Linux' ? "{$this->builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion" : ''; - $ldflags = '--static'; shell()->cd($this->source_dir) ->setEnv([ - 'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags() . ' ' . $cflags), - 'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags() . ' ' . $ldflags), + 'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags()), + 'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags()), 'LIBS' => $this->getLibExtraLibs(), ]) ->execWithEnv('./autogen.sh') From 09c0e435012dae78c1210cd236c10338096d7c21 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 28 Jan 2025 19:37:50 +0800 Subject: [PATCH 14/23] Add gnu based static binary support --- bin/spc-gnu-docker | 1 + config/env.custom.ini | 14 ++++++++++++++ src/SPC/builder/linux/LinuxBuilder.php | 2 +- src/SPC/builder/linux/library/libpng.php | 6 +++++- src/SPC/builder/unix/library/curl.php | 9 ++++++++- src/SPC/builder/unix/library/pkgconfig.php | 2 +- 6 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 config/env.custom.ini diff --git a/bin/spc-gnu-docker b/bin/spc-gnu-docker index e589b8ba..b219402c 100755 --- a/bin/spc-gnu-docker +++ b/bin/spc-gnu-docker @@ -136,5 +136,6 @@ echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' # shellcheck disable=SC2068 # shellcheck disable=SC2086 # shellcheck disable=SC2090 +$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH bin/spc $@ $DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH # bin/spc $@ diff --git a/config/env.custom.ini b/config/env.custom.ini new file mode 100644 index 00000000..a2ae8b42 --- /dev/null +++ b/config/env.custom.ini @@ -0,0 +1,14 @@ +; Modify this file name to `env.custom.ini`, and run `bin/spc-gnu-docker`, +; you can compile a GNU libc based static binary ! +[global] +SPC_SKIP_DOCTOR_CHECK_ITEMS="if musl-wrapper is installed,if musl-cross-make is installed" + +[linux] +CC=gcc +CXX=g++ +AR=ar +LD=ld +SPC_DEFAULT_C_FLAGS=-fPIC +SPC_NO_MUSL_PATH=yes +SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie" +SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil" diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 58281bf4..319a5ec1 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -37,7 +37,7 @@ class LinuxBuilder extends UnixBuilderBase GlobalEnvManager::init($this); // set library path, some libraries need it. (We cannot use `putenv` here, because cmake will be confused) - if (!filter_var(getenv('SPC_NO_MUSL_PATH'), FILTER_VALIDATE_BOOLEAN)) { + if (!filter_var(getenv('SPC_NO_MUSL_PATH'), FILTER_VALIDATE_BOOLEAN) && $this->libc !== LIBC_GLIBC) { $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\""); } diff --git a/src/SPC/builder/linux/library/libpng.php b/src/SPC/builder/linux/library/libpng.php index 617f42a2..53ed0211 100644 --- a/src/SPC/builder/linux/library/libpng.php +++ b/src/SPC/builder/linux/library/libpng.php @@ -44,7 +44,11 @@ class libpng extends LinuxLibraryBase shell()->cd($this->source_dir) ->exec('chmod +x ./configure') ->exec('chmod +x ./install-sh') - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LIBS' => $this->getLibExtraLibs()]) + ->setEnv([ + 'CFLAGS' => trim($this->getLibExtraCFlags() . ' ' . $this->builder->arch_c_flags), + 'LDFLAGS' => $this->getLibExtraLdFlags(), + 'LIBS' => $this->getLibExtraLibs() + ]) ->execWithEnv( 'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' . './configure ' . diff --git a/src/SPC/builder/unix/library/curl.php b/src/SPC/builder/unix/library/curl.php index 96a5bf05..efaa1122 100644 --- a/src/SPC/builder/unix/library/curl.php +++ b/src/SPC/builder/unix/library/curl.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\linux\library\LinuxLibraryBase; +use SPC\builder\linux\LinuxBuilder; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\store\FileSystem; @@ -52,9 +54,14 @@ trait curl FileSystem::resetDir($this->source_dir . '/build'); + $cflags = $this instanceof LinuxLibraryBase && $this->builder->libc === 'glibc' ? '-fPIC' : ''; // compile! shell()->cd($this->source_dir . '/build') - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) + ->setEnv([ + 'CFLAGS' => trim($this->getLibExtraCFlags() . ' ' . $cflags), + 'LDFLAGS' => $this->getLibExtraLdFlags(), + 'LIBS' => $this->getLibExtraLibs() + ]) ->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ../CMakeLists.txt') ->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF {$extra} ..") ->execWithEnv("make -j{$this->builder->concurrency}") diff --git a/src/SPC/builder/unix/library/pkgconfig.php b/src/SPC/builder/unix/library/pkgconfig.php index 4a060f02..796fe96b 100644 --- a/src/SPC/builder/unix/library/pkgconfig.php +++ b/src/SPC/builder/unix/library/pkgconfig.php @@ -10,7 +10,7 @@ trait pkgconfig { protected function build(): void { - $cflags = PHP_OS_FAMILY !== 'Linux' ? '-Wimplicit-function-declaration -Wno-int-conversion' : ''; + $cflags = PHP_OS_FAMILY !== 'Linux' ? "{$this->builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion" : ''; $ldflags = !($this instanceof LinuxLibraryBase) || $this->builder->libc === 'glibc' ? '' : '--static'; shell()->cd($this->source_dir) From ec3c0dc934e7cf7972183ea0be490e45f1272414 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 10 Mar 2025 16:15:47 +0800 Subject: [PATCH 15/23] Add SPC_CMD_VAR_PHP_EMBED_TYPE for embed building in glibc mode --- config/env.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/env.ini b/config/env.ini index 9582946e..0f14c9f9 100644 --- a/config/env.ini +++ b/config/env.ini @@ -117,8 +117,6 @@ SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force" SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg" ; make command SPC_CMD_PREFIX_PHP_MAKE="make -j${CPU_COUNT}" -; embed type for php, static or shared -SPC_CMD_VAR_PHP_EMBED_TYPE="static" ; *** default build vars for building php *** ; CFLAGS for configuring php From 2c644d5c1880113251610f087e65a8ca09c1d461 Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Tue, 11 Mar 2025 07:15:07 +0100 Subject: [PATCH 16/23] cs fix --- src/SPC/builder/linux/library/libpng.php | 2 +- src/SPC/builder/unix/library/curl.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/linux/library/libpng.php b/src/SPC/builder/linux/library/libpng.php index 53ed0211..9ffb7c75 100644 --- a/src/SPC/builder/linux/library/libpng.php +++ b/src/SPC/builder/linux/library/libpng.php @@ -47,7 +47,7 @@ class libpng extends LinuxLibraryBase ->setEnv([ 'CFLAGS' => trim($this->getLibExtraCFlags() . ' ' . $this->builder->arch_c_flags), 'LDFLAGS' => $this->getLibExtraLdFlags(), - 'LIBS' => $this->getLibExtraLibs() + 'LIBS' => $this->getLibExtraLibs(), ]) ->execWithEnv( 'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' . diff --git a/src/SPC/builder/unix/library/curl.php b/src/SPC/builder/unix/library/curl.php index efaa1122..fbe6ca20 100644 --- a/src/SPC/builder/unix/library/curl.php +++ b/src/SPC/builder/unix/library/curl.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace SPC\builder\unix\library; use SPC\builder\linux\library\LinuxLibraryBase; -use SPC\builder\linux\LinuxBuilder; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\store\FileSystem; @@ -60,7 +59,7 @@ trait curl ->setEnv([ 'CFLAGS' => trim($this->getLibExtraCFlags() . ' ' . $cflags), 'LDFLAGS' => $this->getLibExtraLdFlags(), - 'LIBS' => $this->getLibExtraLibs() + 'LIBS' => $this->getLibExtraLibs(), ]) ->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ../CMakeLists.txt') ->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF {$extra} ..") From f246125677ffd44f98d448b7581ec37518612491 Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Tue, 11 Mar 2025 07:44:31 +0100 Subject: [PATCH 17/23] requested changes --- config/env.custom.ini | 14 -------------- config/env.ini | 2 ++ config/source.json | 4 ++-- src/SPC/builder/Extension.php | 9 ++++++--- src/SPC/builder/LibraryBase.php | 20 ++++++++++++++++++++ src/SPC/store/SourcePatcher.php | 5 +++++ 6 files changed, 35 insertions(+), 19 deletions(-) delete mode 100644 config/env.custom.ini diff --git a/config/env.custom.ini b/config/env.custom.ini deleted file mode 100644 index a2ae8b42..00000000 --- a/config/env.custom.ini +++ /dev/null @@ -1,14 +0,0 @@ -; Modify this file name to `env.custom.ini`, and run `bin/spc-gnu-docker`, -; you can compile a GNU libc based static binary ! -[global] -SPC_SKIP_DOCTOR_CHECK_ITEMS="if musl-wrapper is installed,if musl-cross-make is installed" - -[linux] -CC=gcc -CXX=g++ -AR=ar -LD=ld -SPC_DEFAULT_C_FLAGS=-fPIC -SPC_NO_MUSL_PATH=yes -SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie" -SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil" diff --git a/config/env.ini b/config/env.ini index 0f14c9f9..71cdb956 100644 --- a/config/env.ini +++ b/config/env.ini @@ -129,6 +129,8 @@ SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}" SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="${SPC_PHP_DEFAULT_OPTIMIZE_CFLAGS}" ; 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" [freebsd] ; compiler environments diff --git a/config/source.json b/config/source.json index 81204229..e42fc0e7 100644 --- a/config/source.json +++ b/config/source.json @@ -40,7 +40,7 @@ "type": "git", "rev": "v2.5.2", "url": "https://git.savannah.nongnu.org/git/attr.git", - "provide-pre-built": false, + "provide-pre-built": true, "license": { "type": "file", "path": "doc/COPYING" @@ -337,7 +337,7 @@ "type": "git", "rev": "v2.3.2", "url": "https://git.savannah.nongnu.org/git/acl.git", - "provide-pre-built": false, + "provide-pre-built": true, "license": { "type": "file", "path": "doc/COPYING" diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 4cdc796c..a7886cd8 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -139,7 +139,8 @@ class Extension /** * Patch code before ./buildconf - * If you need to patch some code, overwrite this and return true + * If you need to patch some code, overwrite this + * return true if you patched something, false if not */ public function patchBeforeBuildconf(): bool { @@ -148,7 +149,8 @@ class Extension /** * Patch code before ./configure - * If you need to patch some code, overwrite this and return true + * If you need to patch some code, overwrite this + * return true if you patched something, false if not */ public function patchBeforeConfigure(): bool { @@ -157,7 +159,8 @@ class Extension /** * Patch code before make - * If you need to patch some code, overwrite this and return true + * If you need to patch some code, overwrite this + * return true if you patched something, false if not */ public function patchBeforeMake(): bool { diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index deb7c45f..a66b9e6b 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -294,11 +294,31 @@ abstract class LibraryBase // do something before pack, default do nothing. overwrite this method to do something (e.g. modify pkg-config file) } + /** + * Patch code before ./buildconf + * If you need to patch some code, overwrite this + * return true if you patched something, false if notand return true + */ + public function patchBeforeBuildconf(): bool + { + return false; + } + + /** + * Patch code before ./configure + * If you need to patch some code, overwrite this + * return true if you patched something, false if not + */ public function patchBeforeConfigure(): bool { return false; } + /** + * Patch code before make + * If you need to patch some code, overwrite this + * return true if you patched something, false if not + */ public function patchBeforeMake(): bool { return false; diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 3c90e3ec..bbb07a8f 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -47,6 +47,11 @@ class SourcePatcher logger()->info('Extension [' . $ext->getName() . '] patched before buildconf'); } } + foreach ($builder->getLibs() as $lib) { + if ($lib->patchBeforeBuildconf() === true) { + logger()->info('Library [' . $lib->getName() . '] patched before buildconf'); + } + } // patch windows php 8.1 bug if (PHP_OS_FAMILY === 'Windows' && $builder->getPHPVersionID() >= 80100 && $builder->getPHPVersionID() < 80200) { logger()->info('Patching PHP 8.1 windows Fiber bug'); From b534cdce11b4cf105bf6584d0a468ec4dafbf74e Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Tue, 11 Mar 2025 08:53:31 +0100 Subject: [PATCH 18/23] remove line --- bin/spc-gnu-docker | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/spc-gnu-docker b/bin/spc-gnu-docker index b219402c..a3af1431 100755 --- a/bin/spc-gnu-docker +++ b/bin/spc-gnu-docker @@ -136,6 +136,5 @@ echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' # shellcheck disable=SC2068 # shellcheck disable=SC2086 # shellcheck disable=SC2090 -$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH bin/spc $@ -$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH # bin/spc $@ +$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH bin/spc $@ From d15b387bea9b82b2a2e1b1177b055358e0ab8ce4 Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Wed, 12 Mar 2025 08:59:47 +0100 Subject: [PATCH 19/23] don't require libacl and attr for non fpm compilation --- config/env.ini | 13 ++++++++++--- config/lib.json | 5 ----- src/SPC/builder/linux/LinuxBuilder.php | 4 ++++ src/SPC/command/BuildCliCommand.php | 4 ++++ src/SPC/util/GlobalEnvManager.php | 5 ----- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/config/env.ini b/config/env.ini index 71cdb956..0acb903c 100644 --- a/config/env.ini +++ b/config/env.ini @@ -35,7 +35,6 @@ ; SPC_LINUX_DEFAULT_CC: the default compiler for linux. (For alpine linux: `gcc`, default: `$GNU_ARCH-linux-musl-gcc`) ; SPC_LINUX_DEFAULT_CXX: the default c++ compiler for linux. (For alpine linux: `g++`, default: `$GNU_ARCH-linux-musl-g++`) ; SPC_LINUX_DEFAULT_AR: the default archiver for linux. (For alpine linux: `ar`, default: `$GNU_ARCH-linux-musl-ar`) -; SPC_PHP_DEFAULT_LD_LIBRARY_PATH_CMD: the default LD_LIBRARY_PATH for php. (linux: `LD_LIBRARY_PATH=/usr/local/musl/$GNU_ARCH-linux-musl/lib`, default: empty) [global] @@ -45,6 +44,14 @@ SPC_CONCURRENCY=${CPU_COUNT} SPC_SKIP_PHP_VERSION_CHECK="no" ; Ignore some check item for bin/spc doctor command, comma separated (e.g. SPC_SKIP_DOCTOR_CHECK_ITEMS="if homebrew has installed") SPC_SKIP_DOCTOR_CHECK_ITEMS="" +; EXTENSION_DIR where the built php will look for extension when a .ini instructs to load them +; only useful for builds targeting glibc --libc=glibc +; default paths +; Ubuntu/Debian: /usr/lib/php/{PHP_VERSION}/ +; RHEL: /usr/lib64/php/modules +; Alpine: /usr/lib/php{PHP_VERSION}/modules +; where {PHP_VERSION} is 84 for php 8.4 +EXTENSION_DIR= [windows] ; php-sdk-binary-tools path @@ -63,7 +70,7 @@ CXX=${SPC_LINUX_DEFAULT_CXX} AR=${SPC_LINUX_DEFAULT_AR} LD=ld.gold ; default compiler flags, used in CMake toolchain file, openssl and pkg-config build -SPC_DEFAULT_C_FLAGS= +SPC_DEFAULT_C_FLAGS="-fPIC" SPC_DEFAULT_CXX_FLAGS= ; 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= @@ -76,7 +83,7 @@ SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime ; buildconf command SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force" ; configure command -SPC_CMD_PREFIX_PHP_CONFIGURE="${SPC_PHP_DEFAULT_LD_LIBRARY_PATH_CMD} ./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg --with-pic" +SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg --with-pic" ; make command SPC_CMD_PREFIX_PHP_MAKE="make -j${CPU_COUNT}" ; embed type for php, static (libphp.a) or shared (libphp.so) diff --git a/config/lib.json b/config/lib.json index 53c26d2c..bc011b78 100644 --- a/config/lib.json +++ b/config/lib.json @@ -11,11 +11,6 @@ "lib-depends": [ "lib-base", "micro" - ], - "lib-depends-linux": [ - "lib-base", - "libacl", - "micro" ] }, "micro": { diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 319a5ec1..c72f618b 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -40,6 +40,10 @@ class LinuxBuilder extends UnixBuilderBase if (!filter_var(getenv('SPC_NO_MUSL_PATH'), FILTER_VALIDATE_BOOLEAN) && $this->libc !== LIBC_GLIBC) { $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\""); + GlobalEnvManager::putenv("PATH=/usr/local/musl/bin:/usr/local/musl/{$arch}-linux-musl/bin:" . getenv('PATH')); + $configure = getenv('SPC_CMD_PREFIX_PHP_CONFIGURE'); + $configure = "LD_LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\" " . $configure; + GlobalEnvManager::putenv("SPC_CMD_PREFIX_PHP_CONFIGURE={$configure}"); } if (str_ends_with(getenv('CC'), 'linux-musl-gcc') && !file_exists("/usr/local/musl/bin/{$arch}-linux-musl-gcc") && (getenv('SPC_NO_MUSL_PATH') !== 'yes')) { diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index d991719f..abeeeb0b 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace SPC\command; use SPC\builder\BuilderProvider; +use SPC\builder\linux\LinuxBuilder; use SPC\exception\ExceptionHandler; use SPC\exception\WrongUsageException; use SPC\store\Config; @@ -108,6 +109,9 @@ class BuildCliCommand extends BuildCommand $include_suggest_ext = $this->getOption('with-suggested-exts'); $include_suggest_lib = $this->getOption('with-suggested-libs'); [$extensions, $libraries, $not_included] = DependencyUtil::getExtsAndLibs($extensions, $libraries, $include_suggest_ext, $include_suggest_lib); + if ($builder instanceof LinuxBuilder && !in_array('libacl', $libraries) && ($rule & BUILD_TARGET_FPM)) { + array_unshift($libraries, 'attr', 'libacl'); + } $display_libs = array_filter($libraries, fn ($lib) => in_array(Config::getLib($lib, 'type', 'lib'), ['lib', 'package'])); // print info diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index 49f334d9..a82c2669 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -108,11 +108,6 @@ class GlobalEnvManager 'BSD' => self::applyConfig($ini['freebsd']), default => null, }; - - if (PHP_OS_FAMILY === 'Linux' && !filter_var(getenv('SPC_NO_MUSL_PATH'), FILTER_VALIDATE_BOOLEAN)) { - self::putenv("SPC_PHP_DEFAULT_LD_LIBRARY_PATH_CMD=LD_LIBRARY_PATH=/usr/local/musl/{$arch}-linux-musl/lib"); - self::putenv("PATH=/usr/local/musl/bin:/usr/local/musl/{$arch}-linux-musl/bin:" . getenv('PATH')); - } } public static function putenv(string $val): void From 76ac57edf4ba2dd83202bc56304c5eee62ccafcc Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Wed, 12 Mar 2025 09:07:26 +0100 Subject: [PATCH 20/23] download attr and libacl on linux --- src/SPC/command/DownloadCommand.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SPC/command/DownloadCommand.php b/src/SPC/command/DownloadCommand.php index 7bf82ebb..43dd143c 100644 --- a/src/SPC/command/DownloadCommand.php +++ b/src/SPC/command/DownloadCommand.php @@ -81,6 +81,9 @@ class DownloadCommand extends BaseCommand $final_sources = array_merge($final_sources, array_diff($sources, $final_sources)); } if (!empty($final_sources)) { + if (PHP_OS_FAMILY === 'Linux') { + array_unshift($final_sources, 'attr', 'libacl'); + } $input->setArgument('sources', implode(',', $final_sources)); } parent::initialize($input, $output); From 5caf5b7694c5f19ee34c432f82d12f11ac1251c8 Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Wed, 12 Mar 2025 09:19:01 +0100 Subject: [PATCH 21/23] check for libacl in fewer places --- config/lib.json | 5 +++++ src/SPC/command/BuildCliCommand.php | 5 ++--- src/SPC/command/DownloadCommand.php | 3 --- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config/lib.json b/config/lib.json index bc011b78..53c26d2c 100644 --- a/config/lib.json +++ b/config/lib.json @@ -11,6 +11,11 @@ "lib-depends": [ "lib-base", "micro" + ], + "lib-depends-linux": [ + "lib-base", + "libacl", + "micro" ] }, "micro": { diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index abeeeb0b..cee98b73 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace SPC\command; use SPC\builder\BuilderProvider; -use SPC\builder\linux\LinuxBuilder; use SPC\exception\ExceptionHandler; use SPC\exception\WrongUsageException; use SPC\store\Config; @@ -109,8 +108,8 @@ class BuildCliCommand extends BuildCommand $include_suggest_ext = $this->getOption('with-suggested-exts'); $include_suggest_lib = $this->getOption('with-suggested-libs'); [$extensions, $libraries, $not_included] = DependencyUtil::getExtsAndLibs($extensions, $libraries, $include_suggest_ext, $include_suggest_lib); - if ($builder instanceof LinuxBuilder && !in_array('libacl', $libraries) && ($rule & BUILD_TARGET_FPM)) { - array_unshift($libraries, 'attr', 'libacl'); + if (PHP_OS_FAMILY !== 'Linux' || !($rule & BUILD_TARGET_FPM)) { + $libraries = array_filter($libraries, fn ($lib) => !in_array($lib, ['attr', 'libacl'])); } $display_libs = array_filter($libraries, fn ($lib) => in_array(Config::getLib($lib, 'type', 'lib'), ['lib', 'package'])); diff --git a/src/SPC/command/DownloadCommand.php b/src/SPC/command/DownloadCommand.php index 43dd143c..7bf82ebb 100644 --- a/src/SPC/command/DownloadCommand.php +++ b/src/SPC/command/DownloadCommand.php @@ -81,9 +81,6 @@ class DownloadCommand extends BaseCommand $final_sources = array_merge($final_sources, array_diff($sources, $final_sources)); } if (!empty($final_sources)) { - if (PHP_OS_FAMILY === 'Linux') { - array_unshift($final_sources, 'attr', 'libacl'); - } $input->setArgument('sources', implode(',', $final_sources)); } parent::initialize($input, $output); From e7bac8f78d456be81aa49b026bd1354eb70d8b04 Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 12 Mar 2025 20:05:05 +0700 Subject: [PATCH 22/23] Update LibraryBase.php rectify typo --- src/SPC/builder/LibraryBase.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index a66b9e6b..ec5c7b3b 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -261,14 +261,6 @@ abstract class LibraryBase return LIB_STATUS_ALREADY; } - /** - * Patch before build, overwrite this and return true to patch libs. - */ - public function patchBeforeBuild(): bool - { - return false; - } - public function validate(): void { // do nothing, just throw wrong usage exception if not valid @@ -294,10 +286,21 @@ abstract class LibraryBase // do something before pack, default do nothing. overwrite this method to do something (e.g. modify pkg-config file) } + /** + * Patch code before build + * If you need to patch some code, overwrite this + * return true if you patched something, false if not + */ + public function patchBeforeBuild(): bool + { + return false; + } + + /** * Patch code before ./buildconf * If you need to patch some code, overwrite this - * return true if you patched something, false if notand return true + * return true if you patched something, false if not */ public function patchBeforeBuildconf(): bool { From 74edcb7d6f48194fc1f7f3de1cb95ad32edd12b7 Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 12 Mar 2025 20:07:04 +0700 Subject: [PATCH 23/23] Update LibraryBase.php newline --- src/SPC/builder/LibraryBase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index ec5c7b3b..d76aa209 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -296,7 +296,6 @@ abstract class LibraryBase return false; } - /** * Patch code before ./buildconf * If you need to patch some code, overwrite this