diff --git a/.github/workflows/build-libraries.yml b/.github/workflows/build-libraries.yml new file mode 100644 index 000000000..71965c418 --- /dev/null +++ b/.github/workflows/build-libraries.yml @@ -0,0 +1,112 @@ +name: Build Library Dependency Artifacts + +on: + release: + types: + - published + workflow_dispatch: + +jobs: + build-release-artifacts: + name: "Build Library Dependency Artifacts" + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + php-version: + - "8.1" + operating-system: + - "ubuntu-latest" + - "macos-latest" + library: + # Commented out libraries are not yet supported + - brotli + - bzip2 + - curl + - freetype + #- glfw + - gmp + - icu + - imagemagick + - libavif + - libevent + #- libffi + - libiconv + - libjpeg + #- libmcrypt + #- libmemcached + - libpng + - libsodium + - libssh2 + - libwebp + - libxml2 + - libxslt + - libyaml + - libzip + - mcrypt + - ncurses + - nghttp2 + - onig + - openssl + #- pkg-config + - postgresql + #- pthreads4w + - readline + - snappy + - sqlite + - xz + - zlib + - zstd + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + + - name: OS type + id: os-type + run: | + OS="" + if [ "${{ matrix.operating-system }}" = "ubuntu-latest" ]; then + OS="linux-x86_64" + elif [ "${{ matrix.operating-system }}" = "macos-latest" ]; then + OS="macos-x86_64" + fi + echo "OS=$OS" >> $GITHUB_ENV + + - name: Download SPC bin artifact + id: download-spc-artifact + uses: dawidd6/action-download-artifact@v2 + with: + branch: main + workflow: release-build.yml + name: "spc-${{ env.OS }}" + + - name: Validate SPC bin + run: | + chmod +x spc + ./spc --version + + - id: cache-download + uses: actions/cache@v3 + with: + path: downloads + key: php-${{ matrix.php-version }}-dependencies + + # If there's no dependencies cache, fetch sources + - if: steps.cache-download.outputs.cache-hit != 'true' + name: "Download sources" + run: ./spc download --with-php=${{ matrix.php-version }} --all + + - name: "Build library: ${{ matrix.library }}" + run: | + SPC_USE_SUDO=yes ./spc doctor --auto-fix + ./spc build:libs ${{ matrix.library }} --include-suggested + + - name: "Upload Artifact" + uses: actions/upload-artifact@v3 + with: + name: php-${{ matrix.php-version }}-${{ matrix.library }}-${{ env.OS }} + path: | + buildroot/include/ + buildroot/lib/ + if-no-files-found: error diff --git a/.github/workflows/build-linux-x86_64.yml b/.github/workflows/build-linux-x86_64.yml index 90705f332..fbf4ef135 100644 --- a/.github/workflows/build-linux-x86_64.yml +++ b/.github/workflows/build-linux-x86_64.yml @@ -49,7 +49,7 @@ jobs: # If there's no Composer cache, install dependencies - if: steps.cache-composer-deps.outputs.cache-hit != 'true' - run: composer update --no-dev --classmap-authoritative + run: composer install --no-dev --classmap-authoritative # Cache downloaded source - id: cache-download diff --git a/.github/workflows/build-macos-x86_64.yml b/.github/workflows/build-macos-x86_64.yml index 6727fcbd0..5c37e74ac 100644 --- a/.github/workflows/build-macos-x86_64.yml +++ b/.github/workflows/build-macos-x86_64.yml @@ -54,7 +54,7 @@ jobs: # If there's no Composer cache, install dependencies - if: steps.cache-composer-deps.outputs.cache-hit != 'true' - run: composer update --no-dev --classmap-authoritative + run: composer install --no-dev --classmap-authoritative # Cache downloaded source - id: cache-download diff --git a/.github/workflows/download-cache.yml b/.github/workflows/download-cache.yml index 86b4322ea..1638916d8 100644 --- a/.github/workflows/download-cache.yml +++ b/.github/workflows/download-cache.yml @@ -27,7 +27,7 @@ jobs: # If there's no Composer cache, install dependencies - if: steps.cache-composer-deps.outputs.cache-hit != 'true' - run: composer update --no-dev + run: composer install --no-dev # If there's no dependencies cache, fetch sources, with or without debug - if: steps.cache-download.outputs.cache-hit != 'true' diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index c0b662236..8a3b8fe09 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -38,7 +38,7 @@ abstract class BuilderBase * @throws RuntimeException * @throws WrongUsageException */ - public function buildLibs(array $libraries): void + public function buildLibs(array $libraries, bool $includeSuggested = false): void { // search all supported libs $support_lib_list = []; @@ -53,7 +53,7 @@ public function buildLibs(array $libraries): void } // if no libs specified, compile all supported libs - if ($libraries === [] && $this->isLibsOnly()) { + if ($libraries === [] && $this->libs_only) { $libraries = array_keys($support_lib_list); } @@ -63,7 +63,7 @@ public function buildLibs(array $libraries): void } // append dependencies - $libraries = DependencyUtil::getLibsByDeps($libraries); + $libraries = DependencyUtil::getLibsByDeps($libraries, $includeSuggested); // add lib object for builder foreach ($libraries as $library) { @@ -217,14 +217,6 @@ public function makeExtensionArgs(): string return implode(' ', $ret); } - /** - * Get libs only mode. - */ - public function isLibsOnly(): bool - { - return $this->libs_only; - } - /** * Get PHP Version ID from php-src/main/php_version.h */ diff --git a/src/SPC/command/BuildLibsCommand.php b/src/SPC/command/BuildLibsCommand.php index dc3989e6b..d8feec20e 100644 --- a/src/SPC/command/BuildLibsCommand.php +++ b/src/SPC/command/BuildLibsCommand.php @@ -21,6 +21,7 @@ public function configure(): void $this->addOption('clean', null, null, 'Clean old download cache and source before fetch'); $this->addOption('all', 'A', null, 'Build all libs that static-php-cli needed'); $this->addOption('rebuild', 'r', null, 'Delete old build and rebuild'); + $this->addOption('include-suggested', 'I', null, 'Build all library dependencies along with suggested ones'); } public function initialize(InputInterface $input, OutputInterface $output): void @@ -60,7 +61,7 @@ public function handle(): int // 只编译 library 的情况下,标记 $builder->setLibsOnly(); // 编译和检查库完整 - $builder->buildLibs($libraries); + $builder->buildLibs($libraries, $this->getOption('include-suggested')); $time = round(microtime(true) - START_TIME, 3); logger()->info('Build libs complete, used ' . $time . ' s !'); diff --git a/src/SPC/util/DependencyUtil.php b/src/SPC/util/DependencyUtil.php index ba0d839cb..3c335d62f 100644 --- a/src/SPC/util/DependencyUtil.php +++ b/src/SPC/util/DependencyUtil.php @@ -71,7 +71,7 @@ public static function getExtLibsByDeps(array $exts, array $additional_libs = [] * @throws RuntimeException * @throws WrongUsageException */ - public static function getLibsByDeps(array $libs): array + public static function getLibsByDeps(array $libs, bool $includeSuggested = false): array { $sorted = []; $visited = []; @@ -92,7 +92,7 @@ public static function getLibsByDeps(array $libs): array } } foreach ($sorted_suggests as $suggest) { - if (in_array($suggest, $sorted)) { + if (in_array($suggest, $sorted, true) || $includeSuggested) { $final[] = $suggest; } }