From fc053253e7fa3b0af72e59190b2d465717eb79a6 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 20:45:18 +0800 Subject: [PATCH 01/43] Add pre-built lib feature --- .github/workflows/build-linux-arm.yml | 9 ++- .github/workflows/build-linux-x86_64.yml | 9 ++- .github/workflows/build-macos-aarch64.yml | 9 ++- .github/workflows/build-macos-x86_64.yml | 9 ++- .github/workflows/build-windows-x86_64.yml | 9 ++- .github/workflows/tests.yml | 6 ++ .gitignore | 4 + config/pre-built.json | 5 +- config/source.json | 2 + src/SPC/ConsoleApplication.php | 2 + src/SPC/builder/BuilderBase.php | 13 ++-- src/SPC/builder/LibraryBase.php | 86 +++++++++++++++++++-- src/SPC/builder/linux/library/openssl.php | 6 +- src/SPC/builder/macos/library/openssl.php | 6 +- src/SPC/builder/traits/UnixLibraryTrait.php | 2 +- src/SPC/builder/unix/UnixBuilderBase.php | 9 --- src/SPC/command/BuildCliCommand.php | 2 +- src/SPC/command/BuildLibsCommand.php | 2 +- src/SPC/command/DownloadCommand.php | 62 +++++++++++++-- src/SPC/command/dev/PackLibCommand.php | 85 ++++++++++++++++++++ src/SPC/store/Config.php | 10 +++ src/SPC/store/Downloader.php | 67 +++++++++------- src/SPC/store/FileSystem.php | 2 +- src/SPC/store/source/CustomSourceBase.php | 2 +- src/SPC/store/source/PhpSource.php | 4 +- src/SPC/store/source/PostgreSQLSource.php | 2 +- src/globals/defines.php | 11 ++- 27 files changed, 355 insertions(+), 80 deletions(-) create mode 100644 src/SPC/command/dev/PackLibCommand.php diff --git a/.github/workflows/build-linux-arm.yml b/.github/workflows/build-linux-arm.yml index 20f17fb90..cd5acd539 100644 --- a/.github/workflows/build-linux-arm.yml +++ b/.github/workflows/build-linux-arm.yml @@ -34,7 +34,12 @@ on: description: extensions to compile (comma separated) required: true type: string + prefer-pre-built: + description: prefer pre-built binaries (reduce build time) + type: boolean + default: true debug: + description: enable debug logs type: boolean env: @@ -73,6 +78,8 @@ jobs: # With or without debug - if: inputs.debug == true run: echo "SPC_BUILD_DEBUG=--debug" >> $GITHUB_ENV + - if: inputs.prefer-pre-built == true + run: echo "SPC_PRE_BUILT=--prefer-pre-built" >> $env:GITHUB_ENV # With target select: cli, micro or both - if: ${{ inputs.build-cli == true }} @@ -84,7 +91,7 @@ jobs: # If there's no dependencies cache, fetch sources, with or without debug - if: steps.cache-download.outputs.cache-hit != 'true' - run: SPC_USE_ARCH=${{ inputs.operating-system }} ./bin/spc-alpine-docker download --with-php=${{ inputs.version }} --for-extensions=${{ inputs.extensions }} ${{ env.SPC_BUILD_DEBUG }} + run: SPC_USE_ARCH=${{ inputs.operating-system }} ./bin/spc-alpine-docker download --with-php=${{ inputs.version }} --for-extensions=${{ inputs.extensions }} ${{ env.SPC_BUILD_DEBUG }} ${{ env.SPC_PRE_BUILT }} # Run build command - run: SPC_USE_ARCH=${{ inputs.operating-system }} ./bin/spc-alpine-docker build ${{ inputs.extensions }} ${{ env.SPC_BUILD_DEBUG }} ${{ env.SPC_BUILD_CLI }} ${{ env.SPC_BUILD_MICRO }} ${{ env.SPC_BUILD_FPM }} diff --git a/.github/workflows/build-linux-x86_64.yml b/.github/workflows/build-linux-x86_64.yml index 262eb9305..a637dd7c2 100644 --- a/.github/workflows/build-linux-x86_64.yml +++ b/.github/workflows/build-linux-x86_64.yml @@ -28,7 +28,12 @@ on: description: extensions to compile (comma separated) required: true type: string + prefer-pre-built: + description: prefer pre-built binaries (reduce build time) + type: boolean + default: true debug: + description: enable debug logs type: boolean env: @@ -67,6 +72,8 @@ jobs: # With or without debug - if: inputs.debug == true run: echo "SPC_BUILD_DEBUG=--debug" >> $GITHUB_ENV + - if: inputs.prefer-pre-built == true + run: echo "SPC_PRE_BUILT=--prefer-pre-built" >> $env:GITHUB_ENV # With target select: cli, micro or both - if: ${{ inputs.build-cli == true }} @@ -78,7 +85,7 @@ jobs: # If there's no dependencies cache, fetch sources, with or without debug - if: steps.cache-download.outputs.cache-hit != 'true' - run: CACHE_API_EXEC=yes ./bin/spc-alpine-docker download --with-php=${{ inputs.version }} --for-extensions=${{ inputs.extensions }} ${{ env.SPC_BUILD_DEBUG }} + run: CACHE_API_EXEC=yes ./bin/spc-alpine-docker download --with-php=${{ inputs.version }} --for-extensions=${{ inputs.extensions }} ${{ env.SPC_BUILD_DEBUG }} ${{ env.SPC_PRE_BUILT }} # Run build command - run: ./bin/spc-alpine-docker build ${{ inputs.extensions }} ${{ env.SPC_BUILD_DEBUG }} ${{ env.SPC_BUILD_CLI }} ${{ env.SPC_BUILD_MICRO }} ${{ env.SPC_BUILD_FPM }} diff --git a/.github/workflows/build-macos-aarch64.yml b/.github/workflows/build-macos-aarch64.yml index 591b2ad4f..0ffe4bd29 100644 --- a/.github/workflows/build-macos-aarch64.yml +++ b/.github/workflows/build-macos-aarch64.yml @@ -28,7 +28,12 @@ on: description: extensions to compile (comma separated) required: true type: string + prefer-pre-built: + description: prefer pre-built binaries (reduce build time) + type: boolean + default: true debug: + description: enable debug logs type: boolean env: @@ -82,6 +87,8 @@ jobs: # With or without debug - if: inputs.debug == true run: echo "SPC_BUILD_DEBUG=--debug" >> $GITHUB_ENV + - if: inputs.prefer-pre-built == true + run: echo "SPC_PRE_BUILT=--prefer-pre-built" >> $env:GITHUB_ENV # With target select: cli, micro or both - if: ${{ inputs.build-cli == true }} @@ -93,7 +100,7 @@ jobs: # If there's no dependencies cache, fetch sources, with or without debug - if: steps.cache-download.outputs.cache-hit != 'true' - run: ./bin/spc download --with-php=${{ inputs.version }} --for-extensions=${{ inputs.extensions }} ${{ env.SPC_BUILD_DEBUG }} + run: ./bin/spc download --with-php=${{ inputs.version }} --for-extensions=${{ inputs.extensions }} ${{ env.SPC_BUILD_DEBUG }} ${{ env.SPC_PRE_BUILT }} # Run build command - run: ./bin/spc build ${{ inputs.extensions }} ${{ env.SPC_BUILD_DEBUG }} ${{ env.SPC_BUILD_CLI }} ${{ env.SPC_BUILD_MICRO }} ${{ env.SPC_BUILD_FPM }} diff --git a/.github/workflows/build-macos-x86_64.yml b/.github/workflows/build-macos-x86_64.yml index 5f7539888..d02bd09f0 100644 --- a/.github/workflows/build-macos-x86_64.yml +++ b/.github/workflows/build-macos-x86_64.yml @@ -28,7 +28,12 @@ on: description: extensions to compile (comma separated) required: true type: string + prefer-pre-built: + description: prefer pre-built binaries (reduce build time) + type: boolean + default: true debug: + description: enable debug logs type: boolean env: @@ -80,6 +85,8 @@ jobs: # With or without debug - if: inputs.debug == true run: echo "SPC_BUILD_DEBUG=--debug" >> $GITHUB_ENV + - if: inputs.prefer-pre-built == true + run: echo "SPC_PRE_BUILT=--prefer-pre-built" >> $env:GITHUB_ENV # With target select: cli, micro or both - if: ${{ inputs.build-cli == true }} @@ -91,7 +98,7 @@ jobs: # If there's no dependencies cache, fetch sources, with or without debug - if: steps.cache-download.outputs.cache-hit != 'true' - run: ./bin/spc download --with-php=${{ inputs.version }} --for-extensions=${{ inputs.extensions }} ${{ env.SPC_BUILD_DEBUG }} + run: ./bin/spc download --with-php=${{ inputs.version }} --for-extensions=${{ inputs.extensions }} ${{ env.SPC_BUILD_DEBUG }} ${{ env.SPC_PRE_BUILT }} # Run build command - run: ./bin/spc build ${{ inputs.extensions }} ${{ env.SPC_BUILD_DEBUG }} ${{ env.SPC_BUILD_CLI }} ${{ env.SPC_BUILD_MICRO }} ${{ env.SPC_BUILD_FPM }} diff --git a/.github/workflows/build-windows-x86_64.yml b/.github/workflows/build-windows-x86_64.yml index e6665d669..17664851b 100644 --- a/.github/workflows/build-windows-x86_64.yml +++ b/.github/workflows/build-windows-x86_64.yml @@ -25,7 +25,12 @@ on: description: extensions to compile (comma separated) required: true type: string + prefer-pre-built: + description: prefer pre-built binaries (reduce build time) + type: boolean + default: true debug: + description: enable debug logs type: boolean env: @@ -65,6 +70,8 @@ jobs: # With or without debug - if: inputs.debug == true run: echo "SPC_BUILD_DEBUG=--debug" >> $env:GITHUB_ENV + - if: inputs.prefer-pre-built == true + run: echo "SPC_PRE_BUILT=--prefer-pre-built" >> $env:GITHUB_ENV # With target select: cli, micro or both - if: ${{ inputs.build-cli == true }} @@ -76,7 +83,7 @@ jobs: # If there's no dependencies cache, fetch sources, with or without debug - if: steps.cache-download.outputs.cache-hit != 'true' - run: ./bin/spc download --with-php="${{ inputs.version }}" --for-extensions="${{ inputs.extensions }}" ${{ env.SPC_BUILD_DEBUG }} + run: ./bin/spc download --with-php="${{ inputs.version }}" --for-extensions="${{ inputs.extensions }}" ${{ env.SPC_BUILD_DEBUG }} ${{ env.SPC_PRE_BUILT }} # Run build command - run: ./bin/spc build "${{ inputs.extensions }}" ${{ env.SPC_BUILD_DEBUG }} ${{ env.SPC_BUILD_CLI }} ${{ env.SPC_BUILD_MICRO }} ${{ env.SPC_BUILD_FPM }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 14b242600..ed2c0134b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -178,6 +178,12 @@ jobs: run: | bin/spc download --for-extensions="$(php src/globals/test-extensions.php extensions)" --for-libs="$(php src/globals/test-extensions.php libs)" --with-php=${{ matrix.php }} --ignore-cache-sources=php-src --debug --retry=5 --shallow-clone + - name: "Download pre-built libraries for pkg-config" + if: matrix.os != 'windows-latest' + run: | + bin/spc del-download pkg-config + bin/spc download pkg-config --prefer-pre-built --debug + - name: "Run Build Tests (build, *nix)" if: matrix.os != 'windows-latest' run: bin/spc build "$(php src/globals/test-extensions.php extensions)" $(php src/globals/test-extensions.php zts) $(php src/globals/test-extensions.php no_strip) $UPX_CMD --with-libs="$(php src/globals/test-extensions.php libs)" --build-cli --build-micro --build-fpm --debug diff --git a/.gitignore b/.gitignore index 2d19e5701..88d8e95f9 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,10 @@ docker/source/ # default package root directory /pkgroot/ +# default pack:lib and release directory +/dist/ +packlib_files.txt + # tools cache files .php-cs-fixer.cache .phpunit.result.cache diff --git a/config/pre-built.json b/config/pre-built.json index 8b5811e2a..396c88207 100644 --- a/config/pre-built.json +++ b/config/pre-built.json @@ -1,5 +1,6 @@ { "repo": "static-php/static-php-cli-hosted", - "match-pattern": "{name}-{arch}-{os}.tgz", - "pack-config": {} + "prefer-stable": true, + "match-pattern": "{name}-{arch}-{os}.txz", + "suffix": "txz" } \ No newline at end of file diff --git a/config/source.json b/config/source.json index 1593fc839..af82b9efd 100644 --- a/config/source.json +++ b/config/source.json @@ -560,6 +560,7 @@ "pkg-config": { "type": "url", "url": "https://dl.static-php.dev/static-php-cli/deps/pkg-config/pkg-config-0.29.2.tar.gz", + "provide-pre-built": true, "license": { "type": "file", "path": "COPYING" @@ -761,6 +762,7 @@ "repo": "madler/zlib", "match": "zlib.+\\.tar\\.gz", "prefer-stable": true, + "provide-pre-built": true, "license": { "type": "text", "text": "(C) 1995-2022 Jean-loup Gailly and Mark Adler\n\nThis software is provided 'as-is', without any express or implied\nwarranty. In no event will the authors be held liable for any damages\narising from the use of this software.\n\nPermission is granted to anyone to use this software for any purpose,\nincluding commercial applications, and to alter it and redistribute it\nfreely, subject to the following restrictions:\n\n1. The origin of this software must not be misrepresented; you must not\n claim that you wrote the original software. If you use this software\n in a product, an acknowledgment in the product documentation would be\n appreciated but is not required.\n2. Altered source versions must be plainly marked as such, and must not be\n misrepresented as being the original software.\n3. This notice may not be removed or altered from any source distribution.\n\nJean-loup Gailly Mark Adler\njloup@gzip.org madler@alumni.caltech.edu" diff --git a/src/SPC/ConsoleApplication.php b/src/SPC/ConsoleApplication.php index f0a357fc5..8601c8f58 100644 --- a/src/SPC/ConsoleApplication.php +++ b/src/SPC/ConsoleApplication.php @@ -11,6 +11,7 @@ use SPC\command\dev\ExtVerCommand; use SPC\command\dev\GenerateExtDocCommand; use SPC\command\dev\LibVerCommand; +use SPC\command\dev\PackLibCommand; use SPC\command\dev\PhpVerCommand; use SPC\command\dev\SortConfigCommand; use SPC\command\DoctorCommand; @@ -54,6 +55,7 @@ public function __construct() new ExtVerCommand(), new SortConfigCommand(), new GenerateExtDocCommand(), + new PackLibCommand(), ] ); } diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index de5291658..26d1b8742 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -45,20 +45,21 @@ abstract class BuilderBase abstract public function proveLibs(array $sorted_libraries); /** - * Build libraries + * Set-Up libraries * * @throws FileSystemException * @throws RuntimeException * @throws WrongUsageException */ - public function buildLibs(): void + public function setupLibs(): void { // build all libs foreach ($this->libs as $lib) { - match ($lib->tryBuild($this->getOption('rebuild', false))) { - 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'), + match ($lib->setup($this->getOption('rebuild', false))) { + LIB_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] setup success'), + LIB_STATUS_ALREADY => logger()->notice('lib [' . $lib::NAME . '] already built'), + LIB_STATUS_BUILD_FAILED => logger()->error('lib [' . $lib::NAME . '] build failed'), + LIB_STATUS_INSTALL_FAILED => logger()->error('lib [' . $lib::NAME . '] install failed'), default => logger()->warning('lib [' . $lib::NAME . '] build status unknown'), }; } diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index 4ad44c64c..cffee91fa 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -8,6 +8,7 @@ use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\Config; +use SPC\store\FileSystem; use SPC\store\SourceManager; abstract class LibraryBase @@ -32,6 +33,32 @@ public function __construct(?string $source_dir = null) $this->source_dir = $source_dir ?? (SOURCE_PATH . '/' . static::NAME); } + /** + * Try to install or build this library. + * @param bool $force If true, force install or build + * @throws FileSystemException + * @throws RuntimeException + * @throws WrongUsageException + */ + public function setup(bool $force = false): int + { + $lock = json_decode(FileSystem::readFile(DOWNLOAD_PATH . '/.lock.json'), true) ?? []; + $source = Config::getLib(static::NAME, 'source'); + // if source is locked as pre-built, we just tryInstall it + if (isset($lock[$source]) && $lock[$source]['lock_as'] === SPC_LOCK_PRE_BUILT) { + return $this->tryInstall($lock[$source]['filename'], $force); + } + return $this->tryBuild($force); + } + + /** + * Get library name. + */ + public function getName(): string + { + return static::NAME; + } + /** * Get current lib source root dir. */ @@ -119,6 +146,45 @@ public function getHeaders(): array return Config::getLib(static::NAME, 'headers', []); } + /** + * @throws WrongUsageException + * @throws FileSystemException + */ + public function tryInstall(string $install_file, bool $force_install = false): int + { + if ($force_install) { + logger()->info('Installing required library [' . static::NAME . '] from pre-built binaries'); + + // Extract files + try { + FileSystem::extractPackage($install_file, DOWNLOAD_PATH . '/' . $install_file, BUILD_ROOT_PATH); + $this->install(); + return LIB_STATUS_OK; + } catch (FileSystemException|RuntimeException $e) { + logger()->error('Failed to extract pre-built library [' . static::NAME . ']: ' . $e->getMessage()); + return LIB_STATUS_INSTALL_FAILED; + } + } + foreach ($this->getStaticLibs() as $name) { + if (!file_exists(BUILD_LIB_PATH . "/{$name}")) { + $this->tryInstall($install_file, true); + return LIB_STATUS_OK; + } + } + foreach ($this->getHeaders() as $name) { + if (!file_exists(BUILD_INCLUDE_PATH . "/{$name}")) { + $this->tryInstall($install_file, true); + return LIB_STATUS_OK; + } + } + // pkg-config is treated specially. If it is pkg-config, check if the pkg-config binary exists + if (static::NAME === 'pkg-config' && !file_exists(BUILD_ROOT_PATH . '/bin/pkg-config')) { + $this->tryInstall($install_file, true); + return LIB_STATUS_OK; + } + return LIB_STATUS_ALREADY; + } + /** * Try to build this library, before build, we check first. * @@ -152,30 +218,30 @@ public function tryBuild(bool $force_build = false): int $this->getBuilder()->emitPatchPoint('before-library[ ' . static::NAME . ']-build'); $this->build(); $this->getBuilder()->emitPatchPoint('after-library[ ' . static::NAME . ']-build'); - return BUILD_STATUS_OK; + return LIB_STATUS_OK; } // check if these libraries exist, if not, invoke compilation and return the result status foreach ($this->getStaticLibs() as $name) { if (!file_exists(BUILD_LIB_PATH . "/{$name}")) { $this->tryBuild(true); - return BUILD_STATUS_OK; + return LIB_STATUS_OK; } } // header files the same foreach ($this->getHeaders() as $name) { if (!file_exists(BUILD_INCLUDE_PATH . "/{$name}")) { $this->tryBuild(true); - return BUILD_STATUS_OK; + return LIB_STATUS_OK; } } // pkg-config is treated specially. If it is pkg-config, check if the pkg-config binary exists if (static::NAME === 'pkg-config' && !file_exists(BUILD_ROOT_PATH . '/bin/pkg-config')) { $this->tryBuild(true); - return BUILD_STATUS_OK; + return LIB_STATUS_OK; } // if all the files exist at this point, skip the compilation process - return BUILD_STATUS_ALREADY; + return LIB_STATUS_ALREADY; } /** @@ -206,6 +272,11 @@ public function getLibVersion(): ?string */ abstract public function getBuilder(): BuilderBase; + public function beforePack(): void + { + // do something before pack, default do nothing. overwrite this method to do something (e.g. modify pkg-config file) + } + /** * Build this library. * @@ -213,6 +284,11 @@ abstract public function getBuilder(): BuilderBase; */ abstract protected function build(); + protected function install(): void + { + // do something after extracting pre-built files, default do nothing. overwrite this method to do something + } + /** * Add lib dependency * diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index 9c3b043e1..cab385797 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -79,13 +79,13 @@ public function build(): void $this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); // patch for openssl 3.3.0+ if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc'), 'prefix=')) { - FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file); + FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc', 'prefix=${pcfiledir}/../..' . "\n" . $file); } if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc'), 'prefix=')) { - FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file); + FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc', 'prefix=${pcfiledir}/../..' . "\n" . $file); } if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc'), 'prefix=')) { - FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file); + FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', 'prefix=${pcfiledir}/../..' . "\n" . $file); } } } diff --git a/src/SPC/builder/macos/library/openssl.php b/src/SPC/builder/macos/library/openssl.php index b5753b8d6..c20870804 100644 --- a/src/SPC/builder/macos/library/openssl.php +++ b/src/SPC/builder/macos/library/openssl.php @@ -62,13 +62,13 @@ protected function build(): void $this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); // patch for openssl 3.3.0+ if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc'), 'prefix=')) { - FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file); + FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc', 'prefix=${pcfiledir}/../..' . "\n" . $file); } if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc'), 'prefix=')) { - FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file); + FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc', 'prefix=${pcfiledir}/../..' . "\n" . $file); } if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc'), 'prefix=')) { - FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file); + FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', 'prefix=${pcfiledir}/../..' . "\n" . $file); } } } diff --git a/src/SPC/builder/traits/UnixLibraryTrait.php b/src/SPC/builder/traits/UnixLibraryTrait.php index c40db0f45..b1df91946 100644 --- a/src/SPC/builder/traits/UnixLibraryTrait.php +++ b/src/SPC/builder/traits/UnixLibraryTrait.php @@ -75,7 +75,7 @@ public function patchPkgconfPrefix(array $files, int $patch_option = PKGCONF_PAT logger()->debug('Patching ' . $realpath); // replace prefix $file = FileSystem::readFile($realpath); - $file = ($patch_option & PKGCONF_PATCH_PREFIX) === PKGCONF_PATCH_PREFIX ? preg_replace('/^prefix=.*$/m', 'prefix=' . BUILD_ROOT_PATH, $file) : $file; + $file = ($patch_option & PKGCONF_PATCH_PREFIX) === PKGCONF_PATCH_PREFIX ? preg_replace('/^prefix=.*$/m', 'prefix=${pcfiledir}/../..', $file) : $file; $file = ($patch_option & PKGCONF_PATCH_EXEC_PREFIX) === PKGCONF_PATCH_EXEC_PREFIX ? preg_replace('/^exec_prefix=.*$/m', 'exec_prefix=${prefix}', $file) : $file; $file = ($patch_option & PKGCONF_PATCH_LIBDIR) === PKGCONF_PATCH_LIBDIR ? preg_replace('/^libdir=.*$/m', 'libdir=${prefix}/lib', $file) : $file; $file = ($patch_option & PKGCONF_PATCH_INCLUDEDIR) === PKGCONF_PATCH_INCLUDEDIR ? preg_replace('/^includedir=.*$/m', 'includedir=${prefix}/include', $file) : $file; diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 18fb6eb06..3ec21f063 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -11,7 +11,6 @@ use SPC\exception\WrongUsageException; use SPC\store\Config; use SPC\store\FileSystem; -use SPC\store\SourceManager; use SPC\util\DependencyUtil; abstract class UnixBuilderBase extends BuilderBase @@ -129,14 +128,6 @@ public function proveLibs(array $sorted_libraries): void foreach ($this->libs as $lib) { $lib->calcDependency(); } - - // patch point - $this->emitPatchPoint('before-libs-extract'); - - // extract sources - SourceManager::initSource(libs: $sorted_libraries); - - $this->emitPatchPoint('after-libs-extract'); } /** diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index ca6896419..492059ec4 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -148,7 +148,7 @@ public function handle(): int // validate libs and exts $builder->validateLibsAndExts(); // build libraries - $builder->buildLibs(); + $builder->setupLibs(); if ($this->input->getOption('with-clean')) { logger()->info('Cleaning source dir...'); diff --git a/src/SPC/command/BuildLibsCommand.php b/src/SPC/command/BuildLibsCommand.php index 8bb08f617..4f20edf3c 100644 --- a/src/SPC/command/BuildLibsCommand.php +++ b/src/SPC/command/BuildLibsCommand.php @@ -65,7 +65,7 @@ public function handle(): int sleep(2); $builder->proveLibs($libraries); $builder->validateLibsAndExts(); - $builder->buildLibs(); + $builder->setupLibs(); $time = round(microtime(true) - START_TIME, 3); logger()->info('Build libs complete, used ' . $time . ' s !'); diff --git a/src/SPC/command/DownloadCommand.php b/src/SPC/command/DownloadCommand.php index 48fa5e7ae..4134d05b9 100644 --- a/src/SPC/command/DownloadCommand.php +++ b/src/SPC/command/DownloadCommand.php @@ -38,8 +38,9 @@ public function configure(): void $this->addOption('for-extensions', 'e', InputOption::VALUE_REQUIRED, 'Fetch by extensions, e.g "openssl,mbstring"'); $this->addOption('for-libs', 'l', InputOption::VALUE_REQUIRED, 'Fetch by libraries, e.g "libcares,openssl,onig"'); $this->addOption('without-suggestions', null, null, 'Do not fetch suggested sources when using --for-extensions'); - $this->addOption('ignore-cache-sources', null, InputOption::VALUE_OPTIONAL, 'Ignore some source caches, comma separated, e.g "php-src,curl,openssl"', ''); + $this->addOption('ignore-cache-sources', null, InputOption::VALUE_OPTIONAL, 'Ignore some source caches, comma separated, e.g "php-src,curl,openssl"', false); $this->addOption('retry', 'R', InputOption::VALUE_REQUIRED, 'Set retry time when downloading failed (default: 0)', '0'); + $this->addOption('prefer-pre-built', 'P', null, 'Download pre-built libraries when available'); } /** @@ -147,12 +148,22 @@ public function handle(): int } $chosen_sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources')))); - $force_all = empty($this->getOption('ignore-cache-sources')); - if (!$force_all) { - $force_list = array_map('trim', array_filter(explode(',', $this->getOption('ignore-cache-sources')))); - } else { + + $sss = $this->getOption('ignore-cache-sources'); + if ($sss === false) { + // false is no-any-ignores, that is, default. + $force_all = false; $force_list = []; + } elseif ($sss === null) { + // null means all sources will be ignored, equals to --force-all (but we don't want to add too many options) + $force_all = true; + $force_list = []; + } else { + // ignore some sources + $force_all = false; + $force_list = array_map('trim', array_filter(explode(',', $this->getOption('ignore-cache-sources')))); } + if ($this->getOption('all')) { logger()->notice('Downloading with --all option will take more times to download, we recommend you to download with --for-extensions option !'); } @@ -164,6 +175,17 @@ public function handle(): int $custom_urls[$source_name] = $url; } + // If passing --prefer-pre-built option, we need to load pre-built library list from pre-built.json targeted releases + if ($this->getOption('prefer-pre-built')) { + $repo = Config::getPreBuilt('repo'); + $pre_built_libs = Downloader::getLatestGithubRelease($repo, [ + 'repo' => $repo, + 'prefer-stable' => Config::getPreBuilt('prefer-stable'), + ], false); + } else { + $pre_built_libs = []; + } + // Download them f_mkdir(DOWNLOAD_PATH); $cnt = count($chosen_sources); @@ -185,8 +207,21 @@ public function handle(): int logger()->info("Fetching source {$source} from custom url [{$ni}/{$cnt}]"); Downloader::downloadSource($source, $new_config, true); } else { + $config = Config::getSource($source); + // Prefer pre-built, we need to search pre-built library + if ($this->getOption('prefer-pre-built') && ($config['provide-pre-built'] ?? false) === true) { + // We need to replace pattern + $find = str_replace(['{name}', '{arch}', '{os}'], [$source, arch2gnu(php_uname('m')), strtolower(PHP_OS_FAMILY)], Config::getPreBuilt('match-pattern')); + // find filename in asset list + if (($url = $this->findPreBuilt($pre_built_libs, $find)) !== null) { + logger()->info("Fetching pre-built content {$source} [{$ni}/{$cnt}]"); + Downloader::downloadSource($source, ['type' => 'url', 'url' => $url], $force_all || in_array($source, $force_list), SPC_LOCK_PRE_BUILT); + continue; + } + logger()->warning("Pre-built content not found for {$source}, fallback to source download"); + } logger()->info("Fetching source {$source} [{$ni}/{$cnt}]"); - Downloader::downloadSource($source, Config::getSource($source), $force_all || in_array($source, $force_list)); + Downloader::downloadSource($source, $config, $force_all || in_array($source, $force_list)); } } $time = round(microtime(true) - START_TIME, 3); @@ -286,4 +321,19 @@ private function calculateSourcesByLib(array $libs, bool $include_suggests = tru } return array_values(array_unique($sources)); } + + /** + * @param array $assets Asset list from GitHub API + * @param string $filename Match file name, e.g. pkg-config-aarch64-darwin.txz + * @return null|string Return the download URL if found, otherwise null + */ + private function findPreBuilt(array $assets, string $filename): ?string + { + foreach ($assets as $asset) { + if ($asset['name'] === $filename) { + return $asset['browser_download_url']; + } + } + return null; + } } diff --git a/src/SPC/command/dev/PackLibCommand.php b/src/SPC/command/dev/PackLibCommand.php new file mode 100644 index 000000000..8cb9014aa --- /dev/null +++ b/src/SPC/command/dev/PackLibCommand.php @@ -0,0 +1,85 @@ +addArgument('library', InputArgument::REQUIRED, 'The library will be compiled'); + } + + public function handle(): int + { + try { + $lib_name = $this->getArgument('library'); + $builder = BuilderProvider::makeBuilderByInput($this->input); + $builder->setLibsOnly(); + $libraries = DependencyUtil::getLibs([$lib_name]); + logger()->info('Building libraries: ' . implode(',', $libraries)); + sleep(2); + + FileSystem::createDir(WORKING_DIR . '/dist'); + + $builder->proveLibs($libraries); + $builder->validateLibsAndExts(); + foreach ($builder->getLibs() as $lib) { + if ($lib->getName() !== $lib_name) { + // other dependencies: install or build, both ok + $lib->setup(); + } else { + // Get lock info + $lock = json_decode(file_get_contents(DOWNLOAD_PATH . '/.lock.json'), true) ?? []; + $source = Config::getLib($lib->getName(), 'source'); + if (!isset($lock[$source]) || ($lock[$source]['lock_as'] ?? SPC_LOCK_SOURCE) === SPC_LOCK_PRE_BUILT) { + logger()->critical("The library {$lib->getName()} is downloaded as pre-built, we need to build it instead of installing pre-built."); + return static::FAILURE; + } + // Before build: load buildroot/ directory + $before_buildroot = FileSystem::scanDirFiles(BUILD_ROOT_PATH, relative: true); + // build + $lib->tryBuild(true); + // do something like patching pkg-conf files. + $lib->beforePack(); + // After build: load buildroot/ directory, and calculate increase files + $after_buildroot = FileSystem::scanDirFiles(BUILD_ROOT_PATH, relative: true); + $increase_files = array_diff($after_buildroot, $before_buildroot); + // every file mapped with BUILD_ROOT_PATH + // get BUILD_ROOT_PATH last dir part + $buildroot_part = basename(BUILD_ROOT_PATH); + $increase_files = array_map(fn ($file) => $buildroot_part . '/' . $file, $increase_files); + // write list to packlib_files.txt + FileSystem::writeFile(WORKING_DIR . '/packlib_files.txt', implode("\n", $increase_files)); + // pack + $filename = WORKING_DIR . '/dist/' . $lib->getName() . '-' . arch2gnu(php_uname('m')) . '-' . strtolower(PHP_OS_FAMILY) . '.' . Config::getPreBuilt('suffix'); + f_passthru('tar -czf ' . $filename . ' -T ' . WORKING_DIR . '/packlib_files.txt -C ' . WORKING_DIR); + logger()->info('Pack library ' . $lib->getName() . ' to ' . $filename . ' complete.'); + } + } + + $time = round(microtime(true) - START_TIME, 3); + logger()->info('Build libs complete, used ' . $time . ' s !'); + return static::SUCCESS; + } catch (\Throwable $e) { + if ($this->getOption('debug')) { + ExceptionHandler::getInstance()->handle($e); + } else { + logger()->critical('Build failed with ' . get_class($e) . ': ' . $e->getMessage()); + logger()->critical('Please check with --debug option to see more details.'); + } + return static::FAILURE; + } + } +} diff --git a/src/SPC/store/Config.php b/src/SPC/store/Config.php index 653407293..42895894e 100644 --- a/src/SPC/store/Config.php +++ b/src/SPC/store/Config.php @@ -20,6 +20,16 @@ class Config public static ?array $ext = null; + public static ?array $pre_built = null; + + public static function getPreBuilt(string $name): mixed + { + if (self::$pre_built === null) { + self::$pre_built = FileSystem::loadConfigArray('pre-built'); + } + return self::$pre_built[$name] ?? null; + } + /** * 从配置文件读取一个资源(source)的元信息 * diff --git a/src/SPC/store/Downloader.php b/src/SPC/store/Downloader.php index b1e70c617..6e127c98d 100644 --- a/src/SPC/store/Downloader.php +++ b/src/SPC/store/Downloader.php @@ -100,14 +100,15 @@ public static function getLatestGithubTarball(string $name, array $source, strin /** * Get latest version from GitHub release (uploaded archive) * - * @param string $name source name - * @param array $source source meta info: [repo, match] - * @return array [url, filename] + * @param string $name source name + * @param array $source source meta info: [repo, match] + * @param bool $match_result Whether to return matched result by `match` param (default: true) + * @return array When $match_result = true, and we matched, [url, filename]. Otherwise, [{asset object}. ...] * @throws DownloaderException */ - public static function getLatestGithubRelease(string $name, array $source): array + public static function getLatestGithubRelease(string $name, array $source, bool $match_result = true): array { - logger()->debug("finding {$name} source from github releases assests"); + logger()->debug("finding {$name} from github releases assests"); $data = json_decode(self::curlExec( url: "https://api.github.com/repos/{$source['repo']}/releases", hooks: [[CurlHook::class, 'setupGithubToken']], @@ -118,6 +119,9 @@ public static function getLatestGithubRelease(string $name, array $source): arra if (($source['prefer-stable'] ?? false) === true && $release['prerelease'] === true) { continue; } + if (!$match_result) { + return $release['assets']; + } foreach ($release['assets'] as $asset) { if (preg_match('|' . $source['match'] . '|', $asset['name'])) { $url = $asset['browser_download_url']; @@ -127,7 +131,7 @@ public static function getLatestGithubRelease(string $name, array $source): arra } if (!$url) { - throw new DownloaderException("failed to find {$name} source"); + throw new DownloaderException("failed to find {$name} release metadata"); } $filename = basename($url); @@ -176,11 +180,10 @@ public static function getFromFileList(string $name, array $source): array /** * Just download file using system curl command, and lock it * - * @throws DownloaderException - * @throws RuntimeException * @throws FileSystemException + * @throws RuntimeException */ - public static function downloadFile(string $name, string $url, string $filename, ?string $move_path = null): void + public static function downloadFile(string $name, string $url, string $filename, ?string $move_path = null, int $lock_as = SPC_LOCK_SOURCE): void { logger()->debug("Downloading {$url}"); $cancel_func = function () use ($filename) { @@ -193,7 +196,7 @@ public static function downloadFile(string $name, string $url, string $filename, self::curlDown(url: $url, path: FileSystem::convertPath(DOWNLOAD_PATH . "/{$filename}"), retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)); self::unregisterCancelEvent(); logger()->debug("Locking {$filename}"); - self::lockSource($name, ['source_type' => 'archive', 'filename' => $filename, 'move_path' => $move_path]); + self::lockSource($name, ['source_type' => 'archive', 'filename' => $filename, 'move_path' => $move_path, 'lock_as' => $lock_as]); } /** @@ -218,7 +221,7 @@ public static function lockSource(string $name, array $data): void * @throws FileSystemException * @throws RuntimeException */ - public static function downloadGit(string $name, string $url, string $branch, ?string $move_path = null, int $retry = 0): void + public static function downloadGit(string $name, string $url, string $branch, ?string $move_path = null, int $retry = 0, int $lock_as = SPC_LOCK_SOURCE): void { $download_path = FileSystem::convertPath(DOWNLOAD_PATH . "/{$name}"); if (file_exists($download_path)) { @@ -253,7 +256,7 @@ public static function downloadGit(string $name, string $url, string $branch, ?s } // Lock logger()->debug("Locking git source {$name}"); - self::lockSource($name, ['source_type' => 'dir', 'dirname' => $name, 'move_path' => $move_path]); + self::lockSource($name, ['source_type' => 'dir', 'dirname' => $name, 'move_path' => $move_path, 'lock_as' => $lock_as]); /* // 复制目录过去 @@ -313,28 +316,28 @@ public static function downloadPackage(string $name, ?array $pkg = null, bool $f switch ($pkg['type']) { case 'bitbuckettag': // BitBucket Tag [$url, $filename] = self::getLatestBitbucketTag($name, $pkg); - self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null); + self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null, SPC_LOCK_PRE_BUILT); break; case 'ghtar': // GitHub Release (tar) [$url, $filename] = self::getLatestGithubTarball($name, $pkg); - self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null); + self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null, SPC_LOCK_PRE_BUILT); break; case 'ghtagtar': // GitHub Tag (tar) [$url, $filename] = self::getLatestGithubTarball($name, $pkg, 'tags'); - self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null); + self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null, SPC_LOCK_PRE_BUILT); break; case 'ghrel': // GitHub Release (uploaded) [$url, $filename] = self::getLatestGithubRelease($name, $pkg); - self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null); + self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null, SPC_LOCK_PRE_BUILT); break; case 'filelist': // Basic File List (regex based crawler) [$url, $filename] = self::getFromFileList($name, $pkg); - self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null); + self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null, SPC_LOCK_PRE_BUILT); break; case 'url': // Direct download URL $url = $pkg['url']; $filename = $pkg['filename'] ?? basename($pkg['url']); - self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null); + self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null, SPC_LOCK_PRE_BUILT); break; case 'git': // Git repo self::downloadGit( @@ -342,7 +345,8 @@ public static function downloadPackage(string $name, ?array $pkg = null, bool $f $pkg['url'], $pkg['rev'], $pkg['extract'] ?? null, - intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0) + intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0), + SPC_LOCK_PRE_BUILT ); break; case 'custom': // Custom download method, like API-based download or other @@ -371,12 +375,14 @@ public static function downloadPackage(string $name, ?array $pkg = null, bool $f /** * Download source by name and meta. * - * @param string $name source name - * @param null|array $source source meta info: [type, path, rev, url, filename, regex, license] + * @param string $name source name + * @param null|array $source source meta info: [type, path, rev, url, filename, regex, license] + * @param bool $force Whether to force download (default: false) + * @param int $lock_as Lock source type (default: SPC_LOCK_SOURCE) * @throws DownloaderException * @throws FileSystemException */ - public static function downloadSource(string $name, ?array $source = null, bool $force = false): void + public static function downloadSource(string $name, ?array $source = null, bool $force = false, int $lock_as = SPC_LOCK_SOURCE): void { if ($source === null) { $source = Config::getSource($name); @@ -413,28 +419,28 @@ public static function downloadSource(string $name, ?array $source = null, bool switch ($source['type']) { case 'bitbuckettag': // BitBucket Tag [$url, $filename] = self::getLatestBitbucketTag($name, $source); - self::downloadFile($name, $url, $filename, $source['path'] ?? null); + self::downloadFile($name, $url, $filename, $source['path'] ?? null, $lock_as); break; case 'ghtar': // GitHub Release (tar) [$url, $filename] = self::getLatestGithubTarball($name, $source); - self::downloadFile($name, $url, $filename, $source['path'] ?? null); + self::downloadFile($name, $url, $filename, $source['path'] ?? null, $lock_as); break; case 'ghtagtar': // GitHub Tag (tar) [$url, $filename] = self::getLatestGithubTarball($name, $source, 'tags'); - self::downloadFile($name, $url, $filename, $source['path'] ?? null); + self::downloadFile($name, $url, $filename, $source['path'] ?? null, $lock_as); break; case 'ghrel': // GitHub Release (uploaded) [$url, $filename] = self::getLatestGithubRelease($name, $source); - self::downloadFile($name, $url, $filename, $source['path'] ?? null); + self::downloadFile($name, $url, $filename, $source['path'] ?? null, $lock_as); break; case 'filelist': // Basic File List (regex based crawler) [$url, $filename] = self::getFromFileList($name, $source); - self::downloadFile($name, $url, $filename, $source['path'] ?? null); + self::downloadFile($name, $url, $filename, $source['path'] ?? null, $lock_as); break; case 'url': // Direct download URL $url = $source['url']; $filename = $source['filename'] ?? basename($source['url']); - self::downloadFile($name, $url, $filename, $source['path'] ?? null); + self::downloadFile($name, $url, $filename, $source['path'] ?? null, $lock_as); break; case 'git': // Git repo self::downloadGit( @@ -442,14 +448,15 @@ public static function downloadSource(string $name, ?array $source = null, bool $source['url'], $source['rev'], $source['path'] ?? null, - intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0) + intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0), + $lock_as ); break; case 'custom': // Custom download method, like API-based download or other $classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\store\source'); foreach ($classes as $class) { if (is_a($class, CustomSourceBase::class, true) && $class::NAME === $name) { - (new $class())->fetch($force); + (new $class())->fetch($force, $source, $lock_as); break; } } diff --git a/src/SPC/store/FileSystem.php b/src/SPC/store/FileSystem.php index 0d1aee721..cbf6107e9 100644 --- a/src/SPC/store/FileSystem.php +++ b/src/SPC/store/FileSystem.php @@ -16,7 +16,7 @@ class FileSystem */ public static function loadConfigArray(string $config, ?string $config_dir = null): array { - $whitelist = ['ext', 'lib', 'source', 'pkg']; + $whitelist = ['ext', 'lib', 'source', 'pkg', 'pre-built']; if (!in_array($config, $whitelist)) { throw new FileSystemException('Reading ' . $config . '.json is not allowed'); } diff --git a/src/SPC/store/source/CustomSourceBase.php b/src/SPC/store/source/CustomSourceBase.php index da7c4ce13..2df8eb7eb 100644 --- a/src/SPC/store/source/CustomSourceBase.php +++ b/src/SPC/store/source/CustomSourceBase.php @@ -8,5 +8,5 @@ abstract class CustomSourceBase { public const NAME = 'unknown'; - abstract public function fetch(bool $force = false); + abstract public function fetch(bool $force = false, ?array $config = null, int $lock_as = SPC_LOCK_SOURCE): void; } diff --git a/src/SPC/store/source/PhpSource.php b/src/SPC/store/source/PhpSource.php index f4cc7d441..798356365 100644 --- a/src/SPC/store/source/PhpSource.php +++ b/src/SPC/store/source/PhpSource.php @@ -17,7 +17,7 @@ class PhpSource extends CustomSourceBase * @throws DownloaderException * @throws FileSystemException */ - public function fetch(bool $force = false): void + public function fetch(bool $force = false, ?array $config = null, int $lock_as = SPC_LOCK_SOURCE): void { $major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.1'; Downloader::downloadSource('php-src', self::getLatestPHPInfo($major), $force); @@ -45,7 +45,7 @@ public function getLatestPHPInfo(string $major_version): array // 从官网直接下载 return [ 'type' => 'url', - 'url' => "https://www.php.net/distributions/php-{$version}.tar.gz", + 'url' => "https://www.php.net/distributions/php-{$version}.tar.xz", ]; } } diff --git a/src/SPC/store/source/PostgreSQLSource.php b/src/SPC/store/source/PostgreSQLSource.php index 1f5d9bc06..113abc987 100644 --- a/src/SPC/store/source/PostgreSQLSource.php +++ b/src/SPC/store/source/PostgreSQLSource.php @@ -16,7 +16,7 @@ class PostgreSQLSource extends CustomSourceBase * @throws DownloaderException * @throws FileSystemException */ - public function fetch(bool $force = false): void + public function fetch(bool $force = false, ?array $config = null, int $lock_as = SPC_LOCK_SOURCE): void { Downloader::downloadSource('postgresql', self::getLatestInfo(), $force); } diff --git a/src/globals/defines.php b/src/globals/defines.php index bcd59a16a..aa622eb15 100644 --- a/src/globals/defines.php +++ b/src/globals/defines.php @@ -56,15 +56,20 @@ 'zendopcache' => 'opcache', ]; +// spc lock type +const SPC_LOCK_SOURCE = 1; // lock source +const SPC_LOCK_PRE_BUILT = 2; // lock pre-built + // file replace strategy const REPLACE_FILE_STR = 1; const REPLACE_FILE_PREG = 2; const REPLACE_FILE_USER = 3; // library build status -const BUILD_STATUS_OK = 0; -const BUILD_STATUS_ALREADY = 1; -const BUILD_STATUS_FAILED = 2; +const LIB_STATUS_OK = 0; +const LIB_STATUS_ALREADY = 1; +const LIB_STATUS_BUILD_FAILED = 2; +const LIB_STATUS_INSTALL_FAILED = 3; // build target type const BUILD_TARGET_NONE = 0; // no target From ff8863d5a12de4282d3e7b8b3995376bffbfe63d Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 21:18:30 +0800 Subject: [PATCH 02/43] Code style fix and comment addition --- src/SPC/builder/LibraryBase.php | 2 +- src/SPC/command/BuildCliCommand.php | 2 +- src/SPC/command/dev/PackLibCommand.php | 2 +- src/SPC/store/Downloader.php | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index cffee91fa..939ca11ee 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -45,7 +45,7 @@ public function setup(bool $force = false): int $lock = json_decode(FileSystem::readFile(DOWNLOAD_PATH . '/.lock.json'), true) ?? []; $source = Config::getLib(static::NAME, 'source'); // if source is locked as pre-built, we just tryInstall it - if (isset($lock[$source]) && $lock[$source]['lock_as'] === SPC_LOCK_PRE_BUILT) { + if (isset($lock[$source]) && ($lock[$source]['lock_as'] ?? SPC_LOCK_SOURCE) === SPC_LOCK_PRE_BUILT) { return $this->tryInstall($lock[$source]['filename'], $force); } return $this->tryBuild($force); diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index 492059ec4..2356e96f4 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -147,7 +147,7 @@ public function handle(): int $builder->proveExts($extensions); // validate libs and exts $builder->validateLibsAndExts(); - // build libraries + // build or install libraries $builder->setupLibs(); if ($this->input->getOption('with-clean')) { diff --git a/src/SPC/command/dev/PackLibCommand.php b/src/SPC/command/dev/PackLibCommand.php index 8cb9014aa..f97eaabd9 100644 --- a/src/SPC/command/dev/PackLibCommand.php +++ b/src/SPC/command/dev/PackLibCommand.php @@ -64,7 +64,7 @@ public function handle(): int FileSystem::writeFile(WORKING_DIR . '/packlib_files.txt', implode("\n", $increase_files)); // pack $filename = WORKING_DIR . '/dist/' . $lib->getName() . '-' . arch2gnu(php_uname('m')) . '-' . strtolower(PHP_OS_FAMILY) . '.' . Config::getPreBuilt('suffix'); - f_passthru('tar -czf ' . $filename . ' -T ' . WORKING_DIR . '/packlib_files.txt -C ' . WORKING_DIR); + f_passthru('tar -czf ' . $filename . ' -T ' . WORKING_DIR . '/packlib_files.txt'); logger()->info('Pack library ' . $lib->getName() . ' to ' . $filename . ' complete.'); } } diff --git a/src/SPC/store/Downloader.php b/src/SPC/store/Downloader.php index 6e127c98d..32085567f 100644 --- a/src/SPC/store/Downloader.php +++ b/src/SPC/store/Downloader.php @@ -558,7 +558,6 @@ public static function curlDown(string $url, string $path, string $method = 'GET try { f_passthru($cmd); } catch (RuntimeException $e) { - var_dump($e->getCode()); if ($e->getCode() === 2 || $e->getCode() === -1073741510) { throw new WrongUsageException('Keyboard interrupted, download failed !'); } From fc617134ca7fbdb976a5e5bd581d3b144cbdf7e9 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 21:34:04 +0800 Subject: [PATCH 03/43] Add pack-lib tests --- .github/workflows/test-pack-lib.yml | 88 +++++++++++++++++++++++++++++ config/source.json | 2 + src/SPC/store/Downloader.php | 2 +- 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test-pack-lib.yml diff --git a/.github/workflows/test-pack-lib.yml b/.github/workflows/test-pack-lib.yml new file mode 100644 index 000000000..2c9c367cc --- /dev/null +++ b/.github/workflows/test-pack-lib.yml @@ -0,0 +1,88 @@ +name: Tests for PHP Pack Lib + +on: + pull_request: + branches: [ "main" ] + paths: + - 'src/**' + - 'config/**' + - '.github/workflows/tests.yml' + - 'bin/**' + - 'composer.json' + - 'box.json' + - '.php-cs-fixer.php' + +permissions: + contents: read + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + build: + name: "Pack Lib Test (${{ matrix.lib }} for ${{ matrix.os.name }}-${{ matrix.os.arch }})" + runs-on: ${{ matrix.os.runs-on }} + timeout-minutes: 120 + strategy: + matrix: + os: + - runs-on: ubuntu-latest + name: "linux" + arch: "x86_64" + - runs-on: macos-13 + name: "darwin" + arch: "x86_64" + - runs-on: windows-latest + name: "windows" + arch: "x86_64" + - runs-on: macos-14 + name: "darwin" + arch: "aarch64" + lib: + - pkg-config + - zlib + - bzip2 + - gmp + fail-fast: false + steps: + - name: "Checkout" + uses: actions/checkout@v4 + + - name: "Setup PHP" + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + tools: pecl, composer + extensions: curl, openssl, mbstring + ini-values: memory_limit=-1 + + - name: "Cache composer packages" + id: composer-cache + uses: actions/cache@v4 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + # Cache downloaded source + - id: cache-download + uses: actions/cache@v4 + with: + path: downloads + key: pack-lib-dependencies + + - name: "Install Dependencies" + run: composer update -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + + - run: bin/spc doctor --auto-fix + + - run: bin/spc download --for-libs=${{ matrix.lib }} --debug --retry=5 --shallow-clone + + - run: bin/spc dev:pack-lib --debug ${{ matrix.lib }} + + - name: "Upload packed lib (${{ matrix.lib }} for ${{ matrix.os.name }}-${{ matrix.os.arch }})" + uses: actions/upload-artifact@v2 + with: + path: dist/${{ matrix.lib }}-${{ matrix.os.arch }}-${{ matrix.os.name }}.tar.gz + name: ${{ matrix.lib }}-${{ matrix.os.arch }}-${{ matrix.os.name }} \ No newline at end of file diff --git a/config/source.json b/config/source.json index af82b9efd..f3814324c 100644 --- a/config/source.json +++ b/config/source.json @@ -38,6 +38,7 @@ "type": "filelist", "url": "https://sourceware.org/pub/bzip2/", "regex": "/href=\"(?bzip2-(?[^\"]+)\\.tar\\.gz)\"/", + "provide-pre-built": true, "license": { "type": "text", "text": "This program, \"bzip2\", the associated library \"libbzip2\", and all documentation, are copyright (C) 1996-2010 Julian R Seward. All rights reserved. \n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n 2. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.\n 3. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.\n 4. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\nJulian Seward, jseward@bzip.org bzip2/libbzip2 version 1.0.6 of 6 September 2010\n\nPATENTS: To the best of my knowledge, bzip2 and libbzip2 do not use any patented algorithms. However, I do not have the resources to carry out a patent search. Therefore I cannot give any guarantee of the above statement." @@ -182,6 +183,7 @@ "gmp": { "type": "url", "url": "https://dl.static-php.dev/static-php-cli/deps/gmp/gmp-6.3.0.tar.xz", + "provide-pre-built": true, "alt": { "type": "ghtagtar", "repo": "alisw/GMP" diff --git a/src/SPC/store/Downloader.php b/src/SPC/store/Downloader.php index 32085567f..363fe3441 100644 --- a/src/SPC/store/Downloader.php +++ b/src/SPC/store/Downloader.php @@ -404,7 +404,7 @@ public static function downloadSource(string $name, ?array $source = null, bool $lock = json_decode(FileSystem::readFile(DOWNLOAD_PATH . '/.lock.json'), true) ?? []; } // If lock file exists, skip downloading - if (isset($lock[$name]) && !$force) { + if (isset($lock[$name]) && !$force && ($lock[$name]['lock_as'] ?? SPC_LOCK_SOURCE) === $lock_as) { if ($lock[$name]['source_type'] === 'archive' && file_exists(DOWNLOAD_PATH . '/' . $lock[$name]['filename'])) { logger()->notice("source [{$name}] already downloaded: " . $lock[$name]['filename']); return; From 14ce15c85ee01279a0674bb6a5418fd9d6c12590 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 21:39:22 +0800 Subject: [PATCH 04/43] Add pack-lib tests --- .github/workflows/test-pack-lib.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-pack-lib.yml b/.github/workflows/test-pack-lib.yml index 2c9c367cc..f09b0398c 100644 --- a/.github/workflows/test-pack-lib.yml +++ b/.github/workflows/test-pack-lib.yml @@ -77,9 +77,14 @@ jobs: - run: bin/spc doctor --auto-fix - - run: bin/spc download --for-libs=${{ matrix.lib }} --debug --retry=5 --shallow-clone + - run: bin/spc download --for-libs="${{ matrix.lib }}" --debug --retry=5 --shallow-clone - - run: bin/spc dev:pack-lib --debug ${{ matrix.lib }} + - name: "Download pre-built pkg-config for *nix if possible" + if: matrix.os.name == 'linux' || matrix.os.name == 'darwin' + run: bin/spc download --for-libs="pkg-config" --debug --retry=5 --shallow-clone --prefer-pre-built + + - if: matrix.os.name != 'windows' || matrix.lib != 'pkg-config' + run: bin/spc dev:pack-lib --debug ${{ matrix.lib }} - name: "Upload packed lib (${{ matrix.lib }} for ${{ matrix.os.name }}-${{ matrix.os.arch }})" uses: actions/upload-artifact@v2 From 91e089d74a4f57174e27ebc0aac81083253c13e8 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 21:40:57 +0800 Subject: [PATCH 05/43] Remove windows with pkg-config --- .github/workflows/test-pack-lib.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-pack-lib.yml b/.github/workflows/test-pack-lib.yml index f09b0398c..a6b82e4fa 100644 --- a/.github/workflows/test-pack-lib.yml +++ b/.github/workflows/test-pack-lib.yml @@ -23,6 +23,7 @@ jobs: name: "Pack Lib Test (${{ matrix.lib }} for ${{ matrix.os.name }}-${{ matrix.os.arch }})" runs-on: ${{ matrix.os.runs-on }} timeout-minutes: 120 + if: matrix.os.name != 'windows' || matrix.lib != 'pkg-config' strategy: matrix: os: From cc7f9fb44f916276d3a1d99bed04a897666c50b9 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 21:41:48 +0800 Subject: [PATCH 06/43] Remove windows with pkg-config --- .github/workflows/test-pack-lib.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-pack-lib.yml b/.github/workflows/test-pack-lib.yml index a6b82e4fa..55834fbda 100644 --- a/.github/workflows/test-pack-lib.yml +++ b/.github/workflows/test-pack-lib.yml @@ -82,7 +82,9 @@ jobs: - name: "Download pre-built pkg-config for *nix if possible" if: matrix.os.name == 'linux' || matrix.os.name == 'darwin' - run: bin/spc download --for-libs="pkg-config" --debug --retry=5 --shallow-clone --prefer-pre-built + run: | + bin/spc download --for-libs="pkg-config" --debug --retry=5 --shallow-clone --prefer-pre-built + bin/spc build:libs pkg-config --debug - if: matrix.os.name != 'windows' || matrix.lib != 'pkg-config' run: bin/spc dev:pack-lib --debug ${{ matrix.lib }} From ac5f1919b40e6bdff26e6bb8c678bb00dc55f2d5 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 21:49:39 +0800 Subject: [PATCH 07/43] Fix CI --- .github/workflows/test-pack-lib.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-pack-lib.yml b/.github/workflows/test-pack-lib.yml index 55834fbda..f84aae8c3 100644 --- a/.github/workflows/test-pack-lib.yml +++ b/.github/workflows/test-pack-lib.yml @@ -23,7 +23,6 @@ jobs: name: "Pack Lib Test (${{ matrix.lib }} for ${{ matrix.os.name }}-${{ matrix.os.arch }})" runs-on: ${{ matrix.os.runs-on }} timeout-minutes: 120 - if: matrix.os.name != 'windows' || matrix.lib != 'pkg-config' strategy: matrix: os: @@ -44,6 +43,12 @@ jobs: - zlib - bzip2 - gmp + exclude: + - os: + runs-on: windows-latest + arch: "x86_64" + lib: pkg-config + lib: pkg-config fail-fast: false steps: - name: "Checkout" @@ -92,5 +97,5 @@ jobs: - name: "Upload packed lib (${{ matrix.lib }} for ${{ matrix.os.name }}-${{ matrix.os.arch }})" uses: actions/upload-artifact@v2 with: - path: dist/${{ matrix.lib }}-${{ matrix.os.arch }}-${{ matrix.os.name }}.tar.gz + path: dist/${{ matrix.lib }}-${{ matrix.os.arch }}-${{ matrix.os.name }}.txz name: ${{ matrix.lib }}-${{ matrix.os.arch }}-${{ matrix.os.name }} \ No newline at end of file From 768fd0d4a086f768f8fa4addf97fb433fb95aab9 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 22:08:56 +0800 Subject: [PATCH 08/43] Fix CI --- .github/workflows/test-pack-lib.yml | 64 +++++++++++++++++------------ 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/.github/workflows/test-pack-lib.yml b/.github/workflows/test-pack-lib.yml index f84aae8c3..2a42237dd 100644 --- a/.github/workflows/test-pack-lib.yml +++ b/.github/workflows/test-pack-lib.yml @@ -20,37 +20,47 @@ env: jobs: build: - name: "Pack Lib Test (${{ matrix.lib }} for ${{ matrix.os.name }}-${{ matrix.os.arch }})" - runs-on: ${{ matrix.os.runs-on }} + name: "Pack Lib Test (${{ matrix.lib }} for ${{ matrix.runner }})" + runs-on: ${{ matrix.runner }} timeout-minutes: 120 strategy: matrix: - os: - - runs-on: ubuntu-latest - name: "linux" - arch: "x86_64" - - runs-on: macos-13 - name: "darwin" - arch: "x86_64" - - runs-on: windows-latest - name: "windows" - arch: "x86_64" - - runs-on: macos-14 - name: "darwin" - arch: "aarch64" + runner: + - ubuntu-latest + - macos-13 + - windows-latest + - macos-14 lib: - - pkg-config - zlib + - pkg-config - bzip2 - gmp exclude: - - os: - runs-on: windows-latest - arch: "x86_64" - lib: pkg-config - lib: pkg-config + - { runner: "windows-latest", lib: "pkg-config" } + - { runner: "windows-latest", lib: "gmp" } fail-fast: false steps: + - name: "Process env string" + run: | + case "${{ matrix.runner }}" in + ubuntu-latest) + echo "OS=linux" >> $env:GITHUB_ENV + echo "ARCH=x86_64" >> $env:GITHUB_ENV + ;; + windows-latest) + echo "OS=windows" >> $env:GITHUB_ENV + echo "ARCH=x86_64" >> $env:GITHUB_ENV + ;; + macos-13) + echo "OS=darwin" >> $env:GITHUB_ENV + echo "ARCH=x86_64" >> $env:GITHUB_ENV + ;; + macos-14) + echo "OS=darwin" >> $env:GITHUB_ENV + echo "ARCH=aarch64" >> $env:GITHUB_ENV + ;; + esac + - name: "Checkout" uses: actions/checkout@v4 @@ -69,7 +79,7 @@ jobs: path: vendor key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} restore-keys: | - ${{ runner.os }}-php- + ${{ runner.os }}-php # Cache downloaded source - id: cache-download @@ -86,16 +96,16 @@ jobs: - run: bin/spc download --for-libs="${{ matrix.lib }}" --debug --retry=5 --shallow-clone - name: "Download pre-built pkg-config for *nix if possible" - if: matrix.os.name == 'linux' || matrix.os.name == 'darwin' + if: (env.OS == 'linux' || env.OS == 'darwin') && matrix.lib != 'pkg-config' run: | bin/spc download --for-libs="pkg-config" --debug --retry=5 --shallow-clone --prefer-pre-built bin/spc build:libs pkg-config --debug - - if: matrix.os.name != 'windows' || matrix.lib != 'pkg-config' + - if: env.OS != 'windows' || matrix.lib != 'pkg-config' run: bin/spc dev:pack-lib --debug ${{ matrix.lib }} - - name: "Upload packed lib (${{ matrix.lib }} for ${{ matrix.os.name }}-${{ matrix.os.arch }})" + - name: "Upload packed lib (${{ matrix.lib }} for ${{ env.OS }}-${{ env.ARCH }})" uses: actions/upload-artifact@v2 with: - path: dist/${{ matrix.lib }}-${{ matrix.os.arch }}-${{ matrix.os.name }}.txz - name: ${{ matrix.lib }}-${{ matrix.os.arch }}-${{ matrix.os.name }} \ No newline at end of file + path: dist/${{ matrix.lib }}-${{ env.ARCH }}-${{ env.OS }}.txz + name: ${{ matrix.lib }}-${{ env.ARCH }}-${{ env.OS }} \ No newline at end of file From 730d304ca22a62d8e64d75407a5efddbf315ac9d Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 22:11:46 +0800 Subject: [PATCH 09/43] Use bash in windows --- .github/workflows/test-pack-lib.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-pack-lib.yml b/.github/workflows/test-pack-lib.yml index 2a42237dd..65397ec2a 100644 --- a/.github/workflows/test-pack-lib.yml +++ b/.github/workflows/test-pack-lib.yml @@ -41,6 +41,7 @@ jobs: fail-fast: false steps: - name: "Process env string" + shell: bash run: | case "${{ matrix.runner }}" in ubuntu-latest) From 9a954bd75f672a9f75efab15c13a39b2045946b6 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 22:13:58 +0800 Subject: [PATCH 10/43] Fix CI --- .github/workflows/test-pack-lib.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-pack-lib.yml b/.github/workflows/test-pack-lib.yml index 65397ec2a..90b03a475 100644 --- a/.github/workflows/test-pack-lib.yml +++ b/.github/workflows/test-pack-lib.yml @@ -96,7 +96,7 @@ jobs: - run: bin/spc download --for-libs="${{ matrix.lib }}" --debug --retry=5 --shallow-clone - - name: "Download pre-built pkg-config for *nix if possible" + - name: "Download pre-built pkg-config for ${{ env.OS }}-${{ env.ARCH }}" if: (env.OS == 'linux' || env.OS == 'darwin') && matrix.lib != 'pkg-config' run: | bin/spc download --for-libs="pkg-config" --debug --retry=5 --shallow-clone --prefer-pre-built From 6cb2b3f28c1ed57a8fcce9a9a4c6095197b373c2 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 22:29:52 +0800 Subject: [PATCH 11/43] Fix CI --- .github/workflows/test-pack-lib.yml | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test-pack-lib.yml b/.github/workflows/test-pack-lib.yml index 90b03a475..1a589ce37 100644 --- a/.github/workflows/test-pack-lib.yml +++ b/.github/workflows/test-pack-lib.yml @@ -41,24 +41,25 @@ jobs: fail-fast: false steps: - name: "Process env string" + id: process-env shell: bash run: | case "${{ matrix.runner }}" in ubuntu-latest) - echo "OS=linux" >> $env:GITHUB_ENV - echo "ARCH=x86_64" >> $env:GITHUB_ENV + echo "OS=linux" >> "$GITHUB_OUTPUT" + echo "ARCH=x86_64" >> "$GITHUB_OUTPUT" ;; windows-latest) - echo "OS=windows" >> $env:GITHUB_ENV - echo "ARCH=x86_64" >> $env:GITHUB_ENV + echo "OS=windows" >> "$GITHUB_OUTPUT" + echo "ARCH=x86_64" >> "$GITHUB_OUTPUT" ;; macos-13) - echo "OS=darwin" >> $env:GITHUB_ENV - echo "ARCH=x86_64" >> $env:GITHUB_ENV + echo "OS=darwin" >> "$GITHUB_OUTPUT" + echo "ARCH=x86_64" >> "$GITHUB_OUTPUT" ;; macos-14) - echo "OS=darwin" >> $env:GITHUB_ENV - echo "ARCH=aarch64" >> $env:GITHUB_ENV + echo "OS=darwin" >> "$GITHUB_OUTPUT" + echo "ARCH=aarch64" >> "$GITHUB_OUTPUT" ;; esac @@ -96,17 +97,17 @@ jobs: - run: bin/spc download --for-libs="${{ matrix.lib }}" --debug --retry=5 --shallow-clone - - name: "Download pre-built pkg-config for ${{ env.OS }}-${{ env.ARCH }}" - if: (env.OS == 'linux' || env.OS == 'darwin') && matrix.lib != 'pkg-config' + - name: "Download pre-built pkg-config for ${{ matrix.runner }}" + if: matrix.runner != 'windows-latest' && matrix.lib != 'pkg-config' run: | bin/spc download --for-libs="pkg-config" --debug --retry=5 --shallow-clone --prefer-pre-built bin/spc build:libs pkg-config --debug - - if: env.OS != 'windows' || matrix.lib != 'pkg-config' + - if: matrix.runner != 'windows-latest' || matrix.lib != 'pkg-config' run: bin/spc dev:pack-lib --debug ${{ matrix.lib }} - - name: "Upload packed lib (${{ matrix.lib }} for ${{ env.OS }}-${{ env.ARCH }})" + - name: "Upload packed lib (${{ matrix.lib }} for ${{ steps.process-env.outputs.ARCH }}-${{ steps.process-env.outputs.OS }})" uses: actions/upload-artifact@v2 with: path: dist/${{ matrix.lib }}-${{ env.ARCH }}-${{ env.OS }}.txz - name: ${{ matrix.lib }}-${{ env.ARCH }}-${{ env.OS }} \ No newline at end of file + name: ${{ matrix.lib }}-${{ steps.process-env.outputs.ARCH }}-${{ steps.process-env.outputs.OS }} \ No newline at end of file From 9c8b525f89e3875e6e229c67141c279ae9da82fd Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 22:32:01 +0800 Subject: [PATCH 12/43] Fix CI --- .github/workflows/test-pack-lib.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-pack-lib.yml b/.github/workflows/test-pack-lib.yml index 1a589ce37..309ad2ee1 100644 --- a/.github/workflows/test-pack-lib.yml +++ b/.github/workflows/test-pack-lib.yml @@ -109,5 +109,5 @@ jobs: - name: "Upload packed lib (${{ matrix.lib }} for ${{ steps.process-env.outputs.ARCH }}-${{ steps.process-env.outputs.OS }})" uses: actions/upload-artifact@v2 with: - path: dist/${{ matrix.lib }}-${{ env.ARCH }}-${{ env.OS }}.txz + path: dist/${{ matrix.lib }}-${{ steps.process-env.outputs.ARCH }}-${{ steps.process-env.outputs.OS }}.txz name: ${{ matrix.lib }}-${{ steps.process-env.outputs.ARCH }}-${{ steps.process-env.outputs.OS }} \ No newline at end of file From 884d7bf56a96b32db3bde2e8d9fa0b20b5b5bb2c Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 22:51:22 +0800 Subject: [PATCH 13/43] Add aarch64-linux to CI --- .github/workflows/test-pack-lib.yml | 24 ++++++++++++++++++------ bin/spc-alpine-docker | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-pack-lib.yml b/.github/workflows/test-pack-lib.yml index 309ad2ee1..86bcb4d45 100644 --- a/.github/workflows/test-pack-lib.yml +++ b/.github/workflows/test-pack-lib.yml @@ -27,6 +27,7 @@ jobs: matrix: runner: - ubuntu-latest + - ubuntu-20.04 - macos-13 - windows-latest - macos-14 @@ -48,18 +49,27 @@ jobs: ubuntu-latest) echo "OS=linux" >> "$GITHUB_OUTPUT" echo "ARCH=x86_64" >> "$GITHUB_OUTPUT" + echo "CMD=bin/spc" >> "$GITHUB_OUTPUT" + ;; + ubuntu-20.04) + echo "OS=linux" >> "$GITHUB_OUTPUT" + echo "ARCH=aarch64" >> "$GITHUB_OUTPUT" + echo 'CMD="SPC_USE_ARCH=aarch64 bin/spc-alpine-docker"' >> "$GITHUB_OUTPUT" ;; windows-latest) echo "OS=windows" >> "$GITHUB_OUTPUT" echo "ARCH=x86_64" >> "$GITHUB_OUTPUT" + echo "CMD=bin/spc" >> "$GITHUB_OUTPUT" ;; macos-13) echo "OS=darwin" >> "$GITHUB_OUTPUT" echo "ARCH=x86_64" >> "$GITHUB_OUTPUT" + echo "CMD=bin/spc" >> "$GITHUB_OUTPUT" ;; macos-14) echo "OS=darwin" >> "$GITHUB_OUTPUT" echo "ARCH=aarch64" >> "$GITHUB_OUTPUT" + echo "CMD=bin/spc" >> "$GITHUB_OUTPUT" ;; esac @@ -67,6 +77,7 @@ jobs: uses: actions/checkout@v4 - name: "Setup PHP" + if: matrix.runner != 'ubuntu-20.04' uses: shivammathur/setup-php@v2 with: php-version: 8.2 @@ -91,23 +102,24 @@ jobs: key: pack-lib-dependencies - name: "Install Dependencies" + if: matrix.runner != 'ubuntu-20.04' run: composer update -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - - run: bin/spc doctor --auto-fix + - run: ${{ steps.process-env.outputs.CMD }} doctor --auto-fix - - run: bin/spc download --for-libs="${{ matrix.lib }}" --debug --retry=5 --shallow-clone + - run: ${{ steps.process-env.outputs.CMD }} download --for-libs="${{ matrix.lib }}" --debug --retry=5 --shallow-clone - name: "Download pre-built pkg-config for ${{ matrix.runner }}" if: matrix.runner != 'windows-latest' && matrix.lib != 'pkg-config' run: | - bin/spc download --for-libs="pkg-config" --debug --retry=5 --shallow-clone --prefer-pre-built - bin/spc build:libs pkg-config --debug + ${{ steps.process-env.outputs.CMD }} download --for-libs="pkg-config" --debug --retry=5 --shallow-clone --prefer-pre-built + ${{ steps.process-env.outputs.CMD }} build:libs pkg-config --debug - if: matrix.runner != 'windows-latest' || matrix.lib != 'pkg-config' - run: bin/spc dev:pack-lib --debug ${{ matrix.lib }} + run: ${{ steps.process-env.outputs.CMD }} dev:pack-lib --debug ${{ matrix.lib }} - name: "Upload packed lib (${{ matrix.lib }} for ${{ steps.process-env.outputs.ARCH }}-${{ steps.process-env.outputs.OS }})" - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: path: dist/${{ matrix.lib }}-${{ steps.process-env.outputs.ARCH }}-${{ steps.process-env.outputs.OS }}.txz name: ${{ matrix.lib }}-${{ steps.process-env.outputs.ARCH }}-${{ steps.process-env.outputs.OS }} \ No newline at end of file diff --git a/bin/spc-alpine-docker b/bin/spc-alpine-docker index 87e529680..3049bcf4f 100755 --- a/bin/spc-alpine-docker +++ b/bin/spc-alpine-docker @@ -110,4 +110,4 @@ fi # Run docker # shellcheck disable=SC2068 -$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" -v "$(pwd)"/config:/app/config -v "$(pwd)"/src:/app/src -v "$(pwd)"/buildroot:/app/buildroot -v "$(pwd)"/source:/app/source -v "$(pwd)"/downloads:/app/downloads cwcc-spc-$SPC_USE_ARCH bin/spc $@ +$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" -v "$(pwd)"/config:/app/config -v "$(pwd)"/src:/app/src -v "$(pwd)"/buildroot:/app/buildroot -v "$(pwd)"/source:/app/source -v "$(pwd)"/dist:/app/dist -v "$(pwd)"/downloads:/app/downloads cwcc-spc-$SPC_USE_ARCH bin/spc $@ From 28b336c6664df98c8db5b1c4583fde4e5567072f Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 22:53:45 +0800 Subject: [PATCH 14/43] Fix CI quote --- .github/workflows/test-pack-lib.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-pack-lib.yml b/.github/workflows/test-pack-lib.yml index 86bcb4d45..8fa05f17f 100644 --- a/.github/workflows/test-pack-lib.yml +++ b/.github/workflows/test-pack-lib.yml @@ -54,7 +54,7 @@ jobs: ubuntu-20.04) echo "OS=linux" >> "$GITHUB_OUTPUT" echo "ARCH=aarch64" >> "$GITHUB_OUTPUT" - echo 'CMD="SPC_USE_ARCH=aarch64 bin/spc-alpine-docker"' >> "$GITHUB_OUTPUT" + echo CMD="SPC_USE_ARCH=aarch64 bin/spc-alpine-docker" >> "$GITHUB_OUTPUT" ;; windows-latest) echo "OS=windows" >> "$GITHUB_OUTPUT" From 0c30fc2039576cc9122772c4d56f781a0125a21b Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 7 Jul 2024 22:57:42 +0800 Subject: [PATCH 15/43] Fix alpine-docker ssl bug --- bin/spc-alpine-docker | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/spc-alpine-docker b/bin/spc-alpine-docker index 3049bcf4f..5b905e668 100755 --- a/bin/spc-alpine-docker +++ b/bin/spc-alpine-docker @@ -56,6 +56,7 @@ if ! $DOCKER_EXECUTABLE images | grep -q cwcc-spc-$SPC_USE_ARCH; then FROM $ALPINE_FROM $SPC_USE_MIRROR RUN apk update; \ + apk upgrade -a; \ apk add --no-cache \ autoconf \ automake \ From 467c7ae667862896dca29787b77996d876981b47 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 8 Jul 2024 00:06:59 +0800 Subject: [PATCH 16/43] Remove icu tools --- .github/workflows/test-pack-lib.yml | 125 -------------------------- src/SPC/builder/linux/library/icu.php | 4 +- src/SPC/builder/macos/library/icu.php | 2 +- src/globals/test-extensions.php | 2 +- 4 files changed, 4 insertions(+), 129 deletions(-) delete mode 100644 .github/workflows/test-pack-lib.yml diff --git a/.github/workflows/test-pack-lib.yml b/.github/workflows/test-pack-lib.yml deleted file mode 100644 index 8fa05f17f..000000000 --- a/.github/workflows/test-pack-lib.yml +++ /dev/null @@ -1,125 +0,0 @@ -name: Tests for PHP Pack Lib - -on: - pull_request: - branches: [ "main" ] - paths: - - 'src/**' - - 'config/**' - - '.github/workflows/tests.yml' - - 'bin/**' - - 'composer.json' - - 'box.json' - - '.php-cs-fixer.php' - -permissions: - contents: read - -env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - -jobs: - build: - name: "Pack Lib Test (${{ matrix.lib }} for ${{ matrix.runner }})" - runs-on: ${{ matrix.runner }} - timeout-minutes: 120 - strategy: - matrix: - runner: - - ubuntu-latest - - ubuntu-20.04 - - macos-13 - - windows-latest - - macos-14 - lib: - - zlib - - pkg-config - - bzip2 - - gmp - exclude: - - { runner: "windows-latest", lib: "pkg-config" } - - { runner: "windows-latest", lib: "gmp" } - fail-fast: false - steps: - - name: "Process env string" - id: process-env - shell: bash - run: | - case "${{ matrix.runner }}" in - ubuntu-latest) - echo "OS=linux" >> "$GITHUB_OUTPUT" - echo "ARCH=x86_64" >> "$GITHUB_OUTPUT" - echo "CMD=bin/spc" >> "$GITHUB_OUTPUT" - ;; - ubuntu-20.04) - echo "OS=linux" >> "$GITHUB_OUTPUT" - echo "ARCH=aarch64" >> "$GITHUB_OUTPUT" - echo CMD="SPC_USE_ARCH=aarch64 bin/spc-alpine-docker" >> "$GITHUB_OUTPUT" - ;; - windows-latest) - echo "OS=windows" >> "$GITHUB_OUTPUT" - echo "ARCH=x86_64" >> "$GITHUB_OUTPUT" - echo "CMD=bin/spc" >> "$GITHUB_OUTPUT" - ;; - macos-13) - echo "OS=darwin" >> "$GITHUB_OUTPUT" - echo "ARCH=x86_64" >> "$GITHUB_OUTPUT" - echo "CMD=bin/spc" >> "$GITHUB_OUTPUT" - ;; - macos-14) - echo "OS=darwin" >> "$GITHUB_OUTPUT" - echo "ARCH=aarch64" >> "$GITHUB_OUTPUT" - echo "CMD=bin/spc" >> "$GITHUB_OUTPUT" - ;; - esac - - - name: "Checkout" - uses: actions/checkout@v4 - - - name: "Setup PHP" - if: matrix.runner != 'ubuntu-20.04' - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - tools: pecl, composer - extensions: curl, openssl, mbstring - ini-values: memory_limit=-1 - - - name: "Cache composer packages" - id: composer-cache - uses: actions/cache@v4 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php - - # Cache downloaded source - - id: cache-download - uses: actions/cache@v4 - with: - path: downloads - key: pack-lib-dependencies - - - name: "Install Dependencies" - if: matrix.runner != 'ubuntu-20.04' - run: composer update -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - - - run: ${{ steps.process-env.outputs.CMD }} doctor --auto-fix - - - run: ${{ steps.process-env.outputs.CMD }} download --for-libs="${{ matrix.lib }}" --debug --retry=5 --shallow-clone - - - name: "Download pre-built pkg-config for ${{ matrix.runner }}" - if: matrix.runner != 'windows-latest' && matrix.lib != 'pkg-config' - run: | - ${{ steps.process-env.outputs.CMD }} download --for-libs="pkg-config" --debug --retry=5 --shallow-clone --prefer-pre-built - ${{ steps.process-env.outputs.CMD }} build:libs pkg-config --debug - - - if: matrix.runner != 'windows-latest' || matrix.lib != 'pkg-config' - run: ${{ steps.process-env.outputs.CMD }} dev:pack-lib --debug ${{ matrix.lib }} - - - name: "Upload packed lib (${{ matrix.lib }} for ${{ steps.process-env.outputs.ARCH }}-${{ steps.process-env.outputs.OS }})" - uses: actions/upload-artifact@v4 - with: - path: dist/${{ matrix.lib }}-${{ steps.process-env.outputs.ARCH }}-${{ steps.process-env.outputs.OS }}.txz - name: ${{ matrix.lib }}-${{ steps.process-env.outputs.ARCH }}-${{ steps.process-env.outputs.OS }} \ No newline at end of file diff --git a/src/SPC/builder/linux/library/icu.php b/src/SPC/builder/linux/library/icu.php index dc0939da5..458ede5fc 100644 --- a/src/SPC/builder/linux/library/icu.php +++ b/src/SPC/builder/linux/library/icu.php @@ -21,10 +21,10 @@ protected function build(): void '--disable-shared ' . '--with-data-packaging=static ' . '--enable-release=yes ' . - '--enable-extras=yes ' . + '--enable-extras=no ' . '--enable-icuio=yes ' . '--enable-dyload=no ' . - '--enable-tools=yes ' . + '--enable-tools=no ' . '--enable-tests=no ' . '--enable-samples=no ' . '--prefix=' . BUILD_ROOT_PATH diff --git a/src/SPC/builder/macos/library/icu.php b/src/SPC/builder/macos/library/icu.php index 14a0ae945..13078c157 100644 --- a/src/SPC/builder/macos/library/icu.php +++ b/src/SPC/builder/macos/library/icu.php @@ -12,7 +12,7 @@ protected function build(): void { $root = BUILD_ROOT_PATH; shell()->cd($this->source_dir . '/source') - ->exec("./runConfigureICU MacOSX --enable-static --disable-shared --prefix={$root}") + ->exec("./runConfigureICU MacOSX --enable-static --disable-shared --disable-extras --disable-samples --disable-tests --disable-tools --prefix={$root}") ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") ->exec('make install'); diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 335074d19..f8f80834b 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -19,7 +19,7 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'spx', + 'Linux', 'Darwin' => 'intl', 'Windows' => 'mbstring,pdo_sqlite,mbregex,bz2,sqlsrv,pdo_sqlsrv,yaml', }; From cedd58443d527aed97dff327072a5549564c83a8 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 8 Jul 2024 00:07:30 +0800 Subject: [PATCH 17/43] Patch sqlite pkgconf file --- src/SPC/builder/unix/library/sqlite.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SPC/builder/unix/library/sqlite.php b/src/SPC/builder/unix/library/sqlite.php index b706a39fe..d679a3861 100644 --- a/src/SPC/builder/unix/library/sqlite.php +++ b/src/SPC/builder/unix/library/sqlite.php @@ -13,5 +13,6 @@ protected function build(): void ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + $this->patchPkgconfPrefix(['sqlite3.pc']); } } From 125d6ca77273345a3802ac177038e774c22973ca Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 8 Jul 2024 00:23:26 +0800 Subject: [PATCH 18/43] Add liblz4, sqlite for pre-built libs --- config/source.json | 2 ++ src/SPC/builder/unix/library/liblz4.php | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config/source.json b/config/source.json index f3814324c..cd2378e81 100644 --- a/config/source.json +++ b/config/source.json @@ -341,6 +341,7 @@ "repo": "lz4/lz4", "match": "lz4-.+\\.tar\\.gz", "prefer-stable": true, + "provide-pre-built": true, "license": { "type": "file", "path": "LICENSE" @@ -656,6 +657,7 @@ "sqlite": { "type": "url", "url": "https://www.sqlite.org/2023/sqlite-autoconf-3430200.tar.gz", + "provide-pre-built": true, "license": { "type": "text", "text": "The author disclaims copyright to this source code. In place of\na legal notice, here is a blessing:\n\n * May you do good and not evil.\n * May you find forgiveness for yourself and forgive others.\n * May you share freely, never taking more than you give." diff --git a/src/SPC/builder/unix/library/liblz4.php b/src/SPC/builder/unix/library/liblz4.php index 1b33dcc02..697f8ed38 100644 --- a/src/SPC/builder/unix/library/liblz4.php +++ b/src/SPC/builder/unix/library/liblz4.php @@ -8,7 +8,14 @@ trait liblz4 { - protected function build() + public function patchBeforeBuild(): bool + { + // disable executables + FileSystem::replaceFileStr($this->source_dir . '/programs/Makefile', 'install: lz4', "install: lz4\n\ninstallewfwef: lz4"); + return true; + } + + protected function build(): void { shell()->cd($this->source_dir) ->exec("make PREFIX='' clean") From b8f63ec3b9beb6048f2d093fa44c775d37f9bb6e Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 8 Jul 2024 00:51:30 +0800 Subject: [PATCH 19/43] Fix windows sqlite portable build --- src/globals/extra/Makefile-sqlite | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/globals/extra/Makefile-sqlite b/src/globals/extra/Makefile-sqlite index e122cd9d0..4bf0cee22 100644 --- a/src/globals/extra/Makefile-sqlite +++ b/src/globals/extra/Makefile-sqlite @@ -26,7 +26,7 @@ LDFLAGS=/DEBUG /GUARD:CF /INCREMENTAL:NO SQLITE3_STATIC_BASE=libsqlite3_a SQLITE3_DLL_BASE=libsqlite3 SQLITE3_EXE_BASE=sqlite3 -CFLAGS=$(COMMON_CFLAGS) /Zi /MT /guard:cf /Zc:inline /Qspectre /Ox /W3 /GF /GL /Gw +CFLAGS=$(COMMON_CFLAGS) /Zi /MT /guard:cf /Zc:inline /Qspectre /Ox /W3 /GF /Gw LDFLAGS=/GUARD:CF /INCREMENTAL:NO /NXCOMPAT /DYNAMICBASE !ENDIF From 5ec194efb2b587026d9a6b660c1f329361d5ef10 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 8 Jul 2024 10:46:32 +0800 Subject: [PATCH 20/43] Remove initSource for sorted libs in WindowsBuilder --- src/SPC/builder/windows/WindowsBuilder.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/SPC/builder/windows/WindowsBuilder.php b/src/SPC/builder/windows/WindowsBuilder.php index 1c6444885..1c1646d7a 100644 --- a/src/SPC/builder/windows/WindowsBuilder.php +++ b/src/SPC/builder/windows/WindowsBuilder.php @@ -10,7 +10,6 @@ use SPC\exception\WrongUsageException; use SPC\store\Config; use SPC\store\FileSystem; -use SPC\store\SourceManager; use SPC\store\SourcePatcher; use SPC\util\DependencyUtil; use SPC\util\GlobalEnvManager; @@ -245,9 +244,6 @@ public function proveLibs(array $sorted_libraries): void foreach ($this->libs as $lib) { $lib->calcDependency(); } - - // extract sources - SourceManager::initSource(libs: $sorted_libraries); } /** From 8ec50c88caee83a847118a9b5af66a81d29d20ef Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 8 Jul 2024 10:51:09 +0800 Subject: [PATCH 21/43] Remove perl.exe check log in doctor --- src/SPC/doctor/item/WindowsToolCheckList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/doctor/item/WindowsToolCheckList.php b/src/SPC/doctor/item/WindowsToolCheckList.php index df4eb050c..b66737cc8 100644 --- a/src/SPC/doctor/item/WindowsToolCheckList.php +++ b/src/SPC/doctor/item/WindowsToolCheckList.php @@ -71,7 +71,7 @@ public function checkPerl(): ?CheckResult if (($path = SystemUtil::findCommand('perl.exe')) === null) { return CheckResult::fail('perl not found in path.', 'install-perl'); } - if (!str_contains(implode('', cmd()->execWithResult(quote($path) . ' -v')[1]), 'MSWin32')) { + if (!str_contains(implode('', cmd()->execWithResult(quote($path) . ' -v', false)[1]), 'MSWin32')) { return CheckResult::fail($path . ' is not built for msvc.', 'install-perl'); } return CheckResult::ok(); From 8cec136656e607ac37cefe1cb492f64929c4e972 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 8 Jul 2024 11:21:01 +0800 Subject: [PATCH 22/43] Add openssl to pre-built --- config/source.json | 1 + src/SPC/builder/linux/library/openssl.php | 2 ++ src/SPC/builder/macos/library/openssl.php | 2 ++ src/SPC/builder/windows/library/openssl.php | 6 ++++++ src/globals/test-extensions.php | 4 ++-- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/config/source.json b/config/source.json index cd2378e81..76c656f66 100644 --- a/config/source.json +++ b/config/source.json @@ -535,6 +535,7 @@ "type": "filelist", "url": "https://www.openssl.org/source/", "regex": "/href=\"(?openssl-(?[^\"]+)\\.tar\\.gz)\"/", + "provide-pre-built": true, "license": { "type": "file", "path": "LICENSE.txt" diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index cab385797..46fcd75ef 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -87,5 +87,7 @@ public function build(): void if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc'), 'prefix=')) { FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', 'prefix=${pcfiledir}/../..' . "\n" . $file); } + FileSystem::replaceFileRegex(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', '/Libs.private:.*/m', 'Libs.private: ${libdir}/libz.a'); + FileSystem::replaceFileRegex(BUILD_LIB_PATH . '/cmake/OpenSSL/OpenSSLConfig.cmake', '/set\(OPENSSL_LIBCRYPTO_DEPENDENCIES .*\)/m', 'set(OPENSSL_LIBCRYPTO_DEPENDENCIES "${OPENSSL_LIBRARY_DIR}/libz.a")'); } } diff --git a/src/SPC/builder/macos/library/openssl.php b/src/SPC/builder/macos/library/openssl.php index c20870804..1e171ef27 100644 --- a/src/SPC/builder/macos/library/openssl.php +++ b/src/SPC/builder/macos/library/openssl.php @@ -70,5 +70,7 @@ protected function build(): void if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc'), 'prefix=')) { FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', 'prefix=${pcfiledir}/../..' . "\n" . $file); } + FileSystem::replaceFileRegex(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', '/Libs.private:.*/m', 'Libs.private: ${libdir}/libz.a'); + FileSystem::replaceFileRegex(BUILD_LIB_PATH . '/cmake/OpenSSL/OpenSSLConfig.cmake', '/set\(OPENSSL_LIBCRYPTO_DEPENDENCIES .*\)/m', 'set(OPENSSL_LIBCRYPTO_DEPENDENCIES "${OPENSSL_LIBRARY_DIR}/libz.a")'); } } diff --git a/src/SPC/builder/windows/library/openssl.php b/src/SPC/builder/windows/library/openssl.php index 74a3b5108..09c0068bc 100644 --- a/src/SPC/builder/windows/library/openssl.php +++ b/src/SPC/builder/windows/library/openssl.php @@ -41,5 +41,11 @@ protected function build(): void 'CNF_LDFLAGS="/NODEFAULTLIB:kernel32.lib /NODEFAULTLIB:msvcrt /NODEFAULTLIB:msvcrtd /DEFAULTLIB:libcmt /LIBPATH:' . BUILD_LIB_PATH . ' zlibstatic.lib"' ); copy($this->source_dir . '\ms\applink.c', BUILD_INCLUDE_PATH . '\openssl\applink.c'); + + FileSystem::replaceFileRegex( + BUILD_LIB_PATH . '\cmake\OpenSSL\OpenSSLConfig.cmake', + '/set\(OPENSSL_LIBCRYPTO_DEPENDENCIES .*\)/m', + 'set(OPENSSL_LIBCRYPTO_DEPENDENCIES "${OPENSSL_LIBRARY_DIR}" ws2_32.lib gdi32.lib advapi32.lib crypt32.lib user32.lib)' + ); } } diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index f8f80834b..4e81a40c1 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -19,8 +19,8 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'intl', - 'Windows' => 'mbstring,pdo_sqlite,mbregex,bz2,sqlsrv,pdo_sqlsrv,yaml', + 'Linux', 'Darwin' => 'openssl', + 'Windows' => 'mbstring,pdo_sqlite,openssl', }; // If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`). From 32a98bb8a18bb1f3e981445621a70646ff4d40d3 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 8 Jul 2024 12:55:41 +0800 Subject: [PATCH 23/43] Add license installer for build mode --- src/SPC/builder/LibraryBase.php | 23 +++++++++++++++++++++++ src/SPC/util/LicenseDumper.php | 18 ++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index 939ca11ee..1da2336a7 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -217,6 +217,7 @@ public function tryBuild(bool $force_build = false): int } $this->getBuilder()->emitPatchPoint('before-library[ ' . static::NAME . ']-build'); $this->build(); + $this->installLicense(); $this->getBuilder()->emitPatchPoint('after-library[ ' . static::NAME . ']-build'); return LIB_STATUS_OK; } @@ -311,4 +312,26 @@ protected function getSnakeCaseName(): string { return str_replace('-', '_', static::NAME); } + + /** + * Install license files in buildroot directory + */ + protected function installLicense(): void + { + FileSystem::createDir(BUILD_ROOT_PATH . '/source-licenses/' . $this->getName()); + $source = Config::getLib($this->getName(), 'source'); + $license_files = Config::getSource($source)['license'] ?? []; + if (is_assoc_array($license_files)) { + $license_files = [$license_files]; + } + foreach ($license_files as $index => $license) { + if ($license['type'] === 'text') { + FileSystem::writeFile(BUILD_ROOT_PATH . '/source-licenses/' . $this->getName() . "/{$index}.txt", $license['text']); + continue; + } + if ($license['type'] === 'file') { + copy($this->source_dir . '/' . $license['path'], BUILD_ROOT_PATH . '/source-licenses/' . $this->getName() . "/{$index}.txt"); + } + } + } } diff --git a/src/SPC/util/LicenseDumper.php b/src/SPC/util/LicenseDumper.php index 61a6dc060..4c9d63fe4 100644 --- a/src/SPC/util/LicenseDumper.php +++ b/src/SPC/util/LicenseDumper.php @@ -107,9 +107,9 @@ private function getSourceLicenses(string $source_name): iterable } foreach ($licenses as $index => $license) { - yield ($license['suffix'] ?? $index) => match ($license['type']) { + yield $index => match ($license['type']) { 'text' => $license['text'], - 'file' => $this->loadSourceFile($source_name, $license['path'], Config::getSource($source_name)['path'] ?? null), + 'file' => $this->loadSourceFile($source_name, $index, $license['path'], Config::getSource($source_name)['path'] ?? null), default => throw new RuntimeException('source [' . $source_name . '] license type is not allowed'), }; } @@ -118,15 +118,21 @@ private function getSourceLicenses(string $source_name): iterable /** * @throws RuntimeException */ - private function loadSourceFile(string $source_name, ?string $in_path, ?string $custom_base_path = null): string + private function loadSourceFile(string $source_name, int $index, ?string $in_path, ?string $custom_base_path = null): string { if (is_null($in_path)) { throw new RuntimeException('source [' . $source_name . '] license file is not set, please check config/source.json'); } - if (!file_exists(SOURCE_PATH . '/' . ($custom_base_path ?? $source_name) . '/' . $in_path)) { - throw new RuntimeException('source [' . $source_name . '] license file [' . $in_path . '] not exist'); + + if (file_exists(SOURCE_PATH . '/' . ($custom_base_path ?? $source_name) . '/' . $in_path)) { + return file_get_contents(SOURCE_PATH . '/' . ($custom_base_path ?? $source_name) . '/' . $in_path); + } + + if (file_exists(BUILD_ROOT_PATH . '/source-licenses/' . $source_name . '/' . $index . '.txt')) { + logger()->debug('source [' . $source_name . '] license file [' . $index . ':' . $in_path . '] not exist, use installed version instead'); + return file_get_contents(BUILD_ROOT_PATH . '/source-licenses/' . $source_name . '/' . $index . '.txt'); } - return file_get_contents(SOURCE_PATH . '/' . ($custom_base_path ?? $source_name) . '/' . $in_path); + throw new RuntimeException('source [' . $source_name . '] license file [' . $in_path . '] not exist'); } } From ce155987ad4de2db55d9df54faac8b2a43f4542d Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 8 Jul 2024 12:58:57 +0800 Subject: [PATCH 24/43] Remove suffix for LicenseDumper and LicenseDumperTest --- tests/SPC/util/LicenseDumperTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/SPC/util/LicenseDumperTest.php b/tests/SPC/util/LicenseDumperTest.php index 3fdfcf8eb..5462df58a 100644 --- a/tests/SPC/util/LicenseDumperTest.php +++ b/tests/SPC/util/LicenseDumperTest.php @@ -43,7 +43,6 @@ public function testDumpWithSingleLicense(): void 'license' => [ 'type' => 'text', 'text' => 'license', - 'suffix' => 'zend', ], ], ]; @@ -52,7 +51,7 @@ public function testDumpWithSingleLicense(): void $dumper->addLibs(['fake_lib']); $dumper->dump(self::DIRECTORY); - $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_zend.txt'); + $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_0.txt'); } public function testDumpWithMultipleLicenses(): void @@ -76,7 +75,6 @@ public function testDumpWithMultipleLicenses(): void [ 'type' => 'text', 'text' => 'license', - 'suffix' => 'zend', ], ], ], @@ -88,6 +86,6 @@ public function testDumpWithMultipleLicenses(): void $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_0.txt'); $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_1.txt'); - $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_zend.txt'); + $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_2.txt'); } } From 48294c9c5f9338cafd884c01508d4012f22968f5 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 8 Jul 2024 13:27:03 +0800 Subject: [PATCH 25/43] Add brotli, libargon2, libavif, libiconv, libpng, libtiff pre-built libs --- config/source.json | 6 ++++++ src/SPC/builder/unix/library/brotli.php | 4 ++++ src/SPC/builder/unix/library/libargon2.php | 4 ++++ src/SPC/builder/unix/library/libiconv.php | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/config/source.json b/config/source.json index 76c656f66..6bdb8f8bf 100644 --- a/config/source.json +++ b/config/source.json @@ -29,6 +29,7 @@ "brotli": { "type": "ghtar", "repo": "google/brotli", + "provide-pre-built": true, "license": { "type": "file", "path": "LICENSE" @@ -253,6 +254,7 @@ "type": "git", "rev": "master", "url": "https://github.com/static-php/phc-winner-argon2", + "provide-pre-built": true, "license": { "type": "file", "path": "LICENSE" @@ -261,6 +263,7 @@ "libavif": { "type": "ghtar", "repo": "AOMediaCodec/libavif", + "provide-pre-built": true, "license": { "type": "file", "path": "LICENSE" @@ -314,6 +317,7 @@ "type": "filelist", "url": "https://ftp.gnu.org/gnu/libiconv/", "regex": "/href=\"(?libiconv-(?[^\"]+)\\.tar\\.gz)\"/", + "provide-pre-built": true, "license": { "type": "file", "path": "COPYING" @@ -360,6 +364,7 @@ "type": "git", "url": "https://github.com/glennrp/libpng.git", "rev": "libpng16", + "provide-pre-built": true, "license": { "type": "file", "path": "LICENSE" @@ -398,6 +403,7 @@ "type": "filelist", "url": "https://download.osgeo.org/libtiff/", "regex": "/href=\"(?tiff-(?[^\"]+)\\.tar\\.xz)\"/", + "provide-pre-built": true, "license": { "type": "file", "path": "LICENSE.md" diff --git a/src/SPC/builder/unix/library/brotli.php b/src/SPC/builder/unix/library/brotli.php index e84c65778..fddcfbae8 100644 --- a/src/SPC/builder/unix/library/brotli.php +++ b/src/SPC/builder/unix/library/brotli.php @@ -34,5 +34,9 @@ protected function build(): void unlink(BUILD_ROOT_PATH . '/lib/' . $filename); } } + + if (file_exists(BUILD_BIN_PATH . '/brotli')) { + unlink(BUILD_BIN_PATH . '/brotli'); + } } } diff --git a/src/SPC/builder/unix/library/libargon2.php b/src/SPC/builder/unix/library/libargon2.php index 8cdd1e638..e91b71f0e 100644 --- a/src/SPC/builder/unix/library/libargon2.php +++ b/src/SPC/builder/unix/library/libargon2.php @@ -23,5 +23,9 @@ protected function build() unlink(BUILD_ROOT_PATH . '/lib/' . $filename); } } + + if (file_exists(BUILD_BIN_PATH . '/argon2')) { + unlink(BUILD_BIN_PATH . '/argon2'); + } } } diff --git a/src/SPC/builder/unix/library/libiconv.php b/src/SPC/builder/unix/library/libiconv.php index 5096e7245..fd6b5f8e7 100644 --- a/src/SPC/builder/unix/library/libiconv.php +++ b/src/SPC/builder/unix/library/libiconv.php @@ -20,5 +20,9 @@ protected function build(): void ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") ->exec('make install DESTDIR=' . $destdir); + + if (file_exists(BUILD_BIN_PATH . '/iconv')) { + unlink(BUILD_BIN_PATH . '/iconv'); + } } } From a950498fd4651e1ca3519c5c5787d9a710ffd036 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 9 Jul 2024 00:43:38 +0800 Subject: [PATCH 26/43] Add timer for build libs --- src/SPC/builder/BuilderBase.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 26d1b8742..ce92d1dd5 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -55,8 +55,9 @@ public function setupLibs(): void { // build all libs foreach ($this->libs as $lib) { + $starttime = microtime(true); match ($lib->setup($this->getOption('rebuild', false))) { - LIB_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] setup success'), + LIB_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] setup success, took ' . round(microtime(true) - $starttime, 2) . ' s'), LIB_STATUS_ALREADY => logger()->notice('lib [' . $lib::NAME . '] already built'), LIB_STATUS_BUILD_FAILED => logger()->error('lib [' . $lib::NAME . '] build failed'), LIB_STATUS_INSTALL_FAILED => logger()->error('lib [' . $lib::NAME . '] install failed'), From 4b44c3adf718d71e0dd5c7b7ad0f2865c0f4872e Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 9 Jul 2024 00:44:03 +0800 Subject: [PATCH 27/43] Adjust shell debug log --- src/SPC/util/UnixShell.php | 5 ++++- src/globals/functions.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/SPC/util/UnixShell.php b/src/SPC/util/UnixShell.php index 1556336d4..16ae3f8c5 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -41,6 +41,7 @@ public function exec(string $cmd): UnixShell { /* @phpstan-ignore-next-line */ logger()->info(ConsoleColor::yellow('[EXEC] ') . ConsoleColor::green($cmd)); + logger()->debug('Executed at: ' . debug_backtrace()[0]['file'] . ':' . debug_backtrace()[0]['line']); if ($this->cd !== null) { $cmd = 'cd ' . escapeshellarg($this->cd) . ' && ' . $cmd; } @@ -57,8 +58,10 @@ public function execWithResult(string $cmd, bool $with_log = true): array /* @phpstan-ignore-next-line */ logger()->info(ConsoleColor::blue('[EXEC] ') . ConsoleColor::green($cmd)); } else { - logger()->debug('Running command with result: ' . $cmd); + /* @phpstan-ignore-next-line */ + logger()->debug(ConsoleColor::blue('[EXEC] ') . ConsoleColor::gray($cmd)); } + logger()->debug('Executed at: ' . debug_backtrace()[0]['file'] . ':' . debug_backtrace()[0]['line']); exec($cmd, $out, $code); return [$code, $out]; } diff --git a/src/globals/functions.php b/src/globals/functions.php index e61a8d6e1..2a9de6253 100644 --- a/src/globals/functions.php +++ b/src/globals/functions.php @@ -140,7 +140,7 @@ function f_passthru(string $cmd): ?bool if ($danger) { logger()->notice('Running dangerous command: ' . $cmd); } else { - logger()->debug('Running command with direct output: ' . $cmd); + logger()->debug('[PASSTHRU] ' . $cmd); } $ret = passthru($cmd, $code); if ($code !== 0) { From 8632a4e00561ecc4d8c9c2264622394f74b221c3 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 9 Jul 2024 00:44:14 +0800 Subject: [PATCH 28/43] Add onig as pre-built library --- config/source.json | 1 + 1 file changed, 1 insertion(+) diff --git a/config/source.json b/config/source.json index 6bdb8f8bf..88ec33733 100644 --- a/config/source.json +++ b/config/source.json @@ -532,6 +532,7 @@ "repo": "kkos/oniguruma", "match": "onig-.+\\.tar\\.gz", "prefer-stable": true, + "provide-pre-built": true, "license": { "type": "file", "path": "COPYING" From 491eb5c2f20fb0169a84ec1f71007d902cc8634e Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 9 Jul 2024 11:14:58 +0800 Subject: [PATCH 29/43] Fix pkgconf patch with space between '=' bug --- src/SPC/builder/traits/UnixLibraryTrait.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SPC/builder/traits/UnixLibraryTrait.php b/src/SPC/builder/traits/UnixLibraryTrait.php index b1df91946..d5a192096 100644 --- a/src/SPC/builder/traits/UnixLibraryTrait.php +++ b/src/SPC/builder/traits/UnixLibraryTrait.php @@ -75,10 +75,10 @@ public function patchPkgconfPrefix(array $files, int $patch_option = PKGCONF_PAT logger()->debug('Patching ' . $realpath); // replace prefix $file = FileSystem::readFile($realpath); - $file = ($patch_option & PKGCONF_PATCH_PREFIX) === PKGCONF_PATCH_PREFIX ? preg_replace('/^prefix=.*$/m', 'prefix=${pcfiledir}/../..', $file) : $file; - $file = ($patch_option & PKGCONF_PATCH_EXEC_PREFIX) === PKGCONF_PATCH_EXEC_PREFIX ? preg_replace('/^exec_prefix=.*$/m', 'exec_prefix=${prefix}', $file) : $file; - $file = ($patch_option & PKGCONF_PATCH_LIBDIR) === PKGCONF_PATCH_LIBDIR ? preg_replace('/^libdir=.*$/m', 'libdir=${prefix}/lib', $file) : $file; - $file = ($patch_option & PKGCONF_PATCH_INCLUDEDIR) === PKGCONF_PATCH_INCLUDEDIR ? preg_replace('/^includedir=.*$/m', 'includedir=${prefix}/include', $file) : $file; + $file = ($patch_option & PKGCONF_PATCH_PREFIX) === PKGCONF_PATCH_PREFIX ? preg_replace('/^prefix\s*=.*$/m', 'prefix=${pcfiledir}/../..', $file) : $file; + $file = ($patch_option & PKGCONF_PATCH_EXEC_PREFIX) === PKGCONF_PATCH_EXEC_PREFIX ? preg_replace('/^exec_prefix\s*=.*$/m', 'exec_prefix=${prefix}', $file) : $file; + $file = ($patch_option & PKGCONF_PATCH_LIBDIR) === PKGCONF_PATCH_LIBDIR ? preg_replace('/^libdir\s*=.*$/m', 'libdir=${prefix}/lib', $file) : $file; + $file = ($patch_option & PKGCONF_PATCH_INCLUDEDIR) === PKGCONF_PATCH_INCLUDEDIR ? preg_replace('/^includedir\s*=.*$/m', 'includedir=${prefix}/include', $file) : $file; $file = ($patch_option & PKGCONF_PATCH_CUSTOM) === PKGCONF_PATCH_CUSTOM && $custom_replace !== null ? preg_replace($custom_replace[0], $custom_replace[1], $file) : $file; FileSystem::writeFile($realpath, $file); } From 1c79cc9f615230352566fc4878e6603934e64625 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 9 Jul 2024 11:15:34 +0800 Subject: [PATCH 30/43] Provide icu pre-built binary --- config/source.json | 1 + src/SPC/builder/linux/library/icu.php | 4 ++++ src/SPC/builder/macos/library/icu.php | 4 ++++ src/SPC/builder/unix/library/icu.php | 23 +++++++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 src/SPC/builder/unix/library/icu.php diff --git a/config/source.json b/config/source.json index 88ec33733..cdbf2a4fb 100644 --- a/config/source.json +++ b/config/source.json @@ -199,6 +199,7 @@ "repo": "unicode-org/icu", "match": "icu4c.+-src\\.tgz", "prefer-stable": true, + "provide-pre-built": true, "license": { "type": "file", "path": "LICENSE" diff --git a/src/SPC/builder/linux/library/icu.php b/src/SPC/builder/linux/library/icu.php index 458ede5fc..79866525b 100644 --- a/src/SPC/builder/linux/library/icu.php +++ b/src/SPC/builder/linux/library/icu.php @@ -6,6 +6,8 @@ class icu extends LinuxLibraryBase { + use \SPC\builder\unix\library\icu; + public const NAME = 'icu'; protected function build(): void @@ -32,5 +34,7 @@ protected function build(): void ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") ->exec('make install'); + + $this->patchPkgconfPrefix(['icu-i18n.pc', 'icu-io.pc', 'icu-uc.pc'], PKGCONF_PATCH_PREFIX); } } diff --git a/src/SPC/builder/macos/library/icu.php b/src/SPC/builder/macos/library/icu.php index 13078c157..20e9c3686 100644 --- a/src/SPC/builder/macos/library/icu.php +++ b/src/SPC/builder/macos/library/icu.php @@ -6,6 +6,8 @@ class icu extends MacOSLibraryBase { + use \SPC\builder\unix\library\icu; + public const NAME = 'icu'; protected function build(): void @@ -16,5 +18,7 @@ protected function build(): void ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") ->exec('make install'); + + $this->patchPkgconfPrefix(['icu-i18n.pc', 'icu-io.pc', 'icu-uc.pc'], PKGCONF_PATCH_PREFIX); } } diff --git a/src/SPC/builder/unix/library/icu.php b/src/SPC/builder/unix/library/icu.php new file mode 100644 index 000000000..d1aa8dc1e --- /dev/null +++ b/src/SPC/builder/unix/library/icu.php @@ -0,0 +1,23 @@ + Date: Tue, 9 Jul 2024 11:21:20 +0800 Subject: [PATCH 31/43] Provide libcares pre-built binary --- config/source.json | 1 + src/SPC/builder/unix/library/libcares.php | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/config/source.json b/config/source.json index cdbf2a4fb..efd8568da 100644 --- a/config/source.json +++ b/config/source.json @@ -275,6 +275,7 @@ "repo": "c-ares/c-ares", "match": "c-ares-.+\\.tar\\.gz", "prefer-stable": true, + "provide-pre-built": true, "alt": { "type": "filelist", "url": "https://c-ares.org/download/", diff --git a/src/SPC/builder/unix/library/libcares.php b/src/SPC/builder/unix/library/libcares.php index ea56d8cd8..076a10c9d 100644 --- a/src/SPC/builder/unix/library/libcares.php +++ b/src/SPC/builder/unix/library/libcares.php @@ -26,8 +26,10 @@ protected function build(): void { shell()->cd($this->source_dir) ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv('./configure --prefix=' . BUILD_ROOT_PATH . ' --enable-static --disable-shared --disable-tests') + ->execWithEnv('./configure --prefix= --enable-static --disable-shared --disable-tests') ->execWithEnv("make -j {$this->builder->concurrency}") - ->exec('make install'); + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + + $this->patchPkgconfPrefix(['libcares.pc'], PKGCONF_PATCH_PREFIX); } } From 57dd174aff2a3e4482806582c61e26abec33fdb2 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 9 Jul 2024 15:05:53 +0800 Subject: [PATCH 32/43] Provide libevent, libiconv-win, libsodium, libwebp, libyaml, ncurses, readline, unixodbc, xz pre-built libs --- config/source.json | 9 +++++ src/SPC/builder/unix/library/libevent.php | 44 +++++++++++++++++++++ src/SPC/builder/unix/library/libsodium.php | 7 ++-- src/SPC/builder/unix/library/ncurses.php | 20 ++++++++++ src/SPC/builder/windows/library/libwebp.php | 7 ++++ 5 files changed, 84 insertions(+), 3 deletions(-) diff --git a/config/source.json b/config/source.json index efd8568da..6f7e1cb3f 100644 --- a/config/source.json +++ b/config/source.json @@ -291,6 +291,7 @@ "repo": "libevent/libevent", "match": "libevent.+\\.tar\\.gz", "prefer-stable": true, + "provide-pre-built": true, "license": { "type": "file", "path": "LICENSE" @@ -329,6 +330,7 @@ "type": "git", "rev": "master", "url": "https://github.com/static-php/libiconv-win.git", + "provide-pre-built": true, "license": { "type": "file", "path": "source/COPYING" @@ -386,6 +388,7 @@ "repo": "jedisct1/libsodium", "match": "libsodium-\\d+(\\.\\d+)*\\.tar\\.gz", "prefer-stable": true, + "provide-pre-built": true, "license": { "type": "file", "path": "LICENSE" @@ -437,6 +440,7 @@ "libwebp": { "type": "url", "url": "https://github.com/webmproject/libwebp/archive/refs/tags/v1.3.2.tar.gz", + "provide-pre-built": true, "license": { "type": "file", "path": "COPYING" @@ -464,6 +468,7 @@ "repo": "yaml/libyaml", "match": "yaml-.+\\.tar\\.gz", "prefer-stable": true, + "provide-pre-built": true, "license": { "type": "file", "path": "License" @@ -514,6 +519,7 @@ "type": "filelist", "url": "https://ftp.gnu.org/pub/gnu/ncurses/", "regex": "/href=\"(?ncurses-(?[^\"]+)\\.tar\\.gz)\"/", + "provide-pre-built": true, "license": { "type": "file", "path": "COPYING" @@ -629,6 +635,7 @@ "type": "filelist", "url": "https://ftp.gnu.org/pub/gnu/readline/", "regex": "/href=\"(?readline-(?[^\"]+)\\.tar\\.gz)\"/", + "provide-pre-built": true, "license": { "type": "file", "path": "COPYING" @@ -716,6 +723,7 @@ "unixodbc": { "type": "url", "url": "https://www.unixodbc.org/unixODBC-2.3.12.tar.gz", + "provide-pre-built": true, "license": { "type": "file", "path": "COPYING" @@ -746,6 +754,7 @@ "repo": "tukaani-project/xz", "match": "xz.+\\.tar\\.xz", "prefer-stable": true, + "provide-pre-built": true, "license": { "type": "file", "path": "COPYING" diff --git a/src/SPC/builder/unix/library/libevent.php b/src/SPC/builder/unix/library/libevent.php index b3114156c..2e80f32e7 100644 --- a/src/SPC/builder/unix/library/libevent.php +++ b/src/SPC/builder/unix/library/libevent.php @@ -10,12 +10,36 @@ trait libevent { + public function beforePack(): void + { + if (file_exists(BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake')) { + FileSystem::replaceFileRegex( + BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake', + '/set\(_IMPORT_PREFIX .*\)/m', + 'set(_IMPORT_PREFIX "{BUILD_ROOT_PATH}")' + ); + + FileSystem::replaceFileRegex( + BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake', + '/INTERFACE_INCLUDE_DIRECTORIES ".*"/m', + 'INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"' + ); + + FileSystem::replaceFileRegex( + BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake', + '/INTERFACE_LINK_LIBRARIES "libevent::core;.*"/m', + 'INTERFACE_LINK_LIBRARIES "libevent::core;${_IMPORT_PREFIX}/lib/libssl.a;${_IMPORT_PREFIX}/lib/libcrypto.a"' + ); + } + } + /** * @throws RuntimeException * @throws FileSystemException */ protected function build(): void { + [$lib, $include, $destdir] = SEPARATED_PATH; // CMake needs a clean build directory FileSystem::resetDir($this->source_dir . '/build'); // Start build @@ -36,5 +60,25 @@ protected function build(): void ) ->execWithEnv("cmake --build . -j {$this->builder->concurrency}") ->exec('make install'); + + $this->patchPkgconfPrefix(['libevent.pc', 'libevent_core.pc', 'libevent_extra.pc', 'libevent_openssl.pc']); + + $this->patchPkgconfPrefix( + ['libevent_openssl.pc'], + PKGCONF_PATCH_CUSTOM, + [ + '/Libs.private:.*/m', + 'Libs.private: -lssl -lcrypto', + ] + ); + } + + protected function install(): void + { + FileSystem::replaceFileStr( + BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake', + '{BUILD_ROOT_PATH}', + BUILD_ROOT_PATH + ); } } diff --git a/src/SPC/builder/unix/library/libsodium.php b/src/SPC/builder/unix/library/libsodium.php index 555b48d6b..b24d52b7a 100644 --- a/src/SPC/builder/unix/library/libsodium.php +++ b/src/SPC/builder/unix/library/libsodium.php @@ -8,11 +8,12 @@ trait libsodium { protected function build(): void { - $root = BUILD_ROOT_PATH; shell()->cd($this->source_dir) - ->exec("./configure --enable-static --disable-shared --prefix={$root}") + ->exec('./configure --enable-static --disable-shared --prefix=') ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") - ->exec('make install'); + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + + $this->patchPkgconfPrefix(['libsodium.pc'], PKGCONF_PATCH_PREFIX); } } diff --git a/src/SPC/builder/unix/library/ncurses.php b/src/SPC/builder/unix/library/ncurses.php index 29a808850..721d5de6f 100644 --- a/src/SPC/builder/unix/library/ncurses.php +++ b/src/SPC/builder/unix/library/ncurses.php @@ -4,10 +4,13 @@ namespace SPC\builder\unix\library; +use SPC\store\FileSystem; + trait ncurses { protected function build(): void { + $filelist = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true); shell()->cd($this->source_dir) ->exec( './configure ' . @@ -32,5 +35,22 @@ protected function build(): void ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") ->exec('make install'); + + $final = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true); + // Remove the new files + $new_files = array_diff($final, $filelist); + foreach ($new_files as $file) { + @unlink(BUILD_BIN_PATH . '/' . $file); + } + + shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf share/terminfo'); + shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf lib/terminfo'); + + $pkgconf_list = ['form.pc', 'menu.pc', 'ncurses++.pc', 'ncurses.pc', 'panel.pc', 'tic.pc']; + $this->patchPkgconfPrefix($pkgconf_list); + + foreach ($pkgconf_list as $pkgconf) { + FileSystem::replaceFileStr(BUILD_LIB_PATH . '/pkgconfig/' . $pkgconf, '-L' . BUILD_LIB_PATH, '-L${libdir}'); + } } } diff --git a/src/SPC/builder/windows/library/libwebp.php b/src/SPC/builder/windows/library/libwebp.php index c09b76d62..96813e68e 100644 --- a/src/SPC/builder/windows/library/libwebp.php +++ b/src/SPC/builder/windows/library/libwebp.php @@ -41,5 +41,12 @@ protected function build(): void $this->builder->makeSimpleWrapper('cmake'), "--build build --config Release --target install -j{$this->builder->concurrency}" ); + + // Actually we don't need pkgconf in windows, but for packing, we still need patching prefix. + // for libsharpyuv, libwebp, libwebpdecoder, libwebpdemux + FileSystem::replaceFileRegex(BUILD_LIB_PATH . '\pkgconfig\libsharpyuv.pc', '/^prefix=.*/m', 'prefix=${pcfiledir}/../..'); + FileSystem::replaceFileRegex(BUILD_LIB_PATH . '\pkgconfig\libwebp.pc', '/^prefix=.*/m', 'prefix=${pcfiledir}/../..'); + FileSystem::replaceFileRegex(BUILD_LIB_PATH . '\pkgconfig\libwebpdecoder.pc', '/^prefix=.*/m', 'prefix=${pcfiledir}/../..'); + FileSystem::replaceFileRegex(BUILD_LIB_PATH . '\pkgconfig\libwebpdemux.pc', '/^prefix=.*/m', 'prefix=${pcfiledir}/../..'); } } From 942786f2d6909ae6188e68fb4c7520b4088bf0ec Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 9 Jul 2024 16:14:33 +0800 Subject: [PATCH 33/43] Add pkgroot for spc-alpine-docker --- bin/spc-alpine-docker | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bin/spc-alpine-docker b/bin/spc-alpine-docker index 5b905e668..6b56f7606 100755 --- a/bin/spc-alpine-docker +++ b/bin/spc-alpine-docker @@ -109,6 +109,22 @@ else INTERACT='' fi +# Mounting volumes +MOUNT_LIST="" +# shellcheck disable=SC2089 +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/config:/app/config" +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/src:/app/src" +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/buildroot:/app/buildroot" +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/source:/app/source" +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/dist:/app/dist" +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/downloads:/app/downloads" +MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot" + +echo "$MOUNT_LIST" +exit 0 + # Run docker # shellcheck disable=SC2068 -$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" -v "$(pwd)"/config:/app/config -v "$(pwd)"/src:/app/src -v "$(pwd)"/buildroot:/app/buildroot -v "$(pwd)"/source:/app/source -v "$(pwd)"/dist:/app/dist -v "$(pwd)"/downloads:/app/downloads cwcc-spc-$SPC_USE_ARCH bin/spc $@ +# shellcheck disable=SC2086 +# shellcheck disable=SC2090 +$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH bin/spc $@ From 65ace418840a36af0f67e09fc993c50236f2f339 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 9 Jul 2024 16:15:18 +0800 Subject: [PATCH 34/43] Add pkgroot for spc-alpine-docker --- bin/spc-alpine-docker | 3 --- 1 file changed, 3 deletions(-) diff --git a/bin/spc-alpine-docker b/bin/spc-alpine-docker index 6b56f7606..5effefd66 100755 --- a/bin/spc-alpine-docker +++ b/bin/spc-alpine-docker @@ -120,9 +120,6 @@ MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/dist:/app/dist" MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/downloads:/app/downloads" MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot" -echo "$MOUNT_LIST" -exit 0 - # Run docker # shellcheck disable=SC2068 # shellcheck disable=SC2086 From 1d7ded0390b903c01e3180e8a34b165ec7c6fb3d Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 9 Jul 2024 18:20:27 +0800 Subject: [PATCH 35/43] Fix pre-built openssl cannot find source in openssl ext patch --- src/SPC/builder/extension/openssl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/extension/openssl.php b/src/SPC/builder/extension/openssl.php index 44d0c5c72..13f58c604 100644 --- a/src/SPC/builder/extension/openssl.php +++ b/src/SPC/builder/extension/openssl.php @@ -13,7 +13,7 @@ class openssl extends Extension public function patchBeforeMake(): bool { // patch openssl3 with php8.0 bug - if (file_exists(SOURCE_PATH . '/openssl/VERSION.dat') && $this->builder->getPHPVersionID() < 80100) { + if ($this->builder->getPHPVersionID() < 80100) { $openssl_c = file_get_contents(SOURCE_PATH . '/php-src/ext/openssl/openssl.c'); $openssl_c = preg_replace('/REGISTER_LONG_CONSTANT\s*\(\s*"OPENSSL_SSLV23_PADDING"\s*.+;/', '', $openssl_c); file_put_contents(SOURCE_PATH . '/php-src/ext/openssl/openssl.c', $openssl_c); From 54573dfbbe992fd9da98c150e2906025ab539bb0 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 9 Jul 2024 19:31:00 +0800 Subject: [PATCH 36/43] Fix swoole with event extension conflict bug --- src/SPC/builder/extension/swoole.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/SPC/builder/extension/swoole.php b/src/SPC/builder/extension/swoole.php index e95969e32..78aaf339e 100644 --- a/src/SPC/builder/extension/swoole.php +++ b/src/SPC/builder/extension/swoole.php @@ -5,11 +5,24 @@ namespace SPC\builder\extension; use SPC\builder\Extension; +use SPC\builder\macos\MacOSBuilder; +use SPC\store\FileSystem; use SPC\util\CustomExt; #[CustomExt('swoole')] class swoole extends Extension { + public function patchBeforeMake(): bool + { + if ($this->builder instanceof MacOSBuilder) { + // Fix swoole with event extension conflict bug + $util_path = shell()->execWithResult('xcrun --show-sdk-path', false)[1][0] . '/usr/include/util.h'; + FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/swoole/thirdparty/php/standard/proc_open.cc', 'include ', 'include "' . $util_path . '"'); + return true; + } + return false; + } + public function getExtVersion(): ?string { // Get version from source directory From 01c78aa92a48a4fcd2fcead1c686fff9de2cd9a6 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 9 Jul 2024 19:31:44 +0800 Subject: [PATCH 37/43] Remove redundant license debug msg --- src/SPC/util/LicenseDumper.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SPC/util/LicenseDumper.php b/src/SPC/util/LicenseDumper.php index 4c9d63fe4..42ae67469 100644 --- a/src/SPC/util/LicenseDumper.php +++ b/src/SPC/util/LicenseDumper.php @@ -129,7 +129,6 @@ private function loadSourceFile(string $source_name, int $index, ?string $in_pat } if (file_exists(BUILD_ROOT_PATH . '/source-licenses/' . $source_name . '/' . $index . '.txt')) { - logger()->debug('source [' . $source_name . '] license file [' . $index . ':' . $in_path . '] not exist, use installed version instead'); return file_get_contents(BUILD_ROOT_PATH . '/source-licenses/' . $source_name . '/' . $index . '.txt'); } From abdbaa1a81586e6e0564f5efddac661a5efff651 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 12 Jul 2024 13:44:56 +0800 Subject: [PATCH 38/43] Remove libiconv-win pre-built --- config/source.json | 1 - 1 file changed, 1 deletion(-) diff --git a/config/source.json b/config/source.json index 6f7e1cb3f..e1909f6b8 100644 --- a/config/source.json +++ b/config/source.json @@ -330,7 +330,6 @@ "type": "git", "rev": "master", "url": "https://github.com/static-php/libiconv-win.git", - "provide-pre-built": true, "license": { "type": "file", "path": "source/COPYING" From 4e26dc8ab9f9c031469ea7bc80c1c7e62c749167 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 12 Jul 2024 13:50:54 +0800 Subject: [PATCH 39/43] Disable libyuv for libavif --- src/SPC/builder/unix/library/libavif.php | 2 +- src/SPC/builder/windows/library/libavif.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/libavif.php b/src/SPC/builder/unix/library/libavif.php index c427094ec..f8fcdbb87 100644 --- a/src/SPC/builder/unix/library/libavif.php +++ b/src/SPC/builder/unix/library/libavif.php @@ -23,7 +23,7 @@ protected function build(): void // Start build shell()->cd($this->source_dir . '/build') ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF ..") + ->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DAVIF_LIBYUV=OFF ..") ->execWithEnv("cmake --build . -j {$this->builder->concurrency}") ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); // patch pkgconfig diff --git a/src/SPC/builder/windows/library/libavif.php b/src/SPC/builder/windows/library/libavif.php index 0b8390741..86f6748a2 100644 --- a/src/SPC/builder/windows/library/libavif.php +++ b/src/SPC/builder/windows/library/libavif.php @@ -26,6 +26,7 @@ protected function build(): void '-DBUILD_SHARED_LIBS=OFF ' . '-DAVIF_BUILD_APPS=OFF ' . '-DAVIF_BUILD_TESTS=OFF ' . + '-DAVIF_LIBYUV=OFF ' . '-DAVID_ENABLE_GTEST=OFF ' . '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' ) From 483ecd7e9bff73938bcf7fdcecceb3dc7b6399f0 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 12 Jul 2024 14:07:54 +0800 Subject: [PATCH 40/43] Fix opcache for windows not build bug --- config/ext.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/ext.json b/config/ext.json index 79936c578..c521a61f1 100644 --- a/config/ext.json +++ b/config/ext.json @@ -383,7 +383,7 @@ }, "opcache": { "type": "builtin", - "arg-type": "custom" + "arg-type-unix": "custom" }, "openssl": { "notes": true, From d796d5a3e5253930fadb06e2b8339c4c2f73a3ac Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 13 Jul 2024 21:10:05 +0800 Subject: [PATCH 41/43] Tests --- .github/workflows/tests.yml | 2 +- src/globals/test-extensions.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ed2c0134b..1088c1046 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -190,4 +190,4 @@ jobs: - name: "Run Build Tests (build, windows)" if: matrix.os == 'windows-latest' - run: bin/spc build "$(php src/globals/test-extensions.php extensions)" $(php src/globals/test-extensions.php zts) $(php src/globals/test-extensions.php no_strip) $env:UPX_CMD --with-libs="$(php src/globals/test-extensions.php libs)" --build-cli --build-micro --debug --enable-micro-win32 \ No newline at end of file + run: bin/spc build "$(php src/globals/test-extensions.php extensions)" $(php src/globals/test-extensions.php zts) $(php src/globals/test-extensions.php no_strip) $env:UPX_CMD --with-libs="$(php src/globals/test-extensions.php libs)" --build-cli --build-micro --debug \ No newline at end of file diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 4e81a40c1..018838e27 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -19,13 +19,13 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'openssl', - 'Windows' => 'mbstring,pdo_sqlite,openssl', + 'Linux', 'Darwin' => 'swoole,bz2,gmp,intl,password-argon2,gd,mbregex,iconv,redis,sodium,yaml,readline,openssl,sqlite3,sqlsrv,zip,zlib', + 'Windows' => 'amqp,apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,ds,exif,ffi,fileinfo,filter,ftp,gd,iconv,libxml,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pdo,pdo_mysql,pdo_sqlite,pdo_sqlsrv,phar,rar,session,shmop,simdjson,simplexml,soap,sockets,sqlite3,sqlsrv,ssh2,swow,sysvshm,tokenizer,xml,xmlreader,xmlwriter,yac,yaml,zip,zlib', }; // If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`). $with_libs = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => '', + 'Linux', 'Darwin' => 'brotli,bip2,gmp,icu,libargon2,libavif,libcares,libevent,libiconv,liblz4,libpng,libsodium,libtiff,libwebp,libyaml,ncurses,onig,openssl,pkg-config,readline,sqlite,unixodbc,xz,zlib', 'Windows' => '', }; @@ -33,7 +33,7 @@ // You can use `common`, `bulk`, `minimal` or `none`. // note: combination is only available for *nix platform. Windows must use `none` combination $base_combination = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'minimal', + 'Linux', 'Darwin' => 'none', 'Windows' => 'none', }; From ddea35f3fee92a519a4dcb51d3a4832676bf6e1f Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 13 Jul 2024 21:12:23 +0800 Subject: [PATCH 42/43] Tests pre-built feature --- .github/workflows/tests.yml | 2 +- config/lib.json | 1362 +++++++++++++++---------------- src/globals/test-extensions.php | 2 +- 3 files changed, 683 insertions(+), 683 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1088c1046..60fd50b20 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -176,7 +176,7 @@ jobs: - name: "Run Build Tests (download)" run: | - bin/spc download --for-extensions="$(php src/globals/test-extensions.php extensions)" --for-libs="$(php src/globals/test-extensions.php libs)" --with-php=${{ matrix.php }} --ignore-cache-sources=php-src --debug --retry=5 --shallow-clone + bin/spc download --for-extensions="$(php src/globals/test-extensions.php extensions)" --for-libs="$(php src/globals/test-extensions.php libs)" --with-php=${{ matrix.php }} --ignore-cache-sources=php-src --debug --retry=5 --shallow-clone --prefer-pre-built - name: "Download pre-built libraries for pkg-config" if: matrix.os != 'windows-latest' diff --git a/config/lib.json b/config/lib.json index faaef8656..84441f52b 100644 --- a/config/lib.json +++ b/config/lib.json @@ -1,681 +1,681 @@ -{ - "brotli": { - "source": "brotli", - "static-libs-unix": [ - "libbrotlidec.a", - "libbrotlienc.a", - "libbrotlicommon.a" - ], - "static-libs-windows": [ - "brotlicommon.lib", - "brotlienc.lib", - "brotlidec.lib" - ], - "headers": [ - "brotli" - ] - }, - "bzip2": { - "source": "bzip2", - "static-libs-unix": [ - "libbz2.a" - ], - "static-libs-windows": [ - "libbz2.lib", - "libbz2_a.lib" - ], - "headers": [ - "bzlib.h" - ] - }, - "curl": { - "source": "curl", - "static-libs-unix": [ - "libcurl.a" - ], - "static-libs-windows": [ - "libcurl_a.lib" - ], - "headers": [ - "curl" - ], - "lib-depends-unix": [ - "openssl", - "zlib" - ], - "lib-depends-windows": [ - "openssl", - "zlib", - "libssh2", - "nghttp2" - ], - "lib-suggests-unix": [ - "libssh2", - "brotli", - "nghttp2", - "zstd" - ], - "lib-suggests-windows": [ - "brotli", - "zstd" - ], - "frameworks": [ - "CoreFoundation", - "CoreServices", - "SystemConfiguration" - ] - }, - "freetype": { - "source": "freetype", - "static-libs-unix": [ - "libfreetype.a" - ], - "static-libs-windows": [ - "libfreetype_a.lib" - ], - "headers-unix": [ - "freetype2/freetype/freetype.h", - "freetype2/ft2build.h" - ], - "lib-depends": [ - "zlib" - ], - "lib-suggests": [ - "libpng", - "bzip2", - "brotli" - ] - }, - "gettext": { - "source": "gettext", - "static-libs-unix": [ - "libintl.a" - ], - "lib-depends": [ - "libiconv" - ], - "lib-suggests": [ - "ncurses", - "libxml2" - ], - "frameworks": [ - "CoreFoundation" - ] - }, - "glfw": { - "source": "ext-glfw", - "static-libs-unix": [ - "libglfw3.a" - ], - "frameworks": [ - "CoreVideo", - "OpenGL", - "Cocoa", - "IOKit" - ] - }, - "gmp": { - "source": "gmp", - "static-libs-unix": [ - "libgmp.a" - ], - "static-libs-windows": [ - "libgmp.lib" - ], - "headers": [ - "gmp.h" - ] - }, - "icu": { - "source": "icu", - "cpp-library": true, - "static-libs-unix": [ - "libicui18n.a", - "libicuio.a", - "libicuuc.a", - "libicudata.a" - ] - }, - "imagemagick": { - "source": "imagemagick", - "static-libs-unix": [ - "libMagick++-7.Q16HDRI.a", - "libMagickWand-7.Q16HDRI.a", - "libMagickCore-7.Q16HDRI.a" - ], - "lib-depends": [ - "zlib", - "libpng", - "libjpeg", - "libwebp", - "freetype", - "libtiff" - ], - "lib-suggests": [ - "zstd", - "xz", - "bzip2", - "libzip", - "libxml2" - ] - }, - "imap": { - "source": "imap", - "static-libs-unix": [ - "libc-client.a" - ], - "lib-suggests": [ - "openssl" - ] - }, - "ldap": { - "source": "ldap", - "static-libs-unix": [ - "liblber.a", - "libldap.a" - ], - "lib-depends": [ - "openssl", - "zlib", - "gmp", - "libsodium" - ] - }, - "libargon2": { - "source": "libargon2", - "static-libs-unix": [ - "libargon2.a" - ] - }, - "libavif": { - "source": "libavif", - "static-libs-unix": [ - "libavif.a" - ], - "static-libs-windows": [ - "avif.lib" - ] - }, - "libcares": { - "source": "libcares", - "static-libs-unix": [ - "libcares.a" - ], - "headers-unix": [ - "ares.h", - "ares_dns.h", - "ares_nameser.h", - "ares_rules.h" - ] - }, - "libevent": { - "source": "libevent", - "static-libs-unix": [ - "libevent.a", - "libevent_core.a", - "libevent_extra.a", - "libevent_openssl.a" - ], - "lib-depends": [ - "openssl" - ] - }, - "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" - ] - }, - "libffi-win": { - "source": "libffi-win", - "static-libs-windows": [ - "libffi.lib" - ], - "headers-windows": [ - "ffi.h", - "ffitarget.h", - "fficonfig.h" - ] - }, - "libiconv": { - "source": "libiconv", - "static-libs-unix": [ - "libiconv.a", - "libcharset.a" - ], - "headers": [ - "iconv.h", - "libcharset.h", - "localcharset.h" - ] - }, - "libiconv-win": { - "source": "libiconv-win", - "static-libs-windows": [ - "libiconv.lib", - "libiconv_a.lib" - ] - }, - "libjpeg": { - "source": "libjpeg", - "static-libs-unix": [ - "libjpeg.a", - "libturbojpeg.a" - ], - "static-libs-windows": [ - "libjpeg_a.lib" - ], - "lib-suggests-windows": [ - "zlib" - ] - }, - "liblz4": { - "source": "liblz4", - "static-libs-unix": [ - "liblz4.a" - ] - }, - "libmemcached": { - "source": "libmemcached", - "static-libs-unix": [ - "libmemcached.a", - "libmemcachedutil.a" - ] - }, - "libpng": { - "source": "libpng", - "static-libs-unix": [ - "libpng16.a" - ], - "static-libs-windows": [ - "libpng16_static.lib", - "libpng_a.lib" - ], - "headers-unix": [ - "png.h", - "pngconf.h", - "pnglibconf.h" - ], - "headers-windows": [ - "png.h", - "pngconf.h" - ], - "lib-depends": [ - "zlib" - ] - }, - "librabbitmq": { - "source": "librabbitmq", - "static-libs-unix": [ - "librabbitmq.a" - ], - "static-libs-windows": [ - "rabbitmq.4.lib" - ], - "lib-depends": [ - "openssl" - ] - }, - "libsodium": { - "source": "libsodium", - "static-libs-unix": [ - "libsodium.a" - ] - }, - "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" - ] - }, - "libtiff": { - "source": "libtiff", - "static-libs-unix": [ - "libtiff.a" - ] - }, - "libuuid": { - "source": "libuuid", - "static-libs-unix": [ - "libuuid.a" - ], - "headers": [ - "uuid/uuid.h" - ] - }, - "libuv": { - "source": "libuv", - "static-libs-unix": [ - "libuv.a" - ] - }, - "libwebp": { - "source": "libwebp", - "static-libs-unix": [ - "libwebp.a", - "libwebpdecoder.a", - "libwebpdemux.a", - "libwebpmux.a", - "libsharpyuv.a" - ], - "static-libs-windows": [ - "libwebp.lib", - "libwebpdecoder.lib", - "libwebpdemux.lib", - "libsharpyuv.lib" - ] - }, - "libxml2": { - "source": "libxml2", - "static-libs-unix": [ - "libxml2.a" - ], - "static-libs-windows": [ - "libxml2s.lib", - "libxml2_a.lib" - ], - "headers": [ - "libxml2" - ], - "lib-depends-unix": [ - "libiconv" - ], - "lib-suggests-unix": [ - "xz", - "icu", - "zlib" - ], - "lib-depends-windows": [ - "libiconv-win" - ], - "lib-suggests-windows": [ - "zlib" - ] - }, - "libxslt": { - "source": "libxslt", - "static-libs-unix": [ - "libxslt.a", - "libexslt.a" - ], - "lib-depends": [ - "libxml2" - ] - }, - "libyaml": { - "source": "libyaml", - "static-libs-unix": [ - "libyaml.a" - ], - "static-libs-windows": [ - "yaml.lib" - ], - "headers": [ - "yaml.h" - ] - }, - "libzip": { - "source": "libzip", - "static-libs-unix": [ - "libzip.a" - ], - "static-libs-windows": [ - "zip.lib", - "libzip_a.lib" - ], - "headers": [ - "zip.h", - "zipconf.h" - ], - "lib-depends-unix": [ - "zlib" - ], - "lib-suggests-unix": [ - "bzip2", - "xz", - "zstd", - "openssl" - ], - "lib-depends-windows": [ - "zlib", - "bzip2", - "xz" - ], - "lib-suggests-windows": [ - "zstd", - "openssl" - ] - }, - "ncurses": { - "source": "ncurses", - "static-libs-unix": [ - "libncurses.a" - ] - }, - "nghttp2": { - "source": "nghttp2", - "static-libs-unix": [ - "libnghttp2.a" - ], - "static-libs-windows": [ - "nghttp2.lib" - ], - "headers": [ - "nghttp2" - ], - "lib-depends": [ - "zlib", - "openssl" - ], - "lib-suggests": [ - "libxml2" - ] - }, - "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" - ] - }, - "pkg-config": { - "source": "pkg-config" - }, - "postgresql": { - "source": "postgresql", - "static-libs-unix": [ - "libpq.a", - "libpgport.a", - "libpgcommon.a" - ], - "lib-depends": [ - "libiconv", - "libxml2", - "openssl", - "zlib", - "readline" - ], - "lib-suggests": [ - "icu", - "libxslt", - "ldap", - "zstd" - ] - }, - "pthreads4w": { - "source": "pthreads4w", - "static-libs-windows": [ - "libpthreadVC3.lib" - ] - }, - "qdbm": { - "source": "qdbm", - "static-libs-unix": [ - "libqdbm.a" - ], - "static-libs-windows": [ - "qdbm_a.lib" - ], - "headers-windows": [ - "depot.h" - ] - }, - "readline": { - "source": "readline", - "static-libs-unix": [ - "libreadline.a" - ], - "lib-depends": [ - "ncurses" - ] - }, - "snappy": { - "source": "snappy", - "static-libs-unix": [ - "libsnappy.a" - ], - "headers-unix": [ - "snappy.h", - "snappy-c.h", - "snappy-sinksource.h", - "snappy-stubs-public.h" - ], - "lib-depends": [ - "zlib" - ] - }, - "sqlite": { - "source": "sqlite", - "static-libs-unix": [ - "libsqlite3.a" - ], - "static-libs-windows": [ - "libsqlite3_a.lib" - ], - "headers": [ - "sqlite3.h", - "sqlite3ext.h" - ] - }, - "tidy": { - "source": "tidy", - "static-libs-unix": [ - "libtidy.a" - ] - }, - "unixodbc": { - "source": "unixodbc", - "static-libs-unix": [ - "libodbc.a", - "libodbccr.a", - "libodbcinst.a" - ], - "lib-depends": [ - "libiconv" - ] - }, - "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-unix": [ - "libiconv" - ] - }, - "zlib": { - "source": "zlib", - "static-libs-unix": [ - "libz.a" - ], - "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" + ], + "static-libs-windows": [ + "brotlicommon.lib", + "brotlienc.lib", + "brotlidec.lib" + ], + "headers": [ + "brotli" + ] + }, + "bzip2": { + "source": "bzip2", + "static-libs-unix": [ + "libbz2.a" + ], + "static-libs-windows": [ + "libbz2.lib", + "libbz2_a.lib" + ], + "headers": [ + "bzlib.h" + ] + }, + "curl": { + "source": "curl", + "static-libs-unix": [ + "libcurl.a" + ], + "static-libs-windows": [ + "libcurl_a.lib" + ], + "headers": [ + "curl" + ], + "lib-depends-unix": [ + "openssl", + "zlib" + ], + "lib-depends-windows": [ + "openssl", + "zlib", + "libssh2", + "nghttp2" + ], + "lib-suggests-unix": [ + "libssh2", + "brotli", + "nghttp2", + "zstd" + ], + "lib-suggests-windows": [ + "brotli", + "zstd" + ], + "frameworks": [ + "CoreFoundation", + "CoreServices", + "SystemConfiguration" + ] + }, + "freetype": { + "source": "freetype", + "static-libs-unix": [ + "libfreetype.a" + ], + "static-libs-windows": [ + "libfreetype_a.lib" + ], + "headers-unix": [ + "freetype2/freetype/freetype.h", + "freetype2/ft2build.h" + ], + "lib-depends": [ + "zlib" + ], + "lib-suggests": [ + "libpng", + "bzip2", + "brotli" + ] + }, + "gettext": { + "source": "gettext", + "static-libs-unix": [ + "libintl.a" + ], + "lib-depends": [ + "libiconv" + ], + "lib-suggests": [ + "ncurses", + "libxml2" + ], + "frameworks": [ + "CoreFoundation" + ] + }, + "glfw": { + "source": "ext-glfw", + "static-libs-unix": [ + "libglfw3.a" + ], + "frameworks": [ + "CoreVideo", + "OpenGL", + "Cocoa", + "IOKit" + ] + }, + "gmp": { + "source": "gmp", + "static-libs-unix": [ + "libgmp.a" + ], + "static-libs-windows": [ + "libgmp.lib" + ], + "headers": [ + "gmp.h" + ] + }, + "icu": { + "source": "icu", + "cpp-library": true, + "static-libs-unix": [ + "libicui18n.a", + "libicuio.a", + "libicuuc.a", + "libicudata.a" + ] + }, + "imagemagick": { + "source": "imagemagick", + "static-libs-unix": [ + "libMagick++-7.Q16HDRI.a", + "libMagickWand-7.Q16HDRI.a", + "libMagickCore-7.Q16HDRI.a" + ], + "lib-depends": [ + "zlib", + "libpng", + "libjpeg", + "libwebp", + "freetype", + "libtiff" + ], + "lib-suggests": [ + "zstd", + "xz", + "bzip2", + "libzip", + "libxml2" + ] + }, + "imap": { + "source": "imap", + "static-libs-unix": [ + "libc-client.a" + ], + "lib-suggests": [ + "openssl" + ] + }, + "ldap": { + "source": "ldap", + "static-libs-unix": [ + "liblber.a", + "libldap.a" + ], + "lib-depends": [ + "openssl", + "zlib", + "gmp", + "libsodium" + ] + }, + "libargon2": { + "source": "libargon2", + "static-libs-unix": [ + "libargon2.a" + ] + }, + "libavif": { + "source": "libavif", + "static-libs-unix": [ + "libavif.a" + ], + "static-libs-windows": [ + "avif.lib" + ] + }, + "libcares": { + "source": "libcares", + "static-libs-unix": [ + "libcares.a" + ], + "headers-unix": [ + "ares.h", + "ares_dns.h", + "ares_nameser.h", + "ares_rules.h" + ] + }, + "libevent": { + "source": "libevent", + "static-libs-unix": [ + "libevent.a", + "libevent_core.a", + "libevent_extra.a", + "libevent_openssl.a" + ], + "lib-depends": [ + "openssl" + ] + }, + "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" + ] + }, + "libffi-win": { + "source": "libffi-win", + "static-libs-windows": [ + "libffi.lib" + ], + "headers-windows": [ + "ffi.h", + "ffitarget.h", + "fficonfig.h" + ] + }, + "libiconv": { + "source": "libiconv", + "static-libs-unix": [ + "libiconv.a", + "libcharset.a" + ], + "headers": [ + "iconv.h", + "libcharset.h", + "localcharset.h" + ] + }, + "libiconv-win": { + "source": "libiconv-win", + "static-libs-windows": [ + "libiconv.lib", + "libiconv_a.lib" + ] + }, + "libjpeg": { + "source": "libjpeg", + "static-libs-unix": [ + "libjpeg.a", + "libturbojpeg.a" + ], + "static-libs-windows": [ + "libjpeg_a.lib" + ], + "lib-suggests-windows": [ + "zlib" + ] + }, + "liblz4": { + "source": "liblz4", + "static-libs-unix": [ + "liblz4.a" + ] + }, + "libmemcached": { + "source": "libmemcached", + "static-libs-unix": [ + "libmemcached.a", + "libmemcachedutil.a" + ] + }, + "libpng": { + "source": "libpng", + "static-libs-unix": [ + "libpng16.a" + ], + "static-libs-windows": [ + "libpng16_static.lib", + "libpng_a.lib" + ], + "headers-unix": [ + "png.h", + "pngconf.h", + "pnglibconf.h" + ], + "headers-windows": [ + "png.h", + "pngconf.h" + ], + "lib-depends": [ + "zlib" + ] + }, + "librabbitmq": { + "source": "librabbitmq", + "static-libs-unix": [ + "librabbitmq.a" + ], + "static-libs-windows": [ + "rabbitmq.4.lib" + ], + "lib-depends": [ + "openssl" + ] + }, + "libsodium": { + "source": "libsodium", + "static-libs-unix": [ + "libsodium.a" + ] + }, + "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" + ] + }, + "libtiff": { + "source": "libtiff", + "static-libs-unix": [ + "libtiff.a" + ] + }, + "libuuid": { + "source": "libuuid", + "static-libs-unix": [ + "libuuid.a" + ], + "headers": [ + "uuid/uuid.h" + ] + }, + "libuv": { + "source": "libuv", + "static-libs-unix": [ + "libuv.a" + ] + }, + "libwebp": { + "source": "libwebp", + "static-libs-unix": [ + "libwebp.a", + "libwebpdecoder.a", + "libwebpdemux.a", + "libwebpmux.a", + "libsharpyuv.a" + ], + "static-libs-windows": [ + "libwebp.lib", + "libwebpdecoder.lib", + "libwebpdemux.lib", + "libsharpyuv.lib" + ] + }, + "libxml2": { + "source": "libxml2", + "static-libs-unix": [ + "libxml2.a" + ], + "static-libs-windows": [ + "libxml2s.lib", + "libxml2_a.lib" + ], + "headers": [ + "libxml2" + ], + "lib-depends-unix": [ + "libiconv" + ], + "lib-suggests-unix": [ + "xz", + "icu", + "zlib" + ], + "lib-depends-windows": [ + "libiconv-win" + ], + "lib-suggests-windows": [ + "zlib" + ] + }, + "libxslt": { + "source": "libxslt", + "static-libs-unix": [ + "libxslt.a", + "libexslt.a" + ], + "lib-depends": [ + "libxml2" + ] + }, + "libyaml": { + "source": "libyaml", + "static-libs-unix": [ + "libyaml.a" + ], + "static-libs-windows": [ + "yaml.lib" + ], + "headers": [ + "yaml.h" + ] + }, + "libzip": { + "source": "libzip", + "static-libs-unix": [ + "libzip.a" + ], + "static-libs-windows": [ + "zip.lib", + "libzip_a.lib" + ], + "headers": [ + "zip.h", + "zipconf.h" + ], + "lib-depends-unix": [ + "zlib" + ], + "lib-suggests-unix": [ + "bzip2", + "xz", + "zstd", + "openssl" + ], + "lib-depends-windows": [ + "zlib", + "bzip2", + "xz" + ], + "lib-suggests-windows": [ + "zstd", + "openssl" + ] + }, + "ncurses": { + "source": "ncurses", + "static-libs-unix": [ + "libncurses.a" + ] + }, + "nghttp2": { + "source": "nghttp2", + "static-libs-unix": [ + "libnghttp2.a" + ], + "static-libs-windows": [ + "nghttp2.lib" + ], + "headers": [ + "nghttp2" + ], + "lib-depends": [ + "zlib", + "openssl" + ], + "lib-suggests": [ + "libxml2" + ] + }, + "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" + ] + }, + "pkg-config": { + "source": "pkg-config" + }, + "postgresql": { + "source": "postgresql", + "static-libs-unix": [ + "libpq.a", + "libpgport.a", + "libpgcommon.a" + ], + "lib-depends": [ + "libiconv", + "libxml2", + "openssl", + "zlib", + "readline" + ], + "lib-suggests": [ + "icu", + "libxslt", + "ldap", + "zstd" + ] + }, + "pthreads4w": { + "source": "pthreads4w", + "static-libs-windows": [ + "libpthreadVC3.lib" + ] + }, + "qdbm": { + "source": "qdbm", + "static-libs-unix": [ + "libqdbm.a" + ], + "static-libs-windows": [ + "qdbm_a.lib" + ], + "headers-windows": [ + "depot.h" + ] + }, + "readline": { + "source": "readline", + "static-libs-unix": [ + "libreadline.a" + ], + "lib-depends": [ + "ncurses" + ] + }, + "snappy": { + "source": "snappy", + "static-libs-unix": [ + "libsnappy.a" + ], + "headers-unix": [ + "snappy.h", + "snappy-c.h", + "snappy-sinksource.h", + "snappy-stubs-public.h" + ], + "lib-depends": [ + "zlib" + ] + }, + "sqlite": { + "source": "sqlite", + "static-libs-unix": [ + "libsqlite3.a" + ], + "static-libs-windows": [ + "libsqlite3_a.lib" + ], + "headers": [ + "sqlite3.h", + "sqlite3ext.h" + ] + }, + "tidy": { + "source": "tidy", + "static-libs-unix": [ + "libtidy.a" + ] + }, + "unixodbc": { + "source": "unixodbc", + "static-libs-unix": [ + "libodbc.a", + "libodbccr.a", + "libodbcinst.a" + ], + "lib-depends": [ + "libiconv" + ] + }, + "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-unix": [ + "libiconv" + ] + }, + "zlib": { + "source": "zlib", + "static-libs-unix": [ + "libz.a" + ], + "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" + ] + } +} diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 018838e27..008eaeba8 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -25,7 +25,7 @@ // If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`). $with_libs = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'brotli,bip2,gmp,icu,libargon2,libavif,libcares,libevent,libiconv,liblz4,libpng,libsodium,libtiff,libwebp,libyaml,ncurses,onig,openssl,pkg-config,readline,sqlite,unixodbc,xz,zlib', + 'Linux', 'Darwin' => 'brotli,bzip2,gmp,icu,libargon2,libavif,libcares,libevent,libiconv,liblz4,libpng,libsodium,libtiff,libwebp,libyaml,ncurses,onig,openssl,pkg-config,readline,sqlite,unixodbc,xz,zlib', 'Windows' => '', }; From 01518b47b6b442b6fdaa19a1f0c584c61e025674 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 14 Jul 2024 01:19:34 +0800 Subject: [PATCH 43/43] Update docs --- README-zh.md | 20 ++- README.md | 23 ++- docs/.vitepress/components/CliGenerator.vue | 153 ++++++++++++-------- docs/en/develop/source-module.md | 5 +- docs/en/develop/structure.md | 2 +- docs/en/guide/manual-build.md | 14 ++ docs/zh/develop/source-module.md | 2 + docs/zh/develop/structure.md | 2 +- docs/zh/guide/manual-build.md | 14 ++ 9 files changed, 159 insertions(+), 76 deletions(-) diff --git a/README-zh.md b/README-zh.md index c68d52f8c..f677e17d0 100755 --- a/README-zh.md +++ b/README-zh.md @@ -43,15 +43,17 @@ static-php-cli(简称 `spc`)有许多特性: 如果你不想自行编译 PHP,可以从本项目现有的示例 Action 下载 Artifact,也可以从自托管的服务器下载。 -- [扩展组合 - common](https://dl.static-php.dev/static-php-cli/common/):common 组合包含了约 [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) 个常用扩展,体积为 7.5MB 左右。 -- [扩展组合 - bulk](https://dl.static-php.dev/static-php-cli/bulk/):bulk 组合包含了 [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) 个扩展,体积为 25MB 左右。 -- [扩展组合 - minimal](https://dl.static-php.dev/static-php-cli/minimal/):minimal 组合包含了 [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) 个扩展,体积为 3MB 左右。 +| 组合名称 | 组合扩展数 | 系统 | 备注 | +|---------------------------------------------------------------------|----------------------------------------------------------------------------|-------------|--------------| +| [common](https://dl.static-php.dev/static-php-cli/common/) | [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) | Linux/macOS | 体积为 7.5MB 左右 | +| [bulk](https://dl.static-php.dev/static-php-cli/bulk/) | [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) | Linux/macOS | 体积为 25MB 左右 | +| [minimal](https://dl.static-php.dev/static-php-cli/minimal/) | [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) | Linux/macOS | 体积为 3MB 左右 | +| [spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min) | [5](https://dl.static-php.dev/static-php-cli/windows/spc-min/README.txt) | Windows | 体积为 3MB 左右 | +| [spc-max](https://dl.static-php.dev/static-php-cli/windows/spc-max) | [40+](https://dl.static-php.dev/static-php-cli/windows/spc-max/README.txt) | Windows | 体积为 8.5MB 左右 | > Linux 和 Windows 默认启用了 UPX 压缩,可减小 30~50% 的 PHP 二进制体积。 > macOS 当前不支持 UPX,所以上述预编译的 macOS 版本体积可能较大。 -对于 Windows 系统,目前支持的扩展较少,故仅提供 SPC 自身运行的最小扩展组合的 `cli` 和 `micro`:[扩展组合 - spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min/)。 - ## 使用 static-php-cli 构建 PHP ### 编译环境需求 @@ -110,7 +112,7 @@ static-php-cli(简称 `spc`)有许多特性: 如果你选择了 `debug`,则会在构建时输出所有日志,包括编译的日志,以供排查错误。 -### 本地构建(使用 spc 二进制) +### 本地构建(使用 spc 二进制,推荐) 该项目提供了 static-php-cli 的二进制文件:`spc`。 您可以使用 `spc` 二进制文件,无需安装任何运行时(用起来就像 golang 程序)。 @@ -144,6 +146,8 @@ chmod +x ./spc ### 本地构建(使用 git 源码) +如果你需要修改 static-php-cli 源码,或者使用 spc 二进制构建有问题,你可以使用 git 源码下载 static-php-cli。 + ```bash # clone 仓库即可 git clone https://github.com/crazywhalecc/static-php-cli.git @@ -177,6 +181,8 @@ bin/spc --version ./bin/spc download --all # 只拉取编译指定扩展需要的所有依赖(推荐) ./bin/spc download --for-extensions="openssl,pcntl,mbstring,pdo_sqlite" +# 下载依赖时,优先下载有预编译的库(节省编译依赖的时间) +./bin/spc download --for-extensions="openssl,curl,mbstring,mbregex" --prefer-pre-built # 下载编译不同版本的 PHP (--with-php=x.y,推荐 7.3 ~ 8.3) ./bin/spc download --for-extensions="openssl,curl,mbstring" --with-php=8.1 @@ -184,7 +190,7 @@ bin/spc --version ./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl" --build-cli --build-micro # 编译线程安全版本 (--enable-zts) ./bin/spc build "curl,phar" --enable-zts --build-cli -# 编译后使用 UPX 减小可执行文件体积 (--with-upx-pack) (至少压缩至原来的 30~50%) +# 编译后使用 UPX 减小可执行文件体积 (仅 Linux、Windows 可用) (至少压缩至原来的 30~50%) ./bin/spc build "curl,phar" --enable-zts --build-cli --with-upx-pack ``` diff --git a/README.md b/README.md index 4b000aa8a..a386aea4b 100755 --- a/README.md +++ b/README.md @@ -49,16 +49,17 @@ If you don't want to build or want to test first, you can download example pre-c Below are several precompiled static-php binaries with different extension combinations, which can be downloaded directly according to your needs. -- [Extension-Combination - common](https://dl.static-php.dev/static-php-cli/common/): `common` contains about [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) commonly used extensions, and the size is about 7.5MB. -- [Extension-Combination - bulk](https://dl.static-php.dev/static-php-cli/bulk/): `bulk` contains [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) extensions and is about 25MB in size. -- [Extension-Combination - minimal](https://dl.static-php.dev/static-php-cli/minimal/): `minimal` contains [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) extensions and is about 3MB in size. +| Combination | Extension Count | OS | Comment | +|----------------------------------------------------------------------|---------------------------------------------------------------------------|--------------|--------------------------------| +| [common](https://dl.static-php.dev/static-php-cli/common/) | [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) | Linux, macOS | The binary size is about 7.5MB | +| [bulk](https://dl.static-php.dev/static-php-cli/bulk/) | [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) | Linux, macOS | The binary size is about 25MB | +| [minimal](https://dl.static-php.dev/static-php-cli/minimal/) | [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) | Linux, macOS | The binary size is about 3MB | +| [spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min/) | [5](https://dl.static-php.dev/static-php-cli/windows/spc-min/README.txt) | Windows | The binary size is about 3MB | +| [spc-max](https://dl.static-php.dev/static-php-cli/windows/spc-max/) | [10](https://dl.static-php.dev/static-php-cli/windows/spc-max/README.txt) | Windows | The binary size is about 8.5MB | > Linux and Windows supports UPX compression for binaries, which can reduce the size of the binary by 30% to 50%. > macOS does not support UPX compression, so the size of the pre-built binaries for mac is larger. -For Windows systems, there are currently fewer extensions supported, -so only `cli` and `micro` that run the minimum extension combination of SPC itself are provided: [Extension-Combination - spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min/). - ## Build ### Compilation Requirements @@ -97,6 +98,7 @@ Currently supported PHP versions for compilation: | 8.1 | :heavy_check_mark: | PHP official has security fixes only | | 8.2 | :heavy_check_mark: | | | 8.3 | :heavy_check_mark: | | +| 8.4 | :x: | WIP | ### Supported Extensions @@ -121,7 +123,7 @@ and at the same time define the extensions to be compiled by yourself. If you enable `debug`, all logs will be output at build time, including compiled logs, for troubleshooting. -### Build Locally (using SPC binary) +### Build Locally (using SPC binary, recommended) This project provides a binary file of static-php-cli: `spc`. You can use `spc` binary instead of installing any runtime like golang app. @@ -155,6 +157,9 @@ Self-hosted `spc` is built by GitHub Actions, you can also download from Actions ### Build Locally (using git source) +If you need to modify the static-php-cli source code, or have problems using the spc binary build, +you can download static-php-cli using the git source code. + ```bash # just clone me! git clone https://github.com/crazywhalecc/static-php-cli.git @@ -188,6 +193,8 @@ Basic usage for building php with some extensions: ./bin/spc download --all # only fetch necessary sources by needed extensions (recommended) ./bin/spc download --for-extensions="openssl,pcntl,mbstring,pdo_sqlite" +# download pre-built libraries first (save time for compiling dependencies) +./bin/spc download --for-extensions="openssl,curl,mbstring,mbregex" --prefer-pre-built # download different PHP version (--with-php=x.y, recommend 7.3 ~ 8.3) ./bin/spc download --for-extensions="openssl,curl,mbstring" --with-php=8.1 @@ -195,7 +202,7 @@ Basic usage for building php with some extensions: ./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl" --build-cli --build-micro # build thread-safe (ZTS) version (--enable-zts) ./bin/spc build "curl,phar" --enable-zts --build-cli -# build, pack executable with UPX (--with-upx-pack) (reduce binary size for 30~50%) +# build, pack executable with UPX (linux and windows only) (reduce binary size for 30~50%) ./bin/spc build "curl,phar" --enable-zts --build-cli --with-upx-pack ``` diff --git a/docs/.vitepress/components/CliGenerator.vue b/docs/.vitepress/components/CliGenerator.vue index 5ef344954..a3e3bc679 100644 --- a/docs/.vitepress/components/CliGenerator.vue +++ b/docs/.vitepress/components/CliGenerator.vue @@ -10,8 +10,11 @@

{{ I18N[lang].selectExt }}{{ checkedExts.length > 0 ? (' (' + checkedExts.length + ')') : '' }}

- - + + + + +
{{ I18N[lang].selectCommon }}
@@ -46,59 +49,80 @@

{{ I18N[lang].windowsSAPIUnavailable }}

{{ I18N[lang].buildOptions }}

-
- {{ I18N[lang].buildEnvironment }} - -
-
- {{ I18N[lang].selectedArch }} - -
-
- {{ I18N[lang].downloadPhpVersion }} - -
-
- {{ I18N[lang].useDebug }} - - - - - -
-
- {{ I18N[lang].useZTS }} - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{ I18N[lang].buildEnvironment }} + +
{{ I18N[lang].downloadPhpVersion }} + +
{{ I18N[lang].useDebug }} + + + + +
{{ I18N[lang].useZTS }} + + + + +
{{ I18N[lang].resultShowDownload }} + + + + +
{{ I18N[lang].usePreBuilt }} + + + + +
{{ I18N[lang].useUPX }} + + + + +
- - -
-
- {{ I18N[lang].resultShowDownload }} - - - - - -
-
- {{ I18N[lang].useUPX }} - - - - - -

{{ I18N[lang].hardcodedINI }}