Skip to content
Merged
79 changes: 77 additions & 2 deletions .github/workflows/build-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ on:
description: Extensions to build (comma separated)
required: true
type: string
shared-extensions:
description: Shared extensions to build (optional, comma separated)
type: string
extra-libs:
description: Extra libraries to build (optional, comma separated)
type: string
Expand All @@ -42,6 +45,14 @@ on:
build-fpm:
description: Build fpm binary
type: boolean
build-frankenphp:
description: Build frankenphp binary (requires ZTS)
type: boolean
default: false
enable-zts:
description: Enable ZTS
type: boolean
default: false
prefer-pre-built:
description: Prefer pre-built binaries (reduce build time)
type: boolean
Expand Down Expand Up @@ -73,6 +84,9 @@ on:
description: Extensions to build (comma separated)
required: true
type: string
shared-extensions:
description: Shared extensions to build (optional, comma separated)
type: string
extra-libs:
description: Extra libraries to build (optional, comma separated)
type: string
Expand All @@ -86,6 +100,14 @@ on:
build-fpm:
description: Build fpm binary
type: boolean
build-frankenphp:
description: Build frankenphp binary (requires ZTS)
type: boolean
default: false
enable-zts:
description: Enable ZTS
type: boolean
default: false
prefer-pre-built:
description: Prefer pre-built binaries (reduce build time)
type: boolean
Expand Down Expand Up @@ -152,8 +174,19 @@ jobs:
RUNS_ON="macos-15"
;;
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 }}"
STATIC_EXTS="${{ inputs.extensions }}"
SHARED_EXTS="${{ inputs['shared-extensions'] }}"
BUILD_FRANKENPHP="${{ inputs['build-frankenphp'] }}"
ENABLE_ZTS="${{ inputs['enable-zts'] }}"
ALL_EXTS="$STATIC_EXTS"
if [ -n "$SHARED_EXTS" ]; then
ALL_EXTS="$ALL_EXTS,$SHARED_EXTS"
fi
DOWN_CMD="$DOWN_CMD --with-php=${{ inputs.php-version }} --for-extensions=$ALL_EXTS --ignore-cache-sources=php-src"
BUILD_CMD="$BUILD_CMD $STATIC_EXTS"
if [ -n "$SHARED_EXTS" ]; then
BUILD_CMD="$BUILD_CMD --build-shared=$SHARED_EXTS"
fi
if [ -n "${{ inputs.extra-libs }}" ]; then
DOWN_CMD="$DOWN_CMD --for-libs=${{ inputs.extra-libs }}"
BUILD_CMD="$BUILD_CMD --with-libs=${{ inputs.extra-libs }}"
Expand All @@ -177,6 +210,12 @@ jobs:
if [ ${{ inputs.build-fpm }} == true ]; then
BUILD_CMD="$BUILD_CMD --build-fpm"
fi
if [ "$BUILD_FRANKENPHP" = "true" ]; then
BUILD_CMD="$BUILD_CMD --build-frankenphp"
fi
if [ "$ENABLE_ZTS" = "true" ]; then
BUILD_CMD="$BUILD_CMD --enable-zts"
fi
echo 'download='"$DOWN_CMD" >> "$GITHUB_OUTPUT"
echo 'build='"$BUILD_CMD" >> "$GITHUB_OUTPUT"
echo 'run='"$RUNS_ON" >> "$GITHUB_OUTPUT"
Expand All @@ -199,6 +238,27 @@ jobs:
env:
phpts: nts

- if: ${{ inputs['build-frankenphp'] == true }}
name: "Install go-xcaddy for FrankenPHP"
run: |
case "${{ inputs.os }}" in
linux-x86_64|linux-aarch64)
./bin/spc-alpine-docker install-pkg go-xcaddy
;;
linux-x86_64-glibc|linux-aarch64-glibc)
./bin/spc-gnu-docker install-pkg go-xcaddy
;;
macos-x86_64|macos-aarch64)
composer update --no-dev --classmap-authoritative
./bin/spc doctor --auto-fix
./bin/spc install-pkg go-xcaddy
;;
*)
echo "Unsupported OS for go-xcaddy install: ${{ inputs.os }}"
exit 1
;;
esac

# Cache downloaded source
- id: cache-download
uses: actions/cache@v4
Expand Down Expand Up @@ -245,7 +305,22 @@ jobs:
name: php-fpm-${{ inputs.php-version }}-${{ inputs.os }}
path: buildroot/bin/php-fpm

# Upload frankenphp executable
- if: ${{ inputs['build-frankenphp'] == true }}
name: "Upload FrankenPHP SAPI"
uses: actions/upload-artifact@v4
with:
name: php-frankenphp-${{ inputs.php-version }}-${{ inputs.os }}
path: buildroot/bin/frankenphp

# Upload extensions metadata
- if: ${{ inputs['shared-extensions'] != '' }}
name: "Upload shared extensions"
uses: actions/upload-artifact@v4
with:
name: php-shared-ext-${{ inputs.php-version }}-${{ inputs.os }}
path: |
buildroot/modules/*.so
- uses: actions/upload-artifact@v4
name: "Upload License Files"
with:
Expand Down
2 changes: 2 additions & 0 deletions config/env.ini
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
; EXTRA_CFLAGS for `configure` and `make` php
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie -Werror=unknown-warning-option ${SPC_DEFAULT_C_FLAGS}"
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
; minimum compatible macOS version (LLVM vars, availability not guaranteed)
MACOSX_DEPLOYMENT_TARGET=12.0

Expand Down
6 changes: 4 additions & 2 deletions docs/en/guide/action-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ while also defining the extensions to compile.

1. Fork project.
2. Go to the Actions of the project and select `CI`.
3. Select `Run workflow`, fill in the PHP version you want to compile, the target type, and the list of extensions. (extensions comma separated, e.g. `bcmath,curl,mbstring`)
4. After waiting for about a period of time, enter the corresponding task and get `Artifacts`.
3. Select `Run workflow`, fill in the PHP version you want to compile, the target type, and the list of static extensions. (comma separated, e.g. `bcmath,curl,mbstring`)
4. If you need shared extensions (for example `xdebug`), set `shared-extensions` (comma separated, e.g. `xdebug`).
5. If you need FrankenPHP, enable `build-frankenphp` and also enable `enable-zts`.
6. After waiting for about a period of time, enter the corresponding task and get `Artifacts`.

If you enable `debug`, all logs will be output at build time, including compiled logs, for troubleshooting.

Expand Down
2 changes: 1 addition & 1 deletion src/SPC/builder/linux/LinuxBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
throw new WrongUsageException(
"You're building against musl libc statically (the default on Linux), but you're trying to build shared extensions.\n" .
'Static musl libc does not implement `dlopen`, so your php binary is not able to load shared extensions.' . "\n" .
'Either use SPC_LIBC=glibc to link against glibc on a glibc OS, or use SPC_TARGET="native-native-musl -dynamic" to link against musl libc dynamically using `zig cc`.'
'Either use SPC_LIBC=glibc to link against glibc on a glibc OS, use SPC_TARGET="native-native-musl -dynamic" to link against musl libc dynamically using `zig cc` or use SPC_MUSL_DYNAMIC=true on alpine.'
);
}
logger()->info('Building shared extensions...');
Expand Down
Loading