Skip to content

Build for Windows

Build for Windows #23

Workflow file for this run

name: Build for Windows
on:
workflow_dispatch:
inputs:
php-version:
required: true
description: PHP version to compile
default: "8.4"
type: choice
options:
- "8.5"
- "8.4"
- "8.3"
build-cli:
description: Build php cli binary
default: true
type: boolean
build-micro:
description: Build php micro binary
default: true
type: boolean
enable-micro-win32:
description: Enable php micro win32
default: true
type: boolean
enable-zts:
description: Enable ZTS
type: boolean
default: false
extensions:
description: Extensions to compile (comma separated)
required: true
type: string
default: "webview"
extra-libs:
description: Extra libraries to build (optional, comma separated)
type: string
# 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
with-upx-pack:
description: Pack with UPX
type: boolean
default: true
no-strip:
description: Keep debug symbols for debugging
type: boolean
default: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
build:
name: Build PHP ${{ inputs.php-version }} for Windows x86_64
runs-on: windows-latest
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"
shell: bash
run: |
cd static-php-cli
# 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 hashed key for download cache
shell: bash
run: |
INPUT_HASH=$(echo "windows-php-${{ inputs.php-version }}-${{ inputs.extensions }}-webview-${{ github.sha }}" | sha256sum | awk '{print $1}')
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-windows-php-${{ inputs.php-version }}-${{ env.INPUT_HASH }}
- if: ${{ inputs.build-cli == true }}
name: "Build for cli binary"
run: echo "SPC_BUILD_CLI=--build-cli" >> $env:GITHUB_ENV
- if: ${{ inputs.build-micro == true }}
name: "Build for micro binary"
run: echo "SPC_BUILD_MICRO=--build-micro" >> $env:GITHUB_ENV
- if: inputs.debug == true
name: "[Optional] Display full build logs"
run: echo "SPC_DEBUG=--debug" >> $env:GITHUB_ENV
# - if: inputs.prefer-pre-built == true
- name: "[Optional] Prefer pre-built binaries"
run: echo "SPC_PRE_BUILT=--prefer-pre-built" >> $env:GITHUB_ENV
- if: inputs.with-upx-pack == true
name: "[Optional] Pack with UPX"
run: echo "SPC_UPX_PACK=--with-upx-pack" >> $env:GITHUB_ENV
- if: inputs.enable-micro-win32 == true
name: "[Optional] Enable micro win32"
run: echo "SPC_ENABLE_MICRO_WIN32=--enable-micro-win32" >> $env:GITHUB_ENV
- if: inputs.enable-zts == true
name: "[Optional] Enable zts"
run: echo "SPC_ENABLE_ZTS=--enable-zts" >> $env:GITHUB_ENV
- name: "Run doctor"
shell: bash
run: |
cd static-php-cli
./bin/spc doctor --auto-fix
- name: "Download sources"
working-directory: static-php-cli
run: |
./bin/spc download --with-php="${{ inputs.php-version }}" --for-extensions="${{ inputs.extensions }}" ${{ env.SPC_DEBUG }} ${{ env.SPC_PRE_BUILT }}
./bin/spc install-pkg upx
- name: "Build PHP"
working-directory: static-php-cli
run: |
./bin/spc build "${{ inputs.extensions }}" ${{ env.SPC_BUILD_CLI }} ${{ env.SPC_BUILD_MICRO }} ${{ env.SPC_DEBUG }} ${{ env.SPC_UPX_PACK }} ${{ env.SPC_ENABLE_MICRO_WIN32 }} ${{ env.SPC_ENABLE_ZTS }}
- if: ${{ inputs.build-cli == true }}
name: "Upload PHP cli executable"
uses: actions/upload-artifact@v4
with:
name: php-cli-${{ inputs.php-version }}-windows
path: static-php-cli/buildroot/bin/php.exe
- if: ${{ inputs.build-micro == true }}
name: "Upload PHP micro executable"
uses: actions/upload-artifact@v4
with:
name: php-micro-${{ inputs.php-version }}-windows
path: static-php-cli/buildroot/bin/micro.sfx
- uses: actions/upload-artifact@v4
name: "Upload License files"
with:
name: license-files-${{ inputs.php-version }}-windows
path: static-php-cli/buildroot/license/
- uses: actions/upload-artifact@v4
name: "Upload Build metadata"
with:
name: build-meta-${{ inputs.php-version }}-windows
path: |
static-php-cli/buildroot/build-extensions.json
static-php-cli/buildroot/build-libraries.json