From 81a9431357c3a71a6f367e574615b51fcf31a76a Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Fri, 15 Sep 2023 15:25:53 +0200 Subject: [PATCH 1/4] Add GH action to build library artifacts --- .github/workflows/build-libraries.yml | 130 ++++++++++++++++++++++++++ src/SPC/builder/BuilderBase.php | 10 +- 2 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/build-libraries.yml diff --git a/.github/workflows/build-libraries.yml b/.github/workflows/build-libraries.yml new file mode 100644 index 000000000..e269fa09b --- /dev/null +++ b/.github/workflows/build-libraries.yml @@ -0,0 +1,130 @@ +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: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: none + tools: composer:v2 + php-version: "${{ matrix.php-version }}" + ini-values: memory_limit=-1 + + - name: "Get Composer Cache Directory" + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: "Cache Composer dependencies" + uses: "actions/cache@v3" + with: + path: "${{ steps.composer-cache.outputs.dir }}" + key: "php-${{ matrix.php-version }}-locked-composer-${{ hashFiles('**/composer.lock') }}" + restore-keys: | + php-${{ matrix.php-version }}-locked-composer- + + - name: "Install locked dependencies" + run: "composer install --no-interaction --no-progress" + + # Cache downloaded source + - 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 + + - 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: bin/spc download --with-php=${{ matrix.php-version }} --all + + - name: "Build library: ${{ matrix.library }}" + run: | + SPC_USE_SUDO=yes bin/spc doctor --auto-fix + bin/spc build:libs ${{ matrix.library }} + + - name: Upload binaries to release + uses: softprops/action-gh-release@v1 + if: ${{startsWith(github.ref, 'refs/tags/') }} + with: + files: ${{ env.filename }} + + - 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/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index c0b662236..8474226fb 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -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); } @@ -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 */ From 07654a50913afd6eb0a6b1e5e7524b4015c987ab Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Fri, 15 Sep 2023 19:35:18 +0200 Subject: [PATCH 2/4] Allow to build library suggested dependencies --- .github/workflows/build-libraries.yml | 2 +- src/SPC/builder/BuilderBase.php | 4 ++-- src/SPC/command/BuildLibsCommand.php | 3 ++- src/SPC/util/DependencyUtil.php | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-libraries.yml b/.github/workflows/build-libraries.yml index e269fa09b..c44566c4a 100644 --- a/.github/workflows/build-libraries.yml +++ b/.github/workflows/build-libraries.yml @@ -112,7 +112,7 @@ jobs: - name: "Build library: ${{ matrix.library }}" run: | SPC_USE_SUDO=yes bin/spc doctor --auto-fix - bin/spc build:libs ${{ matrix.library }} + bin/spc build:libs ${{ matrix.library }} --include-suggested - name: Upload binaries to release uses: softprops/action-gh-release@v1 diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 8474226fb..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 = []; @@ -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) { 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; } } From 0476ec35f1af8c8cb78b04c8ea165812c3edcde8 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Sat, 16 Sep 2023 17:30:21 +0200 Subject: [PATCH 3/4] Use `composer install` in all GH actions --- .github/workflows/build-linux-x86_64.yml | 2 +- .github/workflows/build-macos-x86_64.yml | 2 +- .github/workflows/download-cache.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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' From 71b64e6913b31a58fb0bd89904c4ac9f6f24c254 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Sat, 16 Sep 2023 17:36:41 +0200 Subject: [PATCH 4/4] Try to re-use existing SPC binary --- .github/workflows/build-libraries.yml | 50 +++++++++------------------ 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build-libraries.yml b/.github/workflows/build-libraries.yml index c44566c4a..71965c418 100644 --- a/.github/workflows/build-libraries.yml +++ b/.github/workflows/build-libraries.yml @@ -62,31 +62,6 @@ jobs: - name: "Checkout" uses: "actions/checkout@v4" - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: none - tools: composer:v2 - php-version: "${{ matrix.php-version }}" - ini-values: memory_limit=-1 - - - name: "Get Composer Cache Directory" - id: composer-cache - run: | - echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: "Cache Composer dependencies" - uses: "actions/cache@v3" - with: - path: "${{ steps.composer-cache.outputs.dir }}" - key: "php-${{ matrix.php-version }}-locked-composer-${{ hashFiles('**/composer.lock') }}" - restore-keys: | - php-${{ matrix.php-version }}-locked-composer- - - - name: "Install locked dependencies" - run: "composer install --no-interaction --no-progress" - - # Cache downloaded source - name: OS type id: os-type run: | @@ -98,6 +73,19 @@ jobs: 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: @@ -107,18 +95,12 @@ jobs: # If there's no dependencies cache, fetch sources - if: steps.cache-download.outputs.cache-hit != 'true' name: "Download sources" - run: bin/spc download --with-php=${{ matrix.php-version }} --all + run: ./spc download --with-php=${{ matrix.php-version }} --all - name: "Build library: ${{ matrix.library }}" run: | - SPC_USE_SUDO=yes bin/spc doctor --auto-fix - bin/spc build:libs ${{ matrix.library }} --include-suggested - - - name: Upload binaries to release - uses: softprops/action-gh-release@v1 - if: ${{startsWith(github.ref, 'refs/tags/') }} - with: - files: ${{ env.filename }} + SPC_USE_SUDO=yes ./spc doctor --auto-fix + ./spc build:libs ${{ matrix.library }} --include-suggested - name: "Upload Artifact" uses: actions/upload-artifact@v3