Skip to content

Build for Unix

Build for Unix #45

Workflow file for this run

name: "Build for Unix"
on:
workflow_dispatch:
inputs:
os:
required: true
description: Build target OS
default: "linux-x86_64"
type: choice
options:
- "macos-x86_64"
- "macos-aarch64"
- "linux-x86_64"
- "linux-aarch64"
php-version:
required: true
description: PHP version to compile
default: "8.4"
type: choice
options:
- "8.5"
- "8.4"
- "8.3"
extensions:
description: Extensions to build (comma separated)
required: true
type: string
default: "webview"
extra-libs:
description: Extra libraries to build (optional, comma separated)
type: string
build-cli:
description: Build for php cli binary
default: true
type: boolean
build-micro:
description: Build for php micro binary
default: true
type: boolean
enable-zts:
description: Enable ZTS
type: boolean
default: false
# prefer-pre-built:
# description: Prefer pre-built binaries (reduce build time)
# type: boolean
# default: true
debug:
description: Display full build logs
type: boolean
default: true
no-strip:
description: Keep debug symbols for debugging
type: boolean
default: false
with-upx-pack:
description: Pack with UPX (Linux only)
type: boolean
default: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
define-build:
name: "Define Build Scripts for ${{ inputs.os }}"
runs-on: ubuntu-22.04
outputs:
runs_on: ${{ steps.gendef.outputs.runs_on }}
fix: ${{ steps.gendef.outputs.fix }}
download: ${{ steps.gendef.outputs.download }}
build: ${{ steps.gendef.outputs.build }}
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Define"
id: gendef
run: |
FIX_CMD="./bin/spc doctor --auto-fix"
DOWN_CMD="./bin/spc download"
BUILD_CMD="./bin/spc build"
case "${{ inputs.os }}" in
macos-x86_64)
RUNS_ON="macos-14-large"
;;
macos-aarch64)
RUNS_ON="macos-14"
;;
linux-x86_64)
RUNS_ON="ubuntu-22.04"
;;
linux-aarch64)
RUNS_ON="ubuntu-22.04-arm"
;;
esac
DOWN_CMD="$DOWN_CMD --with-php=${{ inputs.php-version }} --for-extensions=${{ inputs.extensions }} --ignore-cache-sources=php-src"
BUILD_CMD="$BUILD_CMD ${{ inputs.extensions }}"
if [ -n "${{ inputs.extra-libs }}" ]; then
DOWN_CMD="$DOWN_CMD --for-libs=${{ inputs.extra-libs }}"
BUILD_CMD="$BUILD_CMD --with-libs=${{ inputs.extra-libs }}"
fi
if [ ${{ inputs.debug }} == true ]; then
DOWN_CMD="$DOWN_CMD --debug"
BUILD_CMD="$BUILD_CMD --debug"
FIX_CMD="$FIX_CMD --debug"
fi
# if [ ${{ inputs.prefer-pre-built }} == true ]; then
DOWN_CMD="$DOWN_CMD --prefer-pre-built"
# fi
if [ ${{ inputs.build-cli }} == true ]; then
BUILD_CMD="$BUILD_CMD --build-cli"
fi
if [ ${{ inputs.build-micro }} == true ]; then
BUILD_CMD="$BUILD_CMD --build-micro"
fi
if [ ${{ inputs.enable-zts }} == true ]; then
BUILD_CMD="$BUILD_CMD --enable-zts"
fi
if [[ ${{ inputs.os }} == linux* ]] && [ ${{ inputs.with-upx-pack }} == true ]; then
BUILD_CMD="$BUILD_CMD --with-upx-pack"
fi
echo 'download='"$DOWN_CMD" >> "$GITHUB_OUTPUT"
echo 'build='"$BUILD_CMD" >> "$GITHUB_OUTPUT"
echo 'runs_on='"$RUNS_ON" >> "$GITHUB_OUTPUT"
echo 'fix='"$FIX_CMD" >> "$GITHUB_OUTPUT"
build:
name: "Build PHP ${{ inputs.php-version }} for ${{ inputs.os }}"
runs-on: ${{ needs.define-build.outputs.runs_on }}
needs: define-build
timeout-minutes: 240
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: 8.4
tools: pecl
extensions: curl, openssl, mbstring
ini-values: memory_limit=-1
- name: "Clone static-php-cli"
run: |
git clone https://github.com/crazywhalecc/static-php-cli.git
cd static-php-cli
composer update --no-dev
- name: "Configure webview extension"
working-directory: static-php-cli
run: |
# Add webview extension configuration to config/ext.json
if [ ! -f config/ext.json ]; then
echo '{}' > config/ext.json
fi
# Create temporary config with webview extension
cat config/ext.json | jq '. + {
"webview": {
"type": "external",
"source": "webview",
"frameworks": ["WebKit"],
"cpp-extension": true
}
}' > config/ext.json.tmp && mv config/ext.json.tmp config/ext.json
# Add webview source configuration to config/source.json
if [ ! -f config/source.json ]; then
echo '{}' > config/source.json
fi
# Get current branch/ref
CURRENT_REF="${{ github.ref_name }}"
echo "📌 Using branch/ref: $CURRENT_REF"
# Create temporary config with webview source
cat config/source.json | jq --arg ref "$CURRENT_REF" '. + {
"webview": {
"type": "git",
"path": "php-src/ext/webview",
"rev": $ref,
"url": "https://github.com/happystraw/php-ext-webview",
"license": {
"type": "file",
"path": "LICENSE"
}
}
}' > config/source.json.tmp && mv config/source.json.tmp config/source.json
echo "✅ Webview extension configured"
echo "📄 Extension config:"
cat config/ext.json | jq '.webview'
echo "📄 Source config:"
cat config/source.json | jq '.webview'
- name: "Generate cache key"
shell: bash
run: |
# Use platform-appropriate hash command
if command -v sha256sum >/dev/null 2>&1; then
# Linux
INPUT_HASH=$(echo "${{ inputs.os }}-${{ inputs.php-version }}-${{ inputs.extensions }}-webview-${{ github.sha }}" | sha256sum | awk '{print $1}')
else
# macOS
INPUT_HASH=$(echo "${{ inputs.os }}-${{ inputs.php-version }}-${{ inputs.extensions }}-webview-${{ github.sha }}" | shasum -a 256 | awk '{print $1}')
fi
echo "INPUT_HASH=${INPUT_HASH}" >> "$GITHUB_ENV"
# Cache downloaded source
- id: cache-download
name: "Cache downloaded source"
uses: actions/cache@v4
with:
path: static-php-cli/downloads
key: php-dependencies-${{ inputs.os }}-${{ inputs.php-version }}-${{ env.INPUT_HASH }}
- name: "Setup Linux"
if: startsWith(inputs.os, 'linux')
working-directory: static-php-cli
run: |
# Install GTK and WebKitGTK development packages
sudo apt-get update
sudo apt-get install -y libgtk-4-dev libwebkitgtk-6.0-dev
# Copy pkg-config files to "ext_webview_deps_pc_dir" directory
EXT_WEBVIEW_DEPS_PC_DIR="$(pwd)/ext_webview_deps_pc_dir"
../scripts/copy-pkgconfig.sh --dir "${EXT_WEBVIEW_DEPS_PC_DIR}"
# Setup Linux build environment variables
echo "SPC_TARGET=native-native" >> $GITHUB_ENV
# Only export webview-specific variables if webview extension is included
if [[ "${{ inputs.extensions }}" == *"webview"* ]]; then
echo "SPC_EXTRA_LIBS=$(pkg-config --libs gtk4 webkitgtk-6.0)" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=${EXT_WEBVIEW_DEPS_PC_DIR}" >> $GITHUB_ENV
echo "🔧 Linux build environment variables exported (with webview support):"
echo " SPC_TARGET=native-native"
echo " SPC_EXTRA_LIBS=$(pkg-config --libs gtk4 webkitgtk-6.0)"
echo " PKG_CONFIG_PATH=${EXT_WEBVIEW_DEPS_PC_DIR}"
else
echo "🔧 Linux build environment variables exported (without webview):"
echo " SPC_TARGET=native-native"
fi
# Install Zig compiler
./bin/spc install-pkg zig
if [[ ${{ inputs.with-upx-pack }} == true ]]; then
./bin/spc install-pkg upx
fi
- name: "Download sources"
working-directory: static-php-cli
run: ${{ needs.define-build.outputs.download }}
- name: "Run doctor"
working-directory: static-php-cli
run: ${{ needs.define-build.outputs.fix }}
- name: "Build PHP"
working-directory: static-php-cli
run: ${{ needs.define-build.outputs.build }}
# Upload cli executable
- if: ${{ inputs.build-cli == true }}
name: "Upload PHP cli SAPI"
uses: actions/upload-artifact@v4
with:
name: php-cli-${{ inputs.php-version }}-${{ inputs.os }}
path: static-php-cli/buildroot/bin/php
# Upload micro self-extracted executable
- if: ${{ inputs.build-micro == true }}
name: "Upload PHP micro SAPI"
uses: actions/upload-artifact@v4
with:
name: php-micro-${{ inputs.php-version }}-${{ inputs.os }}
path: static-php-cli/buildroot/bin/micro.sfx
# Upload extensions metadata
- uses: actions/upload-artifact@v4
name: "Upload License files"
with:
name: license-files-${{ inputs.php-version }}-${{ inputs.os }}
path: static-php-cli/buildroot/license/
- uses: actions/upload-artifact@v4
name: "Upload Build metadata"
with:
name: build-meta-${{ inputs.php-version }}-${{ inputs.os }}
path: |
static-php-cli/buildroot/build-extensions.json
static-php-cli/buildroot/build-libraries.json