Use em as a composable WebAssembly build pipeline for PHP in your GitHub Actions workflows. This action compiles PHP to WebAssembly with customizable extensions and configurations.
name: Build PHP WebAssembly
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout PHP source
uses: actions/checkout@v4
with:
repository: php/php-src
ref: PHP-8.3
path: php-src
- name: Build PHP WebAssembly
uses: krakjoe/em@develop
with:
EM_PHP_DIR: ./php-src
bake: all
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: php-wasm
path: |
php-em.js
php-em.wasm| Input | Description | Required | Default |
|---|---|---|---|
EM_PHP_DIR |
Path to PHP source directory | ✅ | |
EM_PHP_CONFIGURE |
Extra configure arguments for PHP | ❌ | '' |
EM_EMSDK_CFLAGS |
Extra CFLAGS for emcc compilation | ❌ | '' |
EM_EMSDK_LDFLAGS |
Extra LDFLAGS for emcc linking | ❌ | '' |
bake |
Space-separated list of recipe collections | ❌ | '' |
without |
Space-separated list of exclusions | ❌ | '' |
with |
Space-separated list of individual recipes | ❌ | '' |
emsdk |
Emscripten SDK version to use | ❌ | '4.0.11' |
| Output | Description |
|---|---|
wasm-file |
Path to generated WASM file |
js-file |
Path to generated JavaScript file |
Pre-defined recipe collections for common use cases:
- uses: krakjoe/em@develop
with:
EM_PHP_DIR: ./php-src
bake: allIncludes: bcmath, calendar, ctype, mbstring, opcache, tokenizer, compression, database, image, and XML extensions.
- uses: krakjoe/em@develop
with:
EM_PHP_DIR: ./php-src
bake: compressionIncludes: zlib, bz2, zip, phar
- uses: krakjoe/em@develop
with:
EM_PHP_DIR: ./php-src
bake: databaseIncludes: sqlite3, pdo, pdo-sqlite
- uses: krakjoe/em@develop
with:
EM_PHP_DIR: ./php-src
bake: imageIncludes: jpeg, png, gd
- uses: krakjoe/em@develop
with:
EM_PHP_DIR: ./php-src
bake: xmlIncludes: libxml, xml, dom, simplexml, xmlreader, xmlwriter
Build specific extensions only:
- uses: krakjoe/em@develop
with:
EM_PHP_DIR: ./php-src
with: "sqlite3 pdo gd"Available extensions:
- Core:
bcmath,calendar,ctype,mbstring,opcache,tokenizer - Compression:
zlib,bz2,zip,phar - Database:
sqlite3,pdo,pdo-sqlite - Image:
jpeg,png,gd - XML:
libxml,xml,dom,simplexml,xmlreader,xmlwriter
Exclude specific extensions from baked collections:
- uses: krakjoe/em@develop
with:
EM_PHP_DIR: ./php-src
bake: all
without: "opcache zip"strategy:
matrix:
php: ["PHP-8.0", "PHP-8.1", "PHP-8.2", "PHP-8.3", "PHP-8.4", "master"]
steps:
- name: Checkout PHP ${{ matrix.php }}
uses: actions/checkout@v4
with:
repository: php/php-src
ref: ${{ matrix.php }}
path: php-src
- name: Build em (${{ matrix.php }})
uses: krakjoe/em@develop
with:
EM_PHP_DIR: ./php-src
bake: all
- name: Upload ${{ matrix.php }} artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.php }}-em
path: |
php-em.js
php-em.wasm- uses: krakjoe/em@develop
with:
EM_PHP_DIR: ./php-src
with: "ctype mbstring"- uses: krakjoe/em@develop
with:
EM_PHP_DIR: ./php-src
bake: "compression database xml"
without: "opcache"The action supports all maintained PHP versions:
| PHP Version | Branch/Tag | Status |
|---|---|---|
| PHP 8.4 | PHP-8.4 |
✅ Latest |
| PHP 8.3 | PHP-8.3 |
✅ Stable |
| PHP 8.2 | PHP-8.2 |
✅ Stable |
| PHP 8.1 | PHP-8.1 |
✅ Stable |
| PHP 8.0 | PHP-8.0 |
✅ Security Only |
| Development | master |
After building, you can test your WebAssembly build:
- name: Run test suite
run: |
./php-em-test.js --verbose- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install build-essential re2c bison autoconfEnsure your PHP source checkout step is correct:
- name: Checkout PHP source
uses: actions/checkout@v4
with:
repository: php/php-src
ref: PHP-8.3 # Make sure this branch/tag exists
path: php-srcSome extensions may conflict, or be undesirable when using bakers. Use exclusions:
- uses: krakjoe/em@develop
with:
EM_PHP_DIR: ./php-src
bake: all
without: "opcache" # Exclude problematic extensionsFound a bug or want to add support for a new extension?
- Check existing issues
- Create a new issue or pull request
- Follow the existing recipe patterns in
/recipe/
This action is licensed under the PHP License 3.01 - see the LICENSE file for details.