From 082617f26bc356934fdf37edee82125c89f8c054 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Sat, 22 Apr 2023 14:21:26 +0800 Subject: [PATCH 01/24] =?UTF-8?q?=E5=AE=8C=E5=96=84=20gd=20=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E4=BE=9D=E8=B5=96=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/ext.json | 6 +- config/lib.json | 72 ++++++++++++++++++++++ config/source.json | 26 ++++++++ quickstart/linux/x86_64/prepare.sh | 3 + src/SPC/builder/linux/library/freetype.php | 44 +++++++++++++ src/SPC/builder/linux/library/libgif.php | 31 ++++++++++ src/SPC/builder/linux/library/libjpeg.php | 45 ++++++++++++++ src/SPC/builder/linux/library/libwebp.php | 51 +++++++++++++++ 8 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 src/SPC/builder/linux/library/freetype.php create mode 100644 src/SPC/builder/linux/library/libgif.php create mode 100644 src/SPC/builder/linux/library/libjpeg.php create mode 100644 src/SPC/builder/linux/library/libwebp.php diff --git a/config/ext.json b/config/ext.json index ceb1ee090..1d6e57cd7 100644 --- a/config/ext.json +++ b/config/ext.json @@ -63,7 +63,11 @@ "arg-type-windows": "with", "lib-depends": [ "zlib", - "libpng" + "libpng", + "libjpeg", + "freetype", + "libgif", + "libwebp" ], "ext-depends": [ "zlib" diff --git a/config/lib.json b/config/lib.json index 41aa95679..5f550b13d 100644 --- a/config/lib.json +++ b/config/lib.json @@ -150,6 +150,78 @@ "zlib" ] }, + "libjpeg": { + "source": "libjpeg", + "static-libs-unix": [ + + ], + "static-libs-windows": [ + + ], + "headers-unix": [ + + ], + "headers-windows": [ + + ], + "lib-depends": [ + + ] + }, + "libgif": { + "source": "libgif", + "static-libs-unix": [ + + ], + "static-libs-windows": [ + + ], + "headers-unix": [ + + ], + "headers-windows": [ + + ], + "lib-depends": [ + + ] + }, + "libwebp": { + "source": "libwebp", + "static-libs-unix": [ + + ], + "static-libs-windows": [ + + ], + "headers-unix": [ + + ], + "headers-windows": [ + + ], + "lib-depends": [ + + ] + }, + "freetype": { + "source": "freetype", + "static-libs-unix": [ + + ], + "static-libs-windows": [ + + ], + "headers-unix": [ + + ], + "headers-windows": [ + + ], + "lib-depends": [ + + ] + }, "libssh2": { "source": "libssh2", "static-libs-unix": [ diff --git a/config/source.json b/config/source.json index cfe329ba4..c70918610 100644 --- a/config/source.json +++ b/config/source.json @@ -95,6 +95,32 @@ "text": "COPYRIGHT NOTICE, DISCLAIMER, and LICENSE\n=========================================\n\nPNG Reference Library License version 2\n---------------------------------------\n\n * Copyright (c) 1995-2019 The PNG Reference Library Authors.\n * Copyright (c) 2018-2019 Cosmin Truta.\n * Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson.\n * Copyright (c) 1996-1997 Andreas Dilger.\n * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n\nThe software is supplied \"as is\", without warranty of any kind,\nexpress or implied, including, without limitation, the warranties\nof merchantability, fitness for a particular purpose, title, and\nnon-infringement. In no event shall the Copyright owners, or\nanyone distributing the software, be liable for any damages or\nother liability, whether in contract, tort or otherwise, arising\nfrom, out of, or in connection with the software, or the use or\nother dealings in the software, even if advised of the possibility\nof such damage.\n\nPermission is hereby granted to use, copy, modify, and distribute\nthis software, or portions hereof, for any purpose, without fee,\nsubject to the following restrictions:\n\n 1. The origin of this software must not be misrepresented; you\n must not claim that you wrote the original software. If you\n use this software in a product, an acknowledgment in the product\n documentation would be appreciated, but is not required.\n\n 2. Altered source versions must be plainly marked as such, and must\n not be misrepresented as being the original software.\n\n 3. This Copyright notice may not be removed or altered from any\n source or altered source distribution.\n\n\nPNG Reference Library License version 1 (for libpng 0.5 through 1.6.35)\n-----------------------------------------------------------------------\n\nlibpng versions 1.0.7, July 1, 2000, through 1.6.35, July 15, 2018 are\nCopyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson, are\nderived from libpng-1.0.6, and are distributed according to the same\ndisclaimer and license as libpng-1.0.6 with the following individuals\nadded to the list of Contributing Authors:\n\n Simon-Pierre Cadieux\n Eric S. Raymond\n Mans Rullgard\n Cosmin Truta\n Gilles Vollant\n James Yu\n Mandar Sahastrabuddhe\n Google Inc.\n Vadim Barkov\n\nand with the following additions to the disclaimer:\n\n There is no warranty against interference with your enjoyment of\n the library or against infringement. There is no warranty that our\n efforts or the library will fulfill any of your particular purposes\n or needs. This library is provided with all faults, and the entire\n risk of satisfactory quality, performance, accuracy, and effort is\n with the user.\n\nSome files in the \"contrib\" directory and some configure-generated\nfiles that are distributed with libpng have other copyright owners, and\nare released under other open source licenses.\n\nlibpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are\nCopyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from\nlibpng-0.96, and are distributed according to the same disclaimer and\nlicense as libpng-0.96, with the following individuals added to the\nlist of Contributing Authors:\n\n Tom Lane\n Glenn Randers-Pehrson\n Willem van Schaik\n\nlibpng versions 0.89, June 1996, through 0.96, May 1997, are\nCopyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,\nand are distributed according to the same disclaimer and license as\nlibpng-0.88, with the following individuals added to the list of\nContributing Authors:\n\n John Bowler\n Kevin Bracey\n Sam Bushell\n Magnus Holmgren\n Greg Roelofs\n Tom Tanner\n\nSome files in the \"scripts\" directory have other copyright owners,\nbut are released under this license.\n\nlibpng versions 0.5, May 1995, through 0.88, January 1996, are\nCopyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n\nFor the purposes of this copyright and license, \"Contributing Authors\"\nis defined as the following set of individuals:\n\n Andreas Dilger\n Dave Martindale\n Guy Eric Schalnat\n Paul Schmidt\n Tim Wegner\n\nThe PNG Reference Library is supplied \"AS IS\". The Contributing\nAuthors and Group 42, Inc. disclaim all warranties, expressed or\nimplied, including, without limitation, the warranties of\nmerchantability and of fitness for any purpose. The Contributing\nAuthors and Group 42, Inc. assume no liability for direct, indirect,\nincidental, special, exemplary, or consequential damages, which may\nresult from the use of the PNG Reference Library, even if advised of\nthe possibility of such damage.\n\nPermission is hereby granted to use, copy, modify, and distribute this\nsource code, or portions hereof, for any purpose, without fee, subject\nto the following restrictions:\n\n 1. The origin of this source code must not be misrepresented.\n\n 2. Altered versions must be plainly marked as such and must not\n be misrepresented as being the original source.\n\n 3. This Copyright notice may not be removed or altered from any\n source or altered source distribution.\n\nThe Contributing Authors and Group 42, Inc. specifically permit,\nwithout fee, and encourage the use of this source code as a component\nto supporting the PNG file format in commercial products. If you use\nthis source code in a product, acknowledgment is not required but would\nbe appreciated.\n" } }, + "libjpeg": { + "type": "git", + "url": "https://github.com/libjpeg-turbo/libjpeg-turbo.git", + "rev": "2.1.91", + "license": { + "type": "file", + "path": "LICENSE" + } + }, + "libgif": { + "type": "url", + "url": "https://nchc.dl.sourceforge.net/project/giflib/giflib-5.2.1.tar.gz", + "license": { + "type": "file", + "path": "LICENSE" + } + }, + "libwebp": { + "type": "git", + "url": "https://chromium.googlesource.com/webm/libwebp", + "rev": "v1.3.0", + "license": { + "type": "file", + "path": "COPYING" + } + }, "libressl": { "type": "filelist", "url": "https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/", diff --git a/quickstart/linux/x86_64/prepare.sh b/quickstart/linux/x86_64/prepare.sh index bd2783309..5d417fdc8 100644 --- a/quickstart/linux/x86_64/prepare.sh +++ b/quickstart/linux/x86_64/prepare.sh @@ -23,3 +23,6 @@ chmod +x bin/spc #./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo,pdo_sqlite,ftp,curl" --cc=gcc --cxx=g++ --debug ./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo,pdo_sqlite,ftp,curl" --cc=clang --cxx=clang++ --debug + + +./bin/spc build gd --debug --cc=clang --cxx=clang++ diff --git a/src/SPC/builder/linux/library/freetype.php b/src/SPC/builder/linux/library/freetype.php new file mode 100644 index 000000000..50eab43ad --- /dev/null +++ b/src/SPC/builder/linux/library/freetype.php @@ -0,0 +1,44 @@ +cd($this->source_dir) + ->exec( + <<builder->configure_env} \\ + BZIP2_CFLAGS="-I{$include}" \\ + BZIP2_LIBS="-L{$lib} -lbz2" \\ + CPPFLAGS="$(pkg-config --cflags-only-I --static zlib libpng libbrotlicommon libbrotlidec libbrotlienc)" \\ + LDFLAGS="$(pkg-config --libs-only-L --static zlib libpng libbrotlicommon libbrotlidec libbrotlienc)" \\ + LIBS="$(pkg-config --libs-only-l --static zlib libpng libbrotlicommon libbrotlidec libbrotlienc)" \\ + ./configure --prefix=/ \\ + --enable-static \\ + --disable-shared \\ + --with-zlib=yes \\ + --with-bzip2=yes \\ + --with-png=yes \\ + --with-harfbuzz=no \\ + --with-brotli=yes +EOF + ) + ->exec("make -j {$this->builder->concurrency}") + ->exec('make install'); + } +} diff --git a/src/SPC/builder/linux/library/libgif.php b/src/SPC/builder/linux/library/libgif.php new file mode 100644 index 000000000..a819eac9d --- /dev/null +++ b/src/SPC/builder/linux/library/libgif.php @@ -0,0 +1,31 @@ +cd($this->source_dir) + ->exec("make -j {$this->builder->concurrency} libgif.a") + ->exec( + <<cd($this->source_dir) + ->exec( + <<builder->configure_env} \\ + cmake -G"Unix Makefiles" \\ + -DCMAKE_INSTALL_PREFIX=/ \\ + -DCMAKE_INSTALL_LIBDIR={$lib} \\ + -DCMAKE_INSTALL_INCLUDEDIR={$include} \\ + -DCMAKE_BUILD_TYPE=Release \\ + -DBUILD_SHARED_LIBS=OFF \\ + -DBUILD_STATIC_LIBS=ON +EOF + ) + ->exec("make -j {$this->builder->concurrency}") + ->exec('make install') + ->exec( + <<cd($this->source_dir) + ->exec( + <<builder->configure_env} \\ + ./autogen.sh + EOF + ) + ->exec( + <<builder->configure_env} \\ + CPPFLAGS="$(pkg-config --cflags-only-I --static libpng libjpeg )" \\ + LDFLAGS="$(pkg-config --libs-only-L --static libpng libjpeg )" \\ + LIBS="$(pkg-config --libs-only-l --static libpng libjpeg )" \\ + ./configure --prefix=/ \\ + --enable-static --disable-shared \\ + --enable-libwebpdecoder \\ + --enable-libwebpextras \\ + --with-pngincludedir={$include} \\ + --with-pnglibdir={$lib} \\ + --with-jpegincludedir={$include} \\ + --with-jpeglibdir={$lib} \\ + --with-gifincludedir={$include} \\ + --with-giflibdir={$lib} \\ + --disable-tiff +EOF + ) + ->exec("make -j {$this->builder->concurrency}") + ->exec('make install'); + } +} From 374197715c297e5d5c88954aa4e6434cd7f635a9 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Sat, 22 Apr 2023 20:11:40 +0800 Subject: [PATCH 02/24] =?UTF-8?q?=E5=AE=8C=E5=96=84libgif=20libpng=20libwe?= =?UTF-8?q?bp=20freetype=20brotli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quickstart/linux/x86_64/prepare.sh | 6 ++++ src/SPC/builder/BuilderBase.php | 2 ++ src/SPC/builder/linux/library/brotli.php | 25 ++++++++------ src/SPC/builder/linux/library/freetype.php | 2 +- src/SPC/builder/linux/library/libgif.php | 8 ++--- src/SPC/builder/linux/library/libjpeg.php | 19 ++++++----- src/SPC/builder/linux/library/libpng.php | 38 ++++++++++++++-------- src/SPC/builder/linux/library/libwebp.php | 4 +-- src/SPC/builder/linux/library/zlib.php | 5 ++- src/globals/defines.php | 8 ++--- 10 files changed, 68 insertions(+), 49 deletions(-) diff --git a/quickstart/linux/x86_64/prepare.sh b/quickstart/linux/x86_64/prepare.sh index 5d417fdc8..d929a3a3e 100644 --- a/quickstart/linux/x86_64/prepare.sh +++ b/quickstart/linux/x86_64/prepare.sh @@ -26,3 +26,9 @@ chmod +x bin/spc ./bin/spc build gd --debug --cc=clang --cxx=clang++ + +./bin/spc build:libs libjpeg --debug --cc=clang --cxx=clang++ +./bin/spc build:libs libjpeg --debug --cc=clang --cxx=clang++ --clean + +./bin/spc build:libs libgif --debug --cc=clang --cxx=clang++ +./bin/spc build:libs libwebp --debug --cc=clang --cxx=clang++ diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 4adb12572..64b54759f 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -87,7 +87,9 @@ public function buildLibs(array $libraries): void foreach ($this->libs as $lib) { $lib->calcDependency(); } + foreach ($this->libs as $lib) { + $lib->build(); match ($lib->tryBuild()) { BUILD_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] build success'), BUILD_STATUS_ALREADY => logger()->notice('lib [' . $lib::NAME . '] already built'), diff --git a/src/SPC/builder/linux/library/brotli.php b/src/SPC/builder/linux/library/brotli.php index 44338f60c..8f193c509 100644 --- a/src/SPC/builder/linux/library/brotli.php +++ b/src/SPC/builder/linux/library/brotli.php @@ -42,18 +42,23 @@ public function build() $this->builder->configure_env . ' cmake ' . '-DCMAKE_BUILD_TYPE=Release ' . '-DBUILD_SHARED_LIBS=OFF ' . - '-DCMAKE_INSTALL_PREFIX=/ ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . + "-DCMAKE_INSTALL_PREFIX={$destdir} " . + "-DCMAKE_INSTALL_LIBDIR={$destdir}/lib " . + "-DCMAKE_INSTALL_INCLUDEDIR={$destdir}/include " . "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . '..' ) - ->exec("cmake --build . -j {$this->builder->concurrency} --target brotlicommon-static") - ->exec("cmake --build . -j {$this->builder->concurrency} --target brotlidec-static") - ->exec("cmake --build . -j {$this->builder->concurrency} --target brotlienc-static") - ->exec('cp libbrotlidec-static.a ' . BUILD_LIB_PATH) - ->exec('cp libbrotlienc-static.a ' . BUILD_LIB_PATH) - ->exec('cp libbrotlicommon-static.a ' . BUILD_LIB_PATH) - ->exec('cp -r ../c/include/brotli ' . BUILD_INCLUDE_PATH); + ->exec("cmake --build . --config Release --target install -j {$this->builder->concurrency}") + ->exec( + <<cd($this->source_dir) ->exec("make -j {$this->builder->concurrency} libgif.a") - ->exec( - <<exec("cp libgif.a {$destdir}/lib//libgif.a") + ->exec("cp gif_lib.h {$destdir}/include/gif_lib.h"); } } diff --git a/src/SPC/builder/linux/library/libjpeg.php b/src/SPC/builder/linux/library/libjpeg.php index 657f01c93..7fc62d9fe 100644 --- a/src/SPC/builder/linux/library/libjpeg.php +++ b/src/SPC/builder/linux/library/libjpeg.php @@ -24,21 +24,24 @@ public function build() <<builder->configure_env} \\ cmake -G"Unix Makefiles" \\ - -DCMAKE_INSTALL_PREFIX=/ \\ - -DCMAKE_INSTALL_LIBDIR={$lib} \\ - -DCMAKE_INSTALL_INCLUDEDIR={$include} \\ + -DCMAKE_INSTALL_PREFIX={$destdir} \\ + -DCMAKE_INSTALL_BINDIR={$destdir}/bin/ \\ + -DCMAKE_INSTALL_LIBDIR={$destdir}/lib \\ + -DCMAKE_INSTALL_INCLUDEDIR={$destdir}/include \\ -DCMAKE_BUILD_TYPE=Release \\ - -DBUILD_SHARED_LIBS=OFF \\ - -DBUILD_STATIC_LIBS=ON + -DENABLE_SHARED=OFF \\ + -DENABLE_STATIC=ON \\ + -DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} + EOF ) ->exec("make -j {$this->builder->concurrency}") ->exec('make install') ->exec( <<builder->arch) { 'x86_64' => '--enable-intel-sse ', @@ -42,24 +43,33 @@ public function build() }; // patch configure - Patcher::patchUnixLibpng(); + // Patcher::patchUnixLibpng(); shell()->cd($this->source_dir) + ->exec('chmod +x ./configure') ->exec( - "{$this->builder->configure_env} ./configure " . - "--host={$this->builder->gnu_arch}-unknown-linux " . - '--disable-shared ' . - '--enable-static ' . - '--enable-hardware-optimizations ' . - '--with-zlib-prefix=' . BUILD_ROOT_PATH . ' ' . - $optimizations . - '--prefix=' + <<builder->configure_env} ./configure \\ + --host={$this->builder->gnu_arch}-unknown-linux \\ + --disable-shared \\ + --enable-static \\ + --enable-hardware-optimizations \\ + --with-zlib-prefix={$destdir} \\ + {$optimizations} \\ + --prefix={$destdir} + EOF ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I. -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la") - ->exec('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH) - ->cd(BUILD_LIB_PATH) - ->exec('ln -sf libpng16.a libpng.a'); + ->exec('make -j ' . $this->builder->concurrency) + ->exec('make install '); + // ->exec('make clean') + // ->exec("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I. -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la") + // ->exec('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH) + // ->cd(BUILD_LIB_PATH) + // ->exec('ln -sf libpng16.a libpng.a'); } } diff --git a/src/SPC/builder/linux/library/libwebp.php b/src/SPC/builder/linux/library/libwebp.php index ce12d2d3d..6acece3e6 100644 --- a/src/SPC/builder/linux/library/libwebp.php +++ b/src/SPC/builder/linux/library/libwebp.php @@ -4,7 +4,6 @@ namespace SPC\builder\linux\library; -use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; class libwebp extends LinuxLibraryBase @@ -13,7 +12,6 @@ class libwebp extends LinuxLibraryBase /** * @throws RuntimeException - * @throws FileSystemException */ public function build() { @@ -32,7 +30,7 @@ public function build() CPPFLAGS="$(pkg-config --cflags-only-I --static libpng libjpeg )" \\ LDFLAGS="$(pkg-config --libs-only-L --static libpng libjpeg )" \\ LIBS="$(pkg-config --libs-only-l --static libpng libjpeg )" \\ - ./configure --prefix=/ \\ + ./configure --prefix={$destdir} \\ --enable-static --disable-shared \\ --enable-libwebpdecoder \\ --enable-libwebpextras \\ diff --git a/src/SPC/builder/linux/library/zlib.php b/src/SPC/builder/linux/library/zlib.php index fcc32c055..04d3fd816 100644 --- a/src/SPC/builder/linux/library/zlib.php +++ b/src/SPC/builder/linux/library/zlib.php @@ -37,10 +37,9 @@ public function build() ->exec( "{$this->builder->configure_env} ./configure " . '--static ' . - '--prefix=' + '--prefix=' . $destdir ) - ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); + ->exec('make install'); } } diff --git a/src/globals/defines.php b/src/globals/defines.php index f241d6084..560060f4b 100644 --- a/src/globals/defines.php +++ b/src/globals/defines.php @@ -6,15 +6,15 @@ use ZM\Logger\ConsoleLogger; define('WORKING_DIR', getcwd()); -const ROOT_DIR = __DIR__ . '/../..'; +define('ROOT_DIR', realpath(__DIR__ . '/../..')); // 程序启动时间 define('START_TIME', microtime(true)); // 规定目录 -define('BUILD_ROOT_PATH', is_string($a = getenv('BUILD_ROOT_PATH')) ? $a : (WORKING_DIR . '/buildroot')); -define('SOURCE_PATH', is_string($a = getenv('SOURCE_PATH')) ? $a : (WORKING_DIR . '/source')); -define('DOWNLOAD_PATH', is_string($a = getenv('DOWNLOAD_PATH')) ? $a : (WORKING_DIR . '/downloads')); +define('BUILD_ROOT_PATH', is_string($a = getenv('BUILD_ROOT_PATH')) ? $a : (ROOT_DIR . '/buildroot')); +define('SOURCE_PATH', is_string($a = getenv('SOURCE_PATH')) ? $a : (ROOT_DIR . '/source')); +define('DOWNLOAD_PATH', is_string($a = getenv('DOWNLOAD_PATH')) ? $a : (ROOT_DIR . '/downloads')); define('BUILD_LIB_PATH', is_string($a = getenv('INSTALL_LIB_PATH')) ? $a : (BUILD_ROOT_PATH . '/lib')); const BUILD_DEPS_PATH = BUILD_ROOT_PATH; define('BUILD_INCLUDE_PATH', is_string($a = getenv('INSTALL_INCLUDE_PATH')) ? $a : (BUILD_ROOT_PATH . '/include')); From 299f56abfea2ff19ab8334bef77dfbf3502d646e Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Sat, 22 Apr 2023 20:14:35 +0800 Subject: [PATCH 03/24] test --- src/SPC/builder/BuilderBase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 64b54759f..bd0a4b886 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -89,7 +89,6 @@ public function buildLibs(array $libraries): void } foreach ($this->libs as $lib) { - $lib->build(); match ($lib->tryBuild()) { BUILD_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] build success'), BUILD_STATUS_ALREADY => logger()->notice('lib [' . $lib::NAME . '] already built'), From 8e4c7829e4a74d03c6c22cd2ea62e9cd1f90bb4a Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Sat, 22 Apr 2023 20:22:55 +0800 Subject: [PATCH 04/24] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84=E9=85=8D=E7=BD=AElibpng=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SPC/builder/linux/library/libpng.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/SPC/builder/linux/library/libpng.php b/src/SPC/builder/linux/library/libpng.php index 6b2f72c4e..0c80ff39e 100644 --- a/src/SPC/builder/linux/library/libpng.php +++ b/src/SPC/builder/linux/library/libpng.php @@ -66,10 +66,5 @@ public function build() ) ->exec('make -j ' . $this->builder->concurrency) ->exec('make install '); - // ->exec('make clean') - // ->exec("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I. -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la") - // ->exec('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH) - // ->cd(BUILD_LIB_PATH) - // ->exec('ln -sf libpng16.a libpng.a'); } } From a70b4b376622b2b9c3b04a6cb5a719761c428b9d Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Sun, 23 Apr 2023 11:51:26 +0800 Subject: [PATCH 05/24] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20china=20mirror?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/setup-runtime | 22 +++++++++++++ quickstart/linux/x86_64/README.md | 19 +++++++++-- quickstart/linux/x86_64/alpine-3.16-init.sh | 25 ++++++++++++-- quickstart/linux/x86_64/debian-11-init.sh | 33 +++++++++++++++---- .../linux/x86_64/run-alpine-3.16-container.sh | 1 + .../linux/x86_64/run-debian-11-container.sh | 1 + src/SPC/builder/linux/LinuxBuilder.php | 2 +- 7 files changed, 91 insertions(+), 12 deletions(-) diff --git a/bin/setup-runtime b/bin/setup-runtime index 54c89455f..e1e057b98 100755 --- a/bin/setup-runtime +++ b/bin/setup-runtime @@ -28,6 +28,28 @@ __PROJECT__=$(cd ${__DIR__}/../ && pwd) __PHP_RUNTIME_URL__="https://github.com/swoole/swoole-src/releases/download/v5.0.1/swoole-cli-v5.0.1-${__OS_FIXED__}-${__ARCH__}.tar.xz" __COMPOSER_URL__="https://getcomposer.org/download/latest-stable/composer.phar" +mirror='' +while [ $# -gt 0 ]; do + case "$1" in + --mirror) + mirror="$2" + shift + ;; + --*) + echo "Illegal option $1" + ;; + esac + shift $(($# > 0 ? 1 : 0)) +done + +case "$mirror" in +china) + __PHP_RUNTIME_URL__="https://wenda-1252906962.file.myqcloud.com/dist/swoole-cli-v5.0.1-${__OS_FIXED__}-${__ARCH__}.tar.xz" + __COMPOSER_URL__="https://mirrors.aliyun.com/composer/composer.phar" + ;; + +esac + # download static-php binary (currently using swoole-cli temporarily) test -d ${__PROJECT__}/downloads || mkdir ${__PROJECT__}/downloads # download static php binary diff --git a/quickstart/linux/x86_64/README.md b/quickstart/linux/x86_64/README.md index deb80a2be..c822abfcb 100644 --- a/quickstart/linux/x86_64/README.md +++ b/quickstart/linux/x86_64/README.md @@ -14,7 +14,10 @@ sh quickstart/linux/x86_64/run-debian-11-container.sh sh quickstart/linux/x86_64/connection-static-php-cli.sh # 准备构建基础软件 -sh quickstart/linux/x86_64/debian-11-init.sh +sh quickstart/linux/x86_64/debian-11-init.sh + +# 准备构建基础软件 使用镜像 +sh quickstart/linux/x86_64/debian-11-init.sh --mirror china ``` @@ -29,6 +32,18 @@ sh quickstart/linux/x86_64/run-alpine-3.16-container.sh sh sh quickstart/linux/x86_64/connection-static-php-cli.sh # 准备构建基础软件 -sh quickstart/linux/x86_64/alpine-3.16-init.sh +sh quickstart/linux/x86_64/alpine-3.16-init.sh + +# 准备构建基础软件 使用镜像 +sh quickstart/linux/x86_64/alpine-3.16-init.sh --mirror china +``` + + +## 准备PHP 运行时镜像 +```bash +sh bin/setup-runtime + +# 使用镜像 +sh bin/setup-runtime --mirror china ``` \ No newline at end of file diff --git a/quickstart/linux/x86_64/alpine-3.16-init.sh b/quickstart/linux/x86_64/alpine-3.16-init.sh index 238e91bdc..18ae828c5 100644 --- a/quickstart/linux/x86_64/alpine-3.16-init.sh +++ b/quickstart/linux/x86_64/alpine-3.16-init.sh @@ -6,8 +6,29 @@ __DIR__=$( pwd ) -test -f /etc/apk/repositories.save || cp /etc/apk/repositories /etc/apk/repositories.save -sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories +mirror='' +while [ $# -gt 0 ]; do + case "$1" in + --mirror) + mirror="$2" + shift + ;; + --*) + echo "Illegal option $1" + ;; + esac + shift $(( $# > 0 ? 1 : 0 )) +done + +case "$mirror" in + china) + test -f /etc/apk/repositories.save || cp /etc/apk/repositories /etc/apk/repositories.save + sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories + ;; + +esac + + apk update diff --git a/quickstart/linux/x86_64/debian-11-init.sh b/quickstart/linux/x86_64/debian-11-init.sh index 9e4463b6b..6dcb52668 100644 --- a/quickstart/linux/x86_64/debian-11-init.sh +++ b/quickstart/linux/x86_64/debian-11-init.sh @@ -6,13 +6,32 @@ __DIR__=$( pwd ) -sed -i "s@deb.debian.org@mirrors.ustc.edu.cn@g" /etc/apt/sources.list && \ -sed -i "s@security.debian.org@mirrors.ustc.edu.cn@g" /etc/apt/sources.list +mirror='' +while [ $# -gt 0 ]; do + case "$1" in + --mirror) + mirror="$2" + shift + ;; + --*) + echo "Illegal option $1" + ;; + esac + shift $(($# > 0 ? 1 : 0)) +done -apt update -y -apt install -y git curl wget ca-certificates -apt install -y xz-utils autoconf automake libclang-13-dev clang lld libtool cmake bison re2c gettext coreutils lzip zip unzip -apt install -y pkg-config bzip2 flex +case "$mirror" in +china) + test -f /etc/apk/repositories.save || cp /etc/apt/sources.list /etc/apt/sources.list.save + sed -i "s@deb.debian.org@mirrors.ustc.edu.cn@g" /etc/apt/sources.list + sed -i "s@security.debian.org@mirrors.ustc.edu.cn@g" /etc/apt/sources.list + ;; + +esac +apt update -y +apt install -y git curl wget ca-certificates +apt install -y xz-utils autoconf automake libclang-13-dev clang lld libtool cmake bison re2c gettext coreutils lzip zip unzip +apt install -y pkg-config bzip2 flex -# apt install build-essential linux-headers-$(uname -r) \ No newline at end of file +# apt install build-essential linux-headers-$(uname -r) diff --git a/quickstart/linux/x86_64/run-alpine-3.16-container.sh b/quickstart/linux/x86_64/run-alpine-3.16-container.sh index b53d9cd43..e0f63ee14 100644 --- a/quickstart/linux/x86_64/run-alpine-3.16-container.sh +++ b/quickstart/linux/x86_64/run-alpine-3.16-container.sh @@ -14,6 +14,7 @@ cd ${__DIR__} { docker stop static-php-cli-dev-1 + sleep 3 } || { echo $? } diff --git a/quickstart/linux/x86_64/run-debian-11-container.sh b/quickstart/linux/x86_64/run-debian-11-container.sh index a9239727a..700d2f6c2 100644 --- a/quickstart/linux/x86_64/run-debian-11-container.sh +++ b/quickstart/linux/x86_64/run-debian-11-container.sh @@ -14,6 +14,7 @@ cd ${__DIR__} { docker stop static-php-cli-dev-1 + sleep 3 } || { echo $? } diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 9d9deaec5..7e1634294 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -161,7 +161,7 @@ public function buildPHP(int $build_micro_rule = BUILD_MICRO_NONE, bool $with_cl $preprocessors .= ' export PATH=' . BUILD_ROOT_PATH . '/bin/:$PATH ;'; $preprocessors .= ' export PACKAGES="libbrotlicommon libbrotlidec libbrotlienc libzip libjpeg libturbojpeg freetype2 libpng libpng16 libwebp " ;'; $preprocessors .= ' export CPPFLAGS="$(pkg-config --cflags-only-I --static $PACKAGES ) " ;'; - $preprocessors .= ' export LIBS="$(pkg-config --libs-only-l --static $PACKAGES ) -lz -lpng16 -lwebpmux -lwebpdemux -lwebpdecoder -lwebp -lm -pthread -lstdc++ " ;'; + $preprocessors .= ' export LIBS="$(pkg-config --libs-only-l --static $PACKAGES ) -lstdc++ " ;'; // -lz -lpng16 -lwebpmux -lwebpdemux -lwebpdecoder -lwebp -lm -pthread $preprocessors .= ' export LD=ld.lld ;'; $use_lld .= ' -L' . BUILD_LIB_PATH; From 31bad1b77c37691e3d44def7c275662bdce036f1 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Sun, 23 Apr 2023 12:41:21 +0800 Subject: [PATCH 06/24] =?UTF-8?q?=E9=AA=8C=E8=AF=81gdz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quickstart/linux/x86_64/prepare.sh | 13 ++++++++----- src/SPC/builder/BuilderBase.php | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/quickstart/linux/x86_64/prepare.sh b/quickstart/linux/x86_64/prepare.sh index 1be41b64c..a02d98f21 100644 --- a/quickstart/linux/x86_64/prepare.sh +++ b/quickstart/linux/x86_64/prepare.sh @@ -15,22 +15,25 @@ composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ chmod +x bin/spc -./bin/spc fetch --all --debug +# ./bin/spc fetch --all --debug ./bin/spc list-ext #./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo,pdo_sqlite,ftp,curl" --cc=gcc --cxx=g++ --debug -./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo,pdo_sqlite,ftp,curl" --cc=clang --cxx=clang++ --debug +#./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo,pdo_sqlite,ftp,curl" --cc=clang --cxx=clang++ --debug -./bin/spc build gd --debug --cc=clang --cxx=clang++ + +./bin/spc build:libs libzip --debug --cc=clang --cxx=clang++ +./bin/spc build:libs libjpeg --debug --cc=clang --cxx=clang++ ./bin/spc build:libs libjpeg --debug --cc=clang --cxx=clang++ -./bin/spc build:libs libjpeg --debug --cc=clang --cxx=clang++ --clean ./bin/spc build:libs libgif --debug --cc=clang --cxx=clang++ ./bin/spc build:libs libwebp --debug --cc=clang --cxx=clang++ -./bin/spc build "bcmath,tokenizer,pdo,ftp,gd" --cc=clang --cxx=clang++ --debug \ No newline at end of file +# ./bin/spc build "bcmath,tokenizer,pdo,ftp,gd" --cc=clang --cxx=clang++ --debug + +# ./bin/spc build gd --debug --cc=clang --cxx=clang++ --debug \ No newline at end of file diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index bd0a4b886..819e2d42c 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -89,7 +89,7 @@ public function buildLibs(array $libraries): void } foreach ($this->libs as $lib) { - match ($lib->tryBuild()) { + match ($lib->tryBuild(true)) { BUILD_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] build success'), BUILD_STATUS_ALREADY => logger()->notice('lib [' . $lib::NAME . '] already built'), BUILD_STATUS_FAILED => logger()->error('lib [' . $lib::NAME . '] build failed'), From b03a0a590a086e5c7d9193d98027ac3f577df269 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Sun, 23 Apr 2023 16:58:29 +0800 Subject: [PATCH 07/24] =?UTF-8?q?=E7=BC=96=E8=AF=91=E6=B7=BB=E5=8A=A0=20pk?= =?UTF-8?q?g-config=20=20=E7=AE=A1=E7=90=86=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/lib.json | 66 ++++++++++++------- src/SPC/builder/BuilderBase.php | 11 +++- src/SPC/builder/extension/gd.php | 7 -- src/SPC/builder/extension/zip.php | 3 +- src/SPC/builder/extension/zlib.php | 3 +- src/SPC/builder/linux/LinuxBuilder.php | 77 +++++++++++++++++----- src/SPC/builder/linux/library/brotli.php | 4 ++ src/SPC/builder/linux/library/bzip2.php | 4 +- src/SPC/builder/linux/library/freetype.php | 2 + src/SPC/builder/linux/library/libpng.php | 1 - src/SPC/builder/linux/library/libzip.php | 1 + 11 files changed, 123 insertions(+), 56 deletions(-) diff --git a/config/lib.json b/config/lib.json index 5f550b13d..265a87eed 100644 --- a/config/lib.json +++ b/config/lib.json @@ -2,9 +2,14 @@ "brotli": { "source": "brotli", "static-libs-unix": [ - "libbrotlidec-static.a", - "libbrotlienc-static.a", - "libbrotlicommon-static.a" + "libbrotlidec.a", + "libbrotlienc.a", + "libbrotlicommon.a" + ], + "pkg-unix": [ + "libbrotlicommon", + "libbrotlidec", + "libbrotlienc" ], "static-libs-windows": [ "brotlicommon-static.lib", @@ -20,6 +25,8 @@ "static-libs-unix": [ "libbz2.a" ], + "pkg-unix": [ + ], "static-libs-windows": [ [ "libbz2.lib", @@ -77,6 +84,9 @@ "static-libs-unix": [ "libfreetype.a" ], + "pkg-unix": [ + "freetype2" + ], "headers-unix": [ "freetype2/freetype/freetype.h", "freetype2/ft2build.h" @@ -134,6 +144,10 @@ "static-libs-unix": [ "libpng.a" ], + "pkg-unix": [ + "libpng", + "libpng16" + ], "static-libs-windows": [ "libpng16_static.lib" ], @@ -153,7 +167,11 @@ "libjpeg": { "source": "libjpeg", "static-libs-unix": [ - + "libjpeg.a" + ], + "pkg-unix": [ + "libjpeg", + "libturbojpeg" ], "static-libs-windows": [ @@ -171,7 +189,7 @@ "libgif": { "source": "libgif", "static-libs-unix": [ - + "libgif.a" ], "static-libs-windows": [ @@ -189,25 +207,18 @@ "libwebp": { "source": "libwebp", "static-libs-unix": [ - - ], - "static-libs-windows": [ - - ], - "headers-unix": [ - - ], - "headers-windows": [ - - ], - "lib-depends": [ - - ] - }, - "freetype": { - "source": "freetype", - "static-libs-unix": [ - + "libwebp.a", + "libwebpdecoder.a", + "libwebpdemux.a", + "libwebpmux.a", + "libsharpyuv.a" + ], + "pkg-unix": [ + "libsharpyuv", + "libwebp", + "libwebpdecoder", + "libwebpdemux", + "libwebpmux" ], "static-libs-windows": [ @@ -287,6 +298,9 @@ "static-libs-unix": [ "libzip.a" ], + "pkg-unix": [ + "libzip" + ], "static-libs-windows": [ [ "zip.lib", @@ -424,6 +438,10 @@ "static-libs-unix": [ "libz.a" ], + + "pkg-unix": [ + "zlib" + ], "static-libs-windows": [ "zlib_a.lib" ], diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 819e2d42c..fa9ee7135 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -74,7 +74,9 @@ public function buildLibs(array $libraries): void // 过滤不支持的库后添加 foreach ($libraries as $library) { if (!isset($support_lib_list[$library])) { - throw new RuntimeException('library [' . $library . '] is in the lib.json list but not supported to compile, but in the future I will support it!'); + throw new RuntimeException( + 'library [' . $library . '] is in the lib.json list but not supported to compile, but in the future I will support it!' + ); } $lib = new ($support_lib_list[$library])($this); $this->addLib($lib); @@ -89,7 +91,8 @@ public function buildLibs(array $libraries): void } foreach ($this->libs as $lib) { - match ($lib->tryBuild(true)) { + // $lib->build(true); + match ($lib->tryBuild()) { BUILD_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] build success'), BUILD_STATUS_ALREADY => logger()->notice('lib [' . $lib::NAME . '] already built'), BUILD_STATUS_FAILED => logger()->error('lib [' . $lib::NAME . '] build failed'), @@ -234,7 +237,9 @@ protected function checkLibsSource(): void '"' . implode(', ', $not_downloaded) . '" totally ' . count($not_downloaded) . ' source' . (count($not_downloaded) === 1 ? '' : 's') . - ' not downloaded, maybe you need to "fetch" ' . (count($not_downloaded) === 1 ? 'it' : 'them') . ' first?' + ' not downloaded, maybe you need to "fetch" ' . (count( + $not_downloaded + ) === 1 ? 'it' : 'them') . ' first?' ); } } diff --git a/src/SPC/builder/extension/gd.php b/src/SPC/builder/extension/gd.php index 1f29d3082..3cddab6cc 100644 --- a/src/SPC/builder/extension/gd.php +++ b/src/SPC/builder/extension/gd.php @@ -13,13 +13,6 @@ class gd extends Extension public function getUnixConfigureArg(): string { $arg = '--enable-gd'; - if ($this->builder->getLib('freetype')) { - $arg .= ' --with-freetype ' . - 'FREETYPE2_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '/freetype2" ' . - 'FREETYPE2_LIBS="' . $this->getLibFilesString() . '"'; - } - $arg .= ' PNG_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' . - 'PNG_LIBS="' . $this->getLibFilesString() . '"'; $arg .= ' --with-jpeg --with-freetype --with-webp'; return $arg; } diff --git a/src/SPC/builder/extension/zip.php b/src/SPC/builder/extension/zip.php index d259441fd..d49e3e629 100644 --- a/src/SPC/builder/extension/zip.php +++ b/src/SPC/builder/extension/zip.php @@ -12,7 +12,6 @@ class zip extends Extension { public function getUnixConfigureArg(): string { - return '--with-zip LIBZIP_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' . - 'LIBZIP_LIBS="' . $this->getLibFilesString() . '"'; + return '--with-zip'; } } diff --git a/src/SPC/builder/extension/zlib.php b/src/SPC/builder/extension/zlib.php index ed0ff4f1b..f08e712a2 100644 --- a/src/SPC/builder/extension/zlib.php +++ b/src/SPC/builder/extension/zlib.php @@ -12,7 +12,6 @@ class zlib extends Extension { public function getUnixConfigureArg(): string { - return '--with-zlib ZLIB_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' . - 'ZLIB_LIBS="' . $this->getLibFilesString() . '"'; + return '--with-zlib'; } } diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 7e1634294..8ecf87e9b 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -10,6 +10,8 @@ use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; +use SPC\store\Config; +use SPC\store\FileSystem; use SPC\util\Patcher; /** @@ -21,7 +23,21 @@ class LinuxBuilder extends BuilderBase use UnixBuilderTrait; /** @var string[] Linux 环境下编译依赖的命令 */ - public const REQUIRED_COMMANDS = ['make', 'bison', 'flex', 'pkg-config', 'git', 'autoconf', 'automake', 'tar', 'unzip', /* 'xz', 好像不需要 */ 'gzip', 'bzip2', 'cmake']; + public const REQUIRED_COMMANDS = [ + 'make', + 'bison', + 'flex', + 'pkg-config', + 'git', + 'autoconf', + 'automake', + 'tar', + 'unzip', + /* 'xz', 好像不需要 */ + 'gzip', + 'bzip2', + 'cmake', + ]; /** @var string 使用的 libc */ public string $libc; @@ -67,7 +83,8 @@ public function __construct(?string $cc = null, ?string $cxx = null, ?string $ar cxx: $this->cxx ); // 设置 pkgconfig - $this->pkgconf_env = 'PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig"'; + $this->pkgconf_env = 'PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig:/lib/pkgconfig:/usr/lib/pkgconfig"'; + $this->pkgconf_env = ''; // 设置 configure 依赖的环境变量 $this->configure_env = $this->pkgconf_env . ' ' . @@ -157,12 +174,26 @@ public function buildPHP(int $build_micro_rule = BUILD_MICRO_NONE, bool $with_cl } $envs = "{$envs} CFLAGS='{$cflags}' "; - $preprocessors = ' set -exu ; export PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig/:/lib/pkgconfig:/usr/lib/pkgconfig ;'; - $preprocessors .= ' export PATH=' . BUILD_ROOT_PATH . '/bin/:$PATH ;'; - $preprocessors .= ' export PACKAGES="libbrotlicommon libbrotlidec libbrotlienc libzip libjpeg libturbojpeg freetype2 libpng libpng16 libwebp " ;'; - $preprocessors .= ' export CPPFLAGS="$(pkg-config --cflags-only-I --static $PACKAGES ) " ;'; - $preprocessors .= ' export LIBS="$(pkg-config --libs-only-l --static $PACKAGES ) -lstdc++ " ;'; // -lz -lpng16 -lwebpmux -lwebpdemux -lwebpdecoder -lwebp -lm -pthread - $preprocessors .= ' export LD=ld.lld ;'; + $lib_meta = FileSystem::loadConfigArray('lib'); + $packages = []; + foreach ($this->libs as $lib) { + if (isset($lib_meta[$lib::NAME]['pkg-unix'])) { + $packages = array_merge($packages, $lib_meta[$lib::NAME]['pkg-unix']); + } + } + $packages = array_unique($packages); + $this->configure_env = ''; + $preprocessors = 'set -exu ' . PHP_EOL; + $preprocessors .= " export CC={$this->cc} " . PHP_EOL; + $preprocessors .= " export CXX={$this->cxx} " . PHP_EOL; + $preprocessors .= ' export PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig:/lib/pkgconfig:/usr/lib/pkgconfig" ' . PHP_EOL; + $preprocessors .= ' export PATH=' . BUILD_ROOT_PATH . '/bin/:$PATH ' . PHP_EOL; + if (!empty($packages)) { + $preprocessors .= ' export PACKAGES="' . implode(' ', $packages) . '" ' . PHP_EOL; + $preprocessors .= ' export CPPFLAGS="$(pkg-config --cflags-only-I --static $PACKAGES )" ' . PHP_EOL; + $preprocessors .= ' export LDFLAGS=$(pkg-config --libs-only-L --static $PACKAGES ) ' . PHP_EOL; + $preprocessors .= ' export LIBS="$(pkg-config --libs-only-l --static $PACKAGES ) -lstdc++ " ' . PHP_EOL; + } $use_lld .= ' -L' . BUILD_LIB_PATH; # Patcher::patchPHPBeforeConfigure($this); @@ -171,9 +202,10 @@ public function buildPHP(int $build_micro_rule = BUILD_MICRO_NONE, bool $with_cl # Patcher::patchPHPConfigure($this); - shell()->cd(SOURCE_PATH . '/php-src') - ->exec($preprocessors) + shell() ->exec( + 'cd ' . SOURCE_PATH . '/php-src' . PHP_EOL . + $preprocessors . PHP_EOL . './configure ' . '--prefix= ' . '--with-valgrind=no ' . @@ -226,7 +258,10 @@ public function buildPHP(int $build_micro_rule = BUILD_MICRO_NONE, bool $with_cl shell()->cd(SOURCE_PATH . '/php-src')->exec('patch -p1 -R < sapi/micro/patches/phar.patch'); } - file_put_contents(SOURCE_PATH . '/php-src/.extensions.json', json_encode($this->plain_extensions, JSON_PRETTY_PRINT)); + file_put_contents( + SOURCE_PATH . '/php-src/.extensions.json', + json_encode($this->plain_extensions, JSON_PRETTY_PRINT) + ); } /** @@ -236,10 +271,14 @@ public function buildCli(string $extra_libs, string $use_lld, string $preprocess { shell()->cd(SOURCE_PATH . '/php-src') ->exec('sed -i "s|//lib|/lib|g" Makefile') - ->exec($preprocessors) ->exec( + 'echo start build' . PHP_EOL . + $preprocessors . PHP_EOL . 'make -j' . $this->concurrency . - ' EXTRA_CFLAGS="-g -Os -fno-ident ' . 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=\"{$extra_libs}\" " . "EXTRA_LDFLAGS_PROGRAM='{$use_lld} -all-static' " . 'cli' @@ -249,7 +288,9 @@ public function buildCli(string $extra_libs, string $use_lld, string $preprocess ->exec("{$this->cross_compile_prefix}objcopy --only-keep-debug php php.debug") ->exec('elfedit --output-osabi linux php') ->exec("{$this->cross_compile_prefix}strip --strip-all php") - ->exec("{$this->cross_compile_prefix}objcopy --update-section .comment=/tmp/comment --add-gnu-debuglink=php.debug --remove-section=.note php"); + ->exec( + "{$this->cross_compile_prefix}objcopy --update-section .comment=/tmp/comment --add-gnu-debuglink=php.debug --remove-section=.note php" + ); $this->deployBinary(BUILD_TYPE_CLI); } @@ -275,13 +316,17 @@ public function buildMicro(string $extra_libs, string $use_lld, string $cflags): ->exec('sed -i "s|//lib|/lib|g" Makefile') ->exec( "make -j{$this->concurrency} " . - 'EXTRA_CFLAGS=' . quote('-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags))) . ' ' . + 'EXTRA_CFLAGS=' . quote( + '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)) + ) . ' ' . 'EXTRA_LIBS=' . quote($extra_libs) . ' ' . 'EXTRA_LDFLAGS_PROGRAM=' . quote("{$cflags} {$use_lld}" . ' -all-static', "'") . ' ' . 'micro' ); - shell()->cd(SOURCE_PATH . '/php-src/sapi/micro')->exec("{$this->cross_compile_prefix}strip --strip-all micro.sfx"); + shell()->cd(SOURCE_PATH . '/php-src/sapi/micro')->exec( + "{$this->cross_compile_prefix}strip --strip-all micro.sfx" + ); $this->deployBinary(BUILD_TYPE_MICRO); } diff --git a/src/SPC/builder/linux/library/brotli.php b/src/SPC/builder/linux/library/brotli.php index 8f193c509..f423e609b 100644 --- a/src/SPC/builder/linux/library/brotli.php +++ b/src/SPC/builder/linux/library/brotli.php @@ -60,5 +60,9 @@ public function build() rm -rf {$destdir}/lib/*.dylib EOF ); + + $this->withPackageName('libbrotlicommon'); + $this->withPackageName('libbrotlidec'); + $this->withPackageName('libbrotlienc'); } } diff --git a/src/SPC/builder/linux/library/bzip2.php b/src/SPC/builder/linux/library/bzip2.php index b6c6acf99..7f91c96f3 100644 --- a/src/SPC/builder/linux/library/bzip2.php +++ b/src/SPC/builder/linux/library/bzip2.php @@ -36,7 +36,9 @@ public function build() shell() ->cd($this->source_dir) ->exec("make {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' clean") - ->exec("make -j{$this->builder->concurrency} {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a") + ->exec( + "make -j{$this->builder->concurrency} {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a" + ) ->exec('cp libbz2.a ' . BUILD_LIB_PATH) ->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH); } diff --git a/src/SPC/builder/linux/library/freetype.php b/src/SPC/builder/linux/library/freetype.php index f4b9369dd..adb982cbb 100644 --- a/src/SPC/builder/linux/library/freetype.php +++ b/src/SPC/builder/linux/library/freetype.php @@ -40,5 +40,7 @@ public function build() ) ->exec("make -j {$this->builder->concurrency}") ->exec('make install'); + + $this->withPackageName('freetype2'); } } diff --git a/src/SPC/builder/linux/library/libpng.php b/src/SPC/builder/linux/library/libpng.php index 0c80ff39e..611ce23e7 100644 --- a/src/SPC/builder/linux/library/libpng.php +++ b/src/SPC/builder/linux/library/libpng.php @@ -46,7 +46,6 @@ public function build() // Patcher::patchUnixLibpng(); shell()->cd($this->source_dir) - ->exec('chmod +x ./configure') ->exec( <<exec("make -j{$this->builder->concurrency}") ->exec('make install DESTDIR=' . $destdir); + $this->withPackageName('libzip'); } } From 6b2472498df80cc60abc972f038f584d47c2d8c8 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Sun, 23 Apr 2023 17:01:06 +0800 Subject: [PATCH 08/24] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=AE=9E=E9=AA=8C?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SPC/builder/linux/library/brotli.php | 4 ---- src/SPC/builder/linux/library/freetype.php | 2 -- src/SPC/builder/linux/library/libzip.php | 1 - 3 files changed, 7 deletions(-) diff --git a/src/SPC/builder/linux/library/brotli.php b/src/SPC/builder/linux/library/brotli.php index f423e609b..8f193c509 100644 --- a/src/SPC/builder/linux/library/brotli.php +++ b/src/SPC/builder/linux/library/brotli.php @@ -60,9 +60,5 @@ public function build() rm -rf {$destdir}/lib/*.dylib EOF ); - - $this->withPackageName('libbrotlicommon'); - $this->withPackageName('libbrotlidec'); - $this->withPackageName('libbrotlienc'); } } diff --git a/src/SPC/builder/linux/library/freetype.php b/src/SPC/builder/linux/library/freetype.php index adb982cbb..f4b9369dd 100644 --- a/src/SPC/builder/linux/library/freetype.php +++ b/src/SPC/builder/linux/library/freetype.php @@ -40,7 +40,5 @@ public function build() ) ->exec("make -j {$this->builder->concurrency}") ->exec('make install'); - - $this->withPackageName('freetype2'); } } diff --git a/src/SPC/builder/linux/library/libzip.php b/src/SPC/builder/linux/library/libzip.php index c905fc214..650f9e83f 100644 --- a/src/SPC/builder/linux/library/libzip.php +++ b/src/SPC/builder/linux/library/libzip.php @@ -102,6 +102,5 @@ public function build() ) ->exec("make -j{$this->builder->concurrency}") ->exec('make install DESTDIR=' . $destdir); - $this->withPackageName('libzip'); } } From 9fb0c81e79dd3b5583977e7b0bc55e234f1b672e Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Mon, 24 Apr 2023 12:05:43 +0800 Subject: [PATCH 09/24] gd for php ok --- config/lib.json | 13 +++++ config/source.json | 8 +-- quickstart/linux/x86_64/debian-11-init.sh | 5 +- quickstart/linux/x86_64/prepare.sh | 25 +++++--- src/SPC/builder/linux/LinuxBuilder.php | 64 +++++++++++++++------ src/SPC/builder/linux/library/brotli.php | 30 +++++----- src/SPC/builder/linux/library/bzip2.php | 3 +- src/SPC/builder/linux/library/freetype.php | 9 ++- src/SPC/builder/linux/library/libgif.php | 5 +- src/SPC/builder/linux/library/libjpeg.php | 6 +- src/SPC/builder/linux/library/libpng.php | 11 ++-- src/SPC/builder/linux/library/libwebp.php | 36 ++++++------ src/SPC/builder/linux/library/libzip.php | 10 ++-- src/SPC/builder/linux/library/zlib.php | 1 + src/SPC/builder/traits/UnixBuilderTrait.php | 2 + src/SPC/util/UnixShell.php | 2 +- 16 files changed, 144 insertions(+), 86 deletions(-) diff --git a/config/lib.json b/config/lib.json index 265a87eed..53d1024bc 100644 --- a/config/lib.json +++ b/config/lib.json @@ -16,6 +16,7 @@ "brotlienc-static.lib", "brotlidec-static.lib" ], + "headers": [ "brotli" ] @@ -27,6 +28,9 @@ ], "pkg-unix": [ ], + "none-pkg-unix": [ + "-lbz2" + ], "static-libs-windows": [ [ "libbz2.lib", @@ -90,6 +94,12 @@ "headers-unix": [ "freetype2/freetype/freetype.h", "freetype2/ft2build.h" + ], + "lib-depends-unix": [ + "zlib", + "libpng", + "brotli", + "bzip2" ] }, "gmp": { @@ -127,6 +137,9 @@ "static-libs-unix": [ "libiconv.a" ], + "none-pkg-unix": [ + "-liconv" + ], "headers": [ "iconv.h", "libcharset.h", diff --git a/config/source.json b/config/source.json index c70918610..b92422e14 100644 --- a/config/source.json +++ b/config/source.json @@ -91,8 +91,8 @@ "url": "https://git.code.sf.net/p/libpng/code", "rev": "libpng16", "license": { - "type": "text", - "text": "COPYRIGHT NOTICE, DISCLAIMER, and LICENSE\n=========================================\n\nPNG Reference Library License version 2\n---------------------------------------\n\n * Copyright (c) 1995-2019 The PNG Reference Library Authors.\n * Copyright (c) 2018-2019 Cosmin Truta.\n * Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson.\n * Copyright (c) 1996-1997 Andreas Dilger.\n * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n\nThe software is supplied \"as is\", without warranty of any kind,\nexpress or implied, including, without limitation, the warranties\nof merchantability, fitness for a particular purpose, title, and\nnon-infringement. In no event shall the Copyright owners, or\nanyone distributing the software, be liable for any damages or\nother liability, whether in contract, tort or otherwise, arising\nfrom, out of, or in connection with the software, or the use or\nother dealings in the software, even if advised of the possibility\nof such damage.\n\nPermission is hereby granted to use, copy, modify, and distribute\nthis software, or portions hereof, for any purpose, without fee,\nsubject to the following restrictions:\n\n 1. The origin of this software must not be misrepresented; you\n must not claim that you wrote the original software. If you\n use this software in a product, an acknowledgment in the product\n documentation would be appreciated, but is not required.\n\n 2. Altered source versions must be plainly marked as such, and must\n not be misrepresented as being the original software.\n\n 3. This Copyright notice may not be removed or altered from any\n source or altered source distribution.\n\n\nPNG Reference Library License version 1 (for libpng 0.5 through 1.6.35)\n-----------------------------------------------------------------------\n\nlibpng versions 1.0.7, July 1, 2000, through 1.6.35, July 15, 2018 are\nCopyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson, are\nderived from libpng-1.0.6, and are distributed according to the same\ndisclaimer and license as libpng-1.0.6 with the following individuals\nadded to the list of Contributing Authors:\n\n Simon-Pierre Cadieux\n Eric S. Raymond\n Mans Rullgard\n Cosmin Truta\n Gilles Vollant\n James Yu\n Mandar Sahastrabuddhe\n Google Inc.\n Vadim Barkov\n\nand with the following additions to the disclaimer:\n\n There is no warranty against interference with your enjoyment of\n the library or against infringement. There is no warranty that our\n efforts or the library will fulfill any of your particular purposes\n or needs. This library is provided with all faults, and the entire\n risk of satisfactory quality, performance, accuracy, and effort is\n with the user.\n\nSome files in the \"contrib\" directory and some configure-generated\nfiles that are distributed with libpng have other copyright owners, and\nare released under other open source licenses.\n\nlibpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are\nCopyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from\nlibpng-0.96, and are distributed according to the same disclaimer and\nlicense as libpng-0.96, with the following individuals added to the\nlist of Contributing Authors:\n\n Tom Lane\n Glenn Randers-Pehrson\n Willem van Schaik\n\nlibpng versions 0.89, June 1996, through 0.96, May 1997, are\nCopyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,\nand are distributed according to the same disclaimer and license as\nlibpng-0.88, with the following individuals added to the list of\nContributing Authors:\n\n John Bowler\n Kevin Bracey\n Sam Bushell\n Magnus Holmgren\n Greg Roelofs\n Tom Tanner\n\nSome files in the \"scripts\" directory have other copyright owners,\nbut are released under this license.\n\nlibpng versions 0.5, May 1995, through 0.88, January 1996, are\nCopyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n\nFor the purposes of this copyright and license, \"Contributing Authors\"\nis defined as the following set of individuals:\n\n Andreas Dilger\n Dave Martindale\n Guy Eric Schalnat\n Paul Schmidt\n Tim Wegner\n\nThe PNG Reference Library is supplied \"AS IS\". The Contributing\nAuthors and Group 42, Inc. disclaim all warranties, expressed or\nimplied, including, without limitation, the warranties of\nmerchantability and of fitness for any purpose. The Contributing\nAuthors and Group 42, Inc. assume no liability for direct, indirect,\nincidental, special, exemplary, or consequential damages, which may\nresult from the use of the PNG Reference Library, even if advised of\nthe possibility of such damage.\n\nPermission is hereby granted to use, copy, modify, and distribute this\nsource code, or portions hereof, for any purpose, without fee, subject\nto the following restrictions:\n\n 1. The origin of this source code must not be misrepresented.\n\n 2. Altered versions must be plainly marked as such and must not\n be misrepresented as being the original source.\n\n 3. This Copyright notice may not be removed or altered from any\n source or altered source distribution.\n\nThe Contributing Authors and Group 42, Inc. specifically permit,\nwithout fee, and encourage the use of this source code as a component\nto supporting the PNG file format in commercial products. If you use\nthis source code in a product, acknowledgment is not required but would\nbe appreciated.\n" + "type": "file", + "path": "LICENSE" } }, "libjpeg": { @@ -101,7 +101,7 @@ "rev": "2.1.91", "license": { "type": "file", - "path": "LICENSE" + "path": "LICENSE.md" } }, "libgif": { @@ -109,7 +109,7 @@ "url": "https://nchc.dl.sourceforge.net/project/giflib/giflib-5.2.1.tar.gz", "license": { "type": "file", - "path": "LICENSE" + "path": "COPYING" } }, "libwebp": { diff --git a/quickstart/linux/x86_64/debian-11-init.sh b/quickstart/linux/x86_64/debian-11-init.sh index 6dcb52668..07cad0e25 100644 --- a/quickstart/linux/x86_64/debian-11-init.sh +++ b/quickstart/linux/x86_64/debian-11-init.sh @@ -31,7 +31,10 @@ esac apt update -y apt install -y git curl wget ca-certificates -apt install -y xz-utils autoconf automake libclang-13-dev clang lld libtool cmake bison re2c gettext coreutils lzip zip unzip +apt install -y xz-utils autoconf automake lld libtool cmake bison re2c gettext coreutils lzip zip unzip apt install -y pkg-config bzip2 flex +apt install -y musl-tools g++ +# apt install -y libclang-13-dev clang +# apt install gcc g++ # apt install build-essential linux-headers-$(uname -r) diff --git a/quickstart/linux/x86_64/prepare.sh b/quickstart/linux/x86_64/prepare.sh index a02d98f21..73ed7ea65 100644 --- a/quickstart/linux/x86_64/prepare.sh +++ b/quickstart/linux/x86_64/prepare.sh @@ -24,16 +24,27 @@ chmod +x bin/spc #./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo,pdo_sqlite,ftp,curl" --cc=clang --cxx=clang++ --debug +cc=gcc +cxx=g++ +:<<'EOF' + cc=clang + cxx=clang++ +EOF +./bin/spc build:libs zlib --debug +./bin/spc build:libs bzip2 --debug +./bin/spc build:libs libzip --debug +./bin/spc build:libs libjpeg --debug +./bin/spc build:libs libpng --debug +./bin/spc build:libs libgif --debug +./bin/spc build:libs libwebp --debug +./bin/spc build:libs brotli --debug +./bin/spc build:libs freetype --debug -./bin/spc build:libs libzip --debug --cc=clang --cxx=clang++ -./bin/spc build:libs libjpeg --debug --cc=clang --cxx=clang++ -./bin/spc build:libs libjpeg --debug --cc=clang --cxx=clang++ - -./bin/spc build:libs libgif --debug --cc=clang --cxx=clang++ -./bin/spc build:libs libwebp --debug --cc=clang --cxx=clang++ # ./bin/spc build "bcmath,tokenizer,pdo,ftp,gd" --cc=clang --cxx=clang++ --debug -# ./bin/spc build gd --debug --cc=clang --cxx=clang++ --debug \ No newline at end of file +# ./bin/spc build gd --debug --cc=clang --cxx=clang++ --debug + +# ./bin/spc build gd,zlib --debug --cc=gcc --cxx=g++ --debug \ No newline at end of file diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 8ecf87e9b..73afbb098 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -67,6 +67,11 @@ public function __construct(?string $cc = null, ?string $cxx = null, ?string $ar $this->arch = $arch ?? php_uname('m'); $this->gnu_arch = arch2gnu($this->arch); $this->libc = 'musl'; // SystemUtil::selectLibc($this->cc); + $this->ld = match ($this->cc) { + 'musl-gcc' => 'musl-ldd', + 'gcc' => 'ld', + 'clang' => 'ld.lld' + }; // 根据 CPU 线程数设置编译进程数 $this->concurrency = SystemUtil::getCpuCount(); @@ -83,14 +88,19 @@ public function __construct(?string $cc = null, ?string $cxx = null, ?string $ar cxx: $this->cxx ); // 设置 pkgconfig - $this->pkgconf_env = 'PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig:/lib/pkgconfig:/usr/lib/pkgconfig"'; - $this->pkgconf_env = ''; + $this->pkgconf_env = 'export PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig:/usr/lib/pkgconfig"'; + $build_lib_path = BUILD_LIB_PATH; // 设置 configure 依赖的环境变量 - $this->configure_env = - $this->pkgconf_env . ' ' . - "CC='{$this->cc}' " . - "CXX='{$this->cxx}' " . - (php_uname('m') === $this->arch ? '' : "CFLAGS='{$this->arch_c_flags}'"); + $this->configure_env = <<cc} + export CXX={$this->cxx} + export LD=ld={$this->ld} + export PATH={$build_lib_path}/bin/:\$PATH + {$this->pkgconf_env} +EOF; + $this->configure_env = PHP_EOL . $this->configure_env . PHP_EOL; + + php_uname('m') === $this->arch ? '' : "CFLAGS='{$this->arch_c_flags}'"; // 交叉编译依赖的,TODO if (php_uname('m') !== $this->arch) { $this->cross_compile_prefix = SystemUtil::getCrossCompilePrefix($this->cc, $this->arch); @@ -159,6 +169,8 @@ public function buildPHP(int $build_micro_rule = BUILD_MICRO_NONE, bool $with_cl $cflags = $this->arch_c_flags; $use_lld = ''; + $this->libc = 'glibc'; + switch ($this->libc) { case 'musl_wrapper': case 'glibc': @@ -173,32 +185,46 @@ public function buildPHP(int $build_micro_rule = BUILD_MICRO_NONE, bool $with_cl throw new WrongUsageException('libc ' . $this->libc . ' is not implemented yet'); } $envs = "{$envs} CFLAGS='{$cflags}' "; + $envs = ''; + echo $envs; + echo PHP_EOL; + echo $this->libc; + echo PHP_EOL; $lib_meta = FileSystem::loadConfigArray('lib'); $packages = []; + $pkg_libs = []; foreach ($this->libs as $lib) { if (isset($lib_meta[$lib::NAME]['pkg-unix'])) { $packages = array_merge($packages, $lib_meta[$lib::NAME]['pkg-unix']); } + if (isset($lib_meta[$lib::NAME]['none-pkg-unix'])) { + $pkg_libs = array_merge($pkg_libs, $lib_meta[$lib::NAME]['none-pkg-unix']); + } } + $packages = array_unique($packages); - $this->configure_env = ''; - $preprocessors = 'set -exu ' . PHP_EOL; - $preprocessors .= " export CC={$this->cc} " . PHP_EOL; - $preprocessors .= " export CXX={$this->cxx} " . PHP_EOL; - $preprocessors .= ' export PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig:/lib/pkgconfig:/usr/lib/pkgconfig" ' . PHP_EOL; - $preprocessors .= ' export PATH=' . BUILD_ROOT_PATH . '/bin/:$PATH ' . PHP_EOL; + + $preprocessors = $this->configure_env; + $preprocessors .= ' CPPFLAGS="-I' . BUILD_ROOT_PATH . '/include" ' . PHP_EOL; + $preprocessors .= ' LDFLAGS="-L' . BUILD_ROOT_PATH . '/lib" ' . PHP_EOL; + $preprocessors .= ' LIBS=" -pthread -lstdc++ " ' . PHP_EOL; + + if (!empty($pkg_libs)) { + $preprocessors .= ' LIBS="$LIBS ' . implode(' ', $pkg_libs) . '"' . PHP_EOL; + } + if (!empty($packages)) { $preprocessors .= ' export PACKAGES="' . implode(' ', $packages) . '" ' . PHP_EOL; - $preprocessors .= ' export CPPFLAGS="$(pkg-config --cflags-only-I --static $PACKAGES )" ' . PHP_EOL; - $preprocessors .= ' export LDFLAGS=$(pkg-config --libs-only-L --static $PACKAGES ) ' . PHP_EOL; - $preprocessors .= ' export LIBS="$(pkg-config --libs-only-l --static $PACKAGES ) -lstdc++ " ' . PHP_EOL; + $preprocessors .= ' export CPPFLAGS="$CPPFLAGS $(pkg-config --cflags-only-I --static $PACKAGES )" ' . PHP_EOL; + $preprocessors .= ' export LDFLAGS="$LDFLAGS $(pkg-config --libs-only-L --static $PACKAGES )" ' . PHP_EOL; + $preprocessors .= ' export LIBS="$LIBS $(pkg-config --libs-only-l --static $PACKAGES )" ' . PHP_EOL; } + $preprocessors .= " export CFLAGS=\"{$cflags}\" " . PHP_EOL; - $use_lld .= ' -L' . BUILD_LIB_PATH; # Patcher::patchPHPBeforeConfigure($this); - shell()->cd(SOURCE_PATH . '/php-src')->exec('./buildconf --force'); + shell()->cd(SOURCE_PATH . '/php-src')->exec($preprocessors . PHP_EOL . './buildconf --force'); # Patcher::patchPHPConfigure($this); @@ -207,7 +233,7 @@ public function buildPHP(int $build_micro_rule = BUILD_MICRO_NONE, bool $with_cl 'cd ' . SOURCE_PATH . '/php-src' . PHP_EOL . $preprocessors . PHP_EOL . './configure ' . - '--prefix= ' . + '--prefix=/' . '--with-valgrind=no ' . '--enable-shared=no ' . '--enable-static=yes ' . diff --git a/src/SPC/builder/linux/library/brotli.php b/src/SPC/builder/linux/library/brotli.php index 8f193c509..60f557826 100644 --- a/src/SPC/builder/linux/library/brotli.php +++ b/src/SPC/builder/linux/library/brotli.php @@ -32,23 +32,25 @@ class brotli extends LinuxLibraryBase public function build() { [$lib, $include, $destdir] = SEPARATED_PATH; - // 清理旧的编译文件 - shell()->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build'); // 使用 cmake 编译 - shell()->cd($this->source_dir . '/build') + shell()->cd($this->source_dir) ->exec( - $this->builder->configure_env . ' cmake ' . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_SHARED_LIBS=OFF ' . - "-DCMAKE_INSTALL_PREFIX={$destdir} " . - "-DCMAKE_INSTALL_LIBDIR={$destdir}/lib " . - "-DCMAKE_INSTALL_INCLUDEDIR={$destdir}/include " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '..' + <<builder->configure_env} + test -d build && rm -rf build + mkdir -p build + cd build + cmake .. \\ + -DCMAKE_BUILD_TYPE=Release \\ + -DBUILD_SHARED_LIBS=OFF \\ + -DCMAKE_INSTALL_PREFIX={$destdir} \\ + -DCMAKE_INSTALL_LIBDIR={$destdir}/lib \\ + -DCMAKE_INSTALL_INCLUDEDIR={$destdir}/include \\ + -DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} + + cmake --build . --config Release --target install -j {$this->builder->concurrency} +EOF ) - ->exec("cmake --build . --config Release --target install -j {$this->builder->concurrency}") ->exec( <<cd($this->source_dir) - ->exec("make {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' clean") ->exec( - "make -j{$this->builder->concurrency} {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a" + $this->builder->configure_env . "make -j{$this->builder->concurrency} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a" ) ->exec('cp libbz2.a ' . BUILD_LIB_PATH) ->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH); diff --git a/src/SPC/builder/linux/library/freetype.php b/src/SPC/builder/linux/library/freetype.php index f4b9369dd..1e0af3464 100644 --- a/src/SPC/builder/linux/library/freetype.php +++ b/src/SPC/builder/linux/library/freetype.php @@ -4,7 +4,6 @@ namespace SPC\builder\linux\library; -use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; class freetype extends LinuxLibraryBase @@ -13,7 +12,6 @@ class freetype extends LinuxLibraryBase /** * @throws RuntimeException - * @throws FileSystemException */ public function build() { @@ -22,9 +20,10 @@ public function build() shell()->cd($this->source_dir) ->exec( <<builder->configure_env} \\ - BZIP2_CFLAGS="-I{$include}" \\ - BZIP2_LIBS="-L{$lib} -lbz2" \\ + test -d objs/.libs && make clean + {$this->builder->configure_env} + BZIP2_CFLAGS="-I{$destdir}/include" \\ + BZIP2_LIBS="-L{$destdir}/lib -lbz2" \\ CPPFLAGS="$(pkg-config --cflags-only-I --static zlib libpng libbrotlicommon libbrotlidec libbrotlienc)" \\ LDFLAGS="$(pkg-config --libs-only-L --static zlib libpng libbrotlicommon libbrotlidec libbrotlienc)" \\ LIBS="$(pkg-config --libs-only-l --static zlib libpng libbrotlicommon libbrotlidec libbrotlienc)" \\ diff --git a/src/SPC/builder/linux/library/libgif.php b/src/SPC/builder/linux/library/libgif.php index 6ec12556b..99ab8dff3 100644 --- a/src/SPC/builder/linux/library/libgif.php +++ b/src/SPC/builder/linux/library/libgif.php @@ -20,8 +20,9 @@ public function build() [$lib, $include, $destdir] = SEPARATED_PATH; shell()->cd($this->source_dir) - ->exec("make -j {$this->builder->concurrency} libgif.a") - ->exec("cp libgif.a {$destdir}/lib//libgif.a") + ->exec('make clean') + ->exec(" {$this->builder->configure_env} make -j {$this->builder->concurrency} libgif.a") + ->exec("cp libgif.a {$destdir}/lib/libgif.a") ->exec("cp gif_lib.h {$destdir}/include/gif_lib.h"); } } diff --git a/src/SPC/builder/linux/library/libjpeg.php b/src/SPC/builder/linux/library/libjpeg.php index 7fc62d9fe..3368bd8d3 100644 --- a/src/SPC/builder/linux/library/libjpeg.php +++ b/src/SPC/builder/linux/library/libjpeg.php @@ -22,8 +22,12 @@ public function build() shell()->cd($this->source_dir) ->exec( <<builder->configure_env} \\ + test -d build && rm -rf build + mkdir -p build + cd build + {$this->builder->configure_env} cmake -G"Unix Makefiles" \\ + .. \\ -DCMAKE_INSTALL_PREFIX={$destdir} \\ -DCMAKE_INSTALL_BINDIR={$destdir}/bin/ \\ -DCMAKE_INSTALL_LIBDIR={$destdir}/lib \\ diff --git a/src/SPC/builder/linux/library/libpng.php b/src/SPC/builder/linux/library/libpng.php index 611ce23e7..235b6fe67 100644 --- a/src/SPC/builder/linux/library/libpng.php +++ b/src/SPC/builder/linux/library/libpng.php @@ -46,22 +46,23 @@ public function build() // Patcher::patchUnixLibpng(); shell()->cd($this->source_dir) + ->exec('make clean') ->exec('chmod +x ./configure') ->exec( <<builder->configure_env} CPPFLAGS="$(pkg-config --cflags-only-I --static zlib )" \\ LDFLAGS="$(pkg-config --libs-only-L --static zlib )" \\ LIBS="$(pkg-config --libs-only-l --static zlib )" \\ - {$this->builder->configure_env} ./configure \\ + ./configure \\ + --prefix={$destdir} \\ --host={$this->builder->gnu_arch}-unknown-linux \\ --disable-shared \\ --enable-static \\ --enable-hardware-optimizations \\ --with-zlib-prefix={$destdir} \\ - {$optimizations} \\ - --prefix={$destdir} - EOF + {$optimizations} +EOF ) ->exec('make -j ' . $this->builder->concurrency) ->exec('make install '); diff --git a/src/SPC/builder/linux/library/libwebp.php b/src/SPC/builder/linux/library/libwebp.php index 6acece3e6..2cfd8cced 100644 --- a/src/SPC/builder/linux/library/libwebp.php +++ b/src/SPC/builder/linux/library/libwebp.php @@ -20,30 +20,26 @@ public function build() shell()->cd($this->source_dir) ->exec( <<builder->configure_env} \\ - ./autogen.sh - EOF - ) - ->exec( - <<builder->configure_env} \\ - CPPFLAGS="$(pkg-config --cflags-only-I --static libpng libjpeg )" \\ - LDFLAGS="$(pkg-config --libs-only-L --static libpng libjpeg )" \\ - LIBS="$(pkg-config --libs-only-l --static libpng libjpeg )" \\ - ./configure --prefix={$destdir} \\ - --enable-static --disable-shared \\ + {$this->builder->configure_env} + ./autogen.sh + CPPFLAGS="$(pkg-config --cflags-only-I --static libpng libpng16 libjpeg libturbojpeg)" \\ + LDFLAGS="$(pkg-config --libs-only-L --static libpng libpng16 libjpeg libturbojpeg)" \\ + LIBS="$(pkg-config --libs-only-l --static libpng libpng16 libjpeg libturbojpeg)" \\ + CFLAGS="-fPIC -fPIE" \\ + ./configure \\ + --prefix={$destdir} \\ + --enable-shared=no \\ + --enable-static=yes \\ + --disable-shared \\ --enable-libwebpdecoder \\ --enable-libwebpextras \\ - --with-pngincludedir={$include} \\ - --with-pnglibdir={$lib} \\ - --with-jpegincludedir={$include} \\ - --with-jpeglibdir={$lib} \\ - --with-gifincludedir={$include} \\ - --with-giflibdir={$lib} \\ - --disable-tiff + --disable-tiff \\ + --disable-gl \\ + --disable-sdl \\ + --disable-wic EOF ) - ->exec("make -j {$this->builder->concurrency}") + ->exec($this->builder->configure_env . "make -j {$this->builder->concurrency}") ->exec('make install'); } } diff --git a/src/SPC/builder/linux/library/libzip.php b/src/SPC/builder/linux/library/libzip.php index 650f9e83f..f02434d2d 100644 --- a/src/SPC/builder/linux/library/libzip.php +++ b/src/SPC/builder/linux/library/libzip.php @@ -80,7 +80,7 @@ public function build() shell() ->cd($this->source_dir) - ->exec('rm -rf build') + ->exec('test -d build && rm -rf build') ->exec('mkdir -p build') ->cd($this->source_dir . '/build') ->exec( @@ -94,13 +94,13 @@ public function build() '-DBUILD_REGRESS=OFF ' . '-DBUILD_TOOLS=OFF ' . $extra . - '-DCMAKE_INSTALL_PREFIX=/ ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . + "-DCMAKE_INSTALL_PREFIX={$destdir} " . + "-DCMAKE_INSTALL_LIBDIR={$destdir}/lib " . + "-DCMAKE_INSTALL_INCLUDEDIR={$destdir}/include " . "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . '..' ) ->exec("make -j{$this->builder->concurrency}") - ->exec('make install DESTDIR=' . $destdir); + ->exec('make install'); } } diff --git a/src/SPC/builder/linux/library/zlib.php b/src/SPC/builder/linux/library/zlib.php index 04d3fd816..45dd5b0b1 100644 --- a/src/SPC/builder/linux/library/zlib.php +++ b/src/SPC/builder/linux/library/zlib.php @@ -34,6 +34,7 @@ public function build() [,,$destdir] = SEPARATED_PATH; shell()->cd($this->source_dir) + ->exec('make clean') ->exec( "{$this->builder->configure_env} ./configure " . '--static ' . diff --git a/src/SPC/builder/traits/UnixBuilderTrait.php b/src/SPC/builder/traits/UnixBuilderTrait.php index c53d9183a..260762a3d 100644 --- a/src/SPC/builder/traits/UnixBuilderTrait.php +++ b/src/SPC/builder/traits/UnixBuilderTrait.php @@ -19,6 +19,8 @@ trait UnixBuilderTrait /** @var string C++ 编译器命令 */ public string $cxx; + public string $ld; + /** @var string cflags 参数 */ public string $arch_c_flags; diff --git a/src/SPC/util/UnixShell.php b/src/SPC/util/UnixShell.php index 90203ec12..033ff9796 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -34,7 +34,7 @@ public function exec(string $cmd): UnixShell /* @phpstan-ignore-next-line */ logger()->info(ConsoleColor::yellow('[EXEC] ') . ConsoleColor::green($cmd)); if ($this->cd !== null) { - $cmd = 'cd ' . escapeshellarg($this->cd) . ' && ' . $cmd; + $cmd = 'cd ' . escapeshellarg($this->cd) . PHP_EOL . $cmd; } if (!$this->debug) { $cmd .= ' 1>/dev/null 2>&1'; From 3eed90756fb2c6e1aba6c0b935fdc9bcd098925f Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Mon, 24 Apr 2023 12:13:16 +0800 Subject: [PATCH 10/24] save changed --- src/SPC/builder/linux/LinuxBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 73afbb098..27b43e923 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -70,7 +70,8 @@ public function __construct(?string $cc = null, ?string $cxx = null, ?string $ar $this->ld = match ($this->cc) { 'musl-gcc' => 'musl-ldd', 'gcc' => 'ld', - 'clang' => 'ld.lld' + 'clang' => 'ld.lld', + default => throw new RuntimeException('no found ld'), }; // 根据 CPU 线程数设置编译进程数 From ea5bdac1a327410e07c5967ff7843ddc22ae9a35 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Tue, 25 Apr 2023 14:45:22 +0800 Subject: [PATCH 11/24] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/lib.json | 4 + quickstart/linux/x86_64/debian-11-init.sh | 6 +- quickstart/linux/x86_64/prepare.sh | 26 +++-- src/SPC/builder/linux/LinuxBuilder.php | 112 ++++++++++---------- src/SPC/builder/linux/library/brotli.php | 19 ++-- src/SPC/builder/linux/library/bzip2.php | 3 +- src/SPC/builder/linux/library/freetype.php | 8 +- src/SPC/builder/linux/library/libgif.php | 2 +- src/SPC/builder/linux/library/libpng.php | 2 +- src/SPC/builder/linux/library/libwebp.php | 1 + src/SPC/builder/linux/library/zlib.php | 6 +- src/SPC/builder/traits/UnixBuilderTrait.php | 16 +-- src/SPC/util/UnixShell.php | 3 + src/globals/defines.php | 6 +- 14 files changed, 117 insertions(+), 97 deletions(-) diff --git a/config/lib.json b/config/lib.json index 53d1024bc..53ea4e42f 100644 --- a/config/lib.json +++ b/config/lib.json @@ -11,6 +11,10 @@ "libbrotlidec", "libbrotlienc" ], + "none-pkg-unix":[ + "-lbrotlicommon", + "-lbrotli" + ], "static-libs-windows": [ "brotlicommon-static.lib", "brotlienc-static.lib", diff --git a/quickstart/linux/x86_64/debian-11-init.sh b/quickstart/linux/x86_64/debian-11-init.sh index 07cad0e25..5cf3f80c8 100644 --- a/quickstart/linux/x86_64/debian-11-init.sh +++ b/quickstart/linux/x86_64/debian-11-init.sh @@ -33,8 +33,8 @@ apt update -y apt install -y git curl wget ca-certificates apt install -y xz-utils autoconf automake lld libtool cmake bison re2c gettext coreutils lzip zip unzip apt install -y pkg-config bzip2 flex -apt install -y musl-tools g++ -# apt install -y libclang-13-dev clang -# apt install gcc g++ +apt install -y musl-tools g++ gcc-multilib +apt install -y clang + # apt install build-essential linux-headers-$(uname -r) diff --git a/quickstart/linux/x86_64/prepare.sh b/quickstart/linux/x86_64/prepare.sh index 73ed7ea65..d1bc98ce1 100644 --- a/quickstart/linux/x86_64/prepare.sh +++ b/quickstart/linux/x86_64/prepare.sh @@ -24,7 +24,7 @@ chmod +x bin/spc #./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo,pdo_sqlite,ftp,curl" --cc=clang --cxx=clang++ --debug -cc=gcc +cc=musl-gcc cxx=g++ :<<'EOF' cc=clang @@ -32,19 +32,23 @@ cxx=g++ EOF -./bin/spc build:libs zlib --debug -./bin/spc build:libs bzip2 --debug -./bin/spc build:libs libzip --debug -./bin/spc build:libs libjpeg --debug -./bin/spc build:libs libpng --debug -./bin/spc build:libs libgif --debug -./bin/spc build:libs libwebp --debug -./bin/spc build:libs brotli --debug -./bin/spc build:libs freetype --debug +./bin/spc build:libs zlib --debug --cc=musl-gcc --cxx=g++ +./bin/spc build:libs bzip2 --debug --cc=musl-gcc --cxx=g++ +./bin/spc build:libs libzip --debug --cc=musl-gcc --cxx=g++ +./bin/spc build:libs libjpeg --debug --cc=musl-gcc --cxx=g++ +./bin/spc build:libs libpng --debug --cc=musl-gcc --cxx=g++ +./bin/spc build:libs libgif --debug --cc=musl-gcc --cxx=g++ +./bin/spc build:libs libwebp --debug --cc=musl-gcc --cxx=g++ +./bin/spc build:libs brotli --debug --cc=musl-gcc --cxx=g++ +./bin/spc build:libs freetype --debug --cc=musl-gcc --cxx=g++ # ./bin/spc build "bcmath,tokenizer,pdo,ftp,gd" --cc=clang --cxx=clang++ --debug # ./bin/spc build gd --debug --cc=clang --cxx=clang++ --debug -# ./bin/spc build gd,zlib --debug --cc=gcc --cxx=g++ --debug \ No newline at end of file +./bin/spc build gd,zlib --cc=gcc --cxx=g++ --build-cli --debug +./bin/spc build gd,zlib --cc=musl-gcc --cxx=g++ --build-cli --debug +./bin/spc build gd,zlib --cc=clang --cxx=clang++ --build-cli --debug + +# musl-gcc/musl-clang(或 gcc-musl/gcc-clang \ No newline at end of file diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 1f230fd2e..0f365d9f5 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -66,10 +66,14 @@ public function __construct(?string $cc = null, ?string $cxx = null, ?string $ar $this->cxx = $cxx ?? 'g++'; $this->arch = $arch ?? php_uname('m'); $this->gnu_arch = arch2gnu($this->arch); - $this->libc = 'musl'; // SystemUtil::selectLibc($this->cc); + $this->libc = match ($this->cc) { + 'gcc' => 'glibc', + 'musl-gcc', 'clang' => 'libc', + default => '' + }; // SystemUtil::selectLibc($this->cc); + $this->ld = match ($this->cc) { - 'musl-gcc' => 'musl-ldd', - 'gcc' => 'ld', + 'musl-gcc', 'gcc' => 'ld', 'clang' => 'ld.lld', default => throw new RuntimeException('no found ld'), }; @@ -88,15 +92,18 @@ public function __construct(?string $cc = null, ?string $cxx = null, ?string $ar cc: $this->cc, cxx: $this->cxx ); - // 设置 pkgconfig - $this->pkgconf_env = 'export PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig:/usr/lib/pkgconfig"'; + $build_root_path = BUILD_ROOT_PATH; $build_lib_path = BUILD_LIB_PATH; + // 设置 pkgconfig + $this->pkgconf_env = 'export PKG_CONFIG_PATH="' . $build_lib_path . '/pkgconfig:/usr/lib/pkgconfig"'; + // 设置 configure 依赖的环境变量 $this->configure_env = <<cc} export CXX={$this->cxx} - export LD=ld={$this->ld} - export PATH={$build_lib_path}/bin/:\$PATH + export LD={$this->ld} + export PATH={$build_root_path}/bin/:\$PATH {$this->pkgconf_env} EOF; $this->configure_env = PHP_EOL . $this->configure_env . PHP_EOL; @@ -120,6 +127,7 @@ public function __construct(?string $cc = null, ?string $cxx = null, ?string $ar } // 创立 pkg-config 和放头文件的目录 + f_mkdir(BUILD_ROOT_PATH . '/bin', recursive: true); f_mkdir(BUILD_LIB_PATH . '/pkgconfig', recursive: true); f_mkdir(BUILD_INCLUDE_PATH, recursive: true); } @@ -164,33 +172,24 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $with_clean ); } - $envs = $this->pkgconf_env . ' ' . - "CC='{$this->cc}' " . - "CXX='{$this->cxx}' "; + $envs = ''; $cflags = $this->arch_c_flags; $use_lld = ''; - $this->libc = 'glibc'; - switch ($this->libc) { case 'musl_wrapper': case 'glibc': $cflags .= ' -static-libgcc -I"' . BUILD_INCLUDE_PATH . '"'; break; case 'musl': + case 'libc': if (str_ends_with($this->cc, 'clang') && SystemUtil::findCommand('lld')) { - $use_lld = '-Xcompiler -fuse-ld=lld'; + $use_lld = '-Xcompiler -fuse-ld=lld'; // lld = ld.lld soft link } break; default: - throw new WrongUsageException('libc ' . $this->libc . ' is not implemented yet'); + throw new WrongUsageException('libc ' . $this->libc . ' is not implemented yet ' . __FILE__ . ':' . __LINE__); } - $envs = "{$envs} CFLAGS='{$cflags}' "; - $envs = ''; - echo $envs; - echo PHP_EOL; - echo $this->libc; - echo PHP_EOL; $lib_meta = FileSystem::loadConfigArray('lib'); $packages = []; @@ -205,34 +204,40 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $with_clean } $packages = array_unique($packages); - - $preprocessors = $this->configure_env; - $preprocessors .= ' CPPFLAGS="-I' . BUILD_ROOT_PATH . '/include" ' . PHP_EOL; - $preprocessors .= ' LDFLAGS="-L' . BUILD_ROOT_PATH . '/lib" ' . PHP_EOL; - $preprocessors .= ' LIBS=" -pthread -lstdc++ " ' . PHP_EOL; + // -I/usr/include -I/usr/local/include + // -L/usr/lib -L/usr/local/lib + $envs = $this->configure_env; + $envs .= ' CPPFLAGS="-I' . BUILD_ROOT_PATH . '/include " ' . PHP_EOL; + $envs .= ' LDFLAGS="-L' . BUILD_ROOT_PATH . '/lib " ' . PHP_EOL; + $envs .= ' LIBS=" -lm -lrt -lpthread -lcrypt -lutil -lresolv " ' . PHP_EOL; + # $envs .= ' LIBS="-lc++ -libc++ -lm -lrt -lpthread -lcrypt -lutil -lxnet -lresolv " ' . PHP_EOL; + // for libc -lm -lrt -lpthread -lcrypt -lutil -lxnet -lresolv if (!empty($pkg_libs)) { - $preprocessors .= ' LIBS="$LIBS ' . implode(' ', $pkg_libs) . '"' . PHP_EOL; + $envs .= ' LIBS="$LIBS ' . implode(' ', $pkg_libs) . '"' . PHP_EOL; } if (!empty($packages)) { - $preprocessors .= ' export PACKAGES="' . implode(' ', $packages) . '" ' . PHP_EOL; - $preprocessors .= ' export CPPFLAGS="$CPPFLAGS $(pkg-config --cflags-only-I --static $PACKAGES )" ' . PHP_EOL; - $preprocessors .= ' export LDFLAGS="$LDFLAGS $(pkg-config --libs-only-L --static $PACKAGES )" ' . PHP_EOL; - $preprocessors .= ' export LIBS="$LIBS $(pkg-config --libs-only-l --static $PACKAGES )" ' . PHP_EOL; + $envs .= ' export PACKAGES="' . implode(' ', $packages) . '" ' . PHP_EOL; + $envs .= ' export CPPFLAGS="$CPPFLAGS $(pkg-config --cflags-only-I --static $PACKAGES )" ' . PHP_EOL; + $envs .= ' export LDFLAGS="$LDFLAGS $(pkg-config --libs-only-L --static $PACKAGES )" ' . PHP_EOL; + $envs .= ' export LIBS="$(pkg-config --libs-only-l --static $PACKAGES ) $LIBS" ' . PHP_EOL; + } + $cflags .= ' -static '; // -std=gnu11 -idirafter /usr/include -nostdinc /usr/lib + if (strlen($cflags) > 0) { + $envs .= " export CFLAGS=\"{$cflags}\" " . PHP_EOL; } - $preprocessors .= " export CFLAGS=\"{$cflags}\" " . PHP_EOL; # Patcher::patchPHPBeforeConfigure($this); - shell()->cd(SOURCE_PATH . '/php-src')->exec($preprocessors . PHP_EOL . './buildconf --force'); - # Patcher::patchPHPConfigure($this); - + $envs .= 'export EXTRA_LDFLAGS_PROGRAM="$LDFLAGS -all-static"'; shell() + ->cd(SOURCE_PATH . '/php-src') ->exec( - 'cd ' . SOURCE_PATH . '/php-src' . PHP_EOL . - $preprocessors . PHP_EOL . + $envs . PHP_EOL . + 'test -f sapi/cli/php_cli.o && make clean ' . PHP_EOL . + './buildconf --force' . PHP_EOL . './configure ' . '--prefix=/' . '--with-valgrind=no ' . @@ -244,18 +249,18 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $with_clean '--disable-phpdbg ' . '--enable-cli ' . '--enable-fpm ' . - '--enable-micro=all-static ' . ($this->zts ? '--enable-zts' : '') . ' ' . - $this->makeExtensionArgs() . ' ' . - $envs + $this->makeExtensionArgs() ); + // '--enable-micro=all-static ' . $extra_libs .= $this->generateExtraLibs(); + echo $envs; file_put_contents('/tmp/comment', $this->note_section); // 清理 - $this->cleanMake(); + // $this->cleanMake(); if ($bloat) { logger()->info('bloat linking'); @@ -264,15 +269,15 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $with_clean if (($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI) { logger()->info('building cli'); - $this->buildCli($extra_libs, $use_lld); + $this->buildCli($extra_libs, $use_lld, $envs); } if (($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM) { logger()->info('building fpm'); - $this->buildFpm($extra_libs, $use_lld); + $this->buildFpm($extra_libs, $use_lld, $envs); } if (($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO) { logger()->info('building micro'); - $this->buildMicro($extra_libs, $use_lld, $cflags); + $this->buildMicro($extra_libs, $use_lld, $cflags, $envs); } if (php_uname('m') === $this->arch) { @@ -287,23 +292,22 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $with_clean /** * @throws RuntimeException */ - public function buildCli(string $extra_libs, string $use_lld, string $preprocessors = ''): void + public function buildCli(string $extra_libs, string $use_lld, string $envs = ''): void { shell()->cd(SOURCE_PATH . '/php-src') - ->exec('sed -i "s|//lib|/lib|g" Makefile') + // ->exec('sed -i "s|//lib|/lib|g" Makefile') ->exec( 'echo start build' . PHP_EOL . - $preprocessors . PHP_EOL . + $envs . PHP_EOL . 'make -j' . $this->concurrency . - ' EXTRA_CFLAGS="-g -Os -fno-ident ' . implode( - ' ', - array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags) - ) . '" ' . - "EXTRA_LIBS=\"{$extra_libs}\" " . - "EXTRA_LDFLAGS_PROGRAM='{$use_lld} -all-static' " . - 'cli' + ' cli' ); - + exit; + /* + . '" ' . + "EXTRA_LIBS=\"{$extra_libs}\" " . + "EXTRA_LDFLAGS_PROGRAM='{$use_lld} -all-static' " . + */ shell()->cd(SOURCE_PATH . '/php-src/sapi/cli') ->exec("{$this->cross_compile_prefix}objcopy --only-keep-debug php php.debug") ->exec('elfedit --output-osabi linux php') diff --git a/src/SPC/builder/linux/library/brotli.php b/src/SPC/builder/linux/library/brotli.php index 60f557826..6a694bbe2 100644 --- a/src/SPC/builder/linux/library/brotli.php +++ b/src/SPC/builder/linux/library/brotli.php @@ -42,13 +42,20 @@ public function build() cd build cmake .. \\ -DCMAKE_BUILD_TYPE=Release \\ - -DBUILD_SHARED_LIBS=OFF \\ -DCMAKE_INSTALL_PREFIX={$destdir} \\ - -DCMAKE_INSTALL_LIBDIR={$destdir}/lib \\ - -DCMAKE_INSTALL_INCLUDEDIR={$destdir}/include \\ - -DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} - - cmake --build . --config Release --target install -j {$this->builder->concurrency} + -DBUILD_SHARED_LIBS=OFF \\ + -DBUILD_STATIC_LIBS=ON \\ + -DBROTLI_SHARED_LIBS=OFF \\ + -DBROTLI_STATIC_LIBS=ON \\ + -DBROTLI_DISABLE_TESTS=OFF \\ + -DBROTLI_BUNDLED_MODE=OFF \\ + -DBROTLI_EMSCRIPTEN=OFF + + cmake --build . --config Release --target install + + # -DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} + # -DCMAKE_INSTALL_LIBDIR={$destdir}/lib \\ + # -DCMAKE_INSTALL_INCLUDEDIR={$destdir}/include \\ EOF ) ->exec( diff --git a/src/SPC/builder/linux/library/bzip2.php b/src/SPC/builder/linux/library/bzip2.php index 3283bf114..9469e1078 100644 --- a/src/SPC/builder/linux/library/bzip2.php +++ b/src/SPC/builder/linux/library/bzip2.php @@ -36,7 +36,8 @@ public function build() shell() ->cd($this->source_dir) ->exec( - $this->builder->configure_env . "make -j{$this->builder->concurrency} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a" + $this->builder->configure_env . + "make -j{$this->builder->concurrency} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a" ) ->exec('cp libbz2.a ' . BUILD_LIB_PATH) ->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH); diff --git a/src/SPC/builder/linux/library/freetype.php b/src/SPC/builder/linux/library/freetype.php index 1e0af3464..c328dc8fe 100644 --- a/src/SPC/builder/linux/library/freetype.php +++ b/src/SPC/builder/linux/library/freetype.php @@ -24,9 +24,9 @@ public function build() {$this->builder->configure_env} BZIP2_CFLAGS="-I{$destdir}/include" \\ BZIP2_LIBS="-L{$destdir}/lib -lbz2" \\ - CPPFLAGS="$(pkg-config --cflags-only-I --static zlib libpng libbrotlicommon libbrotlidec libbrotlienc)" \\ - LDFLAGS="$(pkg-config --libs-only-L --static zlib libpng libbrotlicommon libbrotlidec libbrotlienc)" \\ - LIBS="$(pkg-config --libs-only-l --static zlib libpng libbrotlicommon libbrotlidec libbrotlienc)" \\ + CPPFLAGS="$(pkg-config --cflags-only-I --static zlib libpng libbrotlidec libbrotlienc libbrotlicommon)" \\ + LDFLAGS="$(pkg-config --libs-only-L --static zlib libpng libbrotlidec libbrotlienc libbrotlicommon)" \\ + LIBS="$(pkg-config --libs-only-l --static zlib libpng libbrotlidec libbrotlienc libbrotlicommon)" \\ ./configure --prefix={$destdir} \\ --enable-static \\ --disable-shared \\ @@ -34,7 +34,7 @@ public function build() --with-bzip2=yes \\ --with-png=yes \\ --with-harfbuzz=no \\ - --with-brotli=yes + --with-brotli=yes EOF ) ->exec("make -j {$this->builder->concurrency}") diff --git a/src/SPC/builder/linux/library/libgif.php b/src/SPC/builder/linux/library/libgif.php index 99ab8dff3..9071c4e58 100644 --- a/src/SPC/builder/linux/library/libgif.php +++ b/src/SPC/builder/linux/library/libgif.php @@ -20,7 +20,7 @@ public function build() [$lib, $include, $destdir] = SEPARATED_PATH; shell()->cd($this->source_dir) - ->exec('make clean') + ->exec('test -f libgif.a && make clean') ->exec(" {$this->builder->configure_env} make -j {$this->builder->concurrency} libgif.a") ->exec("cp libgif.a {$destdir}/lib/libgif.a") ->exec("cp gif_lib.h {$destdir}/include/gif_lib.h"); diff --git a/src/SPC/builder/linux/library/libpng.php b/src/SPC/builder/linux/library/libpng.php index 235b6fe67..c086bc62a 100644 --- a/src/SPC/builder/linux/library/libpng.php +++ b/src/SPC/builder/linux/library/libpng.php @@ -46,7 +46,7 @@ public function build() // Patcher::patchUnixLibpng(); shell()->cd($this->source_dir) - ->exec('make clean') + ->exec('test -f .libs/libpng16.a && make clean') ->exec('chmod +x ./configure') ->exec( <<exec( <<builder->configure_env} + test -d src/.libs/libwebp.a && make clean ./autogen.sh CPPFLAGS="$(pkg-config --cflags-only-I --static libpng libpng16 libjpeg libturbojpeg)" \\ LDFLAGS="$(pkg-config --libs-only-L --static libpng libpng16 libjpeg libturbojpeg)" \\ diff --git a/src/SPC/builder/linux/library/zlib.php b/src/SPC/builder/linux/library/zlib.php index 45dd5b0b1..90755c226 100644 --- a/src/SPC/builder/linux/library/zlib.php +++ b/src/SPC/builder/linux/library/zlib.php @@ -34,9 +34,11 @@ public function build() [,,$destdir] = SEPARATED_PATH; shell()->cd($this->source_dir) - ->exec('make clean') + ->exec( - "{$this->builder->configure_env} ./configure " . + "{$this->builder->configure_env} " . PHP_EOL . + 'test -f gzlib.o && make clean' . PHP_EOL . + 'CFLAGS="-fPIE -fPIC" ./configure ' . '--static ' . '--prefix=' . $destdir ) diff --git a/src/SPC/builder/traits/UnixBuilderTrait.php b/src/SPC/builder/traits/UnixBuilderTrait.php index 84454c314..b20ff83ad 100644 --- a/src/SPC/builder/traits/UnixBuilderTrait.php +++ b/src/SPC/builder/traits/UnixBuilderTrait.php @@ -58,15 +58,12 @@ public function getAllStaticLibFiles(): array } /** - * Sanity check after build complete - * * @throws RuntimeException */ - public function sanityCheck(int $build_target): void + public function sanityCheck(int $build_micro_rule): void { - // sanity check for php-cli - if (($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI) { - logger()->info('running cli sanity check'); + logger()->info('running sanity check'); + if ($build_micro_rule == BUILD_TARGET_CLI) { [$ret, $output] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r "echo \"hello\";"'); if ($ret !== 0 || trim(implode('', $output)) !== 'hello') { throw new RuntimeException('cli failed sanity check'); @@ -85,9 +82,7 @@ public function sanityCheck(int $build_target): void } } } - - // sanity check for phpmicro - if (($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO) { + if ($build_micro_rule == BUILD_TARGET_MICRO) { if (file_exists(SOURCE_PATH . '/hello.exe')) { @unlink(SOURCE_PATH . '/hello.exe'); } @@ -116,10 +111,9 @@ public function deployBinary(int $type): bool $src = match ($type) { BUILD_TARGET_CLI => SOURCE_PATH . '/php-src/sapi/cli/php', BUILD_TARGET_MICRO => SOURCE_PATH . '/php-src/sapi/micro/micro.sfx', - BUILD_TARGET_FPM => SOURCE_PATH . '/php-src/sapi/fpm/php-fpm', default => throw new RuntimeException('Deployment does not accept type ' . $type), }; - logger()->info('Deploying ' . $this->getBuildTypeName($type) . ' file'); + logger()->info('Deploying ' . ($type === BUILD_TARGET_CLI ? 'cli' : 'micro') . ' file'); FileSystem::createDir(BUILD_ROOT_PATH . '/bin'); shell()->exec('cp ' . escapeshellarg($src) . ' ' . escapeshellarg(BUILD_ROOT_PATH . '/bin/')); return true; diff --git a/src/SPC/util/UnixShell.php b/src/SPC/util/UnixShell.php index 033ff9796..06e11af2a 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -39,6 +39,9 @@ public function exec(string $cmd): UnixShell if (!$this->debug) { $cmd .= ' 1>/dev/null 2>&1'; } + echo PHP_EOL; + echo $cmd; + echo PHP_EOL; f_passthru($cmd); return $this; } diff --git a/src/globals/defines.php b/src/globals/defines.php index a2cf15422..58ea16c52 100644 --- a/src/globals/defines.php +++ b/src/globals/defines.php @@ -10,9 +10,9 @@ // CLI start time define('START_TIME', microtime(true)); -define('BUILD_ROOT_PATH', is_string($a = getenv('BUILD_ROOT_PATH')) ? $a : (WORKING_DIR . '/buildroot')); -define('SOURCE_PATH', is_string($a = getenv('SOURCE_PATH')) ? $a : (WORKING_DIR . '/source')); -define('DOWNLOAD_PATH', is_string($a = getenv('DOWNLOAD_PATH')) ? $a : (WORKING_DIR . '/downloads')); +define('BUILD_ROOT_PATH', is_string($a = getenv('BUILD_ROOT_PATH')) ? $a : (ROOT_DIR . '/buildroot')); +define('SOURCE_PATH', is_string($a = getenv('SOURCE_PATH')) ? $a : (ROOT_DIR . '/source')); +define('DOWNLOAD_PATH', is_string($a = getenv('DOWNLOAD_PATH')) ? $a : (ROOT_DIR . '/downloads')); define('BUILD_LIB_PATH', is_string($a = getenv('INSTALL_LIB_PATH')) ? $a : (BUILD_ROOT_PATH . '/lib')); const BUILD_DEPS_PATH = BUILD_ROOT_PATH; From 61d9283d3fdad1aeb79b10a830802adfce03a267 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Tue, 25 Apr 2023 14:45:58 +0800 Subject: [PATCH 12/24] =?UTF-8?q?=E9=AA=8C=E8=AF=81musl-gcc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quickstart/linux/x86_64/prepare.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickstart/linux/x86_64/prepare.sh b/quickstart/linux/x86_64/prepare.sh index d1bc98ce1..42d0eb0c0 100644 --- a/quickstart/linux/x86_64/prepare.sh +++ b/quickstart/linux/x86_64/prepare.sh @@ -47,8 +47,8 @@ EOF # ./bin/spc build gd --debug --cc=clang --cxx=clang++ --debug -./bin/spc build gd,zlib --cc=gcc --cxx=g++ --build-cli --debug +# ./bin/spc build gd,zlib --cc=gcc --cxx=g++ --build-cli --debug ./bin/spc build gd,zlib --cc=musl-gcc --cxx=g++ --build-cli --debug -./bin/spc build gd,zlib --cc=clang --cxx=clang++ --build-cli --debug +# ./bin/spc build gd,zlib --cc=clang --cxx=clang++ --build-cli --debug # musl-gcc/musl-clang(或 gcc-musl/gcc-clang \ No newline at end of file From 32bb6912539a656062c6a29d2b8ba289a343e442 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Tue, 25 Apr 2023 14:49:51 +0800 Subject: [PATCH 13/24] save changed --- src/SPC/builder/linux/LinuxBuilder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 0f365d9f5..0600c0b53 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -224,7 +224,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $with_clean $envs .= ' export LIBS="$(pkg-config --libs-only-l --static $PACKAGES ) $LIBS" ' . PHP_EOL; } $cflags .= ' -static '; // -std=gnu11 -idirafter /usr/include -nostdinc /usr/lib - if (strlen($cflags) > 0) { + if (strlen($cflags) > 2) { $envs .= " export CFLAGS=\"{$cflags}\" " . PHP_EOL; } @@ -319,7 +319,7 @@ public function buildCli(string $extra_libs, string $use_lld, string $envs = '') /** * @throws RuntimeException */ - public function buildMicro(string $extra_libs, string $use_lld, string $cflags): void + public function buildMicro(string $extra_libs, string $use_lld, string $cflags, string $envs = ''): void { if ($this->getPHPVersionID() < 80000) { throw new RuntimeException('phpmicro only support PHP >= 8.0!'); @@ -356,7 +356,7 @@ public function buildMicro(string $extra_libs, string $use_lld, string $cflags): /** * @throws RuntimeException */ - public function buildFpm(string $extra_libs, string $use_lld): void + public function buildFpm(string $extra_libs, string $use_lld, string $envs = ''): void { shell()->cd(SOURCE_PATH . '/php-src') ->exec('sed -i "s|//lib|/lib|g" Makefile') From ebb2f6a3c42bb6c28aa64d6060c1d0ee2c04e849 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Tue, 25 Apr 2023 15:25:33 +0800 Subject: [PATCH 14/24] save changed --- config/lib.json | 962 ++++++++++---------- quickstart/linux/x86_64/alpine-3.16-init.sh | 33 +- quickstart/linux/x86_64/debian-11-init.sh | 6 +- src/SPC/builder/linux/library/brotli.php | 12 +- src/SPC/builder/linux/library/freetype.php | 2 +- 5 files changed, 497 insertions(+), 518 deletions(-) diff --git a/config/lib.json b/config/lib.json index 53ea4e42f..4b10abfc5 100644 --- a/config/lib.json +++ b/config/lib.json @@ -1,491 +1,475 @@ { - "brotli": { - "source": "brotli", - "static-libs-unix": [ - "libbrotlidec.a", - "libbrotlienc.a", - "libbrotlicommon.a" - ], - "pkg-unix": [ - "libbrotlicommon", - "libbrotlidec", - "libbrotlienc" - ], - "none-pkg-unix":[ - "-lbrotlicommon", - "-lbrotli" - ], - "static-libs-windows": [ - "brotlicommon-static.lib", - "brotlienc-static.lib", - "brotlidec-static.lib" - ], - - "headers": [ - "brotli" - ] - }, - "bzip2": { - "source": "bzip2", - "static-libs-unix": [ - "libbz2.a" - ], - "pkg-unix": [ - ], - "none-pkg-unix": [ - "-lbz2" - ], - "static-libs-windows": [ - [ - "libbz2.lib", - "libbz2_a.lib" - ] - ], - "headers": [ - "bzlib.h" - ] - }, - "curl": { - "source": "curl", - "static-libs-unix": [ - "libcurl.a" - ], - "static-libs-windows": [ - "libcurl.lib" - ], - "headers": [ - "curl" - ], - "lib-depends-unix": [ - "zlib" - ], - "lib-suggests": [ - "libssh2", - "brotli", - "nghttp2", - "zstd", - "openssl" - ], - "lib-suggests-windows": [ - "zlib", - "libssh2", - "brotli", - "nghttp2", - "zstd", - "openssl", - "idn2", - "psl" - ], - "frameworks": [ - "CoreFoundation", - "SystemConfiguration" - ] - }, - "postgresql": { - "source": "postgresql", - "static-libs-unix": [ - "libpg.a" - ] - }, - "freetype": { - "source": "freetype", - "static-libs-unix": [ - "libfreetype.a" - ], - "pkg-unix": [ - "freetype2" - ], - "headers-unix": [ - "freetype2/freetype/freetype.h", - "freetype2/ft2build.h" - ], - "lib-depends-unix": [ - "zlib", - "libpng", - "brotli", - "bzip2" - ] - }, - "gmp": { - "source": "gmp", - "static-libs-unix": [ - "libgmp.a" - ], - "static-libs-windows": [ - "libgmp.lib" - ], - "headers": [ - "gmp.h" - ] - }, - "libffi": { - "source": "libffi", - "static-libs-unix": [ - "libffi.a" - ], - "static-libs-windows": [ - "libffi.lib" - ], - "headers-unix": [ - "ffi.h", - "ffitarget.h" - ], - "headers-windows": [ - "ffi.h", - "fficonfig.h", - "ffitarget.h" - ] - }, - "libiconv": { - "source": "libiconv", - "static-libs-unix": [ - "libiconv.a" - ], - "none-pkg-unix": [ - "-liconv" - ], - "headers": [ - "iconv.h", - "libcharset.h", - "localcharset.h" - ] - }, - "libmcrypt": { - "source": "libmcrypt", - "static-libs-unix": [ - "libmcrypt.a" - ] - }, - "libpng": { - "source": "libpng", - "static-libs-unix": [ - "libpng.a" - ], - "pkg-unix": [ - "libpng", - "libpng16" - ], - "static-libs-windows": [ - "libpng16_static.lib" - ], - "headers-unix": [ - "png.h", - "pngconf.h", - "pnglibconf.h" - ], - "headers-windows": [ - "png.h", - "pngconf.h" - ], - "lib-depends": [ - "zlib" - ] - }, - "libjpeg": { - "source": "libjpeg", - "static-libs-unix": [ - "libjpeg.a" - ], - "pkg-unix": [ - "libjpeg", - "libturbojpeg" - ], - "static-libs-windows": [ - - ], - "headers-unix": [ - - ], - "headers-windows": [ - - ], - "lib-depends": [ - - ] - }, - "libgif": { - "source": "libgif", - "static-libs-unix": [ - "libgif.a" - ], - "static-libs-windows": [ - - ], - "headers-unix": [ - - ], - "headers-windows": [ - - ], - "lib-depends": [ - - ] - }, - "libwebp": { - "source": "libwebp", - "static-libs-unix": [ - "libwebp.a", - "libwebpdecoder.a", - "libwebpdemux.a", - "libwebpmux.a", - "libsharpyuv.a" - ], - "pkg-unix": [ - "libsharpyuv", - "libwebp", - "libwebpdecoder", - "libwebpdemux", - "libwebpmux" - ], - "static-libs-windows": [ - - ], - "headers-unix": [ - - ], - "headers-windows": [ - - ], - "lib-depends": [ - - ] - }, - "libssh2": { - "source": "libssh2", - "static-libs-unix": [ - "libssh2.a" - ], - "static-libs-windows": [ - "libssh2.lib" - ], - "headers": [ - "libssh2.h", - "libssh2_publickey.h", - "libssh2_sftp.h" - ], - "lib-depends": [ - "openssl" - ], - "lib-suggests": [ - "zlib" - ] - }, - "libxml2": { - "source": "libxml2", - "static-libs-unix": [ - "libxml2.a" - ], - "static-libs-windows": [ - [ - "libxml2s.lib", - "libxml2_a.lib" - ] - ], - "headers": [ - "libxml2" - ], - "lib-depends": [ - "libiconv" - ], - "lib-suggests": [ - "xz", - "zlib" - ], - "lib-suggests-windows": [ - "icu", - "xz", - "zlib", - "pthreads4w" - ] - }, - "libyaml": { - "source": "libyaml", - "static-libs-unix": [ - "libyaml.a" - ], - "static-libs-windows": [ - "yaml.lib" - ], - "headers": [ - "yaml.h" - ] - }, - "libzip": { - "source": "libzip", - "static-libs-unix": [ - "libzip.a" - ], - "pkg-unix": [ - "libzip" - ], - "static-libs-windows": [ - [ - "zip.lib", - "libzip_a.lib" - ] - ], - "headers": [ - "zip.h", - "zipconf.h" - ], - "lib-depends": [ - "zlib" - ], - "lib-suggests": [ - "bzip2", - "xz", - "zstd", - "openssl" - ] - }, - "mcrypt": { - "source": "mcrypt", - "static-libs-unix": [ - "libmcrypt.a" - ] - }, - "nghttp2": { - "source": "nghttp2", - "static-libs-unix": [ - "libnghttp2.a" - ], - "static-libs-windows": [ - "nghttp2.lib" - ], - "headers": [ - "nghttp2" - ], - "lib-depends": [ - "zlib", - "openssl" - ], - "lib-suggests": [ - "libxml2", - "libev", - "libcares", - "libngtcp2", - "libnghttp3", - "libbpf", - "libevent-openssl", - "jansson", - "jemalloc", - "systemd", - "cunit" - ] - }, - "onig": { - "source": "onig", - "static-libs-unix": [ - "libonig.a" - ], - "static-libs-windows": [ - [ - "onig.lib", - "onig_a.lib" - ] - ], - "headers": [ - "oniggnu.h", - "oniguruma.h" - ] - }, - "openssl": { - "source": "openssl", - "static-libs-unix": [ - "libssl.a", - "libcrypto.a" - ], - "static-libs-windows": [ - "libssl.lib", - "libcrypto.lib" - ], - "headers": [ - "openssl" - ], - "lib-depends": [ - "zlib" - ] - }, - "pthreads4w": { - "source": "pthreads4w", - "static-libs-windows": [ - "libpthreadVC3.lib" - ], - "headers-windows": [ - "_ptw32.h", - "pthread.h", - "sched.h", - "semaphore.h" - ] - }, - "sqlite": { - "source": "sqlite", - "static-libs-unix": [ - "libsqlite3.a" - ], - "headers-unix": [ - "sqlite3.h", - "sqlite3ext.h" - ] - }, - "xz": { - "source": "xz", - "static-libs-unix": [ - "liblzma.a" - ], - "static-libs-windows": [ - [ - "liblzma.lib", - "liblzma_a.lib" - ] - ], - "headers-unix": [ - "lzma" - ], - "headers-windows": [ - "lzma", - "lzma.h" - ], - "lib-depends": [ - "libiconv" - ] - }, - "zlib": { - "source": "zlib", - "static-libs-unix": [ - "libz.a" - ], - - "pkg-unix": [ - "zlib" - ], - "static-libs-windows": [ - "zlib_a.lib" - ], - "headers": [ - "zlib.h", - "zconf.h" - ] - }, - "zstd": { - "source": "zstd", - "static-libs-unix": [ - "libzstd.a" - ], - "static-libs-windows": [ - [ - "zstd.lib", - "zstd_static.lib" - ] - ], - "headers-unix": [ - "zdict.h", - "zstd.h", - "zstd_errors.h" - ], - "headers-windows": [ - "zstd.h", - "zstd_errors.h" - ] - } + "brotli": { + "source": "brotli", + "static-libs-unix": [ + "libbrotlidec.a", + "libbrotlienc.a", + "libbrotlicommon.a" + ], + "pkg-unix": [ + "libbrotlicommon", + "libbrotlidec", + "libbrotlienc" + ], + "none-pkg-unix": [ + ], + "static-libs-windows": [ + "brotlicommon-static.lib", + "brotlienc-static.lib", + "brotlidec-static.lib" + ], + "headers": [ + "brotli" + ] + }, + "bzip2": { + "source": "bzip2", + "static-libs-unix": [ + "libbz2.a" + ], + "pkg-unix": [ + ], + "none-pkg-unix": [ + "-lbz2" + ], + "static-libs-windows": [ + [ + "libbz2.lib", + "libbz2_a.lib" + ] + ], + "headers": [ + "bzlib.h" + ] + }, + "curl": { + "source": "curl", + "static-libs-unix": [ + "libcurl.a" + ], + "static-libs-windows": [ + "libcurl.lib" + ], + "headers": [ + "curl" + ], + "lib-depends-unix": [ + "zlib" + ], + "lib-suggests": [ + "libssh2", + "brotli", + "nghttp2", + "zstd", + "openssl" + ], + "lib-suggests-windows": [ + "zlib", + "libssh2", + "brotli", + "nghttp2", + "zstd", + "openssl", + "idn2", + "psl" + ], + "frameworks": [ + "CoreFoundation", + "SystemConfiguration" + ] + }, + "postgresql": { + "source": "postgresql", + "static-libs-unix": [ + "libpg.a" + ] + }, + "freetype": { + "source": "freetype", + "static-libs-unix": [ + "libfreetype.a" + ], + "pkg-unix": [ + "freetype2" + ], + "headers-unix": [ + "freetype2/freetype/freetype.h", + "freetype2/ft2build.h" + ], + "lib-depends-unix": [ + "zlib", + "libpng", + "brotli", + "bzip2" + ] + }, + "gmp": { + "source": "gmp", + "static-libs-unix": [ + "libgmp.a" + ], + "static-libs-windows": [ + "libgmp.lib" + ], + "headers": [ + "gmp.h" + ] + }, + "libffi": { + "source": "libffi", + "static-libs-unix": [ + "libffi.a" + ], + "static-libs-windows": [ + "libffi.lib" + ], + "headers-unix": [ + "ffi.h", + "ffitarget.h" + ], + "headers-windows": [ + "ffi.h", + "fficonfig.h", + "ffitarget.h" + ] + }, + "libiconv": { + "source": "libiconv", + "static-libs-unix": [ + "libiconv.a" + ], + "none-pkg-unix": [ + "-liconv" + ], + "headers": [ + "iconv.h", + "libcharset.h", + "localcharset.h" + ] + }, + "libmcrypt": { + "source": "libmcrypt", + "static-libs-unix": [ + "libmcrypt.a" + ] + }, + "libpng": { + "source": "libpng", + "static-libs-unix": [ + "libpng.a" + ], + "pkg-unix": [ + "libpng", + "libpng16" + ], + "static-libs-windows": [ + "libpng16_static.lib" + ], + "headers-unix": [ + "png.h", + "pngconf.h", + "pnglibconf.h" + ], + "headers-windows": [ + "png.h", + "pngconf.h" + ], + "lib-depends": [ + "zlib" + ] + }, + "libjpeg": { + "source": "libjpeg", + "static-libs-unix": [ + "libjpeg.a" + ], + "pkg-unix": [ + "libjpeg", + "libturbojpeg" + ], + "static-libs-windows": [ + ], + "headers-unix": [ + ], + "headers-windows": [ + ], + "lib-depends": [ + ] + }, + "libgif": { + "source": "libgif", + "static-libs-unix": [ + "libgif.a" + ], + "static-libs-windows": [ + ], + "headers-unix": [ + ], + "headers-windows": [ + ], + "lib-depends": [ + ] + }, + "libwebp": { + "source": "libwebp", + "static-libs-unix": [ + "libwebp.a", + "libwebpdecoder.a", + "libwebpdemux.a", + "libwebpmux.a", + "libsharpyuv.a" + ], + "pkg-unix": [ + "libsharpyuv", + "libwebp", + "libwebpdecoder", + "libwebpdemux", + "libwebpmux" + ], + "static-libs-windows": [ + ], + "headers-unix": [ + ], + "headers-windows": [ + ], + "lib-depends": [ + ] + }, + "libssh2": { + "source": "libssh2", + "static-libs-unix": [ + "libssh2.a" + ], + "static-libs-windows": [ + "libssh2.lib" + ], + "headers": [ + "libssh2.h", + "libssh2_publickey.h", + "libssh2_sftp.h" + ], + "lib-depends": [ + "openssl" + ], + "lib-suggests": [ + "zlib" + ] + }, + "libxml2": { + "source": "libxml2", + "static-libs-unix": [ + "libxml2.a" + ], + "static-libs-windows": [ + [ + "libxml2s.lib", + "libxml2_a.lib" + ] + ], + "headers": [ + "libxml2" + ], + "lib-depends": [ + "libiconv" + ], + "lib-suggests": [ + "xz", + "zlib" + ], + "lib-suggests-windows": [ + "icu", + "xz", + "zlib", + "pthreads4w" + ] + }, + "libyaml": { + "source": "libyaml", + "static-libs-unix": [ + "libyaml.a" + ], + "static-libs-windows": [ + "yaml.lib" + ], + "headers": [ + "yaml.h" + ] + }, + "libzip": { + "source": "libzip", + "static-libs-unix": [ + "libzip.a" + ], + "pkg-unix": [ + "libzip" + ], + "static-libs-windows": [ + [ + "zip.lib", + "libzip_a.lib" + ] + ], + "headers": [ + "zip.h", + "zipconf.h" + ], + "lib-depends": [ + "zlib" + ], + "lib-suggests": [ + "bzip2", + "xz", + "zstd", + "openssl" + ] + }, + "mcrypt": { + "source": "mcrypt", + "static-libs-unix": [ + "libmcrypt.a" + ] + }, + "nghttp2": { + "source": "nghttp2", + "static-libs-unix": [ + "libnghttp2.a" + ], + "static-libs-windows": [ + "nghttp2.lib" + ], + "headers": [ + "nghttp2" + ], + "lib-depends": [ + "zlib", + "openssl" + ], + "lib-suggests": [ + "libxml2", + "libev", + "libcares", + "libngtcp2", + "libnghttp3", + "libbpf", + "libevent-openssl", + "jansson", + "jemalloc", + "systemd", + "cunit" + ] + }, + "onig": { + "source": "onig", + "static-libs-unix": [ + "libonig.a" + ], + "static-libs-windows": [ + [ + "onig.lib", + "onig_a.lib" + ] + ], + "headers": [ + "oniggnu.h", + "oniguruma.h" + ] + }, + "openssl": { + "source": "openssl", + "static-libs-unix": [ + "libssl.a", + "libcrypto.a" + ], + "static-libs-windows": [ + "libssl.lib", + "libcrypto.lib" + ], + "headers": [ + "openssl" + ], + "lib-depends": [ + "zlib" + ] + }, + "pthreads4w": { + "source": "pthreads4w", + "static-libs-windows": [ + "libpthreadVC3.lib" + ], + "headers-windows": [ + "_ptw32.h", + "pthread.h", + "sched.h", + "semaphore.h" + ] + }, + "sqlite": { + "source": "sqlite", + "static-libs-unix": [ + "libsqlite3.a" + ], + "headers-unix": [ + "sqlite3.h", + "sqlite3ext.h" + ] + }, + "xz": { + "source": "xz", + "static-libs-unix": [ + "liblzma.a" + ], + "static-libs-windows": [ + [ + "liblzma.lib", + "liblzma_a.lib" + ] + ], + "headers-unix": [ + "lzma" + ], + "headers-windows": [ + "lzma", + "lzma.h" + ], + "lib-depends": [ + "libiconv" + ] + }, + "zlib": { + "source": "zlib", + "static-libs-unix": [ + "libz.a" + ], + "pkg-unix": [ + "zlib" + ], + "static-libs-windows": [ + "zlib_a.lib" + ], + "headers": [ + "zlib.h", + "zconf.h" + ] + }, + "zstd": { + "source": "zstd", + "static-libs-unix": [ + "libzstd.a" + ], + "static-libs-windows": [ + [ + "zstd.lib", + "zstd_static.lib" + ] + ], + "headers-unix": [ + "zdict.h", + "zstd.h", + "zstd_errors.h" + ], + "headers-windows": [ + "zstd.h", + "zstd_errors.h" + ] + } } \ No newline at end of file diff --git a/quickstart/linux/x86_64/alpine-3.16-init.sh b/quickstart/linux/x86_64/alpine-3.16-init.sh index 18ae828c5..346b91c19 100644 --- a/quickstart/linux/x86_64/alpine-3.16-init.sh +++ b/quickstart/linux/x86_64/alpine-3.16-init.sh @@ -5,31 +5,30 @@ __DIR__=$( cd "$(dirname "$0")" pwd ) +cd ${__DIR__} mirror='' while [ $# -gt 0 ]; do - case "$1" in - --mirror) - mirror="$2" - shift - ;; - --*) - echo "Illegal option $1" - ;; - esac - shift $(( $# > 0 ? 1 : 0 )) + case "$1" in + --mirror) + mirror="$2" + shift + ;; + --*) + echo "Illegal option $1" + ;; + esac + shift $(($# > 0 ? 1 : 0)) done case "$mirror" in - china) - test -f /etc/apk/repositories.save || cp /etc/apk/repositories /etc/apk/repositories.save - sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories - ;; +china) + test -f /etc/apk/repositories.save || cp /etc/apk/repositories /etc/apk/repositories.save + sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories + ;; esac - - apk update -apk add vim alpine-sdk xz autoconf automake linux-headers clang-dev clang lld libtool cmake bison re2c gettext coreutils \ No newline at end of file +apk add vim alpine-sdk xz autoconf automake linux-headers clang-dev clang lld libtool cmake bison re2c gettext coreutils diff --git a/quickstart/linux/x86_64/debian-11-init.sh b/quickstart/linux/x86_64/debian-11-init.sh index 5cf3f80c8..383bc30cc 100644 --- a/quickstart/linux/x86_64/debian-11-init.sh +++ b/quickstart/linux/x86_64/debian-11-init.sh @@ -5,6 +5,7 @@ __DIR__=$( cd "$(dirname "$0")" pwd ) +cd ${__DIR__} mirror='' while [ $# -gt 0 ]; do @@ -33,8 +34,7 @@ apt update -y apt install -y git curl wget ca-certificates apt install -y xz-utils autoconf automake lld libtool cmake bison re2c gettext coreutils lzip zip unzip apt install -y pkg-config bzip2 flex -apt install -y musl-tools g++ gcc-multilib -apt install -y clang - +apt install -y musl-tools g++ +apt install -y clang # apt install build-essential linux-headers-$(uname -r) diff --git a/src/SPC/builder/linux/library/brotli.php b/src/SPC/builder/linux/library/brotli.php index 6a694bbe2..09bb995db 100644 --- a/src/SPC/builder/linux/library/brotli.php +++ b/src/SPC/builder/linux/library/brotli.php @@ -43,19 +43,15 @@ public function build() cmake .. \\ -DCMAKE_BUILD_TYPE=Release \\ -DCMAKE_INSTALL_PREFIX={$destdir} \\ - -DBUILD_SHARED_LIBS=OFF \\ - -DBUILD_STATIC_LIBS=ON \\ - -DBROTLI_SHARED_LIBS=OFF \\ - -DBROTLI_STATIC_LIBS=ON \\ + -DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} \\ + -DCMAKE_INSTALL_LIBDIR={$destdir}/lib \\ + -DCMAKE_INSTALL_INCLUDEDIR={$destdir}/include \\ -DBROTLI_DISABLE_TESTS=OFF \\ -DBROTLI_BUNDLED_MODE=OFF \\ -DBROTLI_EMSCRIPTEN=OFF cmake --build . --config Release --target install - - # -DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} - # -DCMAKE_INSTALL_LIBDIR={$destdir}/lib \\ - # -DCMAKE_INSTALL_INCLUDEDIR={$destdir}/include \\ + EOF ) ->exec( diff --git a/src/SPC/builder/linux/library/freetype.php b/src/SPC/builder/linux/library/freetype.php index c328dc8fe..ca4bb2995 100644 --- a/src/SPC/builder/linux/library/freetype.php +++ b/src/SPC/builder/linux/library/freetype.php @@ -34,7 +34,7 @@ public function build() --with-bzip2=yes \\ --with-png=yes \\ --with-harfbuzz=no \\ - --with-brotli=yes + --with-brotli=no EOF ) ->exec("make -j {$this->builder->concurrency}") From 9663a88c4fac38ae2237fe259330e571a786624b Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Tue, 25 Apr 2023 15:27:17 +0800 Subject: [PATCH 15/24] save changed --- src/SPC/builder/linux/LinuxBuilder.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 0600c0b53..500d5d4bf 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -302,7 +302,6 @@ public function buildCli(string $extra_libs, string $use_lld, string $envs = '') 'make -j' . $this->concurrency . ' cli' ); - exit; /* . '" ' . "EXTRA_LIBS=\"{$extra_libs}\" " . From c886c89a4108faf51acba1d7c53569042d13c768 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Wed, 26 Apr 2023 13:16:10 +0800 Subject: [PATCH 16/24] =?UTF-8?q?=E9=AA=8C=E8=AF=81=20alpine=20=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=8B=20gcc=20=E5=92=8C=20clang=20=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E5=8C=BA=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/setup-runtime | 1 - quickstart/linux/x86_64/alpine-3.16-init.sh | 3 +- quickstart/linux/x86_64/prepare.sh | 34 ++++++++++------ src/SPC/builder/linux/LinuxBuilder.php | 44 ++++++++++++++++----- src/SPC/builder/linux/library/brotli.php | 16 ++++++-- src/SPC/builder/linux/library/bzip2.php | 11 ++++++ src/SPC/builder/linux/library/freetype.php | 11 +++++- src/SPC/builder/linux/library/libgif.php | 12 +++++- src/SPC/builder/linux/library/libjpeg.php | 21 ++++++---- src/SPC/builder/linux/library/libpng.php | 19 ++++++--- src/SPC/builder/linux/library/libwebp.php | 11 +++++- src/SPC/builder/linux/library/libzip.php | 13 ++++-- src/SPC/builder/linux/library/zlib.php | 17 +++++--- 13 files changed, 160 insertions(+), 53 deletions(-) diff --git a/bin/setup-runtime b/bin/setup-runtime index f324c9eb9..588140ad5 100755 --- a/bin/setup-runtime +++ b/bin/setup-runtime @@ -48,7 +48,6 @@ done case "$mirror" in china) -<<<<<<< HEAD __PHP_RUNTIME_URL__="https://wenda-1252906962.file.myqcloud.com/dist/swoole-cli-v4.8.13-${__OS_FIXED__}-${__ARCH__}.tar.xz" __COMPOSER_URL__="https://mirrors.aliyun.com/composer/composer.phar" ;; diff --git a/quickstart/linux/x86_64/alpine-3.16-init.sh b/quickstart/linux/x86_64/alpine-3.16-init.sh index 2ad2d6e61..14809e642 100644 --- a/quickstart/linux/x86_64/alpine-3.16-init.sh +++ b/quickstart/linux/x86_64/alpine-3.16-init.sh @@ -35,4 +35,5 @@ esac apk update -apk add vim alpine-sdk xz autoconf automake linux-headers clang-dev clang lld libtool cmake bison re2c gettext coreutils +apk add vim alpine-sdk xz autoconf automake linux-headers clang-dev clang lld libtool cmake bison re2c gettext coreutils flex +apk add gcc build-base diff --git a/quickstart/linux/x86_64/prepare.sh b/quickstart/linux/x86_64/prepare.sh index 42d0eb0c0..4f0688baa 100644 --- a/quickstart/linux/x86_64/prepare.sh +++ b/quickstart/linux/x86_64/prepare.sh @@ -29,26 +29,34 @@ cxx=g++ :<<'EOF' cc=clang cxx=clang++ + cc=musl-gcc + cxx=g++ EOF -./bin/spc build:libs zlib --debug --cc=musl-gcc --cxx=g++ -./bin/spc build:libs bzip2 --debug --cc=musl-gcc --cxx=g++ -./bin/spc build:libs libzip --debug --cc=musl-gcc --cxx=g++ -./bin/spc build:libs libjpeg --debug --cc=musl-gcc --cxx=g++ -./bin/spc build:libs libpng --debug --cc=musl-gcc --cxx=g++ -./bin/spc build:libs libgif --debug --cc=musl-gcc --cxx=g++ -./bin/spc build:libs libwebp --debug --cc=musl-gcc --cxx=g++ -./bin/spc build:libs brotli --debug --cc=musl-gcc --cxx=g++ -./bin/spc build:libs freetype --debug --cc=musl-gcc --cxx=g++ +./bin/spc build:libs zlib --debug --cc=clang --cxx=clang++ +./bin/spc build:libs bzip2 --debug --cc=clang --cxx=clang++ +./bin/spc build:libs libzip --debug --cc=clang --cxx=clang++ +./bin/spc build:libs libjpeg --debug --cc=clang --cxx=clang++ +./bin/spc build:libs libpng --debug --cc=clang --cxx=clang++ +./bin/spc build:libs libgif --debug --cc=clang --cxx=clang++ +./bin/spc build:libs libwebp --debug --cc=clang --cxx=clang++ +./bin/spc build:libs brotli --debug --cc=clang --cxx=clang++ +./bin/spc build:libs freetype --debug --cc=clang --cxx=clang++ -# ./bin/spc build "bcmath,tokenizer,pdo,ftp,gd" --cc=clang --cxx=clang++ --debug +# ./bin/spc build "bcmath,tokenizer,pdo,ftp,gd" --build-cli --cc=clang --cxx=clang++ --debug -# ./bin/spc build gd --debug --cc=clang --cxx=clang++ --debug -# ./bin/spc build gd,zlib --cc=gcc --cxx=g++ --build-cli --debug -./bin/spc build gd,zlib --cc=musl-gcc --cxx=g++ --build-cli --debug + +## debian + +# ./bin/spc build gd,zlib --cc=musl-gcc --cxx=g++ --build-cli --debug + +## alpine # ./bin/spc build gd,zlib --cc=clang --cxx=clang++ --build-cli --debug +# ./bin/spc build gd,zlib --cc=gcc --cxx=g++ --build-cli --debug + + # musl-gcc/musl-clang(或 gcc-musl/gcc-clang \ No newline at end of file diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 500d5d4bf..34720aaab 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -61,16 +61,33 @@ class LinuxBuilder extends BuilderBase */ public function __construct(?string $cc = null, ?string $cxx = null, ?string $arch = null) { + if (isset(SystemUtil::getOSRelease()['dist'])) { + $os_release = SystemUtil::getOSRelease(); + $os_release_name = $os_release['dist']; + $os_release_version = $os_release['ver']; + } else { + throw new \RuntimeException('no recognize os release'); + } + if ($cc == 'gcc') { + if ($os_release_name == 'alpine') { + $cc = 'gcc'; + $this->libc = 'musl'; + } elseif ($os_release_name == 'debian') { + $cc = 'musl-gcc'; + $this->libc = 'musl'; + } + } else { + $this->libc = 'libc'; + } + // 初始化一些默认参数 - $this->cc = $cc ?? 'musl-gcc'; - $this->cxx = $cxx ?? 'g++'; + + $this->cc = $cc ?? 'clang'; + $this->cxx = $cxx ?? 'clang++'; $this->arch = $arch ?? php_uname('m'); $this->gnu_arch = arch2gnu($this->arch); - $this->libc = match ($this->cc) { - 'gcc' => 'glibc', - 'musl-gcc', 'clang' => 'libc', - default => '' - }; // SystemUtil::selectLibc($this->cc); + + // SystemUtil::selectLibc($this->cc); $this->ld = match ($this->cc) { 'musl-gcc', 'gcc' => 'ld', @@ -232,11 +249,20 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $with_clean # Patcher::patchPHPConfigure($this); $envs .= 'export EXTRA_LDFLAGS_PROGRAM="$LDFLAGS -all-static"'; + shell()->cd(SOURCE_PATH . '/php-src') + ->exec( + <<<'EOF' + if [[ -d php_cli_process_title.lo ]] + then + make clean + fi + +EOF + ); shell() ->cd(SOURCE_PATH . '/php-src') ->exec( $envs . PHP_EOL . - 'test -f sapi/cli/php_cli.o && make clean ' . PHP_EOL . './buildconf --force' . PHP_EOL . './configure ' . '--prefix=/' . @@ -249,10 +275,10 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $with_clean '--disable-phpdbg ' . '--enable-cli ' . '--enable-fpm ' . + '--enable-micro=all-static ' . ($this->zts ? '--enable-zts' : '') . ' ' . $this->makeExtensionArgs() ); - // '--enable-micro=all-static ' . $extra_libs .= $this->generateExtraLibs(); echo $envs; diff --git a/src/SPC/builder/linux/library/brotli.php b/src/SPC/builder/linux/library/brotli.php index 09bb995db..6a7f2bf37 100644 --- a/src/SPC/builder/linux/library/brotli.php +++ b/src/SPC/builder/linux/library/brotli.php @@ -32,14 +32,22 @@ class brotli extends LinuxLibraryBase public function build() { [$lib, $include, $destdir] = SEPARATED_PATH; + shell() + ->cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -d build ]] + then + rm -rf build + fi + mkdir -p build +EOF + ); // 使用 cmake 编译 - shell()->cd($this->source_dir) + shell()->cd($this->source_dir . '/build') ->exec( <<builder->configure_env} - test -d build && rm -rf build - mkdir -p build - cd build cmake .. \\ -DCMAKE_BUILD_TYPE=Release \\ -DCMAKE_INSTALL_PREFIX={$destdir} \\ diff --git a/src/SPC/builder/linux/library/bzip2.php b/src/SPC/builder/linux/library/bzip2.php index 9469e1078..3ddce0f4a 100644 --- a/src/SPC/builder/linux/library/bzip2.php +++ b/src/SPC/builder/linux/library/bzip2.php @@ -33,6 +33,17 @@ class bzip2 extends LinuxLibraryBase */ public function build() { + shell() + ->cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -f blocksort.o ]] + then + make clean + fi +EOF + ); + shell() ->cd($this->source_dir) ->exec( diff --git a/src/SPC/builder/linux/library/freetype.php b/src/SPC/builder/linux/library/freetype.php index ca4bb2995..885d4c4cd 100644 --- a/src/SPC/builder/linux/library/freetype.php +++ b/src/SPC/builder/linux/library/freetype.php @@ -16,11 +16,18 @@ class freetype extends LinuxLibraryBase public function build() { [$lib, $include, $destdir] = SEPARATED_PATH; - + shell()->cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -d objs/.libs ]] + then + make clean + fi +EOF + ); shell()->cd($this->source_dir) ->exec( <<builder->configure_env} BZIP2_CFLAGS="-I{$destdir}/include" \\ BZIP2_LIBS="-L{$destdir}/lib -lbz2" \\ diff --git a/src/SPC/builder/linux/library/libgif.php b/src/SPC/builder/linux/library/libgif.php index 9071c4e58..0f6b4bffb 100644 --- a/src/SPC/builder/linux/library/libgif.php +++ b/src/SPC/builder/linux/library/libgif.php @@ -18,9 +18,17 @@ class libgif extends LinuxLibraryBase public function build() { [$lib, $include, $destdir] = SEPARATED_PATH; - + shell() + ->cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -f libgif.a ]] + then + make clean + fi +EOF + ); shell()->cd($this->source_dir) - ->exec('test -f libgif.a && make clean') ->exec(" {$this->builder->configure_env} make -j {$this->builder->concurrency} libgif.a") ->exec("cp libgif.a {$destdir}/lib/libgif.a") ->exec("cp gif_lib.h {$destdir}/include/gif_lib.h"); diff --git a/src/SPC/builder/linux/library/libjpeg.php b/src/SPC/builder/linux/library/libjpeg.php index 3368bd8d3..da5673fde 100644 --- a/src/SPC/builder/linux/library/libjpeg.php +++ b/src/SPC/builder/linux/library/libjpeg.php @@ -18,13 +18,20 @@ class libjpeg extends LinuxLibraryBase public function build() { [$lib, $include, $destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) + shell() + ->cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -d build ]] + then + rm -rf build + fi + mkdir -p build +EOF + ); + shell()->cd($this->source_dir . '/build/') ->exec( <<builder->configure_env} cmake -G"Unix Makefiles" \\ .. \\ @@ -34,8 +41,8 @@ public function build() -DCMAKE_INSTALL_INCLUDEDIR={$destdir}/include \\ -DCMAKE_BUILD_TYPE=Release \\ -DENABLE_SHARED=OFF \\ - -DENABLE_STATIC=ON \\ - -DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} + -DENABLE_STATIC=ON + # -DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} EOF ) diff --git a/src/SPC/builder/linux/library/libpng.php b/src/SPC/builder/linux/library/libpng.php index c086bc62a..8336b2112 100644 --- a/src/SPC/builder/linux/library/libpng.php +++ b/src/SPC/builder/linux/library/libpng.php @@ -44,13 +44,21 @@ public function build() // patch configure // Patcher::patchUnixLibpng(); - + shell() + ->cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -f .libs/libpng16.a ]] + then + make clean + fi +EOF + ); shell()->cd($this->source_dir) - ->exec('test -f .libs/libpng16.a && make clean') - ->exec('chmod +x ./configure') ->exec( <<builder->configure_env} + chmod +x ./configure CPPFLAGS="$(pkg-config --cflags-only-I --static zlib )" \\ LDFLAGS="$(pkg-config --libs-only-L --static zlib )" \\ LIBS="$(pkg-config --libs-only-l --static zlib )" \\ @@ -60,8 +68,9 @@ public function build() --disable-shared \\ --enable-static \\ --enable-hardware-optimizations \\ - --with-zlib-prefix={$destdir} \\ - {$optimizations} + --with-zlib-prefix={$destdir} + + # {$optimizations} EOF ) ->exec('make -j ' . $this->builder->concurrency) diff --git a/src/SPC/builder/linux/library/libwebp.php b/src/SPC/builder/linux/library/libwebp.php index 6675e7dbc..3d54a499b 100644 --- a/src/SPC/builder/linux/library/libwebp.php +++ b/src/SPC/builder/linux/library/libwebp.php @@ -17,11 +17,20 @@ public function build() { [$lib, $include, $destdir] = SEPARATED_PATH; + shell() + ->cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -f src/.libs/libwebp.a ]] + then + make clean + fi +EOF + ); shell()->cd($this->source_dir) ->exec( <<builder->configure_env} - test -d src/.libs/libwebp.a && make clean ./autogen.sh CPPFLAGS="$(pkg-config --cflags-only-I --static libpng libpng16 libjpeg libturbojpeg)" \\ LDFLAGS="$(pkg-config --libs-only-L --static libpng libpng16 libjpeg libturbojpeg)" \\ diff --git a/src/SPC/builder/linux/library/libzip.php b/src/SPC/builder/linux/library/libzip.php index f02434d2d..c30d7b595 100644 --- a/src/SPC/builder/linux/library/libzip.php +++ b/src/SPC/builder/linux/library/libzip.php @@ -77,11 +77,18 @@ public function build() } [$lib, $include, $destdir] = SEPARATED_PATH; - shell() ->cd($this->source_dir) - ->exec('test -d build && rm -rf build') - ->exec('mkdir -p build') + ->exec( + <<<'EOF' + if [[ -d build ]] + then + rm -rf build + fi + mkdir -p build +EOF + ); + shell() ->cd($this->source_dir . '/build') ->exec( $this->builder->configure_env . ' cmake ' . diff --git a/src/SPC/builder/linux/library/zlib.php b/src/SPC/builder/linux/library/zlib.php index 90755c226..8dd5b4e7c 100644 --- a/src/SPC/builder/linux/library/zlib.php +++ b/src/SPC/builder/linux/library/zlib.php @@ -31,14 +31,21 @@ class zlib extends LinuxLibraryBase */ public function build() { - [,,$destdir] = SEPARATED_PATH; - + [, , $destdir] = SEPARATED_PATH; + shell() + ->cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -f gzlib.o ]] + then + make clean + fi +EOF + ); shell()->cd($this->source_dir) - ->exec( "{$this->builder->configure_env} " . PHP_EOL . - 'test -f gzlib.o && make clean' . PHP_EOL . - 'CFLAGS="-fPIE -fPIC" ./configure ' . + 'CFLAGS="-fPIE -fPIC" ./configure ' . '--static ' . '--prefix=' . $destdir ) From 78e9ff315b43b730f0d98ce316375ea65066811f Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Wed, 26 Apr 2023 15:45:04 +0800 Subject: [PATCH 17/24] =?UTF-8?q?=E9=AA=8C=E8=AF=81macos=20=E5=90=AF?= =?UTF-8?q?=E7=94=A8gd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/lib.json | 3 + quickstart/macOS/x86_64/prepare.sh | 2 + src/SPC/builder/macos/MacOSBuilder.php | 92 +++++++++++++++++----- src/SPC/builder/macos/library/brotli.php | 60 ++++++++++---- src/SPC/builder/macos/library/bzip2.php | 29 ++++++- src/SPC/builder/macos/library/freetype.php | 54 ++++++++----- src/SPC/builder/macos/library/libgif.php | 36 +++++++++ src/SPC/builder/macos/library/libjpeg.php | 59 ++++++++++++++ src/SPC/builder/macos/library/libpng.php | 48 +++++++---- src/SPC/builder/macos/library/libwebp.php | 55 +++++++++++++ src/SPC/builder/macos/library/zlib.php | 30 +++++-- 11 files changed, 389 insertions(+), 79 deletions(-) create mode 100644 src/SPC/builder/macos/library/libgif.php create mode 100644 src/SPC/builder/macos/library/libjpeg.php create mode 100644 src/SPC/builder/macos/library/libwebp.php diff --git a/config/lib.json b/config/lib.json index 4b10abfc5..9b7f1eae2 100644 --- a/config/lib.json +++ b/config/lib.json @@ -260,6 +260,9 @@ "static-libs-unix": [ "libxml2.a" ], + "none-pkg-unix": [ + "-liconv'" + ], "static-libs-windows": [ [ "libxml2s.lib", diff --git a/quickstart/macOS/x86_64/prepare.sh b/quickstart/macOS/x86_64/prepare.sh index 93b835608..e48bbade6 100644 --- a/quickstart/macOS/x86_64/prepare.sh +++ b/quickstart/macOS/x86_64/prepare.sh @@ -22,3 +22,5 @@ chmod +x bin/spc ./bin/spc list-ext ./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo,pdo_sqlite,ftp,curl" --cc=clang --cxx=clang++ --debug + +./bin/spc build gd,zlib --cc=clang --cxx=clang++ --build-cli --debug \ No newline at end of file diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 3c29f00de..11a51f9a0 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -10,6 +10,7 @@ use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; +use SPC\store\FileSystem; use SPC\util\Patcher; /** @@ -47,14 +48,25 @@ public function __construct(?string $cc = null, ?string $cxx = null, ?string $ar $this->arch_cxx_flags = SystemUtil::getArchCFlags($this->arch); // 设置 cmake $this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile('Darwin', $this->arch, $this->arch_c_flags); + + $build_root_path = BUILD_ROOT_PATH; + $build_lib_path = BUILD_LIB_PATH; + // 设置 pkgconfig + $this->pkgconf_env = 'export PKG_CONFIG_PATH="' . $build_lib_path . '/pkgconfig:/usr/lib/pkgconfig"'; + $this->ld = $this->cc == 'clang' ? 'lld' : 'ld'; // 设置 configure 依赖的环境变量 - $this->configure_env = - 'PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig/" ' . - "CC='{$this->cc}' " . - "CXX='{$this->cxx}' " . - "CFLAGS='{$this->arch_c_flags} -Wimplicit-function-declaration'"; + $this->configure_env = <<cc} + export CXX={$this->cxx} + export LD={$this->ld} + export PATH={$build_root_path}/bin/:\$PATH + {$this->pkgconf_env} +EOF; + $this->configure_env = PHP_EOL . $this->configure_env . PHP_EOL; // 创立 pkg-config 和放头文件的目录 + f_mkdir(BUILD_ROOT_PATH . '/bin', recursive: true); f_mkdir(BUILD_LIB_PATH . '/pkgconfig', recursive: true); f_mkdir(BUILD_INCLUDE_PATH, recursive: true); } @@ -135,26 +147,70 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $bloat = fa ); } - // patch before configure - Patcher::patchPHPBeforeConfigure($this); + $envs = ''; + $cflags = $this->arch_c_flags; + $use_lld = ''; + + $lib_meta = FileSystem::loadConfigArray('lib'); + $packages = []; + $pkg_libs = []; + foreach ($this->libs as $lib) { + if (isset($lib_meta[$lib::NAME]['pkg-unix'])) { + $packages = array_merge($packages, $lib_meta[$lib::NAME]['pkg-unix']); + } + if (isset($lib_meta[$lib::NAME]['none-pkg-unix'])) { + $pkg_libs = array_merge($pkg_libs, $lib_meta[$lib::NAME]['none-pkg-unix']); + } + } - shell()->cd(SOURCE_PATH . '/php-src')->exec('./buildconf --force'); + $packages = array_unique($packages); + $envs = $this->configure_env; + $envs .= ' CPPFLAGS="-I' . BUILD_ROOT_PATH . '/include " ' . PHP_EOL; + $envs .= ' LDFLAGS="-L' . BUILD_ROOT_PATH . '/lib " ' . PHP_EOL; + $envs .= ' LIBS=" -lm -lpthread -lutil -lresolv " ' . PHP_EOL; - Patcher::patchPHPConfigure($this); + if (!empty($pkg_libs)) { + $envs .= ' LIBS="$LIBS ' . implode(' ', $pkg_libs) . '"' . PHP_EOL; + } - if ($this->getLib('libxml2') || $this->getExt('iconv')) { - $extra_libs .= ' -liconv'; + if (!empty($packages)) { + $envs .= ' export PACKAGES="' . implode(' ', $packages) . '" ' . PHP_EOL; + $envs .= ' export CPPFLAGS="$CPPFLAGS $(pkg-config --cflags-only-I --static $PACKAGES )" ' . PHP_EOL; + $envs .= ' export LDFLAGS="$LDFLAGS $(pkg-config --libs-only-L --static $PACKAGES )" ' . PHP_EOL; + $envs .= ' export LIBS="$(pkg-config --libs-only-l --static $PACKAGES ) $LIBS" ' . PHP_EOL; } + $cflags .= ' -Wimplicit-function-declaration '; + if (strlen($cflags) > 2) { + $envs .= " export CFLAGS=\"{$cflags}\" " . PHP_EOL; + } + + $envs .= 'export EXTRA_LDFLAGS_PROGRAM="$LDFLAGS -all-static"'; + shell()->cd(SOURCE_PATH . '/php-src') + ->exec( + <<<'EOF' + if [[ -d php_cli_process_title.lo ]] + then + make clean + fi + +EOF + ); + // patch before configure + Patcher::patchPHPBeforeConfigure($this); + + Patcher::patchPHPConfigure($this); shell()->cd(SOURCE_PATH . '/php-src') ->exec( + 'echo "start build php"' . PHP_EOL . + $envs . PHP_EOL . + './buildconf --force ' . PHP_EOL . './configure ' . '--prefix= ' . '--with-valgrind=no ' . // 不检测内存泄漏 '--enable-shared=no ' . '--enable-static=yes ' . "--host={$this->gnu_arch}-apple-darwin " . - "CFLAGS='{$this->arch_c_flags} -Werror=unknown-warning-option' " . '--disable-all ' . '--disable-cgi ' . '--disable-phpdbg ' . @@ -170,15 +226,15 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $bloat = fa if (($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI) { logger()->info('building cli'); - $this->buildCli($extra_libs); + $this->buildCli($extra_libs, $envs); } if (($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM) { logger()->info('building fpm'); - $this->buildFpm($extra_libs); + $this->buildFpm($extra_libs, $envs); } if (($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO) { logger()->info('building micro'); - $this->buildMicro($extra_libs); + $this->buildMicro($extra_libs, $envs); } if (php_uname('m') === $this->arch) { @@ -196,7 +252,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $bloat = fa * @throws RuntimeException * @throws FileSystemException */ - public function buildCli(string $extra_libs): void + public function buildCli(string $extra_libs, string $envs): void { shell()->cd(SOURCE_PATH . '/php-src') ->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" cli") @@ -210,7 +266,7 @@ public function buildCli(string $extra_libs): void * * @throws FileSystemException|RuntimeException */ - public function buildMicro(string $extra_libs): void + public function buildMicro(string $extra_libs, string $envs): void { if ($this->getPHPVersionID() < 80000) { throw new RuntimeException('phpmicro only support PHP >= 8.0!'); @@ -237,7 +293,7 @@ public function buildMicro(string $extra_libs): void * @throws RuntimeException * @throws FileSystemException */ - public function buildFpm(string $extra_libs): void + public function buildFpm(string $extra_libs, string $envs): void { shell()->cd(SOURCE_PATH . '/php-src') ->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" fpm") diff --git a/src/SPC/builder/macos/library/brotli.php b/src/SPC/builder/macos/library/brotli.php index 1ff7efeb2..edb2de2d8 100644 --- a/src/SPC/builder/macos/library/brotli.php +++ b/src/SPC/builder/macos/library/brotli.php @@ -20,28 +20,58 @@ namespace SPC\builder\macos\library; +use SPC\exception\RuntimeException; + class brotli extends MacOSLibraryBase { public const NAME = 'brotli'; - protected function build() + /** + * @throws RuntimeException + */ + public function build() { [$lib, $include, $destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build') - ->cd($this->source_dir . '/build') + shell() + ->cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -d BUILD_DIR ]] + then + rm -rf BUILD_DIR + fi + mkdir -p BUILD_DIR +EOF + ); + // 使用 cmake 编译 + shell()->cd($this->source_dir . '/BUILD_DIR') ->exec( - "{$this->builder->configure_env} cmake " . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DCMAKE_INSTALL_PREFIX=/ ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '..' + <<builder->configure_env} + cmake .. \\ + -DCMAKE_BUILD_TYPE=Release \\ + -DCMAKE_INSTALL_PREFIX={$destdir} \\ + -DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} \\ + -DCMAKE_INSTALL_LIBDIR={$destdir}/lib \\ + -DCMAKE_INSTALL_INCLUDEDIR={$destdir}/include \\ + -DBROTLI_DISABLE_TESTS=OFF \\ + -DBROTLI_BUNDLED_MODE=OFF \\ + -DBROTLI_EMSCRIPTEN=OFF + + cmake --build . --config Release --target install + +EOF ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); + ->exec( + <<cd($this->source_dir) - ->exec("make {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' clean") - ->exec("make -j{$this->builder->concurrency} {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a") + shell() + ->cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -f blocksort.o ]] + then + make clean + fi +EOF + ); + + shell() + ->cd($this->source_dir) + ->exec( + $this->builder->configure_env . + "make -j{$this->builder->concurrency} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a" + ) ->exec('cp libbz2.a ' . BUILD_LIB_PATH) ->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH); } diff --git a/src/SPC/builder/macos/library/freetype.php b/src/SPC/builder/macos/library/freetype.php index 45da31406..375993a3f 100644 --- a/src/SPC/builder/macos/library/freetype.php +++ b/src/SPC/builder/macos/library/freetype.php @@ -4,33 +4,47 @@ namespace SPC\builder\macos\library; -/** - * is a template library class for unix - */ +use SPC\exception\RuntimeException; + class freetype extends MacOSLibraryBase { public const NAME = 'freetype'; - protected function build() + /** + * @throws RuntimeException + */ + public function build() { - [,,$destdir] = SEPARATED_PATH; - - $suggested = ''; - $suggested .= ($this->builder->getLib('libpng') instanceof MacOSLibraryBase) ? ('--with-png=' . BUILD_ROOT_PATH) : '--without-png'; - $suggested .= ' '; - $suggested .= ($this->builder->getLib('bzip2') instanceof MacOSLibraryBase) ? ('--with-bzip2=' . BUILD_ROOT_PATH) : '--without-bzip2'; - $suggested .= ' '; - $suggested .= ($this->builder->getLib('brotli') instanceof MacOSLibraryBase) ? ('--with-brotli=' . BUILD_ROOT_PATH) : '--without-brotli'; - $suggested .= ' '; - + [$lib, $include, $destdir] = SEPARATED_PATH; + shell()->cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -d objs/.libs ]] + then + make clean + fi +EOF + ); shell()->cd($this->source_dir) ->exec( - "{$this->builder->configure_env} ./configure " . - '--enable-static --disable-shared --without-harfbuzz --prefix= ' . - $suggested + <<builder->configure_env} + BZIP2_CFLAGS="-I{$destdir}/include" \\ + BZIP2_LIBS="-L{$destdir}/lib -lbz2" \\ + CPPFLAGS="$(pkg-config --cflags-only-I --static zlib libpng libbrotlidec libbrotlienc libbrotlicommon)" \\ + LDFLAGS="$(pkg-config --libs-only-L --static zlib libpng libbrotlidec libbrotlienc libbrotlicommon)" \\ + LIBS="$(pkg-config --libs-only-l --static zlib libpng libbrotlidec libbrotlienc libbrotlicommon)" \\ + ./configure --prefix={$destdir} \\ + --enable-static \\ + --disable-shared \\ + --with-zlib=yes \\ + --with-bzip2=yes \\ + --with-png=yes \\ + --with-harfbuzz=no \\ + --with-brotli=no +EOF ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); + ->exec("make -j {$this->builder->concurrency}") + ->exec('make install'); } } diff --git a/src/SPC/builder/macos/library/libgif.php b/src/SPC/builder/macos/library/libgif.php new file mode 100644 index 000000000..bf852e32d --- /dev/null +++ b/src/SPC/builder/macos/library/libgif.php @@ -0,0 +1,36 @@ +cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -f libgif.a ]] + then + make clean + fi +EOF + ); + shell()->cd($this->source_dir) + ->exec(" {$this->builder->configure_env} make -j {$this->builder->concurrency} libgif.a") + ->exec("cp libgif.a {$destdir}/lib/libgif.a") + ->exec("cp gif_lib.h {$destdir}/include/gif_lib.h"); + } +} diff --git a/src/SPC/builder/macos/library/libjpeg.php b/src/SPC/builder/macos/library/libjpeg.php new file mode 100644 index 000000000..c67dfdf28 --- /dev/null +++ b/src/SPC/builder/macos/library/libjpeg.php @@ -0,0 +1,59 @@ +cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -d build ]] + then + rm -rf build + fi + mkdir -p build +EOF + ); + shell()->cd($this->source_dir . '/build/') + ->exec( + <<builder->configure_env} + cmake -G"Unix Makefiles" \\ + .. \\ + -DCMAKE_INSTALL_PREFIX={$destdir} \\ + -DCMAKE_INSTALL_BINDIR={$destdir}/bin/ \\ + -DCMAKE_INSTALL_LIBDIR={$destdir}/lib \\ + -DCMAKE_INSTALL_INCLUDEDIR={$destdir}/include \\ + -DCMAKE_BUILD_TYPE=Release \\ + -DENABLE_SHARED=OFF \\ + -DENABLE_STATIC=ON + # -DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} + +EOF + ) + ->exec("make -j {$this->builder->concurrency}") + ->exec('make install') + ->exec( + <<builder->arch) { 'x86_64' => '--enable-intel-sse ', @@ -42,22 +43,37 @@ protected function build() }; // patch configure - Patcher::patchUnixLibpng(); + // Patcher::patchUnixLibpng(); + shell() + ->cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -f .libs/libpng16.a ]] + then + make clean + fi +EOF + ); shell()->cd($this->source_dir) - ->exec('chmod +x ./configure') ->exec( - "{$this->builder->configure_env} ./configure " . - "--host={$this->builder->gnu_arch}-apple-darwin " . - '--disable-shared ' . - '--enable-static ' . - '--enable-hardware-optimizations ' . - $optimizations . - '--prefix=' + <<builder->configure_env} + chmod +x ./configure + CPPFLAGS="$(pkg-config --cflags-only-I --static zlib )" \\ + LDFLAGS="$(pkg-config --libs-only-L --static zlib )" \\ + LIBS="$(pkg-config --libs-only-l --static zlib )" \\ + ./configure \\ + --prefix={$destdir} \\ + --host={$this->builder->gnu_arch}-unknown-linux \\ + --disable-shared \\ + --enable-static \\ + --enable-hardware-optimizations \\ + --with-zlib-prefix={$destdir} + + # {$optimizations} +EOF ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I. -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la") - ->exec('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH) - ->cd(BUILD_LIB_PATH) - ->exec('ln -sf libpng16.a libpng.a'); + ->exec('make -j ' . $this->builder->concurrency) + ->exec('make install '); } } diff --git a/src/SPC/builder/macos/library/libwebp.php b/src/SPC/builder/macos/library/libwebp.php new file mode 100644 index 000000000..c92d62161 --- /dev/null +++ b/src/SPC/builder/macos/library/libwebp.php @@ -0,0 +1,55 @@ +cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -f src/.libs/libwebp.a ]] + then + make clean + fi +EOF + ); + shell()->cd($this->source_dir) + ->exec( + <<builder->configure_env} + ./autogen.sh + CPPFLAGS="$(pkg-config --cflags-only-I --static libpng libpng16 libjpeg libturbojpeg)" \\ + LDFLAGS="$(pkg-config --libs-only-L --static libpng libpng16 libjpeg libturbojpeg)" \\ + LIBS="$(pkg-config --libs-only-l --static libpng libpng16 libjpeg libturbojpeg)" \\ + CFLAGS="-fPIC -fPIE" \\ + ./configure \\ + --prefix={$destdir} \\ + --enable-shared=no \\ + --enable-static=yes \\ + --disable-shared \\ + --enable-libwebpdecoder \\ + --enable-libwebpextras \\ + --disable-tiff \\ + --disable-gl \\ + --disable-sdl \\ + --disable-wic +EOF + ) + ->exec($this->builder->configure_env . "make -j {$this->builder->concurrency}") + ->exec('make install'); + } +} diff --git a/src/SPC/builder/macos/library/zlib.php b/src/SPC/builder/macos/library/zlib.php index 11dab8eb9..4d3ed9aab 100644 --- a/src/SPC/builder/macos/library/zlib.php +++ b/src/SPC/builder/macos/library/zlib.php @@ -20,18 +20,36 @@ namespace SPC\builder\macos\library; +use SPC\exception\RuntimeException; + class zlib extends MacOSLibraryBase { public const NAME = 'zlib'; - protected function build() + /** + * @throws RuntimeException + */ + public function build() { - [,,$destdir] = SEPARATED_PATH; - + [, , $destdir] = SEPARATED_PATH; + shell() + ->cd($this->source_dir) + ->exec( + <<<'EOF' + if [[ -f gzlib.o ]] + then + make clean + fi +EOF + ); shell()->cd($this->source_dir) - ->exec("{$this->builder->configure_env} ./configure --static --prefix=") - ->exec('make clean') + ->exec( + "{$this->builder->configure_env} " . PHP_EOL . + 'CFLAGS="-fPIE -fPIC" ./configure ' . + '--static ' . + '--prefix=' . $destdir + ) ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); + ->exec('make install'); } } From 71ec35b7392a93bd954bee646276cb577c84a579 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Wed, 26 Apr 2023 15:49:09 +0800 Subject: [PATCH 18/24] fix --- src/SPC/builder/linux/library/brotli.php | 6 +++--- src/SPC/builder/macos/MacOSBuilder.php | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/linux/library/brotli.php b/src/SPC/builder/linux/library/brotli.php index 6a7f2bf37..ed4931a16 100644 --- a/src/SPC/builder/linux/library/brotli.php +++ b/src/SPC/builder/linux/library/brotli.php @@ -36,11 +36,11 @@ public function build() ->cd($this->source_dir) ->exec( <<<'EOF' - if [[ -d build ]] + if [[ -d BUILD_DIR ]] then - rm -rf build + rm -rf BUILD_DIR fi - mkdir -p build + mkdir -p BUILD_DIR EOF ); // 使用 cmake 编译 diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 11a51f9a0..5e965f8b3 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -25,6 +25,9 @@ class MacOSBuilder extends BuilderBase /** @var bool 标记是否 patch 了 phar */ private bool $phar_patched = false; + /** @var string env pkgconf */ + private string $pkgconf_env; + /** * @param null|string $cc C编译器名称,如果不传入则默认使用clang * @param null|string $cxx C++编译器名称,如果不传入则默认使用clang++ From d0491e5d53dbb5ef6d5794470343f547c4b8a918 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Thu, 27 Apr 2023 09:56:16 +0800 Subject: [PATCH 19/24] save changed --- src/SPC/builder/linux/LinuxBuilder.php | 26 ++++-------------------- src/SPC/builder/linux/library/brotli.php | 8 ++++---- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 34720aaab..249f62e7d 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -61,32 +61,14 @@ class LinuxBuilder extends BuilderBase */ public function __construct(?string $cc = null, ?string $cxx = null, ?string $arch = null) { - if (isset(SystemUtil::getOSRelease()['dist'])) { - $os_release = SystemUtil::getOSRelease(); - $os_release_name = $os_release['dist']; - $os_release_version = $os_release['ver']; - } else { - throw new \RuntimeException('no recognize os release'); - } - if ($cc == 'gcc') { - if ($os_release_name == 'alpine') { - $cc = 'gcc'; - $this->libc = 'musl'; - } elseif ($os_release_name == 'debian') { - $cc = 'musl-gcc'; - $this->libc = 'musl'; - } - } else { - $this->libc = 'libc'; - } - + // 编译器 选择 参考 https://github.com/crazywhalecc/static-php-cli/issues/50#issuecomment-1522809787 // 初始化一些默认参数 - $this->cc = $cc ?? 'clang'; - $this->cxx = $cxx ?? 'clang++'; + $this->cc = $cc ?? 'musl-gcc'; + $this->cxx = $cxx ?? 'g++'; $this->arch = $arch ?? php_uname('m'); $this->gnu_arch = arch2gnu($this->arch); - + $this->libc = 'libc'; // SystemUtil::selectLibc($this->cc); $this->ld = match ($this->cc) { diff --git a/src/SPC/builder/linux/library/brotli.php b/src/SPC/builder/linux/library/brotli.php index 6a7f2bf37..f5def731f 100644 --- a/src/SPC/builder/linux/library/brotli.php +++ b/src/SPC/builder/linux/library/brotli.php @@ -36,15 +36,15 @@ public function build() ->cd($this->source_dir) ->exec( <<<'EOF' - if [[ -d build ]] + if [[ -d build-dir ]] then - rm -rf build + rm -rf build-dir fi - mkdir -p build + mkdir -p build-dir EOF ); // 使用 cmake 编译 - shell()->cd($this->source_dir . '/build') + shell()->cd($this->source_dir . '/build-dir') ->exec( <<builder->configure_env} From ca346ac044ba9c37be1c2d39c04f006e7d317bf6 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Tue, 2 May 2023 02:59:27 +0800 Subject: [PATCH 20/24] merge code --- src/SPC/builder/linux/LinuxBuilder.php | 3 --- src/SPC/builder/macos/MacOSBuilder.php | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 979837425..ecefc007d 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -270,9 +270,6 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $with_clean $this->makeExtensionArgs() ); - $extra_libs .= $this->generateExtraLibs(); - echo $envs; - SourcePatcher::patchPHPAfterConfigure($this); file_put_contents('/tmp/comment', $this->note_section); diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index e1678a2df..9707f01b6 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -202,7 +202,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE, bool $bloat = fa // patch before configure SourcePatcher::patchPHPBuildconf($this); - Patcher::patchPHPConfigure($this); + // Patcher::patchPHPConfigure($this); shell()->cd(SOURCE_PATH . '/php-src')->exec('./buildconf --force'); From 71414052f46d9da8f9edc6ab3746b3f33b48bc51 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Tue, 2 May 2023 03:01:09 +0800 Subject: [PATCH 21/24] merge code --- config/lib.json | 1 - 1 file changed, 1 deletion(-) diff --git a/config/lib.json b/config/lib.json index 82e6ac35f..500ebe3d2 100644 --- a/config/lib.json +++ b/config/lib.json @@ -430,5 +430,4 @@ "zstd_errors.h" ] } ->>>>>>> refactor } \ No newline at end of file From 7acbd418c71504d054d59f990ce9bd91468ba336 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Wed, 24 May 2023 12:28:04 +0800 Subject: [PATCH 22/24] merge code --- src/SPC/builder/macos/MacOSBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index f43338a69..e11f862bc 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -61,7 +61,7 @@ public function __construct(?string $cc = null, ?string $cxx = null, ?string $ar $this->ld = $this->cc == 'clang' ? 'lld' : 'ld'; // 设置 configure 依赖的环境变量 - $this->configure_env = PHP_EOL . $this->configure_env . PHP_EOL; + $this->configure_env .= PHP_EOL . $this->pkgconf_env . PHP_EOL; $this->configure_env = 'PKG_CONFIG="' . BUILD_ROOT_PATH . '/bin/pkg-config" ' . From 2d777cb3d6ab581614e1f052477a992287f9d277 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Sat, 27 May 2023 17:52:28 +0800 Subject: [PATCH 23/24] stop docker timeout --- quickstart/linux/run-alpine-3.16-container.sh | 2 +- quickstart/linux/run-debian-11-container.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/quickstart/linux/run-alpine-3.16-container.sh b/quickstart/linux/run-alpine-3.16-container.sh index f46bdd161..2fd66c114 100644 --- a/quickstart/linux/run-alpine-3.16-container.sh +++ b/quickstart/linux/run-alpine-3.16-container.sh @@ -14,7 +14,7 @@ cd ${__DIR__} { docker stop static-php-cli-dev-1 - sleep 3 + sleep 5 } || { echo $? } diff --git a/quickstart/linux/run-debian-11-container.sh b/quickstart/linux/run-debian-11-container.sh index eec6a59f8..1e19c7794 100644 --- a/quickstart/linux/run-debian-11-container.sh +++ b/quickstart/linux/run-debian-11-container.sh @@ -14,7 +14,7 @@ cd ${__DIR__} { docker stop static-php-cli-dev-1 - sleep 3 + sleep 5 } || { echo $? } From c05f27bfb1d610ddde72b65a2de25b99a8f5234e Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Sat, 27 May 2023 17:54:08 +0800 Subject: [PATCH 24/24] quickstart delete macos script --- quickstart/macOS/x86_64/prepare.sh | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 quickstart/macOS/x86_64/prepare.sh diff --git a/quickstart/macOS/x86_64/prepare.sh b/quickstart/macOS/x86_64/prepare.sh deleted file mode 100644 index e48bbade6..000000000 --- a/quickstart/macOS/x86_64/prepare.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -set -exu -__DIR__=$( - cd "$(dirname "$0")" - pwd -) -__PROJECT__=$( - cd ${__DIR__}/../../../ - pwd -) -cd ${__PROJECT__} - -export PATH=${__PROJECT__}/bin/runtime:$PATH - -composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ - -chmod +x bin/spc - -./bin/spc fetch --all --debug - -./bin/spc list-ext - -./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo,pdo_sqlite,ftp,curl" --cc=clang --cxx=clang++ --debug - -./bin/spc build gd,zlib --cc=clang --cxx=clang++ --build-cli --debug \ No newline at end of file