Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GH action to build library artifacts #188

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions .github/workflows/build-libraries.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/build-linux-x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-macos-x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/download-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
14 changes: 3 additions & 11 deletions src/SPC/builder/BuilderBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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);
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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
*/
Expand Down
3 changes: 2 additions & 1 deletion src/SPC/command/BuildLibsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 !');
Expand Down
4 changes: 2 additions & 2 deletions src/SPC/util/DependencyUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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;
}
}
Expand Down