From a59e3384381690875bc83e601a394a0aea2a9001 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 8 May 2023 21:30:45 +0800 Subject: [PATCH 01/19] add upload download artifacts --- .github/workflows/build-linux-x86_64.yml | 6 ++++++ .github/workflows/build-macos-x86_64.yml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/.github/workflows/build-linux-x86_64.yml b/.github/workflows/build-linux-x86_64.yml index 5a3a210d..0fbe82d8 100644 --- a/.github/workflows/build-linux-x86_64.yml +++ b/.github/workflows/build-linux-x86_64.yml @@ -114,3 +114,9 @@ jobs: path: | buildroot/build-extensions.json buildroot/build-libraries.json + + # Upload downloaded files + - uses: actions/upload-artifact@v3 + with: + name: download-files + path: downloads/ diff --git a/.github/workflows/build-macos-x86_64.yml b/.github/workflows/build-macos-x86_64.yml index 3270480f..d37900ec 100644 --- a/.github/workflows/build-macos-x86_64.yml +++ b/.github/workflows/build-macos-x86_64.yml @@ -114,3 +114,9 @@ jobs: path: | buildroot/build-extensions.json buildroot/build-libraries.json + + # Upload downloaded files + - uses: actions/upload-artifact@v3 + with: + name: download-files + path: downloads/ From 9daa10e939a5a06fd36ba087a8210e86fe5e88f1 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 10 May 2023 00:46:57 +0800 Subject: [PATCH 02/19] sort config, add imagemagick --- config/ext.json | 16 +++++++--- config/lib.json | 55 ++++++++++++++++++++++++---------- config/source.json | 75 +++++++++++++++++++++++++++++++--------------- 3 files changed, 103 insertions(+), 43 deletions(-) diff --git a/config/ext.json b/config/ext.json index 7e4718e9..6e317239 100644 --- a/config/ext.json +++ b/config/ext.json @@ -1,4 +1,8 @@ { + "apcu": { + "type": "external", + "source": "apcu" + }, "bcmath": { "type": "builtin" }, @@ -35,10 +39,6 @@ "zlib" ] }, - "apcu": { - "type": "external", - "source": "apcu" - }, "event": { "type": "external", "source": "ext-event", @@ -114,6 +114,14 @@ "libiconv" ] }, + "imagick": { + "type": "external", + "source": "ext-imagick", + "arg-type": "custom", + "lib-depends": [ + "imagemagick" + ] + }, "imap": { "type": "builtin", "arg-type": "with", diff --git a/config/lib.json b/config/lib.json index 500ebe3d..b3e86165 100644 --- a/config/lib.json +++ b/config/lib.json @@ -15,21 +15,6 @@ "brotli" ] }, - "ncurses": { - "source": "ncurses", - "static-libs-unix": [ - "libncurses.a" - ] - }, - "readline": { - "source": "readline", - "static-libs-unix": [ - "libreadline.a" - ], - "lib-depends": [ - "ncurses" - ] - }, "bzip2": { "source": "bzip2", "static-libs-unix": [ @@ -111,6 +96,28 @@ "gmp.h" ] }, + "imagemagick": { + "source": "imagemagick", + "static-libs-unix": [ + "libMagick++-7.Q16HDRI.a", + "libMagickCore-7.Q16HDRI.a", + "libMagickWand-7.Q16HDRI.a" + ], + "lib-depends": [ + "zlib", + "libpng", + "libjpeg", + "bzip2" + ], + "lib-suggests": [ + "libwebp", + "freetype", + "zstd", + "xz", + "libzip", + "libxml2" + ] + }, "libavif": { "source": "libavif", "static-libs-unix": [ @@ -294,6 +301,12 @@ "libmcrypt.a" ] }, + "ncurses": { + "source": "ncurses", + "static-libs-unix": [ + "libncurses.a" + ] + }, "nghttp2": { "source": "nghttp2", "static-libs-unix": [ @@ -346,6 +359,9 @@ "zlib" ] }, + "pkg-config": { + "source": "pkg-config" + }, "postgresql": { "source": "postgresql", "static-libs-unix": [ @@ -364,6 +380,15 @@ "semaphore.h" ] }, + "readline": { + "source": "readline", + "static-libs-unix": [ + "libreadline.a" + ], + "lib-depends": [ + "ncurses" + ] + }, "sqlite": { "source": "sqlite", "static-libs-unix": [ diff --git a/config/source.json b/config/source.json index 0b72e00d..950058d3 100644 --- a/config/source.json +++ b/config/source.json @@ -6,6 +6,16 @@ "path": "LICENSE" } }, + "apcu": { + "type": "url", + "url": "http://pecl.php.net/get/APCu", + "path": "php-src/ext/apcu", + "filename": "apcu.tgz", + "license": { + "type": "file", + "path": "LICENSE" + } + }, "brotli": { "type": "ghtar", "repo": "google/brotli", @@ -41,22 +51,14 @@ "path": "LICENSE" } }, - "ncurses": { - "type": "filelist", - "url": "https://ftp.gnu.org/pub/gnu/ncurses/", - "regex": "/href=\"(?ncurses-(?[^\"]+)\\.tar\\.gz)\"/", + "ext-imagick": { + "type": "url", + "url": "https://pecl.php.net/get/imagick", + "path": "php-src/ext/imagick", + "filename": "imagick.tgz", "license": { "type": "file", - "path": "COPYING" - } - }, - "readline": { - "type": "filelist", - "url": "https://ftp.gnu.org/pub/gnu/readline/", - "regex": "/href=\"(?readline-(?[^\"]+)\\.tar\\.gz)\"/", - "license": { - "type": "file", - "path": "COPYING" + "path": "LICENSE" } }, "ext-zstd": { @@ -87,6 +89,14 @@ "text": "Since version 6, GMP is distributed under the dual licenses, GNU LGPL v3 and GNU GPL v2. These licenses make the library free to use, share, and improve, and allow you to pass on the result. The GNU licenses give freedoms, but also set firm restrictions on the use with non-free programs." } }, + "imagemagick": { + "type": "ghtar", + "repo": "ImageMagick/ImageMagick", + "license": { + "type": "file", + "path": "LICENSE" + } + }, "inotify": { "type": "url", "url": "http://pecl.php.net/get/inotify", @@ -209,16 +219,6 @@ "path": "LICENSE" } }, - "apcu": { - "type": "url", - "url": "http://pecl.php.net/get/APCu", - "path": "php-src/ext/apcu", - "filename": "apcu.tgz", - "license": { - "type": "file", - "path": "LICENSE" - } - }, "mcrypt": { "type": "url", "url": "https://jaist.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz", @@ -247,6 +247,15 @@ "path": "LICENSE" } }, + "ncurses": { + "type": "filelist", + "url": "https://ftp.gnu.org/pub/gnu/ncurses/", + "regex": "/href=\"(?ncurses-(?[^\"]+)\\.tar\\.gz)\"/", + "license": { + "type": "file", + "path": "COPYING" + } + }, "nghttp2": { "type": "ghrel", "repo": "nghttp2/nghttp2", @@ -274,6 +283,15 @@ "path": "LICENSE.txt" } }, + "pkg-config": { + "type": "filelist", + "url": "https://pkgconfig.freedesktop.org/releases/", + "regex": "/href=\"(?pkg-config-(?[^\"]+)\\.tar\\.gz)\"/", + "license": { + "type": "file", + "path": "COPYING" + } + }, "postgresql": { "type": "custom", "license": { @@ -300,6 +318,15 @@ "path": "LICENSE" } }, + "readline": { + "type": "filelist", + "url": "https://ftp.gnu.org/pub/gnu/readline/", + "regex": "/href=\"(?readline-(?[^\"]+)\\.tar\\.gz)\"/", + "license": { + "type": "file", + "path": "COPYING" + } + }, "redis": { "type": "git", "path": "php-src/ext/redis", From 7527f9f0994617484b0d56e27b5878ec67643c3b Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 10 May 2023 02:04:08 +0800 Subject: [PATCH 03/19] add imagemagick (imagick) for macos, pkg-config for unix.= --- config/lib.json | 6 +- ext-support.md | 3 +- src/SPC/builder/BuilderBase.php | 3 + src/SPC/builder/LibraryBase.php | 6 ++ src/SPC/builder/extension/imagick.php | 17 ++++++ src/SPC/builder/linux/LinuxBuilder.php | 7 ++- src/SPC/builder/linux/SystemUtil.php | 2 +- .../linux/library/LinuxLibraryBase.php | 5 ++ src/SPC/builder/linux/library/libpng.php | 1 + src/SPC/builder/linux/library/pkgconfig.php | 15 +++++ src/SPC/builder/macos/MacOSBuilder.php | 3 +- src/SPC/builder/macos/library/imagemagick.php | 60 +++++++++++++++++++ src/SPC/builder/macos/library/libpng.php | 1 + src/SPC/builder/macos/library/pkgconfig.php | 15 +++++ src/SPC/builder/traits/UnixLibraryTrait.php | 16 +++++ .../builder/traits/UnixSystemUtilTrait.php | 1 + src/SPC/builder/unix/library/freetype.php | 10 ++++ src/SPC/builder/unix/library/libavif.php | 1 + src/SPC/builder/unix/library/libjpeg.php | 1 + src/SPC/builder/unix/library/libwebp.php | 1 + src/SPC/builder/unix/library/libzip.php | 4 +- src/SPC/builder/unix/library/pkgconfig.php | 43 +++++++++++++ src/SPC/store/SourcePatcher.php | 9 +++ src/globals/functions.php | 10 +++- 24 files changed, 229 insertions(+), 11 deletions(-) create mode 100644 src/SPC/builder/extension/imagick.php create mode 100644 src/SPC/builder/linux/library/pkgconfig.php create mode 100644 src/SPC/builder/macos/library/imagemagick.php create mode 100644 src/SPC/builder/macos/library/pkgconfig.php create mode 100644 src/SPC/builder/unix/library/pkgconfig.php diff --git a/config/lib.json b/config/lib.json index b3e86165..466763b8 100644 --- a/config/lib.json +++ b/config/lib.json @@ -107,11 +107,11 @@ "zlib", "libpng", "libjpeg", - "bzip2" + "bzip2", + "libwebp", + "freetype" ], "lib-suggests": [ - "libwebp", - "freetype", "zstd", "xz", "libzip", diff --git a/ext-support.md b/ext-support.md index afdccdf0..a744794b 100644 --- a/ext-support.md +++ b/ext-support.md @@ -26,6 +26,7 @@ | gettext | | | | | gmp | yes | yes | | | iconv | yes | yes | | +| imagick | | yes | | | inotify | yes | yes | | | mbstring | yes | yes | | | mbregex | yes | yes | | @@ -56,7 +57,7 @@ | xml | yes | yes | | | xmlreader | yes, untested | yes, untested | | | xmlwriter | yes, untested | yes, untested | | -| zip | yes, untested | yes | | +| zip | yes, untested | yes, untested | | | zlib | yes | yes | | | zstd | yes | yes | | diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 09240cb0..83097896 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -63,6 +63,9 @@ abstract class BuilderBase if ($libraries === [] && $this->isLibsOnly()) { $libraries = array_keys($support_lib_list); } + if (!in_array('pkg-config', $libraries)) { + array_unshift($libraries, 'pkg-config'); + } // 排序 libs,根据依赖计算一个新的列表出来 $libraries = DependencyUtil::getLibsByDeps($libraries); diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index dfd6b859..7f234a5b 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SPC\builder; +use SPC\builder\macos\library\MacOSLibraryBase; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\store\Config; @@ -152,6 +153,11 @@ abstract class LibraryBase return BUILD_STATUS_OK; } } + // pkg-config 做特殊处理,如果是 pkg-config 就检查有没有 pkg-config 二进制 + if ($this instanceof MacOSLibraryBase && static::NAME === 'pkg-config' && !file_exists(BUILD_ROOT_PATH . '/bin/pkg-config')) { + $this->tryBuild(true); + return BUILD_STATUS_OK; + } // 到这里说明所有的文件都存在,就跳过编译 return BUILD_STATUS_ALREADY; } diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php new file mode 100644 index 00000000..ed456e17 --- /dev/null +++ b/src/SPC/builder/extension/imagick.php @@ -0,0 +1,17 @@ +cxx ); // 设置 pkgconfig - $this->pkgconf_env = 'PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig"'; + $this->pkgconf_env = 'PKG_CONFIG="' . BUILD_ROOT_PATH . '/bin/pkg-config" PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig"'; // 设置 configure 依赖的环境变量 $this->configure_env = $this->pkgconf_env . ' ' . @@ -141,6 +141,9 @@ class LinuxBuilder extends BuilderBase if ($this->getExt('swoole')) { $extra_libs .= ' -lstdc++'; } + if ($this->getExt('imagick')) { + $extra_libs .= ' /usr/lib/libMagick++-7.Q16HDRI.a /usr/lib/libMagickCore-7.Q16HDRI.a /usr/lib/libMagickWand-7.Q16HDRI.a'; + } $envs = $this->pkgconf_env . ' ' . "CC='{$this->cc}' " . @@ -169,7 +172,7 @@ class LinuxBuilder extends BuilderBase shell()->cd(SOURCE_PATH . '/php-src')->exec('./buildconf --force'); SourcePatcher::patchPHPConfigure($this); - + if ($this->getPHPVersionID() < 80000) { $json_74 = '--enable-json '; } else { diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index b0a43789..5f2df6a3 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -149,7 +149,7 @@ class SystemUtil { $paths = getenv('LIBPATH'); if (!$paths) { - $paths = '/lib:/lib64:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64'; + $paths = '/lib:/lib64:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64:'; } foreach (explode(':', $paths) as $path) { if (file_exists("{$path}/{$name}")) { diff --git a/src/SPC/builder/linux/library/LinuxLibraryBase.php b/src/SPC/builder/linux/library/LinuxLibraryBase.php index 1105578f..2712976b 100644 --- a/src/SPC/builder/linux/library/LinuxLibraryBase.php +++ b/src/SPC/builder/linux/library/LinuxLibraryBase.php @@ -61,6 +61,11 @@ abstract class LinuxLibraryBase extends LibraryBase return BUILD_STATUS_OK; } } + // pkg-config 做特殊处理,如果是 pkg-config 就检查有没有 pkg-config 二进制 + if (static::NAME === 'pkg-config' && !file_exists(BUILD_ROOT_PATH . '/bin/pkg-config')) { + $this->tryBuild(true); + return BUILD_STATUS_OK; + } // 到这里说明所有的文件都存在,就跳过编译 return BUILD_STATUS_ALREADY; } diff --git a/src/SPC/builder/linux/library/libpng.php b/src/SPC/builder/linux/library/libpng.php index 5c28d1e2..e3d0e2ce 100644 --- a/src/SPC/builder/linux/library/libpng.php +++ b/src/SPC/builder/linux/library/libpng.php @@ -61,5 +61,6 @@ class libpng extends LinuxLibraryBase ->cd(BUILD_LIB_PATH) ->exec('ln -sf libpng16.a libpng.a'); $this->patchPkgconfPrefix(['libpng16.pc'], PKGCONF_PATCH_PREFIX); + $this->cleanLaFiles(); } } diff --git a/src/SPC/builder/linux/library/pkgconfig.php b/src/SPC/builder/linux/library/pkgconfig.php new file mode 100644 index 00000000..eacca36d --- /dev/null +++ b/src/SPC/builder/linux/library/pkgconfig.php @@ -0,0 +1,15 @@ +cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile('Darwin', $this->arch, $this->arch_c_flags); // 设置 configure 依赖的环境变量 $this->configure_env = + 'PKG_CONFIG="' . BUILD_ROOT_PATH . '/bin/pkg-config" ' . 'PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig/" ' . "CC='{$this->cc}' " . "CXX='{$this->cxx}' " . @@ -145,7 +146,7 @@ class MacOSBuilder extends BuilderBase if ($this->getLib('libxml2') || $this->getExt('iconv')) { $extra_libs .= ' -liconv'; } - + if ($this->getPHPVersionID() < 80000) { $json_74 = '--enable-json '; } else { diff --git a/src/SPC/builder/macos/library/imagemagick.php b/src/SPC/builder/macos/library/imagemagick.php new file mode 100644 index 00000000..c6a105c5 --- /dev/null +++ b/src/SPC/builder/macos/library/imagemagick.php @@ -0,0 +1,60 @@ +builder->getLib('libjpeg') ? '--with-jpeg ' : ''; + // png support + $extra .= $this->builder->getLib('libpng') ? '--with-png ' : ''; + // webp support + $extra .= $this->builder->getLib('libwebp') ? '--with-webp ' : ''; + // zstd support + // $extra .= $this->builder->getLib('zstd') ? '--with-zstd ' : '--without-zstd '; + // freetype support + $extra .= $this->builder->getLib('freetype') ? '--with-freetype ' : '--without-freetype '; + + shell()->cd($this->source_dir) + ->exec( + "{$this->builder->configure_env} ./configure " . + '--enable-static --disable-shared ' . + $extra . + '--prefix=' + ) + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + $filelist = [ + 'ImageMagick.pc', + 'ImageMagick-7.Q16HDRI.pc', + 'Magick++.pc', + 'Magick++-7.Q16HDRI.pc', + 'MagickCore.pc', + 'MagickCore-7.Q16HDRI.pc', + 'MagickWand.pc', + 'MagickWand-7.Q16HDRI.pc', + ]; + $this->patchPkgconfPrefix($filelist); + foreach ($filelist as $file) { + FileSystem::replaceFile( + BUILD_LIB_PATH . '/pkgconfig/' . $file, + REPLACE_FILE_PREG, + '#includearchdir=/include/ImageMagick-7#m', + 'includearchdir=${prefix}/include/ImageMagick-7' + ); + } + } +} diff --git a/src/SPC/builder/macos/library/libpng.php b/src/SPC/builder/macos/library/libpng.php index 07d3c767..76a0645e 100644 --- a/src/SPC/builder/macos/library/libpng.php +++ b/src/SPC/builder/macos/library/libpng.php @@ -55,5 +55,6 @@ class libpng extends MacOSLibraryBase ->cd(BUILD_LIB_PATH) ->exec('ln -sf libpng16.a libpng.a'); $this->patchPkgconfPrefix(['libpng16.pc'], PKGCONF_PATCH_PREFIX); + $this->cleanLaFiles(); } } diff --git a/src/SPC/builder/macos/library/pkgconfig.php b/src/SPC/builder/macos/library/pkgconfig.php new file mode 100644 index 00000000..bb74dfaa --- /dev/null +++ b/src/SPC/builder/macos/library/pkgconfig.php @@ -0,0 +1,15 @@ +getStaticLibs() as $lib) { + $filename = pathinfo($lib, PATHINFO_FILENAME) . '.la'; + if (file_exists(BUILD_LIB_PATH . '/' . $filename)) { + unlink(BUILD_LIB_PATH . '/' . $filename); + } + } + } } diff --git a/src/SPC/builder/traits/UnixSystemUtilTrait.php b/src/SPC/builder/traits/UnixSystemUtilTrait.php index adc25a5f..46a30ca8 100644 --- a/src/SPC/builder/traits/UnixSystemUtilTrait.php +++ b/src/SPC/builder/traits/UnixSystemUtilTrait.php @@ -47,6 +47,7 @@ SET(CMAKE_CXX_FLAGS "{$cflags}") SET(CMAKE_FIND_ROOT_PATH "{$root}") SET(CMAKE_PREFIX_PATH "{$root}") +set(PKG_CONFIG_EXECUTABLE "{$root}/bin/pkg-config") set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/src/SPC/builder/unix/library/freetype.php b/src/SPC/builder/unix/library/freetype.php index 750622c3..18b77997 100644 --- a/src/SPC/builder/unix/library/freetype.php +++ b/src/SPC/builder/unix/library/freetype.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\store\FileSystem; + trait freetype { protected function build() @@ -25,5 +27,13 @@ trait freetype ->exec("make -j{$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['freetype2.pc']); + FileSystem::replaceFile( + BUILD_ROOT_PATH . '/lib/pkgconfig/freetype2.pc', + REPLACE_FILE_STR, + ' -L/lib ', + ' -L' . BUILD_ROOT_PATH . '/lib ' + ); + + $this->cleanLaFiles(); } } diff --git a/src/SPC/builder/unix/library/libavif.php b/src/SPC/builder/unix/library/libavif.php index 413b471d..ac27a5d9 100644 --- a/src/SPC/builder/unix/library/libavif.php +++ b/src/SPC/builder/unix/library/libavif.php @@ -24,5 +24,6 @@ trait libavif ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); // patch pkgconfig $this->patchPkgconfPrefix(['libavif.pc']); + $this->cleanLaFiles(); } } diff --git a/src/SPC/builder/unix/library/libjpeg.php b/src/SPC/builder/unix/library/libjpeg.php index 08c51d85..65da0c08 100644 --- a/src/SPC/builder/unix/library/libjpeg.php +++ b/src/SPC/builder/unix/library/libjpeg.php @@ -24,5 +24,6 @@ trait libjpeg ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); // patch pkgconfig $this->patchPkgconfPrefix(['libjpeg.pc', 'libturbojpeg.pc']); + $this->cleanLaFiles(); } } diff --git a/src/SPC/builder/unix/library/libwebp.php b/src/SPC/builder/unix/library/libwebp.php index 9d06842d..f6e7a596 100644 --- a/src/SPC/builder/unix/library/libwebp.php +++ b/src/SPC/builder/unix/library/libwebp.php @@ -28,5 +28,6 @@ trait libwebp ->exec("make -j{$this->builder->concurrency}") ->exec('make install DESTDIR=' . $destdir); $this->patchPkgconfPrefix(['libsharpyuv.pc', 'libwebp.pc', 'libwebpdecoder.pc', 'libwebpdemux.pc', 'libwebpmux.pc'], PKGCONF_PATCH_PREFIX); + $this->cleanLaFiles(); } } diff --git a/src/SPC/builder/unix/library/libzip.php b/src/SPC/builder/unix/library/libzip.php index f50a6144..b4b8f99f 100644 --- a/src/SPC/builder/unix/library/libzip.php +++ b/src/SPC/builder/unix/library/libzip.php @@ -15,8 +15,8 @@ trait libzip $extra .= $this->builder->getLib('bzip2') ? '-DENABLE_BZIP2=ON ' : '-DENABLE_BZIP2=OFF '; // lib:xz $extra .= $this->builder->getLib('xz') ? '-DENABLE_LZMA=ON ' : '-DENABLE_LZMA=OFF '; - // lib:zstd - $extra .= $this->builder->getLib('zstd') ? '-DENABLE_ZSTD=ON ' : '-DENABLE_ZSTD=OFF '; + // lib:zstd (disabled due to imagemagick link issue + $extra .= /* $this->builder->getLib('zstd') ? '-DENABLE_ZSTD=ON ' : */ '-DENABLE_ZSTD=OFF '; // lib:openssl $extra .= $this->builder->getLib('openssl') ? '-DENABLE_OPENSSL=ON ' : '-DENABLE_OPENSSL=OFF '; diff --git a/src/SPC/builder/unix/library/pkgconfig.php b/src/SPC/builder/unix/library/pkgconfig.php new file mode 100644 index 00000000..6cc475d9 --- /dev/null +++ b/src/SPC/builder/unix/library/pkgconfig.php @@ -0,0 +1,43 @@ +builder->cc}' " . + "CXX='{$this->builder->cxx}' " . + "CFLAGS='{$this->builder->arch_c_flags} -Wimplicit-function-declaration' "; + $linux_env = 'PKG_CONFIG_PATH="' . BUILD_LIB_PATH . '/pkgconfig" ' . + "CC='{$this->builder->cc}' " . + "CXX='{$this->builder->cxx}' "; + + $extra = match (PHP_OS_FAMILY) { + 'Darwin' => '', + default => '--with-internal-glib ', + }; + shell()->cd($this->source_dir) + ->exec( + match (PHP_OS_FAMILY) { + 'Darwin' => $macos_env, + default => $linux_env, + } . + './configure ' . + '--disable-shared ' . + '--enable-static ' . + $extra . + '--prefix=' . BUILD_ROOT_PATH . ' ' . + '--without-sysroot ' . + '--without-system-include-path ' . + '--without-system-library-path ' . + '--without-pc-path' + ) + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install'); + } +} diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 9319b220..e8171efb 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -6,6 +6,7 @@ namespace SPC\store; use SPC\builder\BuilderBase; use SPC\builder\linux\LinuxBuilder; +use SPC\builder\linux\SystemUtil; use SPC\builder\macos\MacOSBuilder; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; @@ -99,6 +100,14 @@ class SourcePatcher '-lz', BUILD_LIB_PATH . '/libz.a' ); + if (SystemUtil::getOSRelease()['dist'] === 'alpine') { + FileSystem::replaceFile( + SOURCE_PATH . '/libpng/configure', + REPLACE_FILE_STR, + '-lm', + '/usr/lib/libm.a' + ); + } } public static function patchCurlMacOS(): void diff --git a/src/globals/functions.php b/src/globals/functions.php index 9ce84214..5f6cc29f 100644 --- a/src/globals/functions.php +++ b/src/globals/functions.php @@ -66,6 +66,8 @@ function osfamily2dir(): string } /** + * 执行shell,直接输出在终端,出现错误抛出异常 + * * @throws \SPC\exception\RuntimeException */ function f_passthru(string $cmd): ?bool @@ -89,7 +91,13 @@ function f_passthru(string $cmd): ?bool return $ret; } -function f_exec(string $command, &$output, &$result_code) +/** + * 执行命令,不输出内容,返回执行结果和内容 + * + * @param mixed $output + * @param mixed $result_code + */ +function f_exec(string $command, &$output, &$result_code): bool|string { logger()->debug('Running command (no output) : ' . $command); return exec($command, $output, $result_code); From a329445701eb4e00547511c27e38e1c9e4cb179f Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 10 May 2023 02:31:57 +0800 Subject: [PATCH 04/19] add ssh2 support --- config/ext.json | 8 ++++++++ config/source.json | 10 ++++++++++ src/SPC/store/SourcePatcher.php | 13 +++++++++++++ 3 files changed, 31 insertions(+) diff --git a/config/ext.json b/config/ext.json index 6e317239..4c6e6062 100644 --- a/config/ext.json +++ b/config/ext.json @@ -302,6 +302,14 @@ "sqlite" ] }, + "ssh2": { + "type": "external", + "source": "ext-ssh2", + "arg-type": "with-prefix", + "lib-depends": [ + "libssh2" + ] + }, "swoole": { "type": "external", "source": "swoole", diff --git a/config/source.json b/config/source.json index 950058d3..f86b51cd 100644 --- a/config/source.json +++ b/config/source.json @@ -61,6 +61,16 @@ "path": "LICENSE" } }, + "ext-ssh2": { + "type": "url", + "url": "http://pecl.php.net/get/ssh2", + "path": "php-src/ext/ssh2", + "filename": "ssh2.tgz", + "license": { + "type": "file", + "path": "LICENSE" + } + }, "ext-zstd": { "type": "git", "path": "php-src/ext/zstd", diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index e8171efb..aba47b92 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -85,6 +85,9 @@ class SourcePatcher if ($readline = $builder->getExt('readline')) { $patch[] = ['readline patch', '/-lncurses/', $readline->getLibFilesString()]; } + if ($ssh2 = $builder->getExt('ssh2')) { + $patch[] = ['ssh2 patch', '/-lssh2/', $ssh2->getLibFilesString()]; + } $patch[] = ['disable capstone', '/have_capstone="yes"/', 'have_capstone="no"']; foreach ($patch as $item) { logger()->info('Patching configure: ' . $item[0]); @@ -110,6 +113,16 @@ class SourcePatcher } } + public static function patchUnixSsh2(): void + { + FileSystem::replaceFile( + SOURCE_PATH . '/php-src/configure', + REPLACE_FILE_STR, + '-lssh2', + BUILD_LIB_PATH . '/libssh2.a' + ); + } + public static function patchCurlMacOS(): void { FileSystem::replaceFile( From b7f64e46c215fefbe0a40c847e92d791a9b08a71 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 10 May 2023 02:32:27 +0800 Subject: [PATCH 05/19] add ssh2 support --- ext-support.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ext-support.md b/ext-support.md index a744794b..a1c0d6ee 100644 --- a/ext-support.md +++ b/ext-support.md @@ -51,6 +51,7 @@ | soap | yes | yes | | | sockets | yes | yes | | | sqlite3 | yes | yes | | +| ssh2 | | yes, untested | | | swow | yes | yes | | | swoole | [partial](https://github.com/crazywhalecc/static-php-cli/issues/51) | yes | | | tokenizer | yes | yes | | From 09f15742642359920c2ee574d236ae0590f9267e Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 10 May 2023 21:59:33 +0800 Subject: [PATCH 06/19] add macos external extension support --- ext-support.md | 1 + src/SPC/builder/BuilderBase.php | 14 ++++++++------ src/SPC/builder/extension/ffi.php | 3 +-- src/SPC/builder/macos/MacOSBuilder.php | 20 +++++++++++--------- src/SPC/builder/macos/library/libffi.php | 4 ++-- src/SPC/command/BuildCliCommand.php | 3 +++ 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/ext-support.md b/ext-support.md index a1c0d6ee..ee16ed96 100644 --- a/ext-support.md +++ b/ext-support.md @@ -19,6 +19,7 @@ | enchant | | | | | event | yes | yes | | | exif | yes | yes | | +| ffi | | yes, [docs]() | | | filter | yes | yes | | | fileinfo | yes | yes | | | ftp | yes | yes | | diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 83097896..900bb4ed 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -38,6 +38,9 @@ abstract class BuilderBase /** @var bool 本次编译是否只编译 libs,不编译 PHP */ protected bool $libs_only = false; + /** @var bool 是否 strip 最终的二进制 */ + protected bool $strip = true; + /** * 构建指定列表的 libs * @@ -70,12 +73,6 @@ abstract class BuilderBase // 排序 libs,根据依赖计算一个新的列表出来 $libraries = DependencyUtil::getLibsByDeps($libraries); - // 这里筛选 libraries,比如纯静态模式排除掉ffi - if (defined('BUILD_ALL_STATIC') && BUILD_ALL_STATIC) { - $k = array_search('libffi', $libraries, true); - $k !== false && array_splice($libraries, $k, 1); - } - // 过滤不支持的库后添加 foreach ($libraries as $library) { if (!isset($support_lib_list[$library])) { @@ -237,6 +234,11 @@ abstract class BuilderBase return implode(', ', $ls); } + public function setStrip(bool $strip): void + { + $this->strip = $strip; + } + /** * 检查是否存在 lib 库对应的源码,如果不存在,则抛出异常 * diff --git a/src/SPC/builder/extension/ffi.php b/src/SPC/builder/extension/ffi.php index 106f2a64..f0cf9fe6 100644 --- a/src/SPC/builder/extension/ffi.php +++ b/src/SPC/builder/extension/ffi.php @@ -12,7 +12,6 @@ class ffi extends Extension { public function getUnixConfigureArg(): string { - return '--with-ffi FFI_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' . - 'FFI_LIBS="' . $this->getLibFilesString() . '"'; + return '--with-ffi --enable-zend-signals'; } } diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 1eb13e05..296b8580 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -207,10 +207,11 @@ class MacOSBuilder extends BuilderBase */ public function buildCli(string $extra_libs): void { - shell()->cd(SOURCE_PATH . '/php-src') - ->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" cli") - ->exec('dsymutil -f sapi/cli/php') - ->exec('strip sapi/cli/php'); + $shell = shell()->cd(SOURCE_PATH . '/php-src'); + $shell->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" cli"); + if ($this->strip) { + $shell->exec('dsymutil -f sapi/cli/php')->exec('strip sapi/cli/php'); + } $this->deployBinary(BUILD_TARGET_CLI); } @@ -230,7 +231,7 @@ class MacOSBuilder extends BuilderBase } shell()->cd(SOURCE_PATH . '/php-src') - ->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" STRIP=\"dsymutil -f \" micro"); + ->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" " . ($this->strip ? 'STRIP="dsymutil -f " ' : '') . 'micro'); $this->deployBinary(BUILD_TARGET_MICRO); } @@ -242,10 +243,11 @@ class MacOSBuilder extends BuilderBase */ public function buildFpm(string $extra_libs): void { - shell()->cd(SOURCE_PATH . '/php-src') - ->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" fpm") - ->exec('dsymutil -f sapi/fpm/php-fpm') - ->exec('strip sapi/fpm/php-fpm'); + $shell = shell()->cd(SOURCE_PATH . '/php-src'); + $shell->exec("make -j{$this->concurrency} EXTRA_CFLAGS=\"-g -Os -fno-ident\" EXTRA_LIBS=\"{$extra_libs} -lresolv\" fpm"); + if ($this->strip) { + $shell->exec('dsymutil -f sapi/fpm/php-fpm')->exec('strip sapi/fpm/php-fpm'); + } $this->deployBinary(BUILD_TARGET_FPM); } } diff --git a/src/SPC/builder/macos/library/libffi.php b/src/SPC/builder/macos/library/libffi.php index 9fbabfb5..2c67cb46 100644 --- a/src/SPC/builder/macos/library/libffi.php +++ b/src/SPC/builder/macos/library/libffi.php @@ -34,11 +34,11 @@ class libffi extends MacOSLibraryBase '--disable-shared ' . "--host={$this->builder->arch}-apple-darwin " . "--target={$this->builder->arch}-apple-darwin " . - '--prefix= ' . // use prefix=/ - "--libdir={$lib}" + '--prefix= ' // use prefix=/ ) ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") ->exec("make install DESTDIR={$destdir}"); + $this->patchPkgconfPrefix(['libffi.pc']); } } diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index 0c0cfa49..2da580e6 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -25,6 +25,7 @@ class BuildCliCommand extends BuildCommand $this->addOption('build-cli', null, null, 'build cli'); $this->addOption('build-fpm', null, null, 'build fpm'); $this->addOption('build-all', null, null, 'build cli, micro, fpm'); + $this->addOption('no-strip', null, null, 'build without strip, in order to debug and load external extensions'); } public function handle(): int @@ -68,6 +69,8 @@ class BuildCliCommand extends BuildCommand $builder->buildLibs($libraries); // 执行扩展检测 $builder->proveExts($extensions); + // strip + $builder->setStrip(false); // 构建 $builder->buildPHP($rule, $this->getOption('bloat')); // 统计时间 From f0e431dd63c64b4f2c0d8c9d346ae3a8a2208652 Mon Sep 17 00:00:00 2001 From: javalaw <739554820@qq.com> Date: Fri, 12 May 2023 09:47:43 +0000 Subject: [PATCH 07/19] sodium ext support. --- config/ext.json | 2 +- config/lib.json | 6 ++++++ config/source.json | 8 ++++++++ src/SPC/builder/linux/library/libsodium.php | 12 ++++++++++++ src/SPC/builder/macos/library/libsodium.php | 12 ++++++++++++ src/SPC/builder/unix/library/libsodium.php | 17 +++++++++++++++++ 6 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/SPC/builder/linux/library/libsodium.php create mode 100644 src/SPC/builder/macos/library/libsodium.php create mode 100644 src/SPC/builder/unix/library/libsodium.php diff --git a/config/ext.json b/config/ext.json index 4c6e6062..3c0b1960 100644 --- a/config/ext.json +++ b/config/ext.json @@ -292,7 +292,7 @@ "type": "builtin", "arg-type": "with", "lib-depends": [ - "sodium" + "libsodium" ] }, "sqlite3": { diff --git a/config/lib.json b/config/lib.json index 466763b8..bfe6ec6c 100644 --- a/config/lib.json +++ b/config/lib.json @@ -454,5 +454,11 @@ "zstd.h", "zstd_errors.h" ] + }, + "libsodium": { + "source": "libsodium", + "static-libs-unix": [ + "libsodium.a" + ] } } \ No newline at end of file diff --git a/config/source.json b/config/source.json index f86b51cd..d74fd496 100644 --- a/config/source.json +++ b/config/source.json @@ -411,5 +411,13 @@ "type": "file", "path": "LICENSE" } + }, + "libsodium": { + "type": "url", + "url": "https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz", + "license": { + "type": "file", + "path": "LICENSE" + } } } \ No newline at end of file diff --git a/src/SPC/builder/linux/library/libsodium.php b/src/SPC/builder/linux/library/libsodium.php new file mode 100644 index 00000000..76012bec --- /dev/null +++ b/src/SPC/builder/linux/library/libsodium.php @@ -0,0 +1,12 @@ +cd($this->source_dir) + ->exec("{$this->builder->configure_env} ./configure --enable-static --disable-shared --prefix=") + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + } +} From afe81c43068d295895d881ce6d8d46aa8783500c Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Wed, 17 May 2023 13:40:37 +0800 Subject: [PATCH 08/19] Update imagemagick.php --- src/SPC/builder/macos/library/imagemagick.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/macos/library/imagemagick.php b/src/SPC/builder/macos/library/imagemagick.php index c6a105c5..b3a71321 100644 --- a/src/SPC/builder/macos/library/imagemagick.php +++ b/src/SPC/builder/macos/library/imagemagick.php @@ -15,7 +15,7 @@ class imagemagick extends MacOSLibraryBase protected function build(): void { - $extra = '--without-jxl --without-xml --without-zstd '; + $extra = '--without-jxl --without-xml --without-zstd --without-x '; // jpeg support $extra .= $this->builder->getLib('libjpeg') ? '--with-jpeg ' : ''; // png support From 2e50ee37a9232bf9de2aef914da70c4f6fc6d3af Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Wed, 17 May 2023 15:24:08 +0800 Subject: [PATCH 09/19] Update UnixBuilderTrait.php --- src/SPC/builder/traits/UnixBuilderTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/traits/UnixBuilderTrait.php b/src/SPC/builder/traits/UnixBuilderTrait.php index da37cc15..49b952d0 100644 --- a/src/SPC/builder/traits/UnixBuilderTrait.php +++ b/src/SPC/builder/traits/UnixBuilderTrait.php @@ -72,7 +72,7 @@ trait UnixBuilderTrait } foreach ($this->exts as $ext) { logger()->debug('testing ext: ' . $ext->getName()); - [$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php --ri ' . $ext->getDistName(), false); + [$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php --ri "' . $ext->getDistName() . '"', false); if ($ret !== 0) { throw new RuntimeException('extension ' . $ext->getName() . ' failed compile check'); } From 89ad11ebb6847ae8054be542bf2845aebd71434e Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Wed, 17 May 2023 15:24:45 +0800 Subject: [PATCH 10/19] Create opcache.php --- src/SPC/builder/extension/opcache.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/SPC/builder/extension/opcache.php diff --git a/src/SPC/builder/extension/opcache.php b/src/SPC/builder/extension/opcache.php new file mode 100644 index 00000000..f592303a --- /dev/null +++ b/src/SPC/builder/extension/opcache.php @@ -0,0 +1,17 @@ + Date: Wed, 17 May 2023 07:36:23 +0000 Subject: [PATCH 11/19] fix libsodium. --- src/SPC/builder/unix/library/libsodium.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/unix/library/libsodium.php b/src/SPC/builder/unix/library/libsodium.php index bb49e710..2f093d03 100644 --- a/src/SPC/builder/unix/library/libsodium.php +++ b/src/SPC/builder/unix/library/libsodium.php @@ -8,10 +8,11 @@ trait libsodium { protected function build() { + $root = BUILD_ROOT_PATH; shell()->cd($this->source_dir) - ->exec("{$this->builder->configure_env} ./configure --enable-static --disable-shared --prefix=") + ->exec("{$this->builder->configure_env} ./configure --enable-static --disable-shared --prefix={$root}") ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") - ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + ->exec('make install'); } } From f002c8021c7f6147967ce827bad4431fdc7b984e Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 17 May 2023 22:00:41 +0800 Subject: [PATCH 12/19] fix curl 8.1.0 compile problem --- src/SPC/builder/traits/UnixSystemUtilTrait.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/SPC/builder/traits/UnixSystemUtilTrait.php b/src/SPC/builder/traits/UnixSystemUtilTrait.php index 46a30ca8..6e25ab7a 100644 --- a/src/SPC/builder/traits/UnixSystemUtilTrait.php +++ b/src/SPC/builder/traits/UnixSystemUtilTrait.php @@ -38,8 +38,6 @@ trait UnixSystemUtilTrait $cxxLine = 'SET(CMAKE_CXX_COMPILER ' . self::findCommand($cxx) . ')'; } $toolchain = << Date: Wed, 17 May 2023 22:00:59 +0800 Subject: [PATCH 13/19] add sodium support in readme --- ext-support.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ext-support.md b/ext-support.md index ee16ed96..9e375968 100644 --- a/ext-support.md +++ b/ext-support.md @@ -51,6 +51,7 @@ | simplexml | yes | yes | | | soap | yes | yes | | | sockets | yes | yes | | +| sodium | yes | yes | | | sqlite3 | yes | yes | | | ssh2 | | yes, untested | | | swow | yes | yes | | From 125556b73b4e2207cf5bfa48355efcf88200d797 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 17 May 2023 22:08:13 +0800 Subject: [PATCH 14/19] add imagick for linux --- ext-support.md | 2 +- src/SPC/builder/linux/library/imagemagick.php | 15 +++++ src/SPC/builder/macos/library/imagemagick.php | 49 +--------------- src/SPC/builder/unix/library/imagemagick.php | 57 +++++++++++++++++++ 4 files changed, 75 insertions(+), 48 deletions(-) create mode 100644 src/SPC/builder/linux/library/imagemagick.php create mode 100644 src/SPC/builder/unix/library/imagemagick.php diff --git a/ext-support.md b/ext-support.md index 9e375968..aa04efc0 100644 --- a/ext-support.md +++ b/ext-support.md @@ -27,7 +27,7 @@ | gettext | | | | | gmp | yes | yes | | | iconv | yes | yes | | -| imagick | | yes | | +| imagick | yes | yes | | | inotify | yes | yes | | | mbstring | yes | yes | | | mbregex | yes | yes | | diff --git a/src/SPC/builder/linux/library/imagemagick.php b/src/SPC/builder/linux/library/imagemagick.php new file mode 100644 index 00000000..6006a222 --- /dev/null +++ b/src/SPC/builder/linux/library/imagemagick.php @@ -0,0 +1,15 @@ +builder->getLib('libjpeg') ? '--with-jpeg ' : ''; - // png support - $extra .= $this->builder->getLib('libpng') ? '--with-png ' : ''; - // webp support - $extra .= $this->builder->getLib('libwebp') ? '--with-webp ' : ''; - // zstd support - // $extra .= $this->builder->getLib('zstd') ? '--with-zstd ' : '--without-zstd '; - // freetype support - $extra .= $this->builder->getLib('freetype') ? '--with-freetype ' : '--without-freetype '; - - shell()->cd($this->source_dir) - ->exec( - "{$this->builder->configure_env} ./configure " . - '--enable-static --disable-shared ' . - $extra . - '--prefix=' - ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); - $filelist = [ - 'ImageMagick.pc', - 'ImageMagick-7.Q16HDRI.pc', - 'Magick++.pc', - 'Magick++-7.Q16HDRI.pc', - 'MagickCore.pc', - 'MagickCore-7.Q16HDRI.pc', - 'MagickWand.pc', - 'MagickWand-7.Q16HDRI.pc', - ]; - $this->patchPkgconfPrefix($filelist); - foreach ($filelist as $file) { - FileSystem::replaceFile( - BUILD_LIB_PATH . '/pkgconfig/' . $file, - REPLACE_FILE_PREG, - '#includearchdir=/include/ImageMagick-7#m', - 'includearchdir=${prefix}/include/ImageMagick-7' - ); - } - } } diff --git a/src/SPC/builder/unix/library/imagemagick.php b/src/SPC/builder/unix/library/imagemagick.php new file mode 100644 index 00000000..6f1fd461 --- /dev/null +++ b/src/SPC/builder/unix/library/imagemagick.php @@ -0,0 +1,57 @@ +builder->getLib('libzip') ? '--with-zip ' : '--without-zip '; + // jpeg support + $extra .= $this->builder->getLib('libjpeg') ? '--with-jpeg ' : ''; + // png support + $extra .= $this->builder->getLib('libpng') ? '--with-png ' : ''; + // webp support + $extra .= $this->builder->getLib('libwebp') ? '--with-webp ' : ''; + // zstd support + // $extra .= $this->builder->getLib('zstd') ? '--with-zstd ' : '--without-zstd '; + // freetype support + $extra .= $this->builder->getLib('freetype') ? '--with-freetype ' : '--without-freetype '; + + shell()->cd($this->source_dir) + ->exec( + "{$this->builder->configure_env} ./configure " . + '--enable-static --disable-shared ' . + $extra . + '--prefix=' + ) + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + $filelist = [ + 'ImageMagick.pc', + 'ImageMagick-7.Q16HDRI.pc', + 'Magick++.pc', + 'Magick++-7.Q16HDRI.pc', + 'MagickCore.pc', + 'MagickCore-7.Q16HDRI.pc', + 'MagickWand.pc', + 'MagickWand-7.Q16HDRI.pc', + ]; + $this->patchPkgconfPrefix($filelist); + foreach ($filelist as $file) { + FileSystem::replaceFile( + BUILD_LIB_PATH . '/pkgconfig/' . $file, + REPLACE_FILE_PREG, + '#includearchdir=/include/ImageMagick-7#m', + 'includearchdir=${prefix}/include/ImageMagick-7' + ); + } + } +} From 6d638f3721410d83472d1d12739f7782b07b557f Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 17 May 2023 22:10:28 +0800 Subject: [PATCH 15/19] add ssh2 support for linux --- ext-support.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext-support.md b/ext-support.md index aa04efc0..9af15a0d 100644 --- a/ext-support.md +++ b/ext-support.md @@ -53,7 +53,7 @@ | sockets | yes | yes | | | sodium | yes | yes | | | sqlite3 | yes | yes | | -| ssh2 | | yes, untested | | +| ssh2 | yes, untested | yes, untested | | | swow | yes | yes | | | swoole | [partial](https://github.com/crazywhalecc/static-php-cli/issues/51) | yes | | | tokenizer | yes | yes | | From 1b6d0e35ea6c3f7288e4e28acb5a636870a40554 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 17 May 2023 22:19:28 +0800 Subject: [PATCH 16/19] add zts support --- src/SPC/builder/BuilderProvider.php | 2 ++ src/SPC/builder/linux/LinuxBuilder.php | 3 ++- src/SPC/builder/macos/MacOSBuilder.php | 3 ++- src/SPC/command/BuildCliCommand.php | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/SPC/builder/BuilderProvider.php b/src/SPC/builder/BuilderProvider.php index 4a19aef2..879153f8 100644 --- a/src/SPC/builder/BuilderProvider.php +++ b/src/SPC/builder/BuilderProvider.php @@ -31,11 +31,13 @@ class BuilderProvider cc: $input->getOption('cc'), cxx: $input->getOption('cxx'), arch: $input->getOption('arch'), + zts: $input->getOption('enable-zts'), ), 'Linux' => new LinuxBuilder( cc: $input->getOption('cc'), cxx: $input->getOption('cxx'), arch: $input->getOption('arch'), + zts: $input->getOption('enable-zts'), ), default => throw new WrongUsageException('Current OS "' . PHP_OS_FAMILY . '" is not supported yet'), }; diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 208d32ce..b8d8757d 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -43,7 +43,7 @@ class LinuxBuilder extends BuilderBase * @throws RuntimeException * @throws WrongUsageException */ - public function __construct(?string $cc = null, ?string $cxx = null, ?string $arch = null) + public function __construct(?string $cc = null, ?string $cxx = null, ?string $arch = null, bool $zts = false) { // 初始化一些默认参数 $this->cc = $cc ?? match (SystemUtil::getOSRelease()['dist']) { @@ -53,6 +53,7 @@ class LinuxBuilder extends BuilderBase $this->cxx = $cxx ?? 'g++'; $this->arch = $arch ?? php_uname('m'); $this->gnu_arch = arch2gnu($this->arch); + $this->zts = $zts; $this->libc = 'musl'; // SystemUtil::selectLibc($this->cc); // 根据 CPU 线程数设置编译进程数 diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 296b8580..cb7f9f56 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -31,7 +31,7 @@ class MacOSBuilder extends BuilderBase * @throws RuntimeException * @throws WrongUsageException */ - public function __construct(?string $cc = null, ?string $cxx = null, ?string $arch = null) + public function __construct(?string $cc = null, ?string $cxx = null, ?string $arch = null, bool $zts = false) { // 如果是 Debug 模式,才使用 set -x 显示每条执行的命令 $this->set_x = defined('DEBUG_MODE') ? 'set -x' : 'true'; @@ -40,6 +40,7 @@ class MacOSBuilder extends BuilderBase $this->cxx = $cxx ?? 'clang++'; $this->arch = $arch ?? php_uname('m'); $this->gnu_arch = arch2gnu($this->arch); + $this->zts = $zts; // 根据 CPU 线程数设置编译进程数 $this->concurrency = SystemUtil::getCpuCount(); // 设置 cflags diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index 2da580e6..6aad5509 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -26,6 +26,7 @@ class BuildCliCommand extends BuildCommand $this->addOption('build-fpm', null, null, 'build fpm'); $this->addOption('build-all', null, null, 'build cli, micro, fpm'); $this->addOption('no-strip', null, null, 'build without strip, in order to debug and load external extensions'); + $this->addOption('enable-zts', null, null, 'enable ZTS support'); } public function handle(): int From 4a9b171bb4ffec5a558b69d1f84218b39f50129e Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 17 May 2023 22:41:04 +0800 Subject: [PATCH 17/19] update to rc1 version --- README-en.md | 2 +- README.md | 2 +- src/SPC/ConsoleApplication.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README-en.md b/README-en.md index 253b7480..25806844 100755 --- a/README-en.md +++ b/README-en.md @@ -18,7 +18,7 @@ This feature is provided by [dixyes/phpmicro](https://github.com/dixyes/phpmicro [![](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/build-linux-x86_64.yml?branch=refactor&label=Linux%20Build&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml) [![](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/build-macos-x86_64.yml?branch=refactor&label=macOS%20Build&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml) -[![](https://img.shields.io/badge/Extension%20Counter-45+-yellow.svg?style=flat-square)]() +[![](https://img.shields.io/badge/Extension%20Counter-50+-yellow.svg?style=flat-square)]() [![](https://img.shields.io/github/search/crazywhalecc/static-php-cli/TODO?label=TODO%20Counter&style=flat-square)]() ## Compilation Requirements diff --git a/README.md b/README.md index 4da33583..581d9bde 100755 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ If you are using English, see [English README](README-en.md). [![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)]() [![](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/build-linux-x86_64.yml?branch=refactor&label=Linux%20Build&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml) [![](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/build-macos-x86_64.yml?branch=refactor&label=macOS%20Build&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml) -[![](https://img.shields.io/badge/Extension%20Counter-45+-yellow.svg?style=flat-square)]() +[![](https://img.shields.io/badge/Extension%20Counter-50+-yellow.svg?style=flat-square)]() [![](https://img.shields.io/github/search/crazywhalecc/static-php-cli/TODO?label=TODO%20Counter&style=flat-square)]() ## 编译环境需求 diff --git a/src/SPC/ConsoleApplication.php b/src/SPC/ConsoleApplication.php index 33862e3c..9253aa15 100644 --- a/src/SPC/ConsoleApplication.php +++ b/src/SPC/ConsoleApplication.php @@ -16,7 +16,7 @@ use Symfony\Component\Console\Command\ListCommand; */ class ConsoleApplication extends Application { - public const VERSION = '2.0-beta3'; + public const VERSION = '2.0-rc1'; /** * @throws \ReflectionException From c9b47c392e96bcb4baf3b475f20d9c71aa41ada6 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 17 May 2023 22:42:37 +0800 Subject: [PATCH 18/19] update to rc1 version --- README-en.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README-en.md b/README-en.md index 25806844..57f9fcdd 100755 --- a/README-en.md +++ b/README-en.md @@ -13,7 +13,7 @@ This feature is provided by [dixyes/phpmicro](https://github.com/dixyes/phpmicro > This branch is new version, if you are looking for old bash version of static-php-cli, see [bash-version](https://github.com/crazywhalecc/static-php-cli/tree/bash-version). -[![Version](https://img.shields.io/badge/Version-2.0--beta3-orange.svg?style=flat-square)]() +[![Version](https://img.shields.io/badge/Version-2.0--rc1-pink.svg?style=flat-square)]() [![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)]() [![](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/build-linux-x86_64.yml?branch=refactor&label=Linux%20Build&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml) [![](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/build-macos-x86_64.yml?branch=refactor&label=macOS%20Build&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml) diff --git a/README.md b/README.md index 581d9bde..9146684c 100755 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ If you are using English, see [English README](README-en.md). > 此分支为重构的新版,如果你在找纯 Bash 编写的旧版本,请到 [bash-version 分支](https://github.com/crazywhalecc/static-php-cli/tree/bash-version)。 -[![Version](https://img.shields.io/badge/Version-2.0--beta3-orange.svg?style=flat-square)]() +[![Version](https://img.shields.io/badge/Version-2.0--rc1-pink.svg?style=flat-square)]() [![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)]() [![](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/build-linux-x86_64.yml?branch=refactor&label=Linux%20Build&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml) [![](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/build-macos-x86_64.yml?branch=refactor&label=macOS%20Build&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml) From 09ba11affb93128d47d21016f86c5006839c7899 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 17 May 2023 23:07:39 +0800 Subject: [PATCH 19/19] update README and version --- README-en.md | 10 ++++++++-- README.md | 10 ++++++++-- bin/setup-runtime | 4 ++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README-en.md b/README-en.md index 57f9fcdd..4bd3120a 100755 --- a/README-en.md +++ b/README-en.md @@ -11,8 +11,6 @@ This feature is provided by [dixyes/phpmicro](https://github.com/dixyes/phpmicro 截屏2023-05-02 15 52 33 -> This branch is new version, if you are looking for old bash version of static-php-cli, see [bash-version](https://github.com/crazywhalecc/static-php-cli/tree/bash-version). - [![Version](https://img.shields.io/badge/Version-2.0--rc1-pink.svg?style=flat-square)]() [![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)]() [![](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/build-linux-x86_64.yml?branch=refactor&label=Linux%20Build&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml) @@ -129,6 +127,14 @@ If anything goes wrong, use `--debug` option to display full terminal output: ./bin/spc fetch --all --debug ``` +In addition, we build NTS by default. If you are going to build ZTS version, just add `--enable-zts` option. + +```bash +./bin/spc build openssl,pcntl --build-all --enable-zts +``` + +Adding option `--no-strip` can produce binaries with debug symbols, in order to debug (using gdb). Disabling strip will increase the size of static binary. + ### php-cli Usage > php-cli is a single static binary, you can use it like normal php installed on your system. diff --git a/README.md b/README.md index 9146684c..84e93f0f 100755 --- a/README.md +++ b/README.md @@ -12,8 +12,6 @@ If you are using English, see [English README](README-en.md). 截屏2023-05-02 15 52 33 -> 此分支为重构的新版,如果你在找纯 Bash 编写的旧版本,请到 [bash-version 分支](https://github.com/crazywhalecc/static-php-cli/tree/bash-version)。 - [![Version](https://img.shields.io/badge/Version-2.0--rc1-pink.svg?style=flat-square)]() [![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)]() [![](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/build-linux-x86_64.yml?branch=refactor&label=Linux%20Build&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build.yml) @@ -125,6 +123,14 @@ chmod +x bin/spc ./bin/spc fetch --all --debug ``` +此外,默认编译的 PHP 为 NTS 版本。如需编译线程安全版本(ZTS),只需添加参数 `--enable-zts` 即可。 + +```bash +./bin/spc build openssl,pcntl --build-all --enable-zts +``` + +同时,你也可以使用参数 `--no-strip` 来关闭裁剪,关闭裁剪后可以使用 gdb 等工具调试,但这样会让静态二进制体积变大。 + ### 使用 php-cli > php-cli 是一个静态的二进制文件,类似 Go、Rust 语言编译后的单个可移植的二进制文件。 diff --git a/bin/setup-runtime b/bin/setup-runtime index d77d8181..48144f97 100755 --- a/bin/setup-runtime +++ b/bin/setup-runtime @@ -25,7 +25,7 @@ __DIR__=$(cd "$(dirname "$0")" && pwd) __PROJECT__=$(cd ${__DIR__}/../ && pwd) # set download dir -__PHP_RUNTIME_URL__="https://dl.zhamao.xin/static-php-cli/php-8.2.5-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz" +__PHP_RUNTIME_URL__="https://dl.zhamao.xin/static-php-cli/php-8.2.6-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz" __COMPOSER_URL__="https://getcomposer.org/download/latest-stable/composer.phar" # use china mirror @@ -46,7 +46,7 @@ done case "$mirror" in china) - __PHP_RUNTIME_URL__="https://dl.zhamao.xin/static-php-cli/php-8.2.5-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz" + __PHP_RUNTIME_URL__="https://dl.zhamao.xin/static-php-cli/php-8.2.6-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz" __COMPOSER_URL__="https://mirrors.aliyun.com/composer/composer.phar" ;;