-
Notifications
You must be signed in to change notification settings - Fork 68
Build static macOS PHP CLI binaries #3297
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
Merged
+218
−0
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
02bc232
Add macOS PHP CLI build CI
bcotrim 596d9a5
Install Composer for PHP CLI build CI
bcotrim 64c0664
Install PHP build prerequisites in CI
bcotrim b35ef79
Refresh PHP build CI ref
bcotrim 116a465
Install SPC pkg-config for PHP CLI build
bcotrim a9bba61
Fix macOS PHP CLI C++ runtime linking
bcotrim 5e74124
Upload SPC logs when PHP CLI build fails
bcotrim 12daff9
Pin PHP host version for CLI binary builds
bcotrim 43b716d
Use craft config for PHP CLI binary builds
bcotrim 1d65c79
Disable suggested libs for PHP CLI craft build
bcotrim 23245d4
Simplify PHP CLI binary build
bcotrim 0ab8b4f
Simplify PHP CLI Buildkite matrix
bcotrim c4a1b62
update buildkite PHP CLI build
bcotrim 8cc95fc
Use static PHP CLI Buildkite status
bcotrim ee419bc
Add Windows PHP CLI build
bcotrim 2fb0c78
Fix Windows PHP CLI toolchain setup
bcotrim b73fe11
Use vswhere for Windows PHP CLI build
bcotrim bdfa4fe
Fix Windows PHP CLI source extraction
bcotrim d9c41ee
Fix Windows PHP CLI tar extraction path
bcotrim ee48b5e
Fix Windows PHP CLI CMake setup
bcotrim 3531711
Remove macOS quarantine from PHP binary
bcotrim 6c91642
Disable macOS x64 PHP CLI build
bcotrim 6d0ca2e
Merge branch 'trunk' into rsm-1650-codex-build-static-php-cli-binaries
bcotrim 31e5274
Move PHP CLI build to GitHub Actions
bcotrim 709a927
Merge remote-tracking branch 'origin/rsm-1650-codex-build-static-php-…
bcotrim 637658f
Remove PHP binary quarantine cleanup
bcotrim 384f5b9
Authenticate PHP CLI workflow downloads
bcotrim c46005d
Address PHP CLI build review feedback
bcotrim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| name: Build PHP CLI Binaries | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| php_version: | ||
| description: PHP patch version to build | ||
| required: true | ||
| default: 8.4.20 | ||
| spc_ref: | ||
| description: static-php-cli ref | ||
| required: true | ||
| default: 2.8.5 | ||
| prefer_pre_built: | ||
| description: Prefer pre-built static-php-cli libraries | ||
| required: true | ||
| type: boolean | ||
| default: true | ||
| debug: | ||
| description: Enable static-php-cli debug logs | ||
| required: true | ||
| type: boolean | ||
| default: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| env: | ||
| GITHUB_TOKEN: ${{ github.token }} | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build ${{ matrix.target }} | ||
| runs-on: ${{ matrix.runner }} | ||
| timeout-minutes: 240 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - target: macos-aarch64 | ||
| runner: macos-15 | ||
| artifact_platform: macos | ||
| artifact_arch: aarch64 | ||
| archive_extension: tar.gz | ||
| binary_name: php | ||
| extensions: &macos_php_extensions apcu,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,ftp,gd,gettext,iconv,igbinary,imagick,intl,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,readline,redis,session,shmop,simplexml,sockets,sodium,sqlite3,ssh2,tokenizer,xml,xmlreader,xmlwriter,xsl,yaml,zip,zlib | ||
| - target: macos-x86_64 | ||
| runner: macos-15-intel | ||
| artifact_platform: macos | ||
| artifact_arch: x86_64 | ||
| archive_extension: tar.gz | ||
| binary_name: php | ||
| extensions: *macos_php_extensions | ||
| - target: windows-x86_64 | ||
| runner: windows-latest | ||
| artifact_platform: windows | ||
| artifact_arch: x86_64 | ||
| archive_extension: zip | ||
| binary_name: php.exe | ||
| # static-php-cli 2.8.5 has Windows builders for intl and sodium, but not gettext/libxslt. | ||
| extensions: apcu,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,ftp,gd,iconv,igbinary,intl,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pdo,pdo_mysql,pdo_sqlite,phar,redis,session,shmop,simplexml,sockets,sodium,sqlite3,ssh2,tokenizer,xml,xmlreader,xmlwriter,yaml,zip,zlib | ||
| env: | ||
| PHP_VERSION: ${{ github.event_name == 'workflow_dispatch' && inputs.php_version || '8.4.20' }} | ||
| SPC_REF: ${{ github.event_name == 'workflow_dispatch' && inputs.spc_ref || '2.8.5' }} | ||
| PHP_CLI_EXTENSIONS: ${{ matrix.extensions }} | ||
| PHP_CLI_ARTIFACT_PLATFORM: ${{ matrix.artifact_platform }} | ||
| PHP_CLI_ARTIFACT_ARCH: ${{ matrix.artifact_arch }} | ||
| PHP_CLI_ARCHIVE_EXTENSION: ${{ matrix.archive_extension }} | ||
| PHP_CLI_BINARY_NAME: ${{ matrix.binary_name }} | ||
| PREFER_PRE_BUILT: ${{ github.event_name != 'workflow_dispatch' || inputs.prefer_pre_built }} | ||
| SPC_DEBUG: ${{ github.event_name == 'workflow_dispatch' && inputs.debug || false }} | ||
|
|
||
| steps: | ||
| - name: Checkout Studio | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Checkout static-php-cli | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| repository: crazywhalecc/static-php-cli | ||
| ref: ${{ env.SPC_REF }} | ||
| path: .cache/static-php-cli | ||
|
|
||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| coverage: none | ||
| tools: composer:v2 | ||
| php-version: 8.4 | ||
| ini-values: memory_limit=-1 | ||
| extensions: curl, openssl, mbstring | ||
| env: | ||
| phpts: nts | ||
|
|
||
| - name: Install static-php-cli dependencies | ||
| working-directory: .cache/static-php-cli | ||
| run: composer install --no-dev --no-interaction --prefer-dist --classmap-authoritative | ||
|
|
||
| - name: Build PHP CLI on macOS | ||
| if: runner.os == 'macOS' | ||
| working-directory: .cache/static-php-cli | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| download_args=(--with-php="$PHP_VERSION" --for-extensions="$PHP_CLI_EXTENSIONS" --ignore-cache-sources=php-src) | ||
| build_args=("$PHP_CLI_EXTENSIONS" --build-cli) | ||
|
|
||
| if [ "$PREFER_PRE_BUILT" = "true" ]; then | ||
| download_args+=(--prefer-pre-built) | ||
| fi | ||
|
|
||
| if [ "$SPC_DEBUG" = "true" ]; then | ||
| download_args+=(--debug) | ||
| build_args+=(--debug) | ||
| fi | ||
|
|
||
| php bin/spc doctor --auto-fix | ||
| php bin/spc download "${download_args[@]}" | ||
| php bin/spc build "${build_args[@]}" | ||
|
|
||
| - name: Build PHP CLI on Windows | ||
| if: runner.os == 'Windows' | ||
| working-directory: .cache/static-php-cli | ||
| shell: pwsh | ||
| run: | | ||
| $downloadArgs = @( | ||
| "--with-php=$env:PHP_VERSION", | ||
| "--for-extensions=$env:PHP_CLI_EXTENSIONS", | ||
| "--ignore-cache-sources=php-src" | ||
| ) | ||
| $buildArgs = @( $env:PHP_CLI_EXTENSIONS, "--build-cli" ) | ||
|
|
||
| if ( $env:PREFER_PRE_BUILT -eq "true" ) { | ||
| $downloadArgs += "--prefer-pre-built" | ||
| } | ||
|
|
||
| if ( $env:SPC_DEBUG -eq "true" ) { | ||
| $downloadArgs += "--debug" | ||
| $buildArgs += "--debug" | ||
| } | ||
|
|
||
| php bin/spc doctor --auto-fix | ||
| php bin/spc download @downloadArgs | ||
| php bin/spc build @buildArgs | ||
|
|
||
| - name: Package macOS artifact | ||
| if: runner.os == 'macOS' | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| out_dir="$GITHUB_WORKSPACE/out/php-binaries" | ||
| artifact="php-${PHP_VERSION}-cli-${PHP_CLI_ARTIFACT_PLATFORM}-${PHP_CLI_ARTIFACT_ARCH}.${PHP_CLI_ARCHIVE_EXTENSION}" | ||
|
|
||
| mkdir -p "$out_dir" | ||
| cp "$GITHUB_WORKSPACE/.cache/static-php-cli/buildroot/bin/$PHP_CLI_BINARY_NAME" "$RUNNER_TEMP/php" | ||
| chmod +x "$RUNNER_TEMP/php" | ||
| xattr -cr "$RUNNER_TEMP/php" | ||
| tar -czf "$out_dir/$artifact" -C "$RUNNER_TEMP" php | ||
| shasum -a 256 "$out_dir/$artifact" | awk '{print $1}' > "$out_dir/$artifact.sha256" | ||
|
|
||
| - name: Package Windows artifact | ||
| if: runner.os == 'Windows' | ||
| shell: pwsh | ||
| run: | | ||
| $outDir = Join-Path $env:GITHUB_WORKSPACE 'out/php-binaries' | ||
| $artifact = "php-$env:PHP_VERSION-cli-$env:PHP_CLI_ARTIFACT_PLATFORM-$env:PHP_CLI_ARTIFACT_ARCH.$env:PHP_CLI_ARCHIVE_EXTENSION" | ||
| $source = Join-Path $env:GITHUB_WORKSPACE ".cache/static-php-cli/buildroot/bin/$env:PHP_CLI_BINARY_NAME" | ||
| $dest = Join-Path $env:RUNNER_TEMP $env:PHP_CLI_BINARY_NAME | ||
| $archive = Join-Path $outDir $artifact | ||
|
|
||
| New-Item -ItemType Directory -Force $outDir | Out-Null | ||
| Copy-Item -Force $source $dest | ||
| Compress-Archive -Force -Path $dest -DestinationPath $archive | ||
| (Get-FileHash $archive -Algorithm SHA256).Hash.ToLower() | Set-Content -NoNewline "$archive.sha256" | ||
|
|
||
| - name: Upload PHP CLI artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: php-${{ env.PHP_VERSION }}-cli-${{ matrix.target }} | ||
| path: out/php-binaries/* | ||
|
|
||
| - name: Upload static-php-cli logs | ||
| if: ${{ failure() }} | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: spc-logs-${{ matrix.target }} | ||
| path: .cache/static-php-cli/log/*.log | ||
| if-no-files-found: ignore | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Native PHP Binaries | ||
|
|
||
| Use the manual `Build PHP CLI Binaries` GitHub Actions workflow to build Studio | ||
| PHP CLI artifacts. The workflow checks out `crazywhalecc/static-php-cli`, pins | ||
| the requested SPC ref, passes Studio's extension list directly to `spc download` | ||
| and `spc build`, then uploads archives with `.sha256` sidecars. | ||
|
|
||
| The manual workflow currently builds: | ||
|
|
||
| - `php-8.4.20-cli-macos-aarch64.tar.gz` | ||
| - `php-8.4.20-cli-macos-x86_64.tar.gz` | ||
| - `php-8.4.20-cli-windows-x86_64.zip` | ||
|
|
||
| Windows ARM64 Studio builds use the Windows x64 PHP binary under Windows 11 | ||
| emulation. Native Windows ARM64 PHP binaries are not built. | ||
|
|
||
| The `.sha256` sidecars are used to verify downloaded artifacts. When these | ||
| artifacts are published to the Apps CDN, copy those checksums into | ||
| `tools/common/lib/php-binary-metadata.ts`. | ||
| Before publishing macOS artifacts, sign and notarize the `php` binary with the | ||
| existing Studio Developer ID setup. | ||
|
|
||
| Regular Studio app builds upload to the Apps CDN through `fastlane/Fastfile`: | ||
| `upload_file_to_apps_cdn` wraps `upload_build_to_apps_cdn` from | ||
| `fastlane-plugin-wpmreleasetoolkit`. That path requires `WPCOM_API_TOKEN`, the | ||
| Studio Apps CDN site ID, build metadata, and a file path. CDN upload for PHP | ||
| binary artifacts should be added separately after the manual GitHub Actions | ||
| builds are proven. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we build and distribute the binaries ourselves, what do we do with the checksums?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we upload the binaries to the CDN and update the binary metadata, we can store the checksum alongside each CDN URL. It’s a good safety measure to verify the archive after download and before extraction.