From 4576ddd132bdebc5a942da521706fd8d3252157e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 26 Sep 2023 16:30:40 +0200 Subject: [PATCH 01/58] [WIP] imap support --- config/ext.json | 5 +- config/lib.json | 6 ++ config/source.json | 9 +++ src/SPC/builder/extension/imap.php | 21 +++++ src/SPC/builder/linux/library/imap.php | 15 ++++ src/SPC/builder/macos/library/imap.php | 28 +++++++ src/SPC/builder/unix/library/imap.php | 103 +++++++++++++++++++++++++ 7 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 src/SPC/builder/extension/imap.php create mode 100644 src/SPC/builder/linux/library/imap.php create mode 100644 src/SPC/builder/macos/library/imap.php create mode 100644 src/SPC/builder/unix/library/imap.php diff --git a/config/ext.json b/config/ext.json index d5234e4ed..8a202b359 100644 --- a/config/ext.json +++ b/config/ext.json @@ -132,12 +132,13 @@ }, "imap": { "type": "builtin", - "arg-type": "with", + "arg-type": "custom", "lib-depends": [ "imap" ], "lib-suggests": [ - "kerberos" + "kerberos", + "openssl" ] }, "inotify": { diff --git a/config/lib.json b/config/lib.json index 606a1be4b..7d0dab127 100644 --- a/config/lib.json +++ b/config/lib.json @@ -139,6 +139,12 @@ "libxml2" ] }, + "imap": { + "source": "imap", + "static-libs-unix": [ + "libc-client.a" + ] + }, "libavif": { "source": "libavif", "static-libs-unix": [ diff --git a/config/source.json b/config/source.json index 3c052a26d..44af51566 100644 --- a/config/source.json +++ b/config/source.json @@ -153,6 +153,15 @@ "path": "LICENSE" } }, + "imap": { + "type": "git", + "url": "https://github.com/uw-imap/imap.git", + "rev": "master", + "license": { + "type": "file", + "path": "LICENSE" + } + }, "libavif": { "type": "ghtar", "repo": "AOMediaCodec/libavif", diff --git a/src/SPC/builder/extension/imap.php b/src/SPC/builder/extension/imap.php new file mode 100644 index 000000000..eb1cd7f66 --- /dev/null +++ b/src/SPC/builder/extension/imap.php @@ -0,0 +1,21 @@ +builder->getLib('openssl') !== null) { + $arg .= ' --with-imap-ssl=' . BUILD_ROOT_PATH; + } + return $arg; + } +} diff --git a/src/SPC/builder/linux/library/imap.php b/src/SPC/builder/linux/library/imap.php new file mode 100644 index 000000000..d0c168cb5 --- /dev/null +++ b/src/SPC/builder/linux/library/imap.php @@ -0,0 +1,15 @@ + + * + * lwmbs is licensed under Mulan PSL v2. You can use this + * software according to the terms and conditions of the + * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, + * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +declare(strict_types=1); + +namespace SPC\builder\macos\library; + +class imap extends MacOSLibraryBase +{ + use \SPC\builder\unix\library\imap; + + public const NAME = 'imap'; +} diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php new file mode 100644 index 000000000..a45189af0 --- /dev/null +++ b/src/SPC/builder/unix/library/imap.php @@ -0,0 +1,103 @@ +builder->getOption('enable-zts')) { + return; + } + if ($this->builder->getLib('openssl') !== null) { + $this->replace_file_contents( + $this->source_dir . '/Makefile', + 'SSLINCLUDE=/usr/include/openssl', + 'SSLINCLUDE=' . BUILD_INCLUDE_PATH + ); + $this->replace_file_contents( + $this->source_dir . '/Makefile', + 'SSLLIB=/usr/lib', + 'SSLLIB=' . BUILD_LIB_PATH + ); + $this->replace_file_contents( + $this->source_dir . '/Makefile', + '"-DMAC_OSX_KLUDGE=1', + '' + ); + $this->replace_file_contents( + $this->source_dir . '/src/osdep/unix/Makefile', + '-lcrypto -lz', + '-lcrypto' + ); + $this->replace_file_contents( + $this->source_dir . '/src/osdep/unix/Makefile', + '-lcrypto', + '-lcrypto -lz' + ); + $this->replace_file_contents( + $this->source_dir . '/src/osdep/unix/ssl_unix.c', + "#include \n#include ", + "#include \n#include " + ); + // https://salsa.debian.org/holmgren/uw-imap/raw/master/debian/patches/2014_openssl1.1.1_sni.patch + // this was not applied in the github source yet + $this->replace_file_contents( + $this->source_dir . '/src/osdep/unix/ssl_unix.c', + <<<'EOL' +if (!(stream->con = (SSL *) SSL_new (stream->context))) + return "SSL connection failed"; + bio = BIO_new_socket (stream->tcpstream->tcpsi,BIO_NOCLOSE); +EOL, + <<<'EOL' +if (!(stream->con = (SSL *) SSL_new (stream->context))) + return "SSL connection failed"; +#if OPENSSL_VERSION_NUMBER >= 0x10101000 + /* Use SNI in case server requires it with TLSv1.3. + * Literal IP addresses not permitted per RFC 6066. */ + if (!a2i_IPADDRESS(host)) { + ERR_clear_error(); + SSL_set_tlsext_host_name(stream->con,host); + } +#endif + bio = BIO_new_socket (stream->tcpstream->tcpsi,BIO_NOCLOSE);" +EOL + ); + } + $platform = 'lr5'; + shell()->cd($this->source_dir) + ->exec('touch ip6') + ->exec( + "{$this->builder->configure_env} make {$platform}" . + ($this->builder->getLib('openssl') === null ? ' SSLTYPE=none' : '') + ); + shell() + ->exec("cp -rf {$this->source_dir}/c-client/c-client.a " . BUILD_LIB_PATH . '/libc-client.a') + ->exec("cp -rf {$this->source_dir}/c-client/*.h " . BUILD_INCLUDE_PATH) + ->exec("cp -rf {$this->source_dir}/src/osdep/unix/*.h " . BUILD_INCLUDE_PATH); + } + + private function replace_file_contents(string|array $filepath, string $old, string $new): void + { + if (is_string($filepath)) { + $filepath = [$filepath]; + } + foreach ($filepath as $path) { + $str = file_get_contents($path); + $str = str_replace($old, $new, $str); + file_put_contents($path, $str); + } + } +} From 97e2fc018a2ab87836d9918c8ecdf7f174fc7a6a Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 27 Sep 2023 15:50:53 +0200 Subject: [PATCH 02/58] use Filesystem methods, extra args --- config/lib.json | 2 +- config/source.json | 2 +- src/SPC/builder/linux/library/imap.php | 3 -- src/SPC/builder/macos/library/imap.php | 16 --------- src/SPC/builder/unix/library/imap.php | 49 +++++++++++--------------- 5 files changed, 22 insertions(+), 50 deletions(-) diff --git a/config/lib.json b/config/lib.json index 7d0dab127..3e6996a28 100644 --- a/config/lib.json +++ b/config/lib.json @@ -140,7 +140,7 @@ ] }, "imap": { - "source": "imap", + "source": "uwimap", "static-libs-unix": [ "libc-client.a" ] diff --git a/config/source.json b/config/source.json index 44af51566..f2790e980 100644 --- a/config/source.json +++ b/config/source.json @@ -153,7 +153,7 @@ "path": "LICENSE" } }, - "imap": { + "uwimap": { "type": "git", "url": "https://github.com/uw-imap/imap.git", "rev": "master", diff --git a/src/SPC/builder/linux/library/imap.php b/src/SPC/builder/linux/library/imap.php index d0c168cb5..ea48fc8e6 100644 --- a/src/SPC/builder/linux/library/imap.php +++ b/src/SPC/builder/linux/library/imap.php @@ -4,9 +4,6 @@ namespace SPC\builder\linux\library; -/** - * a template library class for unix - */ class imap extends LinuxLibraryBase { use \SPC\builder\unix\library\imap; diff --git a/src/SPC/builder/macos/library/imap.php b/src/SPC/builder/macos/library/imap.php index 9df897337..44adeaef2 100644 --- a/src/SPC/builder/macos/library/imap.php +++ b/src/SPC/builder/macos/library/imap.php @@ -1,20 +1,4 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index a45189af0..3c508498a 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -7,6 +7,7 @@ use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; +use SPC\store\FileSystem; trait imap { @@ -17,44 +18,44 @@ trait imap */ protected function build(): void { - // ext-imap is NOT thread safe, do not build with ZTS builds - if ($this->builder->getOption('enable-zts')) { - return; - } + // ext-imap is NOT thread safe, do not build with ZTS builds + // if ($this->builder->getOption('enable-zts')) { + // return; + // } if ($this->builder->getLib('openssl') !== null) { - $this->replace_file_contents( + FileSystem::replaceFileStr( $this->source_dir . '/Makefile', 'SSLINCLUDE=/usr/include/openssl', 'SSLINCLUDE=' . BUILD_INCLUDE_PATH ); - $this->replace_file_contents( + FileSystem::replaceFileStr( $this->source_dir . '/Makefile', 'SSLLIB=/usr/lib', 'SSLLIB=' . BUILD_LIB_PATH ); - $this->replace_file_contents( + FileSystem::replaceFileStr( $this->source_dir . '/Makefile', '"-DMAC_OSX_KLUDGE=1', '' ); - $this->replace_file_contents( + FileSystem::replaceFileStr( $this->source_dir . '/src/osdep/unix/Makefile', - '-lcrypto -lz', + '-lcrypto -lz -lpam', '-lcrypto' ); - $this->replace_file_contents( + FileSystem::replaceFileStr( $this->source_dir . '/src/osdep/unix/Makefile', '-lcrypto', - '-lcrypto -lz' + '-lcrypto -lz -lpam' ); - $this->replace_file_contents( + FileSystem::replaceFileStr( $this->source_dir . '/src/osdep/unix/ssl_unix.c', "#include \n#include ", "#include \n#include " ); // https://salsa.debian.org/holmgren/uw-imap/raw/master/debian/patches/2014_openssl1.1.1_sni.patch // this was not applied in the github source yet - $this->replace_file_contents( + FileSystem::replaceFileStr( $this->source_dir . '/src/osdep/unix/ssl_unix.c', <<<'EOL' if (!(stream->con = (SSL *) SSL_new (stream->context))) @@ -80,24 +81,14 @@ protected function build(): void shell()->cd($this->source_dir) ->exec('touch ip6') ->exec( - "{$this->builder->configure_env} make {$platform}" . - ($this->builder->getLib('openssl') === null ? ' SSLTYPE=none' : '') + "{$this->builder->configure_env} make {$platform} " . + 'EXTRACFLAGS="-fPIC" ' . + ($this->builder->getLib('openssl') === null ? ' SSLTYPE=none' : 'SPECIALAUTHENTICATORS=ssl SSLTYPE=unix') ); shell() ->exec("cp -rf {$this->source_dir}/c-client/c-client.a " . BUILD_LIB_PATH . '/libc-client.a') - ->exec("cp -rf {$this->source_dir}/c-client/*.h " . BUILD_INCLUDE_PATH) - ->exec("cp -rf {$this->source_dir}/src/osdep/unix/*.h " . BUILD_INCLUDE_PATH); - } - - private function replace_file_contents(string|array $filepath, string $old, string $new): void - { - if (is_string($filepath)) { - $filepath = [$filepath]; - } - foreach ($filepath as $path) { - $str = file_get_contents($path); - $str = str_replace($old, $new, $str); - file_put_contents($path, $str); - } + ->exec("cp -rf {$this->source_dir}/c-client/*.c " . BUILD_LIB_PATH . '/') + ->exec("cp -rf {$this->source_dir}/c-client/*.h " . BUILD_INCLUDE_PATH . '/') + ->exec("cp -rf {$this->source_dir}/src/osdep/unix/*.h " . BUILD_INCLUDE_PATH . '/'); } } From f8cbb79d368c5f99b88cff72a16e5d782f5d87a7 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 28 Sep 2023 17:02:06 +0200 Subject: [PATCH 03/58] add libpam (can't compile with musl yet) --- config/ext.json | 3 ++- config/lib.json | 6 ++++++ config/source.json | 8 ++++++++ src/SPC/builder/linux/library/libpam.php | 12 ++++++++++++ src/SPC/builder/macos/library/libpam.php | 12 ++++++++++++ src/SPC/builder/unix/library/libpam.php | 21 +++++++++++++++++++++ 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/SPC/builder/linux/library/libpam.php create mode 100644 src/SPC/builder/macos/library/libpam.php create mode 100644 src/SPC/builder/unix/library/libpam.php diff --git a/config/ext.json b/config/ext.json index 8a202b359..3168d4518 100644 --- a/config/ext.json +++ b/config/ext.json @@ -134,7 +134,8 @@ "type": "builtin", "arg-type": "custom", "lib-depends": [ - "imap" + "imap", + "libpam" ], "lib-suggests": [ "kerberos", diff --git a/config/lib.json b/config/lib.json index 3e6996a28..222bbf742 100644 --- a/config/lib.json +++ b/config/lib.json @@ -145,6 +145,12 @@ "libc-client.a" ] }, + "libpam": { + "source": "libpam", + "static-libs-unix": [ + "libpam.a" + ] + }, "libavif": { "source": "libavif", "static-libs-unix": [ diff --git a/config/source.json b/config/source.json index f2790e980..1940681e0 100644 --- a/config/source.json +++ b/config/source.json @@ -162,6 +162,14 @@ "path": "LICENSE" } }, + "libpam": { + "type": "ghtar", + "repo": "linux-pam/linux-pam", + "license": { + "type": "file", + "path": "Copyright" + } + }, "libavif": { "type": "ghtar", "repo": "AOMediaCodec/libavif", diff --git a/src/SPC/builder/linux/library/libpam.php b/src/SPC/builder/linux/library/libpam.php new file mode 100644 index 000000000..5f5bfe3e5 --- /dev/null +++ b/src/SPC/builder/linux/library/libpam.php @@ -0,0 +1,12 @@ +cd($this->source_dir) + ->exec("{$this->builder->configure_env} ./configure --enable-static --disable-shared " . + ($this->builder->getLib('openssl') ? '-enable-openssl=' . BUILD_ROOT_PATH . ' ' : '') . + '--disable-prelude --disable-audit --enable-db=no --disable-nis --disable-selinux ' . + "--disable-econf --disable-nls --disable-rpath --disable-pie --disable-doc --prefix={$root}") + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + } +} From ab7d33e696b0e0c0203ecdac8652e1db08aff0fd Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 28 Sep 2023 19:47:25 +0200 Subject: [PATCH 04/58] compiling libpam with gcc, patching imap libs in php-src/configure --- config/lib.json | 8 +++++- config/source.json | 2 +- src/SPC/builder/extension/imap.php | 17 ++++++++++++ src/SPC/builder/unix/library/imap.php | 32 ++++++++++++++++++---- src/SPC/builder/unix/library/libpam.php | 8 ++++-- src/SPC/doctor/item/LinuxToolCheckList.php | 11 ++++++++ 6 files changed, 68 insertions(+), 10 deletions(-) diff --git a/config/lib.json b/config/lib.json index 222bbf742..85f452fc1 100644 --- a/config/lib.json +++ b/config/lib.json @@ -140,15 +140,21 @@ ] }, "imap": { - "source": "uwimap", + "source": "imap", "static-libs-unix": [ "libc-client.a" + ], + "lib-requires": [ + "libpam" ] }, "libpam": { "source": "libpam", "static-libs-unix": [ "libpam.a" + ], + "lib-suggests": [ + "openssl" ] }, "libavif": { diff --git a/config/source.json b/config/source.json index 1940681e0..daebb7854 100644 --- a/config/source.json +++ b/config/source.json @@ -153,7 +153,7 @@ "path": "LICENSE" } }, - "uwimap": { + "imap": { "type": "git", "url": "https://github.com/uw-imap/imap.git", "rev": "master", diff --git a/src/SPC/builder/extension/imap.php b/src/SPC/builder/extension/imap.php index eb1cd7f66..de518fd66 100644 --- a/src/SPC/builder/extension/imap.php +++ b/src/SPC/builder/extension/imap.php @@ -5,6 +5,9 @@ namespace SPC\builder\extension; use SPC\builder\Extension; +use SPC\exception\FileSystemException; +use SPC\exception\WrongUsageException; +use SPC\store\FileSystem; use SPC\util\CustomExt; #[CustomExt('imap')] @@ -18,4 +21,18 @@ public function getUnixConfigureArg(): string } return $arg; } + + /** + * @throws FileSystemException + * @throws WrongUsageException + */ + public function patchBeforeConfigure(): bool + { + FileSystem::replaceFileStr( + SOURCE_PATH . '/php-src/configure', + 'DLIBS="-l$IMAP_LIB $DLIBS"', + 'DLIBS="-l$IMAP_LIB $DLIBS -lpam"' + ); + return true; + } } diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index 3c508498a..02517771c 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -83,12 +83,34 @@ protected function build(): void ->exec( "{$this->builder->configure_env} make {$platform} " . 'EXTRACFLAGS="-fPIC" ' . - ($this->builder->getLib('openssl') === null ? ' SSLTYPE=none' : 'SPECIALAUTHENTICATORS=ssl SSLTYPE=unix') + ($this->builder->getLib('openssl') === null ? ' SSLTYPE=none' : 'SPECIALAUTHENTICATORS=ssl SSLTYPE=unix.nopwd') ); + // todo: answer this with y automatically. using SSLTYPE=nopwd creates imap WITH ssl... + try { + shell() + ->exec("cp -rf {$this->source_dir}/c-client/c-client.a " . BUILD_LIB_PATH . '/libc-client.a') + ->exec("cp -rf {$this->source_dir}/c-client/*.c " . BUILD_LIB_PATH . '/') + ->exec("cp -rf {$this->source_dir}/c-client/*.h " . BUILD_INCLUDE_PATH . '/') + ->exec("cp -rf {$this->source_dir}/src/osdep/unix/*.h " . BUILD_INCLUDE_PATH . '/'); // throws an exception, no idea why since it works + } catch (\Throwable) { + } + shell() - ->exec("cp -rf {$this->source_dir}/c-client/c-client.a " . BUILD_LIB_PATH . '/libc-client.a') - ->exec("cp -rf {$this->source_dir}/c-client/*.c " . BUILD_LIB_PATH . '/') - ->exec("cp -rf {$this->source_dir}/c-client/*.h " . BUILD_INCLUDE_PATH . '/') - ->exec("cp -rf {$this->source_dir}/src/osdep/unix/*.h " . BUILD_INCLUDE_PATH . '/'); + ->exec( + 'echo \'prefix=/opt/static-php-cli/buildroot +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: UW-IMAP +Description: Imap server implementation by University of Washington +Version: 2007f + +Requires: +Libs: -L${libdir} -lc-client -pam +Libs.private: -lpam +Cflags: -I${includedir} +\' > ' . BUILD_LIB_PATH . '/pkgconfig/libc-client.pc' + ); + $this->patchPkgconfPrefix(['libc-client.pc']); } } diff --git a/src/SPC/builder/unix/library/libpam.php b/src/SPC/builder/unix/library/libpam.php index 79c92dd93..cbb3d4092 100644 --- a/src/SPC/builder/unix/library/libpam.php +++ b/src/SPC/builder/unix/library/libpam.php @@ -8,14 +8,16 @@ trait libpam { protected function build(): void { - $root = BUILD_ROOT_PATH; + $config_env = str_replace("CC='musl-gcc'", '', $this->builder->configure_env); shell()->cd($this->source_dir) - ->exec("{$this->builder->configure_env} ./configure --enable-static --disable-shared " . + ->exec('./autogen.sh') + ->exec("{$config_env} ./configure --enable-static --disable-shared " . ($this->builder->getLib('openssl') ? '-enable-openssl=' . BUILD_ROOT_PATH . ' ' : '') . '--disable-prelude --disable-audit --enable-db=no --disable-nis --disable-selinux ' . - "--disable-econf --disable-nls --disable-rpath --disable-pie --disable-doc --prefix={$root}") + '--disable-econf --disable-nls --disable-rpath --disable-pie --disable-doc --prefix=') ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + $this->patchPkgconfPrefix(['pam.pc', 'pam_misc.pc', 'pamc.pc']); } } diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 557ba3dfd..b1f45b98d 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -31,6 +31,17 @@ class LinuxToolCheckList 'xz', ]; + // todo: require those + public const PAM_TOOLS_DEBIAN = [ + 'autoconf', 'automake', 'autopoint', + 'bison', 'bzip2', 'docbook5-xml', + 'docbook-xsl-ns', 'flex', 'gettext', + 'libaudit-dev', 'libdb-dev', 'libfl-dev', + 'libselinux1-dev', 'libssl-dev', 'libtool', + 'libxml2-utils', 'make', 'pkg-config', + 'sed', 'w3m', 'xsltproc', 'xz-utils', + ]; + /** @noinspection PhpUnused */ #[AsCheckItem('if necessary tools are installed', limit_os: 'Linux')] public function checkCliTools(): ?CheckResult From dd9e27df017755459201904184a1c9743a719807 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 29 Sep 2023 14:06:38 +0200 Subject: [PATCH 05/58] fix compilation with openssl --- config/ext.json | 4 ++-- config/lib.json | 3 --- src/SPC/builder/extension/imap.php | 17 ----------------- src/SPC/builder/unix/library/imap.php | 12 +++++++----- src/SPC/builder/unix/library/postgresql.php | 2 +- 5 files changed, 10 insertions(+), 28 deletions(-) diff --git a/config/ext.json b/config/ext.json index 3168d4518..85a616eff 100644 --- a/config/ext.json +++ b/config/ext.json @@ -134,11 +134,11 @@ "type": "builtin", "arg-type": "custom", "lib-depends": [ - "imap", - "libpam" + "imap" ], "lib-suggests": [ "kerberos", + "libpam", "openssl" ] }, diff --git a/config/lib.json b/config/lib.json index 85f452fc1..afdf8e5ee 100644 --- a/config/lib.json +++ b/config/lib.json @@ -143,9 +143,6 @@ "source": "imap", "static-libs-unix": [ "libc-client.a" - ], - "lib-requires": [ - "libpam" ] }, "libpam": { diff --git a/src/SPC/builder/extension/imap.php b/src/SPC/builder/extension/imap.php index de518fd66..eb1cd7f66 100644 --- a/src/SPC/builder/extension/imap.php +++ b/src/SPC/builder/extension/imap.php @@ -5,9 +5,6 @@ namespace SPC\builder\extension; use SPC\builder\Extension; -use SPC\exception\FileSystemException; -use SPC\exception\WrongUsageException; -use SPC\store\FileSystem; use SPC\util\CustomExt; #[CustomExt('imap')] @@ -21,18 +18,4 @@ public function getUnixConfigureArg(): string } return $arg; } - - /** - * @throws FileSystemException - * @throws WrongUsageException - */ - public function patchBeforeConfigure(): bool - { - FileSystem::replaceFileStr( - SOURCE_PATH . '/php-src/configure', - 'DLIBS="-l$IMAP_LIB $DLIBS"', - 'DLIBS="-l$IMAP_LIB $DLIBS -lpam"' - ); - return true; - } } diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index 02517771c..4ac1ce474 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -77,13 +77,16 @@ protected function build(): void EOL ); } - $platform = 'lr5'; shell()->cd($this->source_dir) ->exec('touch ip6') ->exec( - "{$this->builder->configure_env} make {$platform} " . + "{$this->builder->configure_env} make slx " . 'EXTRACFLAGS="-fPIC" ' . - ($this->builder->getLib('openssl') === null ? ' SSLTYPE=none' : 'SPECIALAUTHENTICATORS=ssl SSLTYPE=unix.nopwd') + ( + $this->builder->getLib('openssl') === null ? + 'SSLTYPE=none' : + 'SPECIALAUTHENTICATORS=ssl SSLTYPE=unix.nopwd SSLINCLUDE=' . BUILD_INCLUDE_PATH + ) ); // todo: answer this with y automatically. using SSLTYPE=nopwd creates imap WITH ssl... try { @@ -106,8 +109,7 @@ protected function build(): void Version: 2007f Requires: -Libs: -L${libdir} -lc-client -pam -Libs.private: -lpam +Libs: -L${libdir} -lc-client Cflags: -I${includedir} \' > ' . BUILD_LIB_PATH . '/pkgconfig/libc-client.pc' ); diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index b2fa4b27c..ae55844df 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -64,7 +64,7 @@ protected function build(): void '--without-zstd ' . '--without-perl ' . '--without-python ' . - '--without-pam ' . + ($this->builder->getLib('pam') ? '--with-pam ' : '--without-pam ') . '--without-ldap ' . '--without-bonjour ' . '--without-tcl ' From 359f53f4561a8a255c86241f8090b95da39e7510 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 29 Sep 2023 14:30:07 +0200 Subject: [PATCH 06/58] remove unnecessary space --- src/SPC/builder/unix/library/imap.php | 39 ++++----------------- src/SPC/builder/unix/library/postgresql.php | 2 +- src/SPC/doctor/item/LinuxToolCheckList.php | 9 +++++ 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index 4ac1ce474..b1898bab2 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -8,6 +8,7 @@ use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\FileSystem; +use function Safe\xdiff_file_patch_binary; trait imap { @@ -23,16 +24,6 @@ protected function build(): void // return; // } if ($this->builder->getLib('openssl') !== null) { - FileSystem::replaceFileStr( - $this->source_dir . '/Makefile', - 'SSLINCLUDE=/usr/include/openssl', - 'SSLINCLUDE=' . BUILD_INCLUDE_PATH - ); - FileSystem::replaceFileStr( - $this->source_dir . '/Makefile', - 'SSLLIB=/usr/lib', - 'SSLLIB=' . BUILD_LIB_PATH - ); FileSystem::replaceFileStr( $this->source_dir . '/Makefile', '"-DMAC_OSX_KLUDGE=1', @@ -40,13 +31,13 @@ protected function build(): void ); FileSystem::replaceFileStr( $this->source_dir . '/src/osdep/unix/Makefile', - '-lcrypto -lz -lpam', + '-lcrypto -lz', '-lcrypto' ); FileSystem::replaceFileStr( $this->source_dir . '/src/osdep/unix/Makefile', '-lcrypto', - '-lcrypto -lz -lpam' + '-lcrypto -lz' ); FileSystem::replaceFileStr( $this->source_dir . '/src/osdep/unix/ssl_unix.c', @@ -73,7 +64,7 @@ protected function build(): void SSL_set_tlsext_host_name(stream->con,host); } #endif - bio = BIO_new_socket (stream->tcpstream->tcpsi,BIO_NOCLOSE);" + bio = BIO_new_socket (stream->tcpstream->tcpsi,BIO_NOCLOSE); EOL ); } @@ -85,7 +76,7 @@ protected function build(): void ( $this->builder->getLib('openssl') === null ? 'SSLTYPE=none' : - 'SPECIALAUTHENTICATORS=ssl SSLTYPE=unix.nopwd SSLINCLUDE=' . BUILD_INCLUDE_PATH + 'SPECIALAUTHENTICATORS=ssl SSLTYPE=unix.nopwd SSLINCLUDE=' . BUILD_INCLUDE_PATH . ' SSLLIB=' . BUILD_LIB_PATH ) ); // todo: answer this with y automatically. using SSLTYPE=nopwd creates imap WITH ssl... @@ -94,25 +85,9 @@ protected function build(): void ->exec("cp -rf {$this->source_dir}/c-client/c-client.a " . BUILD_LIB_PATH . '/libc-client.a') ->exec("cp -rf {$this->source_dir}/c-client/*.c " . BUILD_LIB_PATH . '/') ->exec("cp -rf {$this->source_dir}/c-client/*.h " . BUILD_INCLUDE_PATH . '/') - ->exec("cp -rf {$this->source_dir}/src/osdep/unix/*.h " . BUILD_INCLUDE_PATH . '/'); // throws an exception, no idea why since it works + ->exec("cp -rf {$this->source_dir}/src/osdep/unix/*.h " . BUILD_INCLUDE_PATH . '/'); } catch (\Throwable) { + // last command throws an exception, no idea why since it works } - - shell() - ->exec( - 'echo \'prefix=/opt/static-php-cli/buildroot -libdir=${prefix}/lib -includedir=${prefix}/include - -Name: UW-IMAP -Description: Imap server implementation by University of Washington -Version: 2007f - -Requires: -Libs: -L${libdir} -lc-client -Cflags: -I${includedir} -\' > ' . BUILD_LIB_PATH . '/pkgconfig/libc-client.pc' - ); - $this->patchPkgconfPrefix(['libc-client.pc']); } } diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index ae55844df..7719459e9 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -20,7 +20,7 @@ protected function build(): void $builddir = BUILD_ROOT_PATH; $env = $this->builder->configure_env; $envs = $env; - $packages = 'openssl zlib readline libxml-2.0'; // icu-uc icu-io icu-i18n libzstd + $packages = 'openssl zlib readline libxml-2.0'; // icu-uc icu-io icu-i18n libzstd $pkgconfig_executable = $builddir . '/bin/pkg-config'; $output = shell()->execWithResult($env . " {$pkgconfig_executable} --cflags-only-I --static " . $packages); diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index b1f45b98d..302b78d4f 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -41,6 +41,15 @@ class LinuxToolCheckList 'libxml2-utils', 'make', 'pkg-config', 'sed', 'w3m', 'xsltproc', 'xz-utils', ]; + + // todo: require those + public const PAM_TOOLS_RHEL = [ + 'autoconf', 'automake', 'bison', + 'bzip2', 'flex', 'make', 'gettext', + 'pkg-config', 'sed', 'w3m', 'xz', + 'libdb-devel', 'libselinux-devel', + 'openssl-devel', 'libtool', 'libxml2', + 'docbook-xsl-ns', 'libxslt' ]; /** @noinspection PhpUnused */ #[AsCheckItem('if necessary tools are installed', limit_os: 'Linux')] From ce1381ae9725845079727155cfdbdfb408ab1ff1 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 29 Sep 2023 15:54:49 +0200 Subject: [PATCH 07/58] throw error when compiling imap with zts --- src/SPC/builder/unix/library/imap.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index b1898bab2..317044ff4 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -8,7 +8,6 @@ use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\FileSystem; -use function Safe\xdiff_file_patch_binary; trait imap { @@ -19,10 +18,9 @@ trait imap */ protected function build(): void { - // ext-imap is NOT thread safe, do not build with ZTS builds - // if ($this->builder->getOption('enable-zts')) { - // return; - // } + if ($this->builder->getOption('enable-zts')) { + throw new WrongUsageException('ext-imap is not thread safe, do not build it with ZTS builds'); + } if ($this->builder->getLib('openssl') !== null) { FileSystem::replaceFileStr( $this->source_dir . '/Makefile', From 8f9e803eb0a2359cd4210fcc4fcd488306ecf159 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 1 Oct 2023 20:01:23 +0200 Subject: [PATCH 08/58] add comma --- config/source.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/source.json b/config/source.json index a1e349993..83d3b08ef 100644 --- a/config/source.json +++ b/config/source.json @@ -161,7 +161,7 @@ "type": "file", "path": "LICENSE" } - } + }, "ldap": { "type": "filelist", "url": "https://www.openldap.org/software/download/OpenLDAP/openldap-release/", From 4717658cc8fdeecc8418ddb013ba106ffe1df4ad Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 1 Oct 2023 20:36:37 +0200 Subject: [PATCH 09/58] run cs fix --- src/SPC/doctor/item/LinuxToolCheckList.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 4ff16dcca..77566d29a 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -50,15 +50,15 @@ class LinuxToolCheckList 'libxml2-utils', 'make', 'pkg-config', 'sed', 'w3m', 'xsltproc', 'xz-utils', ]; - + // todo: require those public const PAM_TOOLS_RHEL = [ 'autoconf', 'automake', 'bison', 'bzip2', 'flex', 'make', 'gettext', 'pkg-config', 'sed', 'w3m', 'xz', 'libdb-devel', 'libselinux-devel', - 'openssl-devel', 'libtool', 'libxml2', - 'docbook-xsl-ns', 'libxslt' + 'openssl-devel', 'libtool', 'libxml2', + 'docbook-xsl-ns', 'libxslt', ]; /** @noinspection PhpUnused */ From fdd34bbee0cffdb7fc63b53dac0080be9b2387d5 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 3 Oct 2023 15:53:00 +0800 Subject: [PATCH 10/58] add linux OS debug message --- 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 bae677651..30b85fe5e 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -37,7 +37,7 @@ class LinuxBuilder extends BuilderBase public function __construct(array $options = []) { $this->options = $options; - + logger()->debug('Current OS: ' . SystemUtil::getOSRelease()['dist'] . ' ' . SystemUtil::getOSRelease()['ver']); // ---------- set necessary options ---------- // set C Compiler (default: alpine: gcc, others: musl-gcc) $this->setOptionIfNotExist('cc', match (SystemUtil::getOSRelease()['dist']) { From a7814c2a1f7550a430e051ea3c545e84161fbf6d Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 3 Oct 2023 15:53:11 +0800 Subject: [PATCH 11/58] add imap lib suggests --- config/lib.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/lib.json b/config/lib.json index 45521f656..2a3ea31ed 100644 --- a/config/lib.json +++ b/config/lib.json @@ -143,6 +143,9 @@ "source": "imap", "static-libs-unix": [ "libc-client.a" + ], + "lib-suggests": [ + "openssl" ] }, "ldap": { From cb017ff93e783814327dc756dbd11407bc55e542 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 3 Oct 2023 16:37:10 +0800 Subject: [PATCH 12/58] add SoucePatcher::patchFile --- src/SPC/store/SourcePatcher.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 1bbe04761..b0edc3032 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -117,6 +117,30 @@ public static function patchMicro(?array $list = null, bool $reverse = false): b return true; } + /** + * Use existing patch file for patching + * + * @param string $patch_name Patch file name in src/globals/patch/ + * @param string $cwd Working directory for patch command + * @param bool $reverse Reverse patches (default: False) + * @throws RuntimeException + */ + public static function patchFile(string $patch_name, string $cwd, bool $reverse = false): bool + { + if (!file_exists(ROOT_DIR . "/src/globals/patch/{$patch_name}")) { + return false; + } + + $patch_file = ROOT_DIR . "/src/globals/patch/{$patch_name}"; + $patch_str = str_replace('/', DIRECTORY_SEPARATOR, $patch_file); + + f_passthru( + 'cd ' . $cwd . ' && ' . + (PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . $patch_str . ' | patch -p1 ' . ($reverse ? '-R' : '') + ); + return true; + } + /** * @throws FileSystemException */ From 2b9ce4dd0c1278db0914668edc16ba72a92f35aa Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 3 Oct 2023 16:38:22 +0800 Subject: [PATCH 13/58] remove redundant function and adjust patch functions --- src/SPC/builder/LibraryBase.php | 12 ++++-- .../linux/library/LinuxLibraryBase.php | 41 ------------------- 2 files changed, 9 insertions(+), 44 deletions(-) diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index e9d7abd11..bd7752ace 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -4,7 +4,6 @@ namespace SPC\builder; -use SPC\builder\macos\library\MacOSLibraryBase; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; @@ -19,6 +18,8 @@ abstract class LibraryBase protected array $dependencies = []; + protected bool $patched = false; + /** * @throws RuntimeException */ @@ -130,10 +131,15 @@ public function getHeaders(): array */ public function tryBuild(bool $force_build = false): int { + if (file_exists($this->source_dir . '/.spc.patched')) { + $this->patched = true; + } // force means just build if ($force_build) { logger()->info('Building required library [' . static::NAME . ']'); - $this->patchBeforeBuild(); + if (!$this->patched && $this->patchBeforeBuild()) { + file_put_contents($this->source_dir . '/.spc.patched', 'PATCHED!!!'); + } $this->build(); return BUILD_STATUS_OK; } @@ -153,7 +159,7 @@ public function tryBuild(bool $force_build = false): int } } // pkg-config is treated specially. If it is pkg-config, check if the pkg-config binary exists - if ($this instanceof MacOSLibraryBase && static::NAME === 'pkg-config' && !file_exists(BUILD_ROOT_PATH . '/bin/pkg-config')) { + if (static::NAME === 'pkg-config' && !file_exists(BUILD_ROOT_PATH . '/bin/pkg-config')) { $this->tryBuild(true); return BUILD_STATUS_OK; } diff --git a/src/SPC/builder/linux/library/LinuxLibraryBase.php b/src/SPC/builder/linux/library/LinuxLibraryBase.php index 5ec8c7c28..89dc46bd8 100644 --- a/src/SPC/builder/linux/library/LinuxLibraryBase.php +++ b/src/SPC/builder/linux/library/LinuxLibraryBase.php @@ -8,9 +8,6 @@ use SPC\builder\LibraryBase; use SPC\builder\linux\LinuxBuilder; use SPC\builder\traits\UnixLibraryTrait; -use SPC\exception\FileSystemException; -use SPC\exception\RuntimeException; -use SPC\exception\WrongUsageException; abstract class LinuxLibraryBase extends LibraryBase { @@ -37,44 +34,6 @@ public function getBuilder(): BuilderBase return $this->builder; } - /** - * @throws RuntimeException - * @throws FileSystemException - * @throws WrongUsageException - */ - public function tryBuild(bool $force_build = false): int - { - // 传入 true,表明直接编译 - if ($force_build) { - logger()->info('Building required library [' . static::NAME . ']'); - $this->patchBeforeBuild(); - $this->build(); - return BUILD_STATUS_OK; - } - - // 看看这些库是不是存在,如果不存在,则调用编译并返回结果状态 - foreach ($this->getStaticLibs() as $name) { - if (!file_exists(BUILD_LIB_PATH . "/{$name}")) { - $this->tryBuild(true); - return BUILD_STATUS_OK; - } - } - // 头文件同理 - foreach ($this->getHeaders() as $name) { - if (!file_exists(BUILD_INCLUDE_PATH . "/{$name}")) { - $this->tryBuild(true); - return BUILD_STATUS_OK; - } - } - // pkg-config 做特殊处理,如果是 pkg-config 就检查有没有 pkg-config 二进制 - if (static::NAME === 'pkg-config' && !file_exists(BUILD_ROOT_PATH . '/bin/pkg-config')) { - $this->tryBuild(true); - return BUILD_STATUS_OK; - } - // 到这里说明所有的文件都存在,就跳过编译 - return BUILD_STATUS_ALREADY; - } - protected function makeFakePkgconfs(): void { $workspace = BUILD_ROOT_PATH; From 225fa0e2a93143b8a7785a50117d45093436a75e Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 3 Oct 2023 16:39:04 +0800 Subject: [PATCH 14/58] enable `--with-clean` for real --- src/SPC/command/BuildCliCommand.php | 5 +++++ src/SPC/command/BuildCommand.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index 00be75596..db08187fb 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -7,6 +7,7 @@ use SPC\builder\BuilderProvider; use SPC\exception\ExceptionHandler; use SPC\exception\WrongUsageException; +use SPC\store\FileSystem; use SPC\store\SourcePatcher; use SPC\util\DependencyUtil; use SPC\util\LicenseDumper; @@ -70,6 +71,10 @@ public function handle(): int logger()->warning('some extensions will be enabled due to dependencies: ' . implode(',', $not_included)); } sleep(2); + if ($this->input->getOption('with-clean')) { + logger()->info('Cleaning source dir...'); + FileSystem::removeDir(SOURCE_PATH); + } // compile libraries $builder->buildLibs($libraries); // check extensions diff --git a/src/SPC/command/BuildCommand.php b/src/SPC/command/BuildCommand.php index 8a7211892..98bb77b3a 100644 --- a/src/SPC/command/BuildCommand.php +++ b/src/SPC/command/BuildCommand.php @@ -28,7 +28,7 @@ public function __construct(string $name = null) break; } - $this->addOption('with-clean', null, null, 'fresh build, `make clean` before `make`'); + $this->addOption('with-clean', null, null, 'fresh build, remove `source` dir before `make`'); $this->addOption('bloat', null, null, 'add all libraries into binary'); } } From c2715e8933b03e3037a0155be0283190d273c8bb Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 3 Oct 2023 16:39:55 +0800 Subject: [PATCH 15/58] change imap-openssl patches --- src/SPC/builder/unix/library/imap.php | 72 +++++++------------ .../patch/1006_openssl1.1_autoverify.patch | 58 +++++++++++++++ src/globals/patch/2014_openssl1.1.1_sni.patch | 42 +++++++++++ 3 files changed, 124 insertions(+), 48 deletions(-) create mode 100644 src/globals/patch/1006_openssl1.1_autoverify.patch create mode 100644 src/globals/patch/2014_openssl1.1.1_sni.patch diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index 317044ff4..a29adcaa6 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -8,9 +8,30 @@ use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\FileSystem; +use SPC\store\SourcePatcher; trait imap { + public function patchBeforeBuild(): bool + { + if ($this->builder->getLib('openssl')) { + FileSystem::replaceFileStr($this->source_dir . '/Makefile', '-DMAC_OSX_KLUDGE=1', ''); + FileSystem::replaceFileStr($this->source_dir . '/src/osdep/unix/Makefile', '-lcrypto -lz', '-lcrypto'); + FileSystem::replaceFileStr($this->source_dir . '/src/osdep/unix/Makefile', '-lcrypto', '-lcrypto -lz'); + FileSystem::replaceFileStr( + $this->source_dir . '/src/osdep/unix/ssl_unix.c', + "#include \n#include ", + "#include \n#include " + ); + SourcePatcher::patchFile('1007_openssl1.1_autoverify.patch', $this->source_dir); + SourcePatcher::patchFile('2014_openssl1.1.1_sni.patch', $this->source_dir); + FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'SSLINCLUDE=/usr/include/openssl', 'SSLINCLUDE=' . BUILD_INCLUDE_PATH . '/openssl'); + FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'SSLINCLUDE=/usr/lib', 'SSLINCLUDE=' . BUILD_LIB_PATH); + return true; + } + return false; + } + /** * @throws FileSystemException * @throws RuntimeException @@ -21,60 +42,15 @@ protected function build(): void if ($this->builder->getOption('enable-zts')) { throw new WrongUsageException('ext-imap is not thread safe, do not build it with ZTS builds'); } - if ($this->builder->getLib('openssl') !== null) { - FileSystem::replaceFileStr( - $this->source_dir . '/Makefile', - '"-DMAC_OSX_KLUDGE=1', - '' - ); - FileSystem::replaceFileStr( - $this->source_dir . '/src/osdep/unix/Makefile', - '-lcrypto -lz', - '-lcrypto' - ); - FileSystem::replaceFileStr( - $this->source_dir . '/src/osdep/unix/Makefile', - '-lcrypto', - '-lcrypto -lz' - ); - FileSystem::replaceFileStr( - $this->source_dir . '/src/osdep/unix/ssl_unix.c', - "#include \n#include ", - "#include \n#include " - ); - // https://salsa.debian.org/holmgren/uw-imap/raw/master/debian/patches/2014_openssl1.1.1_sni.patch - // this was not applied in the github source yet - FileSystem::replaceFileStr( - $this->source_dir . '/src/osdep/unix/ssl_unix.c', - <<<'EOL' -if (!(stream->con = (SSL *) SSL_new (stream->context))) - return "SSL connection failed"; - bio = BIO_new_socket (stream->tcpstream->tcpsi,BIO_NOCLOSE); -EOL, - <<<'EOL' -if (!(stream->con = (SSL *) SSL_new (stream->context))) - return "SSL connection failed"; -#if OPENSSL_VERSION_NUMBER >= 0x10101000 - /* Use SNI in case server requires it with TLSv1.3. - * Literal IP addresses not permitted per RFC 6066. */ - if (!a2i_IPADDRESS(host)) { - ERR_clear_error(); - SSL_set_tlsext_host_name(stream->con,host); - } -#endif - bio = BIO_new_socket (stream->tcpstream->tcpsi,BIO_NOCLOSE); -EOL - ); - } shell()->cd($this->source_dir) ->exec('touch ip6') ->exec( "{$this->builder->configure_env} make slx " . 'EXTRACFLAGS="-fPIC" ' . ( - $this->builder->getLib('openssl') === null ? - 'SSLTYPE=none' : - 'SPECIALAUTHENTICATORS=ssl SSLTYPE=unix.nopwd SSLINCLUDE=' . BUILD_INCLUDE_PATH . ' SSLLIB=' . BUILD_LIB_PATH + $this->builder->getLib('openssl') ? + ('SPECIALAUTHENTICATORS=ssl SSLTYPE=unix.nopwd SSLINCLUDE=' . BUILD_INCLUDE_PATH . ' SSLLIB=' . BUILD_LIB_PATH) + : 'SSLTYPE=none' ) ); // todo: answer this with y automatically. using SSLTYPE=nopwd creates imap WITH ssl... diff --git a/src/globals/patch/1006_openssl1.1_autoverify.patch b/src/globals/patch/1006_openssl1.1_autoverify.patch new file mode 100644 index 000000000..087e747d5 --- /dev/null +++ b/src/globals/patch/1006_openssl1.1_autoverify.patch @@ -0,0 +1,58 @@ +Description: Support OpenSSL 1.1 + When building with OpenSSL 1.1 and newer, use the new built-in + hostname verification instead of code that doesn't compile due to + structs having been made opaque. +Bug-Debian: https://bugs.debian.org/828589 + +--- a/src/osdep/unix/ssl_unix.c ++++ b/src/osdep/unix/ssl_unix.c +@@ -227,8 +227,16 @@ static char *ssl_start_work (SSLSTREAM * + /* disable certificate validation? */ + if (flags & NET_NOVALIDATECERT) + SSL_CTX_set_verify (stream->context,SSL_VERIFY_NONE,NIL); +- else SSL_CTX_set_verify (stream->context,SSL_VERIFY_PEER,ssl_open_verify); ++ else { ++#if OPENSSL_VERSION_NUMBER >= 0x10100000 ++ X509_VERIFY_PARAM *param = SSL_CTX_get0_param(stream->context); ++ X509_VERIFY_PARAM_set_hostflags(param, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); ++ X509_VERIFY_PARAM_set1_host(param, host, 0); ++#endif ++ ++ SSL_CTX_set_verify (stream->context,SSL_VERIFY_PEER,ssl_open_verify); + /* set default paths to CAs... */ ++ } + SSL_CTX_set_default_verify_paths (stream->context); + /* ...unless a non-standard path desired */ + if (s = (char *) mail_parameters (NIL,GET_SSLCAPATH,NIL)) +@@ -266,6 +274,7 @@ static char *ssl_start_work (SSLSTREAM * + if (SSL_write (stream->con,"",0) < 0) + return ssl_last_error ? ssl_last_error : "SSL negotiation failed"; + /* need to validate host names? */ ++#if OPENSSL_VERSION_NUMBER < 0x10100000 + if (!(flags & NET_NOVALIDATECERT) && + (err = ssl_validate_cert (cert = SSL_get_peer_certificate (stream->con), + host))) { +@@ -275,6 +284,7 @@ static char *ssl_start_work (SSLSTREAM * + sprintf (tmp,"*%.128s: %.255s",err,cert ? cert->name : "???"); + return ssl_last_error = cpystr (tmp); + } ++#endif + return NIL; + } + +@@ -313,6 +323,7 @@ static int ssl_open_verify (int ok,X509_ + * Returns: NIL if validated, else string of error message + */ + ++#if OPENSSL_VERSION_NUMBER < 0x10100000 + static char *ssl_validate_cert (X509 *cert,char *host) + { + int i,n; +@@ -342,6 +353,7 @@ static char *ssl_validate_cert (X509 *ce + else ret = "Unable to locate common name in certificate"; + return ret; + } ++#endif + + /* Case-independent wildcard pattern match + * Accepts: base string diff --git a/src/globals/patch/2014_openssl1.1.1_sni.patch b/src/globals/patch/2014_openssl1.1.1_sni.patch new file mode 100644 index 000000000..0d753dd32 --- /dev/null +++ b/src/globals/patch/2014_openssl1.1.1_sni.patch @@ -0,0 +1,42 @@ +Bug-Debian: https://bugs.debian.org/916041 +Bug-Ubuntu: https://bugs.launchpad.net/bugs/1834340 +Description: + Google IMAP servers require SNI if TLSv1.3 is used, + otherwise it sends a self-signed certificate which + fails validation. + + OpenSSL support/versions: + - TLSv1.3 on 1.1.1, + - a2i_IPADDRESS() on 0.9.8'ish, + - SSL_set_tlsext_host_name() on 0.9.8'ish/1.0.0; + per 'git blame/describe' and the CHANGES file. + + So check for TLSv1.3 support / OpenSSL 1.1.1 + not to incur behavior changes on pre-TLSv1.3, + and set host_name to 'host' (ssl_open_verify() + validates this, via 'ssl_last_host' variable) + + This patch just combines these two patches: + - BTS#916041 (message #5) by Ed Spiridonov, + - LP#1834340 (comment #6) by David Zuelke. +Author: Mauricio Faria de Oliveira + +Index: uw-imap-2007f~dfsg/src/osdep/unix/ssl_unix.c +=================================================================== +--- uw-imap-2007f~dfsg.orig/src/osdep/unix/ssl_unix.c ++++ uw-imap-2007f~dfsg/src/osdep/unix/ssl_unix.c +@@ -266,6 +266,14 @@ static char *ssl_start_work (SSLSTREAM * + /* create connection */ + if (!(stream->con = (SSL *) SSL_new (stream->context))) + return "SSL connection failed"; ++#if OPENSSL_VERSION_NUMBER >= 0x10101000 ++ /* Use SNI in case server requires it with TLSv1.3. ++ * Literal IP addresses not permitted per RFC 6066. */ ++ if (!a2i_IPADDRESS(host)) { ++ ERR_clear_error(); ++ SSL_set_tlsext_host_name(stream->con,host); ++ } ++#endif + bio = BIO_new_socket (stream->tcpstream->tcpsi,BIO_NOCLOSE); + SSL_set_bio (stream->con,bio,bio); + SSL_set_connect_state (stream->con); From 3b1e2b9892fa429fa7fa4799424e1324bc670cc2 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 3 Oct 2023 13:44:05 +0200 Subject: [PATCH 16/58] fix imap on debian systems --- src/SPC/builder/extension/imap.php | 17 +++++++++++++++++ src/SPC/builder/unix/library/imap.php | 13 ++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/extension/imap.php b/src/SPC/builder/extension/imap.php index eb1cd7f66..314236417 100644 --- a/src/SPC/builder/extension/imap.php +++ b/src/SPC/builder/extension/imap.php @@ -5,6 +5,8 @@ namespace SPC\builder\extension; use SPC\builder\Extension; +use SPC\exception\FileSystemException; +use SPC\store\FileSystem; use SPC\util\CustomExt; #[CustomExt('imap')] @@ -18,4 +20,19 @@ public function getUnixConfigureArg(): string } return $arg; } + + /** + * @throws FileSystemException + */ + public function patchBeforeConfigure(): bool + { + if (!$this->builder->getLib('libpam')) { + return true; + } + return (bool) FileSystem::replaceFileStr( + SOURCE_PATH . '/php-src/configure', + 'DLIBS="-l$IMAP_LIB $DLIBS"', + 'DLIBS="-l$IMAP_LIB $DLIBS -lpam"' + ); + } } diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index a29adcaa6..90a499631 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -4,6 +4,7 @@ namespace SPC\builder\unix\library; +use SPC\builder\linux\SystemUtil; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; @@ -42,10 +43,20 @@ protected function build(): void if ($this->builder->getOption('enable-zts')) { throw new WrongUsageException('ext-imap is not thread safe, do not build it with ZTS builds'); } + $distro = match (SystemUtil::getOSRelease()['distro']) { + 'centos' => 'slx', + 'almalinux' => 'slx', + 'rhel' => 'slx', + 'alpine' => 'slx', + default => 'ldb' + }; + if ($distro === 'ldb' && !$this->builder->getLib('libpam')) { + throw new WrongUsageException('ext-imap built on your system requires libpam, please build with --with-libs=libpam'); + } shell()->cd($this->source_dir) ->exec('touch ip6') ->exec( - "{$this->builder->configure_env} make slx " . + "{$this->builder->configure_env} make {$distro} " . 'EXTRACFLAGS="-fPIC" ' . ( $this->builder->getLib('openssl') ? From b93a568c2d63fbe46f2675a5d5b49e9dface06fa Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 3 Oct 2023 14:02:50 +0200 Subject: [PATCH 17/58] fix distro detection to properly detect any redhat distro --- src/SPC/builder/linux/SystemUtil.php | 26 +++++++++++----------- src/SPC/builder/unix/library/imap.php | 5 +---- src/SPC/doctor/item/LinuxMuslCheck.php | 5 ++--- src/SPC/doctor/item/LinuxToolCheckList.php | 17 ++++++-------- 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index bb3cb7d5b..ddecc6e0c 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -20,6 +20,19 @@ public static function getOSRelease(): array 'ver' => 'unknown', ]; switch (true) { + case file_exists('/etc/centos-release'): + $lines = file('/etc/centos-release'); + goto rh; + case file_exists('/etc/redhat-release'): + $lines = file('/etc/redhat-release'); + rh: + foreach ($lines as $line) { + if (preg_match('/release\s+(\d*(\.\d+)*)/', $line, $matches)) { + $ret['dist'] = 'redhat'; + $ret['ver'] = $matches[1]; + } + } + break; case file_exists('/etc/os-release'): $lines = file('/etc/os-release'); foreach ($lines as $line) { @@ -36,19 +49,6 @@ public static function getOSRelease(): array $ret['dist'] = 'redhat'; } break; - case file_exists('/etc/centos-release'): - $lines = file('/etc/centos-release'); - goto rh; - case file_exists('/etc/redhat-release'): - $lines = file('/etc/redhat-release'); - rh: - foreach ($lines as $line) { - if (preg_match('/release\s+(\d+(\.\d+)*)/', $line, $matches)) { - $ret['dist'] = 'redhat'; - $ret['ver'] = $matches[1]; - } - } - break; } return $ret; } diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index 90a499631..b5c3ef8b4 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -44,10 +44,7 @@ protected function build(): void throw new WrongUsageException('ext-imap is not thread safe, do not build it with ZTS builds'); } $distro = match (SystemUtil::getOSRelease()['distro']) { - 'centos' => 'slx', - 'almalinux' => 'slx', - 'rhel' => 'slx', - 'alpine' => 'slx', + 'redhat', 'alpine' => 'slx', default => 'ldb' }; if ($distro === 'ldb' && !$this->builder->getLib('libpam')) { diff --git a/src/SPC/doctor/item/LinuxMuslCheck.php b/src/SPC/doctor/item/LinuxMuslCheck.php index 3e5cb75a1..bcba4ecc2 100644 --- a/src/SPC/doctor/item/LinuxMuslCheck.php +++ b/src/SPC/doctor/item/LinuxMuslCheck.php @@ -24,7 +24,7 @@ public function checkMusl(): ?CheckResult // non-exist, need to recognize distro $distro = SystemUtil::getOSRelease(); return match ($distro['dist']) { - 'ubuntu', 'alpine', 'debian', 'rhel', 'almalinux' => CheckResult::fail('musl-libc is not installed on your system', 'fix-musl', [$distro]), + 'ubuntu', 'alpine', 'debian', 'redhat' => CheckResult::fail('musl-libc is not installed on your system', 'fix-musl', [$distro]), default => CheckResult::fail('musl-libc is not installed on your system'), }; } @@ -45,8 +45,7 @@ public function fixMusl(array $distro): bool $install_cmd = match ($distro['dist']) { 'ubuntu', 'debian' => 'apt-get install musl musl-tools -y', 'alpine' => 'apk add musl musl-utils musl-dev', - 'rhel' => $rhel_install, - 'almalinux' => $rhel_install, + 'redhat' => $rhel_install, default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'), }; $prefix = ''; diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 77566d29a..74ba77190 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -49,6 +49,7 @@ class LinuxToolCheckList 'libselinux1-dev', 'libssl-dev', 'libtool', 'libxml2-utils', 'make', 'pkg-config', 'sed', 'w3m', 'xsltproc', 'xz-utils', + 'libpam0g-dev', ]; // todo: require those @@ -68,10 +69,9 @@ public function checkCliTools(): ?CheckResult $distro = SystemUtil::getOSRelease(); $required = match ($distro['dist']) { - 'alpine' => self::TOOLS_ALPINE, - 'almalinux' => self::TOOLS_RHEL, - 'rhel' => self::TOOLS_RHEL, - default => self::TOOLS_DEBIAN, + 'alpine' => array_unique(array_merge(self::TOOLS_ALPINE, self::PAM_TOOLS_RHEL)), + 'redhat' => array_unique(array_merge(self::TOOLS_RHEL, self::PAM_TOOLS_RHEL)), + default => array_unique(array_merge(self::TOOLS_DEBIAN, self::PAM_TOOLS_DEBIAN)), }; $missing = []; foreach ($required as $cmd) { @@ -83,8 +83,7 @@ public function checkCliTools(): ?CheckResult return match ($distro['dist']) { 'ubuntu', 'alpine', - 'rhel', - 'almalinux', + 'redhat' . 'debian' => CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', [$distro, $missing]), default => CheckResult::fail(implode(', ', $missing) . ' not installed on your system'), }; @@ -116,8 +115,7 @@ public function fixBuildTools(array $distro, array $missing): bool $install_cmd = match ($distro['dist']) { 'ubuntu', 'debian' => 'apt-get install -y', 'alpine' => 'apk add', - 'rhel' => 'dnf install -y', - 'almalinux' => 'dnf install -y', + 'redhat' => 'dnf install -y', default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'), }; $prefix = ''; @@ -126,8 +124,7 @@ public function fixBuildTools(array $distro, array $missing): bool logger()->warning('Current user is not root, using sudo for running command'); } try { - $is_rhel = in_array($distro['dist'], ['rhel', 'almalinux']); - $to_install = $is_rhel ? $missing : str_replace('xz', 'xz-utils', $missing); + $to_install = $distro['dist'] === 'redhat' ? $missing : str_replace('xz', 'xz-utils', $missing); shell(true)->exec($prefix . $install_cmd . ' ' . implode(' ', $to_install)); } catch (RuntimeException) { return false; From ece3fd98425a1408316245dbcb33cc511a23d846 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 3 Oct 2023 14:10:53 +0200 Subject: [PATCH 18/58] fix auto-fix for rhel --- src/SPC/doctor/item/LinuxToolCheckList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 74ba77190..6ae4b630f 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -83,7 +83,7 @@ public function checkCliTools(): ?CheckResult return match ($distro['dist']) { 'ubuntu', 'alpine', - 'redhat' . + 'redhat', 'debian' => CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', [$distro, $missing]), default => CheckResult::fail(implode(', ', $missing) . ' not installed on your system'), }; From 97744458f1defb58a2983e61218b7120476523b4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 3 Oct 2023 14:50:02 +0200 Subject: [PATCH 19/58] bring in fixes from c++ branch (sslinclude path, ssllib typo) --- src/SPC/builder/extension/imap.php | 7 ++++++- src/SPC/builder/unix/library/imap.php | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/extension/imap.php b/src/SPC/builder/extension/imap.php index 314236417..025e3c87e 100644 --- a/src/SPC/builder/extension/imap.php +++ b/src/SPC/builder/extension/imap.php @@ -27,8 +27,13 @@ public function getUnixConfigureArg(): string public function patchBeforeConfigure(): bool { if (!$this->builder->getLib('libpam')) { - return true; + return false; } + $extra_libs = $this->builder->getOption('extra-libs', ''); + if (!str_contains($extra_libs, 'lpam') && !str_contains($extra_libs, 'libpam.a')) { + $extra_libs .= ' ' . BUILD_LIB_PATH . '/libpam.a'; + } + $this->builder->setOption('extra-libs', $extra_libs); return (bool) FileSystem::replaceFileStr( SOURCE_PATH . '/php-src/configure', 'DLIBS="-l$IMAP_LIB $DLIBS"', diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index b5c3ef8b4..abdea75fe 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -26,8 +26,8 @@ public function patchBeforeBuild(): bool ); SourcePatcher::patchFile('1007_openssl1.1_autoverify.patch', $this->source_dir); SourcePatcher::patchFile('2014_openssl1.1.1_sni.patch', $this->source_dir); - FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'SSLINCLUDE=/usr/include/openssl', 'SSLINCLUDE=' . BUILD_INCLUDE_PATH . '/openssl'); - FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'SSLINCLUDE=/usr/lib', 'SSLINCLUDE=' . BUILD_LIB_PATH); + FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'SSLINCLUDE=/usr/include/openssl', 'SSLINCLUDE=' . BUILD_INCLUDE_PATH); + FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'SSLLIB=/usr/lib', 'SSLLIB=' . BUILD_LIB_PATH); return true; } return false; From 3b659710d2de5019b4f720fc4cb85701fa7ac29a Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 3 Oct 2023 22:35:25 +0200 Subject: [PATCH 20/58] fix -lstdc++ coming first in php-config for embed-sapi, which causes link errors to undefined symbols for libraries after --- src/SPC/builder/linux/LinuxBuilder.php | 6 ++++++ src/SPC/builder/unix/library/imap.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index ddaf490d3..85f898d08 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -228,6 +228,12 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/Makefile', 'OVERALL_TARGET =', 'OVERALL_TARGET = libphp.la'); } $this->buildEmbed($extra_libs, $use_lld); + // php-config puts extra_libs in wrong order, fix it here... + FileSystem::replaceFileRegex( + BUILD_ROOT_PATH . '/bin/php-config', + '/libs="\s*-lstdc\+\+\s+(.*)"/', + 'libs="$1 -lstdc++"' + ); } if (php_uname('m') === $this->getOption('arch')) { diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index abdea75fe..3cd399b97 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -43,7 +43,7 @@ protected function build(): void if ($this->builder->getOption('enable-zts')) { throw new WrongUsageException('ext-imap is not thread safe, do not build it with ZTS builds'); } - $distro = match (SystemUtil::getOSRelease()['distro']) { + $distro = match (SystemUtil::getOSRelease()['dist']) { 'redhat', 'alpine' => 'slx', default => 'ldb' }; From 554986d40e9648d35faccf06f53b64541df09ab5 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 3 Oct 2023 22:44:25 +0200 Subject: [PATCH 21/58] fix openssl requiring zlib extension (require zlib in pkgconfig instead) --- config/ext.json | 4 +--- src/SPC/builder/linux/library/openssl.php | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config/ext.json b/config/ext.json index 35ca3ac63..c90865479 100644 --- a/config/ext.json +++ b/config/ext.json @@ -237,9 +237,7 @@ "type": "builtin", "arg-type": "with", "lib-depends": [ - "openssl" - ], - "ext-depends": [ + "openssl", "zlib" ] }, diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index af3400b60..ac1fff544 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -24,6 +24,7 @@ use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; +use SPC\store\FileSystem; class openssl extends LinuxLibraryBase { @@ -75,6 +76,12 @@ public function build(): void ->exec('make clean') ->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") ->exec("make install_sw DESTDIR={$destdir}"); + + FileSystem::replaceFileStr( + $destdir . '/lib/pkgconfig/openssl.pc', + 'Requires: libssl libcrypto', + 'Requires: libssl libcrypto zlib' + ); $this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); } } From ee966adafbb9153d90e7eb689de0202ce5890c00 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 3 Oct 2023 22:55:08 +0200 Subject: [PATCH 22/58] patch openssl pc for macos too --- src/SPC/builder/linux/library/openssl.php | 6 ++---- src/SPC/builder/macos/library/openssl.php | 13 +++++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index ac1fff544..f49e326cb 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -37,8 +37,6 @@ class openssl extends LinuxLibraryBase */ public function build(): void { - [,,$destdir] = SEPARATED_PATH; - $extra = ''; $ex_lib = '-ldl -pthread'; @@ -75,10 +73,10 @@ public function build(): void ) ->exec('make clean') ->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") - ->exec("make install_sw DESTDIR={$destdir}"); + ->exec('make install_sw DESTDIR=' . BUILD_ROOT_PATH); FileSystem::replaceFileStr( - $destdir . '/lib/pkgconfig/openssl.pc', + BUILD_ROOT_PATH . '/lib/pkgconfig/openssl.pc', 'Requires: libssl libcrypto', 'Requires: libssl libcrypto zlib' ); diff --git a/src/SPC/builder/macos/library/openssl.php b/src/SPC/builder/macos/library/openssl.php index 8ac99b7fd..18612a30c 100644 --- a/src/SPC/builder/macos/library/openssl.php +++ b/src/SPC/builder/macos/library/openssl.php @@ -23,6 +23,7 @@ use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; +use SPC\store\FileSystem; class openssl extends MacOSLibraryBase { @@ -35,8 +36,6 @@ class openssl extends MacOSLibraryBase */ protected function build(): void { - [$lib,,$destdir] = SEPARATED_PATH; - // lib:zlib $extra = ''; $ex_lib = ''; @@ -50,13 +49,19 @@ protected function build(): void ->exec( "{$this->builder->configure_env} ./Configure no-shared {$extra} " . '--prefix=/ ' . // use prefix=/ - "--libdir={$lib} " . + '--libdir=' . BUILD_LIB_PATH . ' ' . '--openssldir=/System/Library/OpenSSL ' . "darwin64-{$this->builder->getOption('arch')}-cc" ) ->exec('make clean') ->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") - ->exec("make install_sw DESTDIR={$destdir}"); + ->exec('make install_sw DESTDIR=' . BUILD_ROOT_PATH); + + FileSystem::replaceFileStr( + BUILD_ROOT_PATH . '/lib/pkgconfig/openssl.pc', + 'Requires: libssl libcrypto', + 'Requires: libssl libcrypto zlib' + ); $this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); } } From f00b60f3402bf27bc5f71d33dfb0b644830f63f7 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 4 Oct 2023 14:57:16 +0200 Subject: [PATCH 23/58] always put lstdc++ last --- src/SPC/builder/linux/LinuxBuilder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 85f898d08..64809f28c 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -231,8 +231,8 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void // php-config puts extra_libs in wrong order, fix it here... FileSystem::replaceFileRegex( BUILD_ROOT_PATH . '/bin/php-config', - '/libs="\s*-lstdc\+\+\s+(.*)"/', - 'libs="$1 -lstdc++"' + '/libs="\s*(.*)\s*-lstdc\+\+\s+(.*)"/', + 'libs="$1 $2 -lstdc++"' ); } From 6d715578906f19ecbf4b43aac73b8df0f7d6c92c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 4 Oct 2023 21:10:57 +0200 Subject: [PATCH 24/58] fix libpam build on musl includes can remove this after https://github.com/linux-pam/linux-pam/commit/5374f677e4cae669eb9accf2449178b602e8a40a is merged fix libzip depending on bzip2 without requiring it --- src/SPC/builder/unix/library/libpam.php | 9 ++++- src/SPC/builder/unix/library/libzip.php | 16 +++++++-- src/SPC/doctor/item/LinuxToolCheckList.php | 2 +- .../patch/linux-pam_musl_termios.patch | 36 +++++++++++++++++++ 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 src/globals/patch/linux-pam_musl_termios.patch diff --git a/src/SPC/builder/unix/library/libpam.php b/src/SPC/builder/unix/library/libpam.php index cbb3d4092..3b0243552 100644 --- a/src/SPC/builder/unix/library/libpam.php +++ b/src/SPC/builder/unix/library/libpam.php @@ -4,8 +4,15 @@ namespace SPC\builder\unix\library; +use SPC\store\SourcePatcher; + trait libpam { + public function patchBeforeBuild(): bool + { + return SourcePatcher::patchFile('linux-pam_musl_termios.patch', $this->source_dir); + } + protected function build(): void { $config_env = str_replace("CC='musl-gcc'", '', $this->builder->configure_env); @@ -14,7 +21,7 @@ protected function build(): void ->exec("{$config_env} ./configure --enable-static --disable-shared " . ($this->builder->getLib('openssl') ? '-enable-openssl=' . BUILD_ROOT_PATH . ' ' : '') . '--disable-prelude --disable-audit --enable-db=no --disable-nis --disable-selinux ' . - '--disable-econf --disable-nls --disable-rpath --disable-pie --disable-doc --prefix=') + '--disable-econf --disable-nls --disable-rpath --disable-pie --disable-doc --disable-examples --prefix=') ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); diff --git a/src/SPC/builder/unix/library/libzip.php b/src/SPC/builder/unix/library/libzip.php index f21678ae5..429151093 100644 --- a/src/SPC/builder/unix/library/libzip.php +++ b/src/SPC/builder/unix/library/libzip.php @@ -29,8 +29,8 @@ protected function build(): void FileSystem::resetDir($this->source_dir . '/build'); shell()->cd($this->source_dir . '/build') ->exec( - "{$this->builder->configure_env} " . ' cmake ' . - "{$this->builder->makeCmakeArgs()} " . + $this->builder->configure_env . ' cmake ' . + $this->builder->makeCmakeArgs() . ' ' . '-DENABLE_GNUTLS=OFF ' . '-DENABLE_MBEDTLS=OFF ' . '-DBUILD_SHARED_LIBS=OFF ' . @@ -43,6 +43,18 @@ protected function build(): void ) ->exec("make -j{$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + $required_libs = '-lzip'; + if ($this->builder->getLib('openssl')) { + $required_libs .= ' -lssl -lcrypto -lz'; + } + if ($this->builder->getLib('bzip2')) { + $required_libs .= ' -lbz2'; + } + FileSystem::replaceFileRegex( + BUILD_LIB_PATH . '/pkgconfig/libzip.pc', + '/Libs: .*/', + 'Libs: -L${libdir} ' . $required_libs + ); $this->patchPkgconfPrefix(['libzip.pc'], PKGCONF_PATCH_PREFIX); } } diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 6ae4b630f..211643b18 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -59,7 +59,7 @@ class LinuxToolCheckList 'pkg-config', 'sed', 'w3m', 'xz', 'libdb-devel', 'libselinux-devel', 'openssl-devel', 'libtool', 'libxml2', - 'docbook-xsl-ns', 'libxslt', + 'docbook-xsl-ns', 'libxslt', 'gettext-autopoint', ]; /** @noinspection PhpUnused */ diff --git a/src/globals/patch/linux-pam_musl_termios.patch b/src/globals/patch/linux-pam_musl_termios.patch new file mode 100644 index 000000000..ac3801a7f --- /dev/null +++ b/src/globals/patch/linux-pam_musl_termios.patch @@ -0,0 +1,36 @@ +From 5374f677e4cae669eb9accf2449178b602e8a40a Mon Sep 17 00:00:00 2001 +From: Violet Purcell +Date: Thu, 11 May 2023 12:50:34 -0400 +Subject: [PATCH] examples/tty_conv: fix build on musl + +termio.h is the old System V version of the interface header, and is +only provided in glibc and dietlibc as far as I can tell. +This fixes it to use the POSIX termios.h instead. +--- + examples/tty_conv.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/examples/tty_conv.c b/examples/tty_conv.c +index 23f0684cc..9a0e1ad99 100644 +--- a/examples/tty_conv.c ++++ b/examples/tty_conv.c +@@ -6,8 +6,9 @@ + #include + #include + #include +-#include ++#include + #include ++#include + + /*************************************** + * @brief echo off/on +@@ -16,7 +17,7 @@ + ***************************************/ + static void echoOff(int fd, int off) + { +- struct termio tty; ++ struct termios tty; + if (ioctl(fd, TCGETA, &tty) < 0) + { + fprintf(stderr, "TCGETA failed: %s\n", strerror(errno)); \ No newline at end of file From 0fb081f750440daf633d7ffacca1ab6279a03f6a Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 4 Oct 2023 22:56:54 +0200 Subject: [PATCH 25/58] add zstd to imagick when it's active fix webp not requiring needed libs --- src/SPC/builder/extension/imagick.php | 8 +++++++- src/SPC/builder/unix/library/imagemagick.php | 4 ++-- src/SPC/builder/unix/library/libwebp.php | 5 +++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 217b7aa9f..311aa946d 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -15,8 +15,14 @@ public function patchBeforeBuildconf(): bool // linux need to link library manually, we add it to extra-libs $extra_libs = $this->builder->getOption('extra-libs', ''); if (!str_contains($extra_libs, 'libMagickCore')) { - $extra_libs .= ' /usr/lib/libMagick++-7.Q16HDRI.a /usr/lib/libMagickCore-7.Q16HDRI.a /usr/lib/libMagickWand-7.Q16HDRI.a'; + $extra_libs .= ' /usr/lib/libMagick++-7.Q16HDRI.a /usr/lib/libMagickCore-7.Q16HDRI.a /usr/lib/libMagickWand-7.Q16HDRI.a '; } + $extra_libs .= $this->builder->getLib('libzip') ? '-lzip ' : ''; + $extra_libs .= $this->builder->getLib('libjpeg') ? '-ljpeg ' : ''; + $extra_libs .= $this->builder->getLib('libpng') ? '-lpng ' : ''; + $extra_libs .= $this->builder->getLib('libwebp') ? '-lwebp ' : ''; + $extra_libs .= $this->builder->getLib('zstd') ? '-lzstd ' : ''; + $extra_libs .= $this->builder->getLib('freetype') ? '-lfreetype ' : ''; $this->builder->setOption('extra-libs', $extra_libs); return true; } diff --git a/src/SPC/builder/unix/library/imagemagick.php b/src/SPC/builder/unix/library/imagemagick.php index f1530b76a..8eeeb6b4a 100644 --- a/src/SPC/builder/unix/library/imagemagick.php +++ b/src/SPC/builder/unix/library/imagemagick.php @@ -16,7 +16,7 @@ trait imagemagick */ protected function build(): void { - $extra = '--without-jxl --without-xml --without-zstd --without-x --disable-openmp '; + $extra = '--without-jxl --without-xml --without-x --disable-openmp '; // libzip support $extra .= $this->builder->getLib('libzip') ? '--with-zip ' : '--without-zip '; // jpeg support @@ -26,7 +26,7 @@ protected function build(): void // webp support $extra .= $this->builder->getLib('libwebp') ? '--with-webp ' : ''; // zstd support - // $extra .= $this->builder->getLib('zstd') ? '--with-zstd ' : '--without-zstd '; + $extra .= $this->builder->getLib('zstd') ? '--with-zstd ' : '--without-zstd '; // freetype support $extra .= $this->builder->getLib('freetype') ? '--with-freetype ' : '--without-freetype '; diff --git a/src/SPC/builder/unix/library/libwebp.php b/src/SPC/builder/unix/library/libwebp.php index 32aa72016..29fb05e93 100644 --- a/src/SPC/builder/unix/library/libwebp.php +++ b/src/SPC/builder/unix/library/libwebp.php @@ -32,6 +32,11 @@ protected function build(): void ->exec("cmake --build . -j {$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); // patch pkgconfig + FileSystem::replaceFileRegex( + BUILD_LIB_PATH . '/pkgconfig/libwebp.pc', + '/Libs: -L\$\{libdir} -lwebp.*/', + 'Libs: -L${libdir} -lwebp -lwebpdecoder -lwebpdemux -lwebpmux' + ); $this->patchPkgconfPrefix(['libsharpyuv.pc', 'libwebp.pc', 'libwebpdecoder.pc', 'libwebpdemux.pc', 'libwebpmux.pc'], PKGCONF_PATCH_PREFIX | PKGCONF_PATCH_LIBDIR); $this->patchPkgconfPrefix(['libsharpyuv.pc'], PKGCONF_PATCH_CUSTOM, ['/^includedir=.*$/m', 'includedir=${prefix}/include/webp']); $this->cleanLaFiles(); From b05115062eb320c25e888ac990cb382154868672 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 1 Oct 2023 20:35:25 +0200 Subject: [PATCH 26/58] add c++ support for linux systems --- composer.json | 1 + src/SPC/builder/linux/LinuxBuilder.php | 13 ++++--- src/SPC/builder/linux/library/icu.php | 3 +- src/SPC/builder/unix/library/ldap.php | 3 +- src/SPC/builder/unix/library/snappy.php | 3 +- src/SPC/command/DownloadCommand.php | 2 +- src/SPC/doctor/item/LinuxMuslCheck.php | 43 ++++++++++++++++------ src/SPC/doctor/item/LinuxToolCheckList.php | 3 +- src/SPC/store/SourceExtractor.php | 2 +- 9 files changed, 49 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index 706f8d646..4a7fedde8 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "php": ">= 8.1", "ext-mbstring": "*", "ext-pcntl": "*", + "ext-zip": "*", "laravel/prompts": "^0.1.3", "symfony/console": "^5.4 || ^6 || ^7", "zhamao/logger": "^1.0" diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 64809f28c..f87215fa3 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -41,12 +41,14 @@ public function __construct(array $options = []) logger()->debug('Current OS: ' . SystemUtil::getOSRelease()['dist'] . ' ' . SystemUtil::getOSRelease()['ver']); // ---------- set necessary options ---------- // set C Compiler (default: alpine: gcc, others: musl-gcc) - $this->setOptionIfNotExist('cc', match (SystemUtil::getOSRelease()['dist']) { - 'alpine' => 'gcc', - default => 'musl-gcc' - }); + $compiler_prefix = match (arch2gnu(php_uname('m'))) { + 'x86_64' => 'x86_64-linux-musl-', + 'aarch64' => 'aarch64-linux-musl-', + }; + $this->setOptionIfNotExist('library_path', '/usr/local/musl/lib:/usr/local/musl/' . substr($compiler_prefix, 0, -1) . '/lib'); + $this->setOptionIfNotExist('cc', "{$compiler_prefix}gcc"); // set C++ Compiler (default: g++) - $this->setOptionIfNotExist('cxx', 'g++'); + $this->setOptionIfNotExist('cxx', "{$compiler_prefix}g++"); // set arch (default: current) $this->setOptionIfNotExist('arch', php_uname('m')); $this->setOptionIfNotExist('gnu-arch', arch2gnu($this->getOption('arch'))); @@ -270,6 +272,7 @@ public function buildCli(string $extra_libs, string $use_lld): void * * @throws RuntimeException * @throws FileSystemException + * @throws WrongUsageException */ public function buildMicro(string $extra_libs, string $use_lld, string $cflags): void { diff --git a/src/SPC/builder/linux/library/icu.php b/src/SPC/builder/linux/library/icu.php index 39125675b..bc7a3b53e 100644 --- a/src/SPC/builder/linux/library/icu.php +++ b/src/SPC/builder/linux/library/icu.php @@ -11,6 +11,7 @@ class icu extends LinuxLibraryBase protected function build(): void { $root = BUILD_ROOT_PATH; + $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; $cppflag = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"'; shell()->cd($this->source_dir . '/source') ->exec( @@ -28,7 +29,7 @@ protected function build(): void "--prefix={$root}" ) ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") + ->exec("LD_LIBRARY_PATH=/usr/local/musl/{$arch}/lib make -j{$this->builder->concurrency}") ->exec('make install'); } } diff --git a/src/SPC/builder/unix/library/ldap.php b/src/SPC/builder/unix/library/ldap.php index d1ffcbd78..0753b76ca 100644 --- a/src/SPC/builder/unix/library/ldap.php +++ b/src/SPC/builder/unix/library/ldap.php @@ -10,7 +10,7 @@ protected function build(): void { $alt = ''; // openssl support - $alt .= $this->builder->getLib('openssl') && $this->builder->getExt('zlib') ? '--with-tls=openssl ' : ''; + $alt .= $this->builder->getLib('openssl') ? '--with-tls=openssl ' : ''; // gmp support $alt .= $this->builder->getLib('gmp') ? '--with-mp=gmp ' : ''; // libsodium support @@ -23,7 +23,6 @@ protected function build(): void '--enable-static ' . '--disable-shared ' . '--disable-slapd ' . - '--disable-slurpd ' . '--without-systemd ' . '--without-cyrus-sasl ' . $alt . diff --git a/src/SPC/builder/unix/library/snappy.php b/src/SPC/builder/unix/library/snappy.php index 112cf5ede..1738ef192 100644 --- a/src/SPC/builder/unix/library/snappy.php +++ b/src/SPC/builder/unix/library/snappy.php @@ -29,6 +29,7 @@ protected function build(): void '../..' ) ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + ->exec('make install') + ->exec('mv ' . BUILD_ROOT_PATH . '/lib64/libsnappy.a ' . BUILD_ROOT_PATH . '/lib/libsnappy.a'); } } diff --git a/src/SPC/command/DownloadCommand.php b/src/SPC/command/DownloadCommand.php index b1977459c..e6588a415 100644 --- a/src/SPC/command/DownloadCommand.php +++ b/src/SPC/command/DownloadCommand.php @@ -28,7 +28,7 @@ public function configure(): void $this->addArgument('sources', InputArgument::REQUIRED, 'The sources will be compiled, comma separated'); $this->addOption('shallow-clone', null, null, 'Clone shallow'); $this->addOption('with-openssl11', null, null, 'Use openssl 1.1'); - $this->addOption('with-php', null, InputOption::VALUE_REQUIRED, 'version in major.minor format like 8.1', '8.1'); + $this->addOption('with-php', null, InputOption::VALUE_REQUIRED, 'version in major.minor format (default 8.2)', '8.2'); $this->addOption('clean', null, null, 'Clean old download cache and source before fetch'); $this->addOption('all', 'A', null, 'Fetch all sources that static-php-cli needed'); $this->addOption('custom-url', 'U', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Specify custom source download url, e.g "php-src:https://downloads.php.net/~eric/php-8.3.0beta1.tar.gz"'); diff --git a/src/SPC/doctor/item/LinuxMuslCheck.php b/src/SPC/doctor/item/LinuxMuslCheck.php index bcba4ecc2..24a10aa7d 100644 --- a/src/SPC/doctor/item/LinuxMuslCheck.php +++ b/src/SPC/doctor/item/LinuxMuslCheck.php @@ -8,34 +8,51 @@ use SPC\doctor\AsCheckItem; use SPC\doctor\AsFixItem; use SPC\doctor\CheckResult; +use SPC\exception\DownloaderException; +use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\exception\WrongUsageException; +use SPC\store\Downloader; class LinuxMuslCheck { /** @noinspection PhpUnused */ + /** + * @throws WrongUsageException + */ #[AsCheckItem('if musl-libc is installed', limit_os: 'Linux')] - public function checkMusl(): ?CheckResult + public function checkMusl(): CheckResult { - $file = sprintf('/lib/ld-musl-%s.so.1', php_uname('m')); + $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; + $file = "/usr/local/musl/{$arch}/lib/libc.a"; if (file_exists($file)) { return CheckResult::ok(); } - - // non-exist, need to recognize distro - $distro = SystemUtil::getOSRelease(); - return match ($distro['dist']) { - 'ubuntu', 'alpine', 'debian', 'redhat' => CheckResult::fail('musl-libc is not installed on your system', 'fix-musl', [$distro]), - default => CheckResult::fail('musl-libc is not installed on your system'), - }; + return CheckResult::fail('musl-libc is not installed on your system', 'fix-musl'); } /** * @throws RuntimeException - * @noinspection PhpUnused + * @throws DownloaderException + * @throws FileSystemException + * @throws WrongUsageException */ #[AsFixItem('fix-musl')] - public function fixMusl(array $distro): bool + public function fixMusl(): bool { + $distro = SystemUtil::getOSRelease(); + $source = [ + 'type' => 'git', + 'url' => 'https://github.com/richfelker/musl-cross-make', + 'rev' => 'master', + ]; + Downloader::downloadSource('musl-cross-make', $source); + $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; + $install_musl_wrapper_cmd = 'cd ' . DOWNLOAD_PATH . '/musl-cross-make && \ + make install TARGET=' . $arch . ' OUTPUT=/usr/local/musl -j && \ + if [[ ! "$PATH" =~ (^|:)"/usr/local/musl/bin"(:|$) ]]; then echo "export PATH=/usr/local/musl/bin:$PATH" >> ~/.bash_profile + fi && \ + source ~/.bash_profile'; $rhel_install = 'wget https://musl.libc.org/releases/musl-1.2.4.tar.gz && tar -zxvf musl-1.2.4.tar.gz && \ rm -f musl-1.2.4.tar.gz && cd musl-1.2.4 && if [[ ! "$PATH" =~ (^|:)"/usr/local/musl/bin"(:|$) ]]; then echo "export PATH=/usr/local/musl/bin:$PATH" >> ~/.bash_profile @@ -54,7 +71,9 @@ public function fixMusl(array $distro): bool logger()->warning('Current user is not root, using sudo for running command'); } try { - shell(true)->exec($prefix . $install_cmd); + shell(true) + ->exec($prefix . $install_cmd) + ->exec($install_musl_wrapper_cmd); return true; } catch (RuntimeException) { return false; diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 211643b18..13aafc59e 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -36,7 +36,8 @@ class LinuxToolCheckList 'git', 'autoconf', 'automake', 'tar', 'unzip', 'gzip', 'gcc', 'bzip2', 'cmake', 'patch', - 'xz', + 'xz', 'g++', 'libtool', + 'curl', // needed to download openssl 'wget', // to get musl ]; diff --git a/src/SPC/store/SourceExtractor.php b/src/SPC/store/SourceExtractor.php index 4a68bef8a..fd8f1e549 100644 --- a/src/SPC/store/SourceExtractor.php +++ b/src/SPC/store/SourceExtractor.php @@ -52,7 +52,7 @@ public static function initSource(?array $sources = null, ?array $libs = null, ? // start check foreach ($sources_extracted as $source => $item) { if (Config::getSource($source) === null) { - throw new WrongUsageException("Source [{$source}] not exists, please check name and correct it !"); + throw new WrongUsageException("Source [{$source}] does not exist, please check the name and correct it !"); } if (!isset($lock[$source])) { throw new WrongUsageException('Source [' . $source . '] not downloaded or not locked, you should download it first !'); From 55e27767957ea3e5ab7b3c4c3c76bd6f19c453f4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 1 Oct 2023 20:39:38 +0200 Subject: [PATCH 27/58] run cs fix --- src/SPC/builder/linux/LinuxBuilder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index f87215fa3..968deeacb 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -44,6 +44,7 @@ public function __construct(array $options = []) $compiler_prefix = match (arch2gnu(php_uname('m'))) { 'x86_64' => 'x86_64-linux-musl-', 'aarch64' => 'aarch64-linux-musl-', + default => '' }; $this->setOptionIfNotExist('library_path', '/usr/local/musl/lib:/usr/local/musl/' . substr($compiler_prefix, 0, -1) . '/lib'); $this->setOptionIfNotExist('cc', "{$compiler_prefix}gcc"); From b1b4a299d928e2c25a124b83138c589b2d647e34 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 1 Oct 2023 22:24:02 +0200 Subject: [PATCH 28/58] optimize musl install --- src/SPC/doctor/item/LinuxMuslCheck.php | 42 ++++++++++++++------------ src/SPC/store/FileSystem.php | 1 - 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/SPC/doctor/item/LinuxMuslCheck.php b/src/SPC/doctor/item/LinuxMuslCheck.php index 24a10aa7d..a5c29c8d8 100644 --- a/src/SPC/doctor/item/LinuxMuslCheck.php +++ b/src/SPC/doctor/item/LinuxMuslCheck.php @@ -13,6 +13,7 @@ use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\Downloader; +use SPC\store\FileSystem; class LinuxMuslCheck { @@ -24,8 +25,9 @@ class LinuxMuslCheck public function checkMusl(): CheckResult { $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; - $file = "/usr/local/musl/{$arch}/lib/libc.a"; - if (file_exists($file)) { + $cross_compile_lib = "/usr/local/musl/{$arch}/lib/libc.a"; + $musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m')); + if (file_exists($musl_wrapper_lib) && file_exists($cross_compile_lib)) { return CheckResult::ok(); } return CheckResult::fail('musl-libc is not installed on your system', 'fix-musl'); @@ -40,31 +42,32 @@ public function checkMusl(): CheckResult #[AsFixItem('fix-musl')] public function fixMusl(): bool { - $distro = SystemUtil::getOSRelease(); - $source = [ + $musl_source = [ + 'type' => 'url', + 'url' => 'https://musl.libc.org/releases/musl-1.2.4.tar.gz', + ]; + $musl_cross_compile_source = [ 'type' => 'git', 'url' => 'https://github.com/richfelker/musl-cross-make', 'rev' => 'master', ]; - Downloader::downloadSource('musl-cross-make', $source); + Downloader::downloadSource('musl-cross-make', $musl_cross_compile_source); + Downloader::downloadSource('musl-1.2.4', $musl_source); + FileSystem::extractSource('musl-1.2.4', DOWNLOAD_PATH . '/musl-1.2.4.tar.gz'); $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; $install_musl_wrapper_cmd = 'cd ' . DOWNLOAD_PATH . '/musl-cross-make && \ - make install TARGET=' . $arch . ' OUTPUT=/usr/local/musl -j && \ - if [[ ! "$PATH" =~ (^|:)"/usr/local/musl/bin"(:|$) ]]; then echo "export PATH=/usr/local/musl/bin:$PATH" >> ~/.bash_profile - fi && \ - source ~/.bash_profile'; - $rhel_install = 'wget https://musl.libc.org/releases/musl-1.2.4.tar.gz && tar -zxvf musl-1.2.4.tar.gz && \ - rm -f musl-1.2.4.tar.gz && cd musl-1.2.4 && - if [[ ! "$PATH" =~ (^|:)"/usr/local/musl/bin"(:|$) ]]; then echo "export PATH=/usr/local/musl/bin:$PATH" >> ~/.bash_profile - fi && \ + make install TARGET=' . $arch . ' OUTPUT=/usr/local/musl -j'; + $musl_install = 'cd ' . SOURCE_PATH . '/musl-1.2.4 && \ ./configure --enable-wrapper=gcc && \ - make -j && make install && cd .. && rm -rf musl-1.2.4'; - $install_cmd = match ($distro['dist']) { + make -j && make install'; + $musl_install_cmd = match (SystemUtil::getOSRelease()['dist']) { 'ubuntu', 'debian' => 'apt-get install musl musl-tools -y', 'alpine' => 'apk add musl musl-utils musl-dev', - 'redhat' => $rhel_install, - default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'), + default => $musl_install, }; + $fix_path = 'if [[ ! "$PATH" =~ (^|:)"/usr/local/musl/bin"(:|$) ]]; then echo "export PATH=/usr/local/musl/bin:$PATH" >> ~/.bash_profile + fi && \ + source ~/.bash_profile'; $prefix = ''; if (get_current_user() !== 'root') { $prefix = 'sudo '; @@ -72,8 +75,9 @@ public function fixMusl(): bool } try { shell(true) - ->exec($prefix . $install_cmd) - ->exec($install_musl_wrapper_cmd); + ->exec($prefix . $musl_install_cmd) + ->exec($install_musl_wrapper_cmd) + ->exec($prefix . $fix_path); return true; } catch (RuntimeException) { return false; diff --git a/src/SPC/store/FileSystem.php b/src/SPC/store/FileSystem.php index f4bf86640..efafdd8ac 100644 --- a/src/SPC/store/FileSystem.php +++ b/src/SPC/store/FileSystem.php @@ -163,7 +163,6 @@ public static function extractSource(string $name, string $filename, ?string $mo self::emitSourceExtractHook($name); return; } - if (PHP_OS_FAMILY === 'Darwin' || PHP_OS_FAMILY === 'Linux') { if (f_mkdir(directory: $target, recursive: true) !== true) { throw new FileSystemException('create ' . $name . 'source dir failed'); From 6fb0b66f319aeeb783eae22e83f693510d992c61 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 1 Oct 2023 22:56:59 +0200 Subject: [PATCH 29/58] fix opcache loading wrong libstdc++.so.6 --- src/SPC/builder/linux/LinuxBuilder.php | 2 ++ src/SPC/builder/linux/library/libxml2.php | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 968deeacb..452df8b88 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -188,8 +188,10 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO; $enableEmbed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED; + $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; shell()->cd(SOURCE_PATH . '/php-src') ->exec( + 'LD_LIBRARY_PATH=/usr/local/musl/' . $arch . '/lib ' . './configure ' . '--prefix= ' . '--with-valgrind=no ' . diff --git a/src/SPC/builder/linux/library/libxml2.php b/src/SPC/builder/linux/library/libxml2.php index 9856f5272..ae44b9ebd 100644 --- a/src/SPC/builder/linux/library/libxml2.php +++ b/src/SPC/builder/linux/library/libxml2.php @@ -19,7 +19,7 @@ class libxml2 extends LinuxLibraryBase public function build(): void { $enable_zlib = $this->builder->getLib('zlib') ? 'ON' : 'OFF'; - // $enable_icu = $this->builder->getLib('icu') ? 'ON' : 'OFF'; + $enable_icu = $this->builder->getLib('icu') ? 'ON' : 'OFF'; $enable_xz = $this->builder->getLib('xz') ? 'ON' : 'OFF'; FileSystem::resetDir($this->source_dir . '/build'); @@ -34,7 +34,7 @@ public function build(): void '-DLIBXML2_WITH_ICONV=ON ' . '-DIconv_IS_BUILT_IN=OFF ' . "-DLIBXML2_WITH_ZLIB={$enable_zlib} " . - '-DLIBXML2_WITH_ICU=OFF ' . + "-DLIBXML2_WITH_ICU={$enable_icu} " . "-DLIBXML2_WITH_LZMA={$enable_xz} " . '-DLIBXML2_WITH_PYTHON=OFF ' . '-DLIBXML2_WITH_PROGRAMS=OFF ' . @@ -42,6 +42,8 @@ public function build(): void '..' ) ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + ->exec('make install') + ->exec('mv ' . BUILD_ROOT_PATH . '/lib64/pkgconfig/* ' . BUILD_ROOT_PATH . '/lib/pkgconfig/') + ->exec('mv ' . BUILD_ROOT_PATH . '/lib64/*.a ' . BUILD_ROOT_PATH . '/lib/'); } } From 8f175776cd239419efd4a1c8a7310abfd54f3876 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 1 Oct 2023 22:58:07 +0200 Subject: [PATCH 30/58] move everything for libsnappy too --- src/SPC/builder/unix/library/snappy.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/snappy.php b/src/SPC/builder/unix/library/snappy.php index 1738ef192..8f612e826 100644 --- a/src/SPC/builder/unix/library/snappy.php +++ b/src/SPC/builder/unix/library/snappy.php @@ -30,6 +30,7 @@ protected function build(): void ) ->exec("cmake --build . -j {$this->builder->concurrency}") ->exec('make install') - ->exec('mv ' . BUILD_ROOT_PATH . '/lib64/libsnappy.a ' . BUILD_ROOT_PATH . '/lib/libsnappy.a'); + ->exec('mv ' . BUILD_ROOT_PATH . '/lib64/pkgconfig/* ' . BUILD_ROOT_PATH . '/lib/pkgconfig/') + ->exec('mv ' . BUILD_ROOT_PATH . '/lib64/*.a ' . BUILD_ROOT_PATH . '/lib/'); } } From 7b1432dd138137494bb7b481f1c780ba1a464f3a Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 2 Oct 2023 12:34:46 +0200 Subject: [PATCH 31/58] fix compilation errors (did ldap compilation work for you without -lz?) --- src/SPC/builder/linux/library/icu.php | 2 +- src/SPC/builder/linux/library/libxml2.php | 3 +-- src/SPC/builder/unix/library/ldap.php | 1 + src/SPC/builder/unix/library/snappy.php | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/SPC/builder/linux/library/icu.php b/src/SPC/builder/linux/library/icu.php index bc7a3b53e..1a414483a 100644 --- a/src/SPC/builder/linux/library/icu.php +++ b/src/SPC/builder/linux/library/icu.php @@ -30,6 +30,6 @@ protected function build(): void ) ->exec('make clean') ->exec("LD_LIBRARY_PATH=/usr/local/musl/{$arch}/lib make -j{$this->builder->concurrency}") - ->exec('make install'); + ->exec("LD_LIBRARY_PATH=/usr/local/musl/{$arch}/lib make install"); } } diff --git a/src/SPC/builder/linux/library/libxml2.php b/src/SPC/builder/linux/library/libxml2.php index ae44b9ebd..a7d7949be 100644 --- a/src/SPC/builder/linux/library/libxml2.php +++ b/src/SPC/builder/linux/library/libxml2.php @@ -43,7 +43,6 @@ public function build(): void ) ->exec("cmake --build . -j {$this->builder->concurrency}") ->exec('make install') - ->exec('mv ' . BUILD_ROOT_PATH . '/lib64/pkgconfig/* ' . BUILD_ROOT_PATH . '/lib/pkgconfig/') - ->exec('mv ' . BUILD_ROOT_PATH . '/lib64/*.a ' . BUILD_ROOT_PATH . '/lib/'); + ->exec('cp -rf ' . BUILD_ROOT_PATH . '/lib64/* ' . BUILD_ROOT_PATH . '/lib/'); } } diff --git a/src/SPC/builder/unix/library/ldap.php b/src/SPC/builder/unix/library/ldap.php index 0753b76ca..b9a28ba5e 100644 --- a/src/SPC/builder/unix/library/ldap.php +++ b/src/SPC/builder/unix/library/ldap.php @@ -19,6 +19,7 @@ protected function build(): void ->exec( $this->builder->configure_env . ' ' . $this->builder->makeAutoconfFlags(AUTOCONF_LDFLAGS | AUTOCONF_CPPFLAGS) . + 'LIBS="-lssl -lcrypto -lz"' . ' ./configure ' . '--enable-static ' . '--disable-shared ' . diff --git a/src/SPC/builder/unix/library/snappy.php b/src/SPC/builder/unix/library/snappy.php index 8f612e826..4f868903a 100644 --- a/src/SPC/builder/unix/library/snappy.php +++ b/src/SPC/builder/unix/library/snappy.php @@ -30,7 +30,6 @@ protected function build(): void ) ->exec("cmake --build . -j {$this->builder->concurrency}") ->exec('make install') - ->exec('mv ' . BUILD_ROOT_PATH . '/lib64/pkgconfig/* ' . BUILD_ROOT_PATH . '/lib/pkgconfig/') - ->exec('mv ' . BUILD_ROOT_PATH . '/lib64/*.a ' . BUILD_ROOT_PATH . '/lib/'); + ->exec('cp -rf ' . BUILD_ROOT_PATH . '/lib64/* ' . BUILD_ROOT_PATH . '/lib/'); } } From dd826734f8c4bc58f4c028f8a28112edcac3a9db Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 2 Oct 2023 19:48:00 +0200 Subject: [PATCH 32/58] fix pgsql + intl + ldap --- src/SPC/builder/linux/library/libxml2.php | 5 +++++ src/SPC/builder/unix/library/postgresql.php | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/linux/library/libxml2.php b/src/SPC/builder/linux/library/libxml2.php index a7d7949be..6e55e356b 100644 --- a/src/SPC/builder/linux/library/libxml2.php +++ b/src/SPC/builder/linux/library/libxml2.php @@ -44,5 +44,10 @@ public function build(): void ->exec("cmake --build . -j {$this->builder->concurrency}") ->exec('make install') ->exec('cp -rf ' . BUILD_ROOT_PATH . '/lib64/* ' . BUILD_ROOT_PATH . '/lib/'); + FileSystem::replaceFileStr( + BUILD_ROOT_PATH . '/lib/pkgconfig/libxml-2.0.pc', + '-licudata -licui18n -licuuc', + '-licui18n -licuuc -licudata' + ); } } diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 782574017..069f9eae4 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -21,6 +21,9 @@ protected function build(): void $env = $this->builder->configure_env; $envs = $env; $packages = 'openssl zlib readline libxml-2.0'; // icu-uc icu-io icu-i18n libzstd + if ($this->builder->getLib('ldap')) { + $packages .= ' ldap'; + } $pkgconfig_executable = $builddir . '/bin/pkg-config'; $output = shell()->execWithResult($env . " {$pkgconfig_executable} --cflags-only-I --static " . $packages); @@ -36,7 +39,11 @@ protected function build(): void $output = shell()->execWithResult($env . " {$pkgconfig_executable} --libs-only-l --static " . $packages); if (!empty($output[1][0])) { $libs = $output[1][0]; - $envs .= " LIBS=\"{$libs}\" "; + $libcpp = ''; + if ($this->builder->getLib('icu')) { + $libcpp = $this instanceof MacOSLibraryBase ? ' -lc++' : ' -lstdc++'; + } + $envs .= " LIBS=\"{$libs}{$libcpp}\""; } FileSystem::resetDir($this->source_dir . '/build'); @@ -57,8 +64,8 @@ protected function build(): void '--with-ssl=openssl ' . '--with-readline ' . '--with-libxml ' . - ($this->builder->getLib('ldap') ? '--with-ldap ' : '--without-ldap ') . ($this->builder->getLib('icu') ? '--with-icu ' : '--without-icu ') . + ($this->builder->getLib('ldap') ? '--with-ldap ' : '--without-ldap ') . ($this->builder->getLib('pam') ? '--with-pam ' : '--without-pam ') . '--without-libxslt ' . '--without-lz4 ' . From c1c813172d814f27a436a8acbcc281a02ff5ac87 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 2 Oct 2023 20:55:23 +0200 Subject: [PATCH 33/58] only run necessary musl install steps --- src/SPC/builder/linux/LinuxBuilder.php | 2 +- src/SPC/doctor/item/LinuxMuslCheck.php | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 452df8b88..b087e2846 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -336,7 +336,7 @@ public function buildFpm(string $extra_libs, string $use_lld): void public function buildEmbed(string $extra_libs, string $use_lld): void { $vars = SystemUtil::makeEnvVarString([ - 'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)), + 'EXTRA_CFLAGS' => '-g -Os -fno-ident -fPIE ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)), 'EXTRA_LIBS' => $extra_libs, 'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static", ]); diff --git a/src/SPC/doctor/item/LinuxMuslCheck.php b/src/SPC/doctor/item/LinuxMuslCheck.php index a5c29c8d8..f23bc3d47 100644 --- a/src/SPC/doctor/item/LinuxMuslCheck.php +++ b/src/SPC/doctor/item/LinuxMuslCheck.php @@ -51,12 +51,14 @@ public function fixMusl(): bool 'url' => 'https://github.com/richfelker/musl-cross-make', 'rev' => 'master', ]; + $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; + $cross_compile_lib = "/usr/local/musl/{$arch}/lib/libc.a"; + $musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m')); Downloader::downloadSource('musl-cross-make', $musl_cross_compile_source); Downloader::downloadSource('musl-1.2.4', $musl_source); FileSystem::extractSource('musl-1.2.4', DOWNLOAD_PATH . '/musl-1.2.4.tar.gz'); - $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; $install_musl_wrapper_cmd = 'cd ' . DOWNLOAD_PATH . '/musl-cross-make && \ - make install TARGET=' . $arch . ' OUTPUT=/usr/local/musl -j'; + make install TARGET=' . $arch . ' OUTPUT=/usr/local/musl CFLAGS="-fPIE" -j'; $musl_install = 'cd ' . SOURCE_PATH . '/musl-1.2.4 && \ ./configure --enable-wrapper=gcc && \ make -j && make install'; @@ -65,19 +67,22 @@ public function fixMusl(): bool 'alpine' => 'apk add musl musl-utils musl-dev', default => $musl_install, }; - $fix_path = 'if [[ ! "$PATH" =~ (^|:)"/usr/local/musl/bin"(:|$) ]]; then echo "export PATH=/usr/local/musl/bin:$PATH" >> ~/.bash_profile - fi && \ - source ~/.bash_profile'; + $fix_path = 'if [[ ! "$PATH" =~ (^|:)"/usr/local/musl/bin"(:|$) ]]; then echo "export PATH=/usr/local/musl/bin:$PATH" >> ~/.bash_profile && export PATH=/usr/local/musl/bin:$PATH + fi'; $prefix = ''; if (get_current_user() !== 'root') { $prefix = 'sudo '; logger()->warning('Current user is not root, using sudo for running command'); } try { - shell(true) - ->exec($prefix . $musl_install_cmd) - ->exec($install_musl_wrapper_cmd) - ->exec($prefix . $fix_path); + if (!file_exists($musl_wrapper_lib)) { + shell(true)->exec($prefix . $musl_install_cmd); + } + if (!file_exists($cross_compile_lib)) { + shell(true)->exec($prefix . $install_musl_wrapper_cmd); + } + + shell(true)->exec($prefix . $fix_path); return true; } catch (RuntimeException) { return false; From 904b730f41302e1a9ed6a69015da8628761fa9db Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 3 Oct 2023 01:06:23 +0200 Subject: [PATCH 34/58] return false|int instead of bool|int in replaceFile methods --- src/SPC/store/FileSystem.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SPC/store/FileSystem.php b/src/SPC/store/FileSystem.php index efafdd8ac..cb674f20c 100644 --- a/src/SPC/store/FileSystem.php +++ b/src/SPC/store/FileSystem.php @@ -55,7 +55,7 @@ public static function readFile(string $filename): string /** * @throws FileSystemException */ - public static function replaceFileStr(string $filename, mixed $search = null, mixed $replace = null): bool|int + public static function replaceFileStr(string $filename, mixed $search = null, mixed $replace = null): false|int { return self::replaceFile($filename, REPLACE_FILE_STR, $search, $replace); } @@ -63,7 +63,7 @@ public static function replaceFileStr(string $filename, mixed $search = null, mi /** * @throws FileSystemException */ - public static function replaceFileRegex(string $filename, mixed $search = null, mixed $replace = null): bool|int + public static function replaceFileRegex(string $filename, mixed $search = null, mixed $replace = null): false|int { return self::replaceFile($filename, REPLACE_FILE_PREG, $search, $replace); } @@ -71,7 +71,7 @@ public static function replaceFileRegex(string $filename, mixed $search = null, /** * @throws FileSystemException */ - public static function replaceFileUser(string $filename, mixed $callback = null): bool|int + public static function replaceFileUser(string $filename, mixed $callback = null): false|int { return self::replaceFile($filename, REPLACE_FILE_USER, $callback); } @@ -445,7 +445,7 @@ public static function isRelativePath(string $path): bool /** * @throws FileSystemException */ - private static function replaceFile(string $filename, int $replace_type = REPLACE_FILE_STR, mixed $callback_or_search = null, mixed $to_replace = null): bool|int + private static function replaceFile(string $filename, int $replace_type = REPLACE_FILE_STR, mixed $callback_or_search = null, mixed $to_replace = null): false|int { logger()->debug('Replacing file with type[' . $replace_type . ']: ' . $filename); $file = self::readFile($filename); From 47000717dc251536d06de5fc5dfd77fbad17829e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 3 Oct 2023 01:08:06 +0200 Subject: [PATCH 35/58] fix libxml pc patch --- src/SPC/builder/linux/library/libxml2.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/linux/library/libxml2.php b/src/SPC/builder/linux/library/libxml2.php index 6e55e356b..cb27c995e 100644 --- a/src/SPC/builder/linux/library/libxml2.php +++ b/src/SPC/builder/linux/library/libxml2.php @@ -42,12 +42,12 @@ public function build(): void '..' ) ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install') - ->exec('cp -rf ' . BUILD_ROOT_PATH . '/lib64/* ' . BUILD_ROOT_PATH . '/lib/'); + ->exec('make install'); FileSystem::replaceFileStr( - BUILD_ROOT_PATH . '/lib/pkgconfig/libxml-2.0.pc', + BUILD_ROOT_PATH . '/lib64/pkgconfig/libxml-2.0.pc', '-licudata -licui18n -licuuc', '-licui18n -licuuc -licudata' ); + shell()->exec('cp -rf ' . BUILD_ROOT_PATH . '/lib64/* ' . BUILD_ROOT_PATH . '/lib/'); } } From ebc880b3562daae4197809532526c6e3f6bb61c4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 4 Oct 2023 23:15:26 +0200 Subject: [PATCH 36/58] add pam tools for alpine (package names need to be adjusted) --- src/SPC/doctor/item/LinuxToolCheckList.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 13aafc59e..30b90f34d 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -41,7 +41,17 @@ class LinuxToolCheckList 'wget', // to get musl ]; - // todo: require those + public const PAM_TOOLS_ALPINE = [ + 'autoconf', 'automake', 'autopoint', + 'bison', 'bzip2', 'docbook5-xml', + 'docbook-xsl-ns', 'flex', 'gettext', + 'libaudit-dev', 'libdb-dev', 'libfl-dev', + 'libselinux1-dev', 'libssl-dev', 'libtool', + 'libxml2-utils', 'make', 'pkg-config', + 'sed', 'w3m', 'xsltproc', 'xz-utils', + 'libpam0g-dev', + ]; + public const PAM_TOOLS_DEBIAN = [ 'autoconf', 'automake', 'autopoint', 'bison', 'bzip2', 'docbook5-xml', @@ -53,7 +63,6 @@ class LinuxToolCheckList 'libpam0g-dev', ]; - // todo: require those public const PAM_TOOLS_RHEL = [ 'autoconf', 'automake', 'bison', 'bzip2', 'flex', 'make', 'gettext', @@ -70,7 +79,7 @@ public function checkCliTools(): ?CheckResult $distro = SystemUtil::getOSRelease(); $required = match ($distro['dist']) { - 'alpine' => array_unique(array_merge(self::TOOLS_ALPINE, self::PAM_TOOLS_RHEL)), + 'alpine' => array_unique(array_merge(self::TOOLS_ALPINE, self::PAM_TOOLS_ALPINE)), 'redhat' => array_unique(array_merge(self::TOOLS_RHEL, self::PAM_TOOLS_RHEL)), default => array_unique(array_merge(self::TOOLS_DEBIAN, self::PAM_TOOLS_DEBIAN)), }; From d17d336a09590edaac905c6e0fab8e9e1bd30731 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 5 Oct 2023 10:54:24 +0200 Subject: [PATCH 37/58] remove --disable-opcache-jit on building embed --- 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 b087e2846..7d9425c94 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -202,7 +202,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void '--disable-phpdbg ' . ($enableCli ? '--enable-cli ' : '--disable-cli ') . ($enableFpm ? '--enable-fpm ' : '--disable-fpm ') . - ($enableEmbed ? '--enable-embed=static --disable-opcache-jit ' : '--disable-embed ') . + ($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') . $json_74 . $zts . $maxExecutionTimers . From ccd22d2e3e07abf3f655bcf869a4fed0acffd518 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 10 Oct 2023 12:33:49 +0200 Subject: [PATCH 38/58] fix imap build (without libpam) on aarch64 - CC=cc has to be replaced in osdep/unix/Makefile --- src/SPC/builder/unix/library/imap.php | 6 ++++++ src/SPC/builder/unix/library/libpam.php | 3 +-- src/SPC/doctor/item/LinuxMuslCheck.php | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index 3cd399b97..4850fba9e 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -13,10 +13,15 @@ trait imap { + /** + * @throws FileSystemException + * @throws RuntimeException + */ public function patchBeforeBuild(): bool { if ($this->builder->getLib('openssl')) { FileSystem::replaceFileStr($this->source_dir . '/Makefile', '-DMAC_OSX_KLUDGE=1', ''); + FileSystem::replaceFileStr($this->source_dir . '/src/osdep/unix/Makefile', 'CC=cc', 'CC=' . $this->builder->getOption('cc')); FileSystem::replaceFileStr($this->source_dir . '/src/osdep/unix/Makefile', '-lcrypto -lz', '-lcrypto'); FileSystem::replaceFileStr($this->source_dir . '/src/osdep/unix/Makefile', '-lcrypto', '-lcrypto -lz'); FileSystem::replaceFileStr( @@ -51,6 +56,7 @@ protected function build(): void throw new WrongUsageException('ext-imap built on your system requires libpam, please build with --with-libs=libpam'); } shell()->cd($this->source_dir) + ->exec('make clean') ->exec('touch ip6') ->exec( "{$this->builder->configure_env} make {$distro} " . diff --git a/src/SPC/builder/unix/library/libpam.php b/src/SPC/builder/unix/library/libpam.php index 3b0243552..6113d3755 100644 --- a/src/SPC/builder/unix/library/libpam.php +++ b/src/SPC/builder/unix/library/libpam.php @@ -15,10 +15,9 @@ public function patchBeforeBuild(): bool protected function build(): void { - $config_env = str_replace("CC='musl-gcc'", '', $this->builder->configure_env); shell()->cd($this->source_dir) ->exec('./autogen.sh') - ->exec("{$config_env} ./configure --enable-static --disable-shared " . + ->exec("{$this->builder->configure_env} ./configure --enable-static --disable-shared " . ($this->builder->getLib('openssl') ? '-enable-openssl=' . BUILD_ROOT_PATH . ' ' : '') . '--disable-prelude --disable-audit --enable-db=no --disable-nis --disable-selinux ' . '--disable-econf --disable-nls --disable-rpath --disable-pie --disable-doc --disable-examples --prefix=') diff --git a/src/SPC/doctor/item/LinuxMuslCheck.php b/src/SPC/doctor/item/LinuxMuslCheck.php index f23bc3d47..0711de739 100644 --- a/src/SPC/doctor/item/LinuxMuslCheck.php +++ b/src/SPC/doctor/item/LinuxMuslCheck.php @@ -58,7 +58,8 @@ public function fixMusl(): bool Downloader::downloadSource('musl-1.2.4', $musl_source); FileSystem::extractSource('musl-1.2.4', DOWNLOAD_PATH . '/musl-1.2.4.tar.gz'); $install_musl_wrapper_cmd = 'cd ' . DOWNLOAD_PATH . '/musl-cross-make && \ - make install TARGET=' . $arch . ' OUTPUT=/usr/local/musl CFLAGS="-fPIE" -j'; + make install TARGET=' . $arch . ' CFLAGS="-fPIE" -j && \ + cd -rf output/* /usr/local/musl'; $musl_install = 'cd ' . SOURCE_PATH . '/musl-1.2.4 && \ ./configure --enable-wrapper=gcc && \ make -j && make install'; From 958d91e67fe85a4c86eff172c52b1f29c3883e25 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 10 Oct 2023 16:09:22 +0200 Subject: [PATCH 39/58] add -lsharpyuv to dependencies when patching pkgconfig --- src/SPC/builder/unix/library/libwebp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/libwebp.php b/src/SPC/builder/unix/library/libwebp.php index 29fb05e93..41972f3b3 100644 --- a/src/SPC/builder/unix/library/libwebp.php +++ b/src/SPC/builder/unix/library/libwebp.php @@ -35,7 +35,7 @@ protected function build(): void FileSystem::replaceFileRegex( BUILD_LIB_PATH . '/pkgconfig/libwebp.pc', '/Libs: -L\$\{libdir} -lwebp.*/', - 'Libs: -L${libdir} -lwebp -lwebpdecoder -lwebpdemux -lwebpmux' + 'Libs: -L${libdir} -lwebp -lwebpdecoder -lwebpdemux -lwebpmux -lsharpyuv' ); $this->patchPkgconfPrefix(['libsharpyuv.pc', 'libwebp.pc', 'libwebpdecoder.pc', 'libwebpdemux.pc', 'libwebpmux.pc'], PKGCONF_PATCH_PREFIX | PKGCONF_PATCH_LIBDIR); $this->patchPkgconfPrefix(['libsharpyuv.pc'], PKGCONF_PATCH_CUSTOM, ['/^includedir=.*$/m', 'includedir=${prefix}/include/webp']); From 956da4640fbf629a4524b60a2a53db2cc3682d03 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 10 Oct 2023 16:52:31 +0200 Subject: [PATCH 40/58] allow patchBeforeMake to patch extra_libs on linux as well (worked on MacOS already) --- src/SPC/builder/linux/LinuxBuilder.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 7d9425c94..898521ea9 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -217,22 +217,22 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void if ($enableCli) { logger()->info('building cli'); - $this->buildCli($extra_libs, $use_lld); + $this->buildCli($use_lld); } if ($enableFpm) { logger()->info('building fpm'); - $this->buildFpm($extra_libs, $use_lld); + $this->buildFpm($use_lld); } if ($enableMicro) { logger()->info('building micro'); - $this->buildMicro($extra_libs, $use_lld, $cflags); + $this->buildMicro($use_lld, $cflags); } if ($enableEmbed) { logger()->info('building embed'); if ($enableMicro) { FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/Makefile', 'OVERALL_TARGET =', 'OVERALL_TARGET = libphp.la'); } - $this->buildEmbed($extra_libs, $use_lld); + $this->buildEmbed($use_lld); // php-config puts extra_libs in wrong order, fix it here... FileSystem::replaceFileRegex( BUILD_ROOT_PATH . '/bin/php-config', @@ -252,11 +252,11 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void * @throws RuntimeException * @throws FileSystemException */ - public function buildCli(string $extra_libs, string $use_lld): void + public function buildCli(string $use_lld): void { $vars = SystemUtil::makeEnvVarString([ 'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)), - 'EXTRA_LIBS' => $extra_libs, + 'EXTRA_LIBS' => $this->getOption('extra-libs'), 'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static", ]); shell()->cd(SOURCE_PATH . '/php-src') @@ -277,7 +277,7 @@ public function buildCli(string $extra_libs, string $use_lld): void * @throws FileSystemException * @throws WrongUsageException */ - public function buildMicro(string $extra_libs, string $use_lld, string $cflags): void + public function buildMicro(string $use_lld, string $cflags): void { if ($this->getPHPVersionID() < 80000) { throw new RuntimeException('phpmicro only support PHP >= 8.0!'); @@ -290,7 +290,7 @@ public function buildMicro(string $extra_libs, string $use_lld, string $cflags): $enable_fake_cli = $this->getOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : ''; $vars = SystemUtil::makeEnvVarString([ 'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)) . $enable_fake_cli, - 'EXTRA_LIBS' => $extra_libs, + 'EXTRA_LIBS' => $this->getOption('extra-libs'), 'EXTRA_LDFLAGS_PROGRAM' => "{$cflags} {$use_lld} -all-static", ]); shell()->cd(SOURCE_PATH . '/php-src') @@ -314,11 +314,11 @@ public function buildMicro(string $extra_libs, string $use_lld, string $cflags): * @throws FileSystemException * @throws RuntimeException */ - public function buildFpm(string $extra_libs, string $use_lld): void + public function buildFpm(string $use_lld): void { $vars = SystemUtil::makeEnvVarString([ 'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)), - 'EXTRA_LIBS' => $extra_libs, + 'EXTRA_LIBS' => $this->getOption('extra-libs'), 'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static", ]); @@ -333,11 +333,11 @@ public function buildFpm(string $extra_libs, string $use_lld): void $this->deployBinary(BUILD_TARGET_FPM); } - public function buildEmbed(string $extra_libs, string $use_lld): void + public function buildEmbed(string $use_lld): void { $vars = SystemUtil::makeEnvVarString([ 'EXTRA_CFLAGS' => '-g -Os -fno-ident -fPIE ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)), - 'EXTRA_LIBS' => $extra_libs, + 'EXTRA_LIBS' => $this->getOption('extra-libs'), 'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static", ]); From 46a16b8f9c91a2cdf54e6feb2afd87908182864c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 10 Oct 2023 16:52:59 +0200 Subject: [PATCH 41/58] get build-cli working for imagick (undefined references, like always) --- src/SPC/builder/extension/imagick.php | 30 ++++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 311aa946d..58085efef 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -12,17 +12,27 @@ class imagick extends Extension { public function patchBeforeBuildconf(): bool { - // linux need to link library manually, we add it to extra-libs $extra_libs = $this->builder->getOption('extra-libs', ''); - if (!str_contains($extra_libs, 'libMagickCore')) { - $extra_libs .= ' /usr/lib/libMagick++-7.Q16HDRI.a /usr/lib/libMagickCore-7.Q16HDRI.a /usr/lib/libMagickWand-7.Q16HDRI.a '; - } - $extra_libs .= $this->builder->getLib('libzip') ? '-lzip ' : ''; - $extra_libs .= $this->builder->getLib('libjpeg') ? '-ljpeg ' : ''; - $extra_libs .= $this->builder->getLib('libpng') ? '-lpng ' : ''; - $extra_libs .= $this->builder->getLib('libwebp') ? '-lwebp ' : ''; - $extra_libs .= $this->builder->getLib('zstd') ? '-lzstd ' : ''; - $extra_libs .= $this->builder->getLib('freetype') ? '-lfreetype ' : ''; + $LIB_PATH = BUILD_LIB_PATH; + // always add these even if they aren't needed, php-imagick pulls MagickWand before MagickCore which leads to undefined references + $extra_libs .= " {$LIB_PATH}/libMagick++-7.Q16HDRI.a {$LIB_PATH}/libMagickWand-7.Q16HDRI.a {$LIB_PATH}/libMagickCore-7.Q16HDRI.a "; + $extra_libs .= $this->builder->getLib('libzip') ? "{$LIB_PATH}/libzip.a " : ''; + $extra_libs .= $this->builder->getLib('libjpeg') ? "{$LIB_PATH}/libjpeg.a " : ''; + $extra_libs .= $this->builder->getLib('libpng') ? "{$LIB_PATH}/libpng.a " : ''; + $extra_libs .= $this->builder->getLib('libwebp') ? "{$LIB_PATH}/libwebp.a " : ''; + $extra_libs .= $this->builder->getLib('zstd') ? "{$LIB_PATH}/libzstd.a " : ''; + $extra_libs .= $this->builder->getLib('freetype') ? "{$LIB_PATH}/libfreetype.a " : ''; + $this->builder->setOption('extra-libs', $extra_libs); + return true; + } + + public function patchBeforeMake(): bool + { + $extra_libs = $this->builder->getOption('extra-libs', ''); + $LIB_PATH = BUILD_LIB_PATH; + // always add these even if they aren't needed, php-imagick pulls MagickWand before MagickCore which leads to undefined references + $extra_libs .= " {$LIB_PATH}/libMagick++-7.Q16HDRI.a {$LIB_PATH}/libMagickWand-7.Q16HDRI.a {$LIB_PATH}/libMagickCore-7.Q16HDRI.a "; + $extra_libs .= '-lgomp '; $this->builder->setOption('extra-libs', $extra_libs); return true; } From e9f31920799da6bf7d33b1a9ac979a5c5d42fa5c Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 10 Oct 2023 19:45:47 +0200 Subject: [PATCH 42/58] use prebuilt musl-gcc (gcc 12.2+ fails to build musl-cross-compile) --- src/SPC/builder/linux/library/libxml2.php | 20 +++-- src/SPC/builder/unix/library/snappy.php | 6 +- src/SPC/doctor/item/LinuxMuslCheck.php | 91 ++++++++++++---------- src/SPC/doctor/item/LinuxToolCheckList.php | 2 +- 4 files changed, 71 insertions(+), 48 deletions(-) diff --git a/src/SPC/builder/linux/library/libxml2.php b/src/SPC/builder/linux/library/libxml2.php index cb27c995e..ce4dc327c 100644 --- a/src/SPC/builder/linux/library/libxml2.php +++ b/src/SPC/builder/linux/library/libxml2.php @@ -43,11 +43,19 @@ public function build(): void ) ->exec("cmake --build . -j {$this->builder->concurrency}") ->exec('make install'); - FileSystem::replaceFileStr( - BUILD_ROOT_PATH . '/lib64/pkgconfig/libxml-2.0.pc', - '-licudata -licui18n -licuuc', - '-licui18n -licuuc -licudata' - ); - shell()->exec('cp -rf ' . BUILD_ROOT_PATH . '/lib64/* ' . BUILD_ROOT_PATH . '/lib/'); + if (file_exists(BUILD_ROOT_PATH . '/lib64/libxml2.a')) { + FileSystem::replaceFileStr( + BUILD_ROOT_PATH . '/lib64/pkgconfig/libxml-2.0.pc', + '-licudata -licui18n -licuuc', + '-licui18n -licuuc -licudata' + ); + shell()->exec('cp -rf ' . BUILD_ROOT_PATH . '/lib64/* ' . BUILD_ROOT_PATH . '/lib/'); + } else { + FileSystem::replaceFileStr( + BUILD_ROOT_PATH . '/lib/pkgconfig/libxml-2.0.pc', + '-licudata -licui18n -licuuc', + '-licui18n -licuuc -licudata' + ); + } } } diff --git a/src/SPC/builder/unix/library/snappy.php b/src/SPC/builder/unix/library/snappy.php index 4f868903a..c5d62f9db 100644 --- a/src/SPC/builder/unix/library/snappy.php +++ b/src/SPC/builder/unix/library/snappy.php @@ -29,7 +29,9 @@ protected function build(): void '../..' ) ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install') - ->exec('cp -rf ' . BUILD_ROOT_PATH . '/lib64/* ' . BUILD_ROOT_PATH . '/lib/'); + ->exec('make install'); + if (file_exists(BUILD_ROOT_PATH . '/lib64/libsnappy.a')) { + shell()->exec('cp -rf ' . BUILD_ROOT_PATH . '/lib64/* ' . BUILD_ROOT_PATH . '/lib/'); + } } } diff --git a/src/SPC/doctor/item/LinuxMuslCheck.php b/src/SPC/doctor/item/LinuxMuslCheck.php index 0711de739..a296e7fc5 100644 --- a/src/SPC/doctor/item/LinuxMuslCheck.php +++ b/src/SPC/doctor/item/LinuxMuslCheck.php @@ -4,7 +4,6 @@ namespace SPC\doctor\item; -use SPC\builder\linux\SystemUtil; use SPC\doctor\AsCheckItem; use SPC\doctor\AsFixItem; use SPC\doctor\CheckResult; @@ -33,6 +32,7 @@ public function checkMusl(): CheckResult return CheckResult::fail('musl-libc is not installed on your system', 'fix-musl'); } + /** @noinspection PhpUnused */ /** * @throws RuntimeException * @throws DownloaderException @@ -40,53 +40,66 @@ public function checkMusl(): CheckResult * @throws WrongUsageException */ #[AsFixItem('fix-musl')] - public function fixMusl(): bool + public function fixMusl(): void { - $musl_source = [ - 'type' => 'url', - 'url' => 'https://musl.libc.org/releases/musl-1.2.4.tar.gz', - ]; - $musl_cross_compile_source = [ - 'type' => 'git', - 'url' => 'https://github.com/richfelker/musl-cross-make', - 'rev' => 'master', - ]; $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; - $cross_compile_lib = "/usr/local/musl/{$arch}/lib/libc.a"; $musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m')); - Downloader::downloadSource('musl-cross-make', $musl_cross_compile_source); - Downloader::downloadSource('musl-1.2.4', $musl_source); - FileSystem::extractSource('musl-1.2.4', DOWNLOAD_PATH . '/musl-1.2.4.tar.gz'); - $install_musl_wrapper_cmd = 'cd ' . DOWNLOAD_PATH . '/musl-cross-make && \ - make install TARGET=' . $arch . ' CFLAGS="-fPIE" -j && \ - cd -rf output/* /usr/local/musl'; - $musl_install = 'cd ' . SOURCE_PATH . '/musl-1.2.4 && \ - ./configure --enable-wrapper=gcc && \ - make -j && make install'; - $musl_install_cmd = match (SystemUtil::getOSRelease()['dist']) { - 'ubuntu', 'debian' => 'apt-get install musl musl-tools -y', - 'alpine' => 'apk add musl musl-utils musl-dev', - default => $musl_install, - }; - $fix_path = 'if [[ ! "$PATH" =~ (^|:)"/usr/local/musl/bin"(:|$) ]]; then echo "export PATH=/usr/local/musl/bin:$PATH" >> ~/.bash_profile && export PATH=/usr/local/musl/bin:$PATH - fi'; + $cross_compile_lib = '/usr/local/musl/lib/libc.a'; + + if (!file_exists($musl_wrapper_lib)) { + $this->installMuslWrapper(); + } + if (!file_exists($cross_compile_lib)) { + $this->installMuslCrossMake($arch); + } + $prefix = ''; if (get_current_user() !== 'root') { $prefix = 'sudo '; logger()->warning('Current user is not root, using sudo for running command'); } - try { - if (!file_exists($musl_wrapper_lib)) { - shell(true)->exec($prefix . $musl_install_cmd); - } - if (!file_exists($cross_compile_lib)) { - shell(true)->exec($prefix . $install_musl_wrapper_cmd); - } - + if (!getenv('PATH') || !str_contains(getenv('PATH'), '/usr/local/musl/bin')) { + $fix_path = 'echo "export PATH=/usr/local/musl/bin:$PATH" >> ~/.bash_profile && export PATH=/usr/local/musl/bin:$PATH'; shell(true)->exec($prefix . $fix_path); - return true; - } catch (RuntimeException) { - return false; } } + + /** + * @throws DownloaderException + * @throws RuntimeException + * @throws FileSystemException + */ + public function installMuslWrapper(): void + { + $prefix = ''; + if (get_current_user() !== 'root') { + $prefix = 'sudo '; + logger()->warning('Current user is not root, using sudo for running command'); + } + $musl_source = [ + 'type' => 'url', + 'url' => 'https://musl.libc.org/releases/musl-1.2.4.tar.gz', + ]; + Downloader::downloadSource('musl-1.2.4', $musl_source); + FileSystem::extractSource('musl-1.2.4', DOWNLOAD_PATH . '/musl-1.2.4.tar.gz'); + $musl_gcc_install_cmd = 'cd ' . SOURCE_PATH . '/musl-1.2.4 && \ + ./configure --enable-wrapper=gcc && \ + make -j && make install'; + shell(true)->exec($prefix . $musl_gcc_install_cmd); + } + + /** + * @throws DownloaderException + * @throws RuntimeException + * @throws FileSystemException + */ + public function installMuslCrossMake(string $arch): void + { + $musl_compile_source = [ + 'type' => 'url', + 'url' => "https://musl.cc/{$arch}-native.tgz", + ]; + Downloader::downloadSource('musl-compile-native', $musl_compile_source); + FileSystem::extractSource('musl-compile-native', DOWNLOAD_PATH . "/{$arch}-native.tgz", '/usr/local/musl'); + } } diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 30b90f34d..d12a31cee 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -59,7 +59,7 @@ class LinuxToolCheckList 'libaudit-dev', 'libdb-dev', 'libfl-dev', 'libselinux1-dev', 'libssl-dev', 'libtool', 'libxml2-utils', 'make', 'pkg-config', - 'sed', 'w3m', 'xsltproc', 'xz-utils', + 'sed', 'w3m', 'xsltproc', 'xz', 'libpam0g-dev', ]; From 2e9e10dcf04261275f40e815f9086b54618cdced Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 10 Oct 2023 19:51:24 +0200 Subject: [PATCH 43/58] fix bash profile file for non-bash systems --- src/SPC/doctor/item/LinuxMuslCheck.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SPC/doctor/item/LinuxMuslCheck.php b/src/SPC/doctor/item/LinuxMuslCheck.php index a296e7fc5..05c7c8b7c 100644 --- a/src/SPC/doctor/item/LinuxMuslCheck.php +++ b/src/SPC/doctor/item/LinuxMuslCheck.php @@ -58,8 +58,9 @@ public function fixMusl(): void $prefix = 'sudo '; logger()->warning('Current user is not root, using sudo for running command'); } + $profile = file_exists('~/.bash_profile') ? '~/.bash_profile' : '~/.profile'; if (!getenv('PATH') || !str_contains(getenv('PATH'), '/usr/local/musl/bin')) { - $fix_path = 'echo "export PATH=/usr/local/musl/bin:$PATH" >> ~/.bash_profile && export PATH=/usr/local/musl/bin:$PATH'; + $fix_path = 'echo "export PATH=/usr/local/musl/bin:$PATH" >> ' . $profile . ' && export PATH=/usr/local/musl/bin:$PATH'; shell(true)->exec($prefix . $fix_path); } } From dd273d4c820f1820a7590c45e9f89eca13f1bfe1 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 10 Oct 2023 19:54:53 +0200 Subject: [PATCH 44/58] make fixmusl return bool again --- src/SPC/doctor/item/LinuxMuslCheck.php | 37 +++++++++++++++----------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/SPC/doctor/item/LinuxMuslCheck.php b/src/SPC/doctor/item/LinuxMuslCheck.php index 05c7c8b7c..b49c03a2a 100644 --- a/src/SPC/doctor/item/LinuxMuslCheck.php +++ b/src/SPC/doctor/item/LinuxMuslCheck.php @@ -40,28 +40,33 @@ public function checkMusl(): CheckResult * @throws WrongUsageException */ #[AsFixItem('fix-musl')] - public function fixMusl(): void + public function fixMusl(): bool { $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; $musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m')); $cross_compile_lib = '/usr/local/musl/lib/libc.a'; - if (!file_exists($musl_wrapper_lib)) { - $this->installMuslWrapper(); - } - if (!file_exists($cross_compile_lib)) { - $this->installMuslCrossMake($arch); - } + try { + if (!file_exists($musl_wrapper_lib)) { + $this->installMuslWrapper(); + } + if (!file_exists($cross_compile_lib)) { + $this->installMuslCrossMake($arch); + } - $prefix = ''; - if (get_current_user() !== 'root') { - $prefix = 'sudo '; - logger()->warning('Current user is not root, using sudo for running command'); - } - $profile = file_exists('~/.bash_profile') ? '~/.bash_profile' : '~/.profile'; - if (!getenv('PATH') || !str_contains(getenv('PATH'), '/usr/local/musl/bin')) { - $fix_path = 'echo "export PATH=/usr/local/musl/bin:$PATH" >> ' . $profile . ' && export PATH=/usr/local/musl/bin:$PATH'; - shell(true)->exec($prefix . $fix_path); + $prefix = ''; + if (get_current_user() !== 'root') { + $prefix = 'sudo '; + logger()->warning('Current user is not root, using sudo for running command'); + } + $profile = file_exists('~/.bash_profile') ? '~/.bash_profile' : '~/.profile'; + if (!getenv('PATH') || !str_contains(getenv('PATH'), '/usr/local/musl/bin')) { + $fix_path = 'echo "export PATH=/usr/local/musl/bin:$PATH" >> ' . $profile . ' && export PATH=/usr/local/musl/bin:$PATH'; + shell(true)->exec($prefix . $fix_path); + } + return true; + } catch (RuntimeException) { + return false; } } From f151a314bd76bfa17911d4b079752fd3a6294793 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 11 Oct 2023 18:00:42 +0200 Subject: [PATCH 45/58] support alpine again, just use preinstalled gcc and g++ --- src/SPC/builder/BuilderBase.php | 6 ++-- src/SPC/builder/linux/LinuxBuilder.php | 30 ++++++++++++-------- src/SPC/builder/linux/library/icu.php | 14 ++++++---- src/SPC/doctor/item/LinuxMuslCheck.php | 32 ++++++++++++++++------ src/SPC/doctor/item/LinuxToolCheckList.php | 22 +++++++-------- 5 files changed, 64 insertions(+), 40 deletions(-) diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 6ba6d9a8a..8d8d46dd1 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -148,14 +148,12 @@ public function hasCppExtension(): bool { // judge cpp-extension $exts = array_keys($this->getExts()); - $cpp = false; foreach ($exts as $ext) { if (Config::getExt($ext, 'cpp-extension', false) === true) { - $cpp = true; - break; + return true; } } - return $cpp; + return false; } /** diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 898521ea9..639e220c2 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -40,16 +40,22 @@ public function __construct(array $options = []) $this->options = $options; logger()->debug('Current OS: ' . SystemUtil::getOSRelease()['dist'] . ' ' . SystemUtil::getOSRelease()['ver']); // ---------- set necessary options ---------- - // set C Compiler (default: alpine: gcc, others: musl-gcc) - $compiler_prefix = match (arch2gnu(php_uname('m'))) { - 'x86_64' => 'x86_64-linux-musl-', - 'aarch64' => 'aarch64-linux-musl-', - default => '' - }; - $this->setOptionIfNotExist('library_path', '/usr/local/musl/lib:/usr/local/musl/' . substr($compiler_prefix, 0, -1) . '/lib'); - $this->setOptionIfNotExist('cc', "{$compiler_prefix}gcc"); - // set C++ Compiler (default: g++) - $this->setOptionIfNotExist('cxx', "{$compiler_prefix}g++"); + if (SystemUtil::getOSRelease()['dist'] === 'alpine') { + $this->setOptionIfNotExist('cc', 'gcc'); + // set C++ Compiler (default: g++) + $this->setOptionIfNotExist('cxx', 'g++'); + } else { + $compiler_prefix = match (arch2gnu(php_uname('m'))) { + 'x86_64' => 'x86_64-linux-musl-', + 'aarch64' => 'aarch64-linux-musl-', + default => '' + }; + $this->setOptionIfNotExist('library_path', '/usr/local/musl/lib:/usr/local/musl/' . substr($compiler_prefix, 0, -1) . '/lib'); + // set C Compiler (default: alpine: gcc, others: musl-gcc) + $this->setOptionIfNotExist('cc', "{$compiler_prefix}gcc"); + // set C++ Compiler (default: g++) + $this->setOptionIfNotExist('cxx', "{$compiler_prefix}g++"); + } // set arch (default: current) $this->setOptionIfNotExist('arch', php_uname('m')); $this->setOptionIfNotExist('gnu-arch', arch2gnu($this->getOption('arch'))); @@ -137,7 +143,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void } else { $extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", array_filter($this->getAllStaticLibFiles()))); } - // add libstdc++, some extensions or libraries need it (C++ cannot be linked statically) + // add libstdc++, some extensions or libraries need it $extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCppExtension() ? '-lstdc++ ' : ''); $this->setOption('extra-libs', $extra_libs); @@ -191,7 +197,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; shell()->cd(SOURCE_PATH . '/php-src') ->exec( - 'LD_LIBRARY_PATH=/usr/local/musl/' . $arch . '/lib ' . + (SystemUtil::getOSRelease()['dist'] === 'alpine' ? '' : "LD_LIBRARY_PATH=/usr/local/musl/{$arch}/lib ") . './configure ' . '--prefix= ' . '--with-valgrind=no ' . diff --git a/src/SPC/builder/linux/library/icu.php b/src/SPC/builder/linux/library/icu.php index 1a414483a..b7a8edcf2 100644 --- a/src/SPC/builder/linux/library/icu.php +++ b/src/SPC/builder/linux/library/icu.php @@ -4,6 +4,8 @@ namespace SPC\builder\linux\library; +use SPC\builder\linux\SystemUtil; + class icu extends LinuxLibraryBase { public const NAME = 'icu'; @@ -11,11 +13,13 @@ class icu extends LinuxLibraryBase protected function build(): void { $root = BUILD_ROOT_PATH; - $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; - $cppflag = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"'; + $is_alpine = SystemUtil::getOSRelease()['dist'] === 'alpine'; + $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl/' : 'aarch64-linux-musl/'; + $ld_library_path = $is_alpine ? '' : "LD_LIBRARY_PATH=/usr/local/musl/{$arch}/lib "; + $cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"'; shell()->cd($this->source_dir . '/source') ->exec( - "{$this->builder->configure_env} {$cppflag} ./runConfigureICU Linux " . + "{$this->builder->configure_env} {$cppflags} ./runConfigureICU Linux " . '--enable-static ' . '--disable-shared ' . '--with-data-packaging=static ' . @@ -29,7 +33,7 @@ protected function build(): void "--prefix={$root}" ) ->exec('make clean') - ->exec("LD_LIBRARY_PATH=/usr/local/musl/{$arch}/lib make -j{$this->builder->concurrency}") - ->exec("LD_LIBRARY_PATH=/usr/local/musl/{$arch}/lib make install"); + ->exec("{$ld_library_path}make -j{$this->builder->concurrency}") + ->exec("{$ld_library_path}make install"); } } diff --git a/src/SPC/doctor/item/LinuxMuslCheck.php b/src/SPC/doctor/item/LinuxMuslCheck.php index b49c03a2a..38f237b69 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; @@ -20,21 +21,27 @@ class LinuxMuslCheck /** * @throws WrongUsageException */ - #[AsCheckItem('if musl-libc is installed', limit_os: 'Linux')] + #[AsCheckItem('if musl-gcc is installed', limit_os: 'Linux')] public function checkMusl(): CheckResult { $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; - $cross_compile_lib = "/usr/local/musl/{$arch}/lib/libc.a"; + $cross_compile_lib = '/usr/local/musl/lib/libc.a'; + $cross_compile_gcc = "/usr/local/musl/bin/{$arch}-gcc"; $musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m')); - if (file_exists($musl_wrapper_lib) && file_exists($cross_compile_lib)) { - return CheckResult::ok(); + if (file_exists($musl_wrapper_lib)) { + // alpine doesn't need musl-compile because gcc targets musl by default + if (SystemUtil::getOSRelease()['dist'] === 'alpine') { + return CheckResult::ok(); + } + if (file_exists($cross_compile_lib) || file_exists($cross_compile_gcc)) { + return CheckResult::ok(); + } } return CheckResult::fail('musl-libc is not installed on your system', 'fix-musl'); } /** @noinspection PhpUnused */ /** - * @throws RuntimeException * @throws DownloaderException * @throws FileSystemException * @throws WrongUsageException @@ -44,13 +51,18 @@ public function fixMusl(): bool { $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; $musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m')); + $musl_wrapper_gcc = '/usr/local/musl/bin/musl-gcc'; $cross_compile_lib = '/usr/local/musl/lib/libc.a'; + $cross_compile_gcc = "/usr/local/musl/bin/{$arch}-gcc"; try { - if (!file_exists($musl_wrapper_lib)) { + if (!file_exists(DOWNLOAD_PATH)) { + FileSystem::createDir(DOWNLOAD_PATH); + } + if (!file_exists($musl_wrapper_lib) || !file_exists($musl_wrapper_gcc)) { $this->installMuslWrapper(); } - if (!file_exists($cross_compile_lib)) { + if (SystemUtil::getOSRelease()['dist'] !== 'alpine' && (!file_exists($cross_compile_lib) || !file_exists($cross_compile_gcc))) { $this->installMuslCrossMake($arch); } @@ -60,6 +72,9 @@ public function fixMusl(): bool logger()->warning('Current user is not root, using sudo for running command'); } $profile = file_exists('~/.bash_profile') ? '~/.bash_profile' : '~/.profile'; + if (!file_exists($profile)) { + shell(true)->exec($prefix . 'touch ' . $profile); + } if (!getenv('PATH') || !str_contains(getenv('PATH'), '/usr/local/musl/bin')) { $fix_path = 'echo "export PATH=/usr/local/musl/bin:$PATH" >> ' . $profile . ' && export PATH=/usr/local/musl/bin:$PATH'; shell(true)->exec($prefix . $fix_path); @@ -106,6 +121,7 @@ public function installMuslCrossMake(string $arch): void 'url' => "https://musl.cc/{$arch}-native.tgz", ]; Downloader::downloadSource('musl-compile-native', $musl_compile_source); - FileSystem::extractSource('musl-compile-native', DOWNLOAD_PATH . "/{$arch}-native.tgz", '/usr/local/musl'); + FileSystem::extractSource('musl-compile-native', DOWNLOAD_PATH . "/{$arch}-native.tgz"); + shell(true)->exec('cp -rf ' . SOURCE_PATH . '/musl-compile-native/* /usr/local/musl'); } } diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index d12a31cee..2e671660d 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -20,7 +20,7 @@ class LinuxToolCheckList 'git', 'autoconf', 'automake', 'tar', 'unzip', 'gzip', 'bzip2', 'cmake', 'gcc', - 'g++', 'patch', + 'g++', 'patch', 'curl', ]; public const TOOLS_DEBIAN = [ @@ -28,7 +28,7 @@ class LinuxToolCheckList 'git', 'autoconf', 'automake', 'tar', 'unzip', 'gzip', 'bzip2', 'cmake', 'patch', - 'xz', + 'xz', 'curl', ]; public const TOOLS_RHEL = [ @@ -42,14 +42,14 @@ class LinuxToolCheckList ]; public const PAM_TOOLS_ALPINE = [ - 'autoconf', 'automake', 'autopoint', - 'bison', 'bzip2', 'docbook5-xml', - 'docbook-xsl-ns', 'flex', 'gettext', - 'libaudit-dev', 'libdb-dev', 'libfl-dev', - 'libselinux1-dev', 'libssl-dev', 'libtool', - 'libxml2-utils', 'make', 'pkg-config', - 'sed', 'w3m', 'xsltproc', 'xz-utils', - 'libpam0g-dev', + 'autoconf', 'automake', 'gettext', + 'bison', 'bzip2', 'docbook-xml', + 'docbook-xsl', 'flex', 'gettext', + 'audit-dev', 'db-dev', 'flex-libs', + 'libselinux-dev', 'openssl-dev', 'libtool', + 'libxml2-utils', 'make', 'pkgconfig', + 'sed', 'w3m', 'libxslt-dev', 'xz', + 'linux-pam-dev', ]; public const PAM_TOOLS_DEBIAN = [ @@ -134,7 +134,7 @@ public function fixBuildTools(array $distro, array $missing): bool logger()->warning('Current user is not root, using sudo for running command'); } try { - $to_install = $distro['dist'] === 'redhat' ? $missing : str_replace('xz', 'xz-utils', $missing); + $to_install = $distro['dist'] !== 'debian' ? $missing : str_replace('xz', 'xz-utils', $missing); shell(true)->exec($prefix . $install_cmd . ' ' . implode(' ', $to_install)); } catch (RuntimeException) { return false; From c1c442035900b76c8baec41c2675c2fb28bd585e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 11 Oct 2023 18:18:20 +0200 Subject: [PATCH 46/58] answer imap without openssl automatically --- src/SPC/builder/unix/library/imap.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index 4850fba9e..f2d2802b8 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -59,7 +59,7 @@ protected function build(): void ->exec('make clean') ->exec('touch ip6') ->exec( - "{$this->builder->configure_env} make {$distro} " . + "yes | {$this->builder->configure_env} make {$distro} " . 'EXTRACFLAGS="-fPIC" ' . ( $this->builder->getLib('openssl') ? @@ -67,7 +67,6 @@ protected function build(): void : 'SSLTYPE=none' ) ); - // todo: answer this with y automatically. using SSLTYPE=nopwd creates imap WITH ssl... try { shell() ->exec("cp -rf {$this->source_dir}/c-client/c-client.a " . BUILD_LIB_PATH . '/libc-client.a') From 394426f375ec0823aa349d172a479db92fa33b67 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 11 Oct 2023 19:07:02 +0200 Subject: [PATCH 47/58] full libiconv path instead of -liconv --- src/SPC/builder/extension/iconv.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/extension/iconv.php b/src/SPC/builder/extension/iconv.php index 6e2df2e54..3280d65e8 100644 --- a/src/SPC/builder/extension/iconv.php +++ b/src/SPC/builder/extension/iconv.php @@ -14,8 +14,8 @@ public function patchBeforeConfigure(): bool { // macOS need to link iconv dynamically, we add it to extra-libs $extra_libs = $this->builder->getOption('extra-libs', ''); - if (!str_contains($extra_libs, '-liconv')) { - $extra_libs .= ' -liconv'; + if (!str_contains($extra_libs, 'iconv')) { + $extra_libs .= ' ' . BUILD_LIB_PATH . '/libiconv.a'; } $this->builder->setOption('extra-libs', $extra_libs); return true; From f999045857312a9465758f94b13a858c94413081 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 11 Oct 2023 19:14:51 +0200 Subject: [PATCH 48/58] move imap zts check to extension rather than lib --- src/SPC/builder/extension/imap.php | 4 ++++ src/SPC/builder/unix/library/imap.php | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/extension/imap.php b/src/SPC/builder/extension/imap.php index 025e3c87e..04a99b028 100644 --- a/src/SPC/builder/extension/imap.php +++ b/src/SPC/builder/extension/imap.php @@ -6,6 +6,7 @@ use SPC\builder\Extension; use SPC\exception\FileSystemException; +use SPC\exception\WrongUsageException; use SPC\store\FileSystem; use SPC\util\CustomExt; @@ -14,6 +15,9 @@ class imap extends Extension { public function getUnixConfigureArg(): string { + if ($this->builder->getOption('enable-zts')) { + throw new WrongUsageException('ext-imap is not thread safe, do not build it with ZTS builds'); + } $arg = '--with-imap=' . BUILD_ROOT_PATH; if ($this->builder->getLib('openssl') !== null) { $arg .= ' --with-imap-ssl=' . BUILD_ROOT_PATH; diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index f2d2802b8..84d82fadd 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -45,9 +45,6 @@ public function patchBeforeBuild(): bool */ protected function build(): void { - if ($this->builder->getOption('enable-zts')) { - throw new WrongUsageException('ext-imap is not thread safe, do not build it with ZTS builds'); - } $distro = match (SystemUtil::getOSRelease()['dist']) { 'redhat', 'alpine' => 'slx', default => 'ldb' From acb9fc3bd682b979107f909fdc85de2183a68f95 Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Thu, 12 Oct 2023 16:54:41 +0200 Subject: [PATCH 49/58] simplify build --- src/SPC/builder/linux/LinuxBuilder.php | 26 +++++++++---------------- src/SPC/builder/unix/library/snappy.php | 2 +- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 639e220c2..17f93fde2 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -42,19 +42,12 @@ public function __construct(array $options = []) // ---------- set necessary options ---------- if (SystemUtil::getOSRelease()['dist'] === 'alpine') { $this->setOptionIfNotExist('cc', 'gcc'); - // set C++ Compiler (default: g++) $this->setOptionIfNotExist('cxx', 'g++'); } else { - $compiler_prefix = match (arch2gnu(php_uname('m'))) { - 'x86_64' => 'x86_64-linux-musl-', - 'aarch64' => 'aarch64-linux-musl-', - default => '' - }; - $this->setOptionIfNotExist('library_path', '/usr/local/musl/lib:/usr/local/musl/' . substr($compiler_prefix, 0, -1) . '/lib'); - // set C Compiler (default: alpine: gcc, others: musl-gcc) - $this->setOptionIfNotExist('cc', "{$compiler_prefix}gcc"); - // set C++ Compiler (default: g++) - $this->setOptionIfNotExist('cxx', "{$compiler_prefix}g++"); + $arch = arch2gnu(php_uname('m')); + $this->setOptionIfNotExist('library_path', '/usr/local/musl/lib'); + $this->setOptionIfNotExist('cc', "{$arch}-linux-musl-gcc"); + $this->setOptionIfNotExist('cxx', "{$arch}-linux-musl-g++"); } // set arch (default: current) $this->setOptionIfNotExist('arch', php_uname('m')); @@ -62,7 +55,7 @@ public function __construct(array $options = []) // ---------- set necessary compile environments ---------- // set libc - $this->libc = $this->getOption('cc', 'gcc') === 'musl-gcc' ? 'musl_wrapper' : 'musl'; // SystemUtil::selectLibc($this->cc); + $this->libc = str_ends_with($this->getOption('cc', 'gcc'), 'musl-gcc') ? 'musl_wrapper' : 'musl'; // SystemUtil::selectLibc($this->cc); // concurrency $this->concurrency = SystemUtil::getCpuCount(); // cflags @@ -144,7 +137,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", array_filter($this->getAllStaticLibFiles()))); } // add libstdc++, some extensions or libraries need it - $extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCppExtension() ? '-lstdc++ ' : ''); + $extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCppExtension() ? '/usr/local/musl/lib/libstdc++.a ' : ''); $this->setOption('extra-libs', $extra_libs); $cflags = $this->arch_c_flags; @@ -153,7 +146,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void switch ($this->libc) { case 'musl_wrapper': case 'glibc': - $cflags .= ' -static-libgcc -I"' . BUILD_INCLUDE_PATH . '"'; + $cflags .= ' -static-libgcc -static-libstdc++ -I"' . BUILD_INCLUDE_PATH . '"'; break; case 'musl': if (str_ends_with($this->getOption('cc'), 'clang') && SystemUtil::findCommand('lld')) { @@ -194,10 +187,9 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO; $enableEmbed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED; - $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl'; shell()->cd(SOURCE_PATH . '/php-src') ->exec( - (SystemUtil::getOSRelease()['dist'] === 'alpine' ? '' : "LD_LIBRARY_PATH=/usr/local/musl/{$arch}/lib ") . + (SystemUtil::getOSRelease()['dist'] === 'alpine' ? '' : 'LD_LIBRARY_PATH=/usr/local/musl/lib ') . './configure ' . '--prefix= ' . '--with-valgrind=no ' . @@ -209,10 +201,10 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void ($enableCli ? '--enable-cli ' : '--disable-cli ') . ($enableFpm ? '--enable-fpm ' : '--disable-fpm ') . ($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') . + ($enableMicro ? '--enable-micro=all-static ' : '--disable-micro ') . $json_74 . $zts . $maxExecutionTimers . - ($enableMicro ? '--enable-micro=all-static ' : '--disable-micro ') . $this->makeExtensionArgs() . ' ' . $envs ); diff --git a/src/SPC/builder/unix/library/snappy.php b/src/SPC/builder/unix/library/snappy.php index c5d62f9db..b713271a1 100644 --- a/src/SPC/builder/unix/library/snappy.php +++ b/src/SPC/builder/unix/library/snappy.php @@ -28,7 +28,7 @@ protected function build(): void '-DSNAPPY_BUILD_BENCHMARKS=OFF ' . '../..' ) - ->exec("cmake --build . -j {$this->builder->concurrency}") + ->exec("cmake --build . -j{$this->builder->concurrency}") ->exec('make install'); if (file_exists(BUILD_ROOT_PATH . '/lib64/libsnappy.a')) { shell()->exec('cp -rf ' . BUILD_ROOT_PATH . '/lib64/* ' . BUILD_ROOT_PATH . '/lib/'); From de18ed30389de74a4ec370c3baad318874ea7e73 Mon Sep 17 00:00:00 2001 From: Marc Henderkes Date: Fri, 13 Oct 2023 10:30:35 +0200 Subject: [PATCH 50/58] update icu --- config/source.json | 4 ++-- src/SPC/builder/linux/library/icu.php | 18 +++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/config/source.json b/config/source.json index 83d3b08ef..8e8b2c075 100644 --- a/config/source.json +++ b/config/source.json @@ -128,8 +128,8 @@ } }, "icu": { - "type": "url", - "url": "https://github.com/unicode-org/icu/releases/download/release-73-1/icu4c-73_1-src.tgz", + "type": "ghtar", + "repo": "unicode-org/icu", "license": { "type": "file", "path": "LICENSE" diff --git a/src/SPC/builder/linux/library/icu.php b/src/SPC/builder/linux/library/icu.php index b7a8edcf2..64fd00702 100644 --- a/src/SPC/builder/linux/library/icu.php +++ b/src/SPC/builder/linux/library/icu.php @@ -4,22 +4,18 @@ namespace SPC\builder\linux\library; -use SPC\builder\linux\SystemUtil; - class icu extends LinuxLibraryBase { public const NAME = 'icu'; protected function build(): void { - $root = BUILD_ROOT_PATH; - $is_alpine = SystemUtil::getOSRelease()['dist'] === 'alpine'; - $arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl/' : 'aarch64-linux-musl/'; - $ld_library_path = $is_alpine ? '' : "LD_LIBRARY_PATH=/usr/local/musl/{$arch}/lib "; $cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"'; - shell()->cd($this->source_dir . '/source') + $ldflags = 'LDFLAGS="-static" LIBS="/usr/local/musl/lib/libstdc++.a"'; + shell()->cd($this->source_dir . '/icu4c/source') ->exec( - "{$this->builder->configure_env} {$cppflags} ./runConfigureICU Linux " . + "{$this->builder->configure_env} {$cppflags} {$ldflags} " . + './runConfigureICU Linux ' . '--enable-static ' . '--disable-shared ' . '--with-data-packaging=static ' . @@ -30,10 +26,10 @@ protected function build(): void '--enable-tools=yes ' . '--enable-tests=no ' . '--enable-samples=no ' . - "--prefix={$root}" + '--prefix=' . BUILD_ROOT_PATH ) ->exec('make clean') - ->exec("{$ld_library_path}make -j{$this->builder->concurrency}") - ->exec("{$ld_library_path}make install"); + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install'); } } From 2067ce4ad8e86482a130b2b8f4e2a571010c5278 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 13 Oct 2023 13:26:54 +0200 Subject: [PATCH 51/58] intl doesn't work anymore?! --- src/SPC/builder/linux/LinuxBuilder.php | 2 +- src/SPC/builder/linux/library/icu.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 17f93fde2..4d767f1ea 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -137,7 +137,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", array_filter($this->getAllStaticLibFiles()))); } // add libstdc++, some extensions or libraries need it - $extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCppExtension() ? '/usr/local/musl/lib/libstdc++.a ' : ''); + $extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCppExtension() ? '-lstdc++ ' : ''); $this->setOption('extra-libs', $extra_libs); $cflags = $this->arch_c_flags; diff --git a/src/SPC/builder/linux/library/icu.php b/src/SPC/builder/linux/library/icu.php index 64fd00702..edd01ca53 100644 --- a/src/SPC/builder/linux/library/icu.php +++ b/src/SPC/builder/linux/library/icu.php @@ -11,10 +11,12 @@ class icu extends LinuxLibraryBase protected function build(): void { $cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"'; - $ldflags = 'LDFLAGS="-static" LIBS="/usr/local/musl/lib/libstdc++.a"'; + $cxxflags = 'CXXFLAGS="-std=c++11"'; + $ldflags = 'LDFLAGS="-static"'; + $libs = file_exists('/usr/local/musl/lib/libstdc++.a') ? 'LIBS="/usr/local/musl/lib/libstdc++.a"' : 'LIBS="-lstdc++"'; shell()->cd($this->source_dir . '/icu4c/source') ->exec( - "{$this->builder->configure_env} {$cppflags} {$ldflags} " . + "{$this->builder->configure_env} {$cppflags} {$cxxflags} {$ldflags} {$libs} " . './runConfigureICU Linux ' . '--enable-static ' . '--disable-shared ' . From 9c0a6bd5cd73e87353279762aa6080462314f591 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 13 Oct 2023 15:30:53 +0200 Subject: [PATCH 52/58] make php-cs-fixer happy --- src/SPC/store/FileSystem.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/SPC/store/FileSystem.php b/src/SPC/store/FileSystem.php index cb674f20c..9cd32df1b 100644 --- a/src/SPC/store/FileSystem.php +++ b/src/SPC/store/FileSystem.php @@ -255,14 +255,13 @@ public static function convertPath(string $path): string /** * 递归或非递归扫描目录,可返回相对目录的文件列表或绝对目录的文件列表 * - * @param string $dir 目录 - * @param bool $recursive 是否递归扫描子目录 - * @param bool|string $relative 是否返回相对目录,如果为true则返回相对目录,如果为false则返回绝对目录 - * @param bool $include_dir 非递归模式下,是否包含目录 - * @return array|false + * @param string $dir 目录 + * @param bool $recursive 是否递归扫描子目录 + * @param bool|string $relative 是否返回相对目录,如果为true则返回相对目录,如果为false则返回绝对目录 + * @param bool $include_dir 非递归模式下,是否包含目录 * @since 2.5 */ - public static function scanDirFiles(string $dir, bool $recursive = true, bool|string $relative = false, bool $include_dir = false): bool|array + public static function scanDirFiles(string $dir, bool $recursive = true, bool|string $relative = false, bool $include_dir = false): array|false { $dir = self::convertPath($dir); // 不是目录不扫,直接 false 处理 @@ -402,7 +401,7 @@ public static function createDir(string $path): void * @param mixed ...$args Arguments passed to file_put_contents * @throws FileSystemException */ - public static function writeFile(string $path, mixed $content, ...$args): bool|string|int + public static function writeFile(string $path, mixed $content, ...$args): bool|int|string { $dir = pathinfo($path, PATHINFO_DIRNAME); if (!is_dir($dir) && !mkdir($dir, 0755, true)) { From 7a010ca822cb87b798532457aeeb4e19eddd9c46 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 13 Oct 2023 16:09:29 +0200 Subject: [PATCH 53/58] icu 73.2 flags --- config/source.json | 4 ++-- src/SPC/builder/linux/library/icu.php | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config/source.json b/config/source.json index 8e8b2c075..bf2d6109d 100644 --- a/config/source.json +++ b/config/source.json @@ -128,8 +128,8 @@ } }, "icu": { - "type": "ghtar", - "repo": "unicode-org/icu", + "type": "url", + "url": "https://github.com/unicode-org/icu/releases/download/release-73-2/icu4c-73_2-src.tgz", "license": { "type": "file", "path": "LICENSE" diff --git a/src/SPC/builder/linux/library/icu.php b/src/SPC/builder/linux/library/icu.php index edd01ca53..ab38db6de 100644 --- a/src/SPC/builder/linux/library/icu.php +++ b/src/SPC/builder/linux/library/icu.php @@ -4,6 +4,8 @@ namespace SPC\builder\linux\library; +use SPC\builder\linux\SystemUtil; + class icu extends LinuxLibraryBase { public const NAME = 'icu'; @@ -13,8 +15,8 @@ protected function build(): void $cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"'; $cxxflags = 'CXXFLAGS="-std=c++11"'; $ldflags = 'LDFLAGS="-static"'; - $libs = file_exists('/usr/local/musl/lib/libstdc++.a') ? 'LIBS="/usr/local/musl/lib/libstdc++.a"' : 'LIBS="-lstdc++"'; - shell()->cd($this->source_dir . '/icu4c/source') + $libs = SystemUtil::getOSRelease()['dist'] === 'alpine' ? '' : 'LIBS="/usr/local/musl/lib/libstdc++.a"'; + shell()->cd($this->source_dir . '/source') ->exec( "{$this->builder->configure_env} {$cppflags} {$cxxflags} {$ldflags} {$libs} " . './runConfigureICU Linux ' . From 4993bdfcfe665b4be3f0e1e1083a11d7bd6c8c49 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 13 Oct 2023 16:43:09 +0200 Subject: [PATCH 54/58] imagemagick doesn't require all libs, suggest them instead --- config/lib.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/config/lib.json b/config/lib.json index 2a3ea31ed..97c360289 100644 --- a/config/lib.json +++ b/config/lib.json @@ -125,18 +125,18 @@ "libMagickWand-7.Q16HDRI.a" ], "lib-depends": [ - "zlib", - "libpng", - "libjpeg", - "bzip2", - "libwebp", - "freetype" + "zlib" ], "lib-suggests": [ "zstd", "xz", "libzip", - "libxml2" + "libpng", + "libxml2", + "bzip2", + "libwebp", + "libjpeg", + "freetype" ] }, "imap": { From 733b71da58629216a0bf0f23bee98a0d31815c07 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 15 Oct 2023 17:15:58 +0200 Subject: [PATCH 55/58] refactor imap code to be more understandable --- src/SPC/builder/unix/library/imap.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/SPC/builder/unix/library/imap.php b/src/SPC/builder/unix/library/imap.php index 84d82fadd..53f78c8b3 100644 --- a/src/SPC/builder/unix/library/imap.php +++ b/src/SPC/builder/unix/library/imap.php @@ -52,17 +52,16 @@ protected function build(): void if ($distro === 'ldb' && !$this->builder->getLib('libpam')) { throw new WrongUsageException('ext-imap built on your system requires libpam, please build with --with-libs=libpam'); } + if ($this->builder->getLib('openssl')) { + $ssl_options = 'SPECIALAUTHENTICATORS=ssl SSLTYPE=unix.nopwd SSLINCLUDE=' . BUILD_INCLUDE_PATH . ' SSLLIB=' . BUILD_LIB_PATH; + } else { + $ssl_options = 'SSLTYPE=none'; + } shell()->cd($this->source_dir) ->exec('make clean') ->exec('touch ip6') ->exec( - "yes | {$this->builder->configure_env} make {$distro} " . - 'EXTRACFLAGS="-fPIC" ' . - ( - $this->builder->getLib('openssl') ? - ('SPECIALAUTHENTICATORS=ssl SSLTYPE=unix.nopwd SSLINCLUDE=' . BUILD_INCLUDE_PATH . ' SSLLIB=' . BUILD_LIB_PATH) - : 'SSLTYPE=none' - ) + "yes | {$this->builder->configure_env} make {$distro} {$ssl_options}" ); try { shell() From 314c04e86e7cfa9b6ffac4d782b83ab28e71bff1 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 15 Oct 2023 17:16:22 +0200 Subject: [PATCH 56/58] testing changes to use cross-toolchain --- src/SPC/builder/linux/LinuxBuilder.php | 2 +- src/SPC/builder/linux/library/icu.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 4d767f1ea..667156089 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -189,7 +189,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void shell()->cd(SOURCE_PATH . '/php-src') ->exec( - (SystemUtil::getOSRelease()['dist'] === 'alpine' ? '' : 'LD_LIBRARY_PATH=/usr/local/musl/lib ') . + (SystemUtil::getOSRelease()['dist'] === 'alpine' ? '' : 'LD_LIBRARY_PATH=/usr/local/musl/x86_64-linux-musl/lib ') . './configure ' . '--prefix= ' . '--with-valgrind=no ' . diff --git a/src/SPC/builder/linux/library/icu.php b/src/SPC/builder/linux/library/icu.php index ab38db6de..7bd61ac0d 100644 --- a/src/SPC/builder/linux/library/icu.php +++ b/src/SPC/builder/linux/library/icu.php @@ -15,7 +15,7 @@ protected function build(): void $cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"'; $cxxflags = 'CXXFLAGS="-std=c++11"'; $ldflags = 'LDFLAGS="-static"'; - $libs = SystemUtil::getOSRelease()['dist'] === 'alpine' ? '' : 'LIBS="/usr/local/musl/lib/libstdc++.a"'; + $libs = SystemUtil::getOSRelease()['dist'] === 'alpine' ? '' : 'LIBS="-lstdc++"'; shell()->cd($this->source_dir . '/source') ->exec( "{$this->builder->configure_env} {$cppflags} {$cxxflags} {$ldflags} {$libs} " . From c3162c68c11b5d68b079c6ed0f50cca5426a752e Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 16 Oct 2023 10:54:03 +0200 Subject: [PATCH 57/58] remove ext-zip dependency --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 4a7fedde8..706f8d646 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,6 @@ "php": ">= 8.1", "ext-mbstring": "*", "ext-pcntl": "*", - "ext-zip": "*", "laravel/prompts": "^0.1.3", "symfony/console": "^5.4 || ^6 || ^7", "zhamao/logger": "^1.0" From 6cf8a4ba6fb287a4a4039d05aed2ee1d0b2ea085 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Mon, 16 Oct 2023 11:10:27 +0200 Subject: [PATCH 58/58] introduce disable-opcache-jit option to allow frankenphp to compile on alpine-x86 fails with a strange error otherwise --- src/SPC/builder/linux/LinuxBuilder.php | 4 +++- src/SPC/command/BuildCommand.php | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 667156089..edf572316 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -181,6 +181,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $maxExecutionTimers = ''; $zts = ''; } + $disable_jit = $this->getOption('disable-opcache-jit', false) ? '--disable-opcache-jit ' : ''; $enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI; $enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM; @@ -202,6 +203,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void ($enableFpm ? '--enable-fpm ' : '--disable-fpm ') . ($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') . ($enableMicro ? '--enable-micro=all-static ' : '--disable-micro ') . + $disable_jit . $json_74 . $zts . $maxExecutionTimers . @@ -334,7 +336,7 @@ public function buildFpm(string $use_lld): void public function buildEmbed(string $use_lld): void { $vars = SystemUtil::makeEnvVarString([ - 'EXTRA_CFLAGS' => '-g -Os -fno-ident -fPIE ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)), + 'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)), 'EXTRA_LIBS' => $this->getOption('extra-libs'), 'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static", ]); diff --git a/src/SPC/command/BuildCommand.php b/src/SPC/command/BuildCommand.php index 98bb77b3a..072347774 100644 --- a/src/SPC/command/BuildCommand.php +++ b/src/SPC/command/BuildCommand.php @@ -30,5 +30,6 @@ public function __construct(string $name = null) $this->addOption('with-clean', null, null, 'fresh build, remove `source` dir before `make`'); $this->addOption('bloat', null, null, 'add all libraries into binary'); + $this->addOption('disable-opcache-jit', null, null, 'disables opcache-jit'); } }