Skip to content

Commit 295df19

Browse files
Add shared-extensions, frankenphp and zts to build-unix workflow (#1062)
Co-authored-by: crazywhalecc <jesse2061@outlook.com>
1 parent b970bf8 commit 295df19

5 files changed

Lines changed: 87 additions & 6 deletions

File tree

.github/workflows/build-unix.yml

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ on:
2929
description: Extensions to build (comma separated)
3030
required: true
3131
type: string
32+
shared-extensions:
33+
description: Shared extensions to build (optional, comma separated)
34+
type: string
3235
extra-libs:
3336
description: Extra libraries to build (optional, comma separated)
3437
type: string
@@ -42,6 +45,14 @@ on:
4245
build-fpm:
4346
description: Build fpm binary
4447
type: boolean
48+
build-frankenphp:
49+
description: Build frankenphp binary (requires ZTS)
50+
type: boolean
51+
default: false
52+
enable-zts:
53+
description: Enable ZTS
54+
type: boolean
55+
default: false
4556
prefer-pre-built:
4657
description: Prefer pre-built binaries (reduce build time)
4758
type: boolean
@@ -73,6 +84,9 @@ on:
7384
description: Extensions to build (comma separated)
7485
required: true
7586
type: string
87+
shared-extensions:
88+
description: Shared extensions to build (optional, comma separated)
89+
type: string
7690
extra-libs:
7791
description: Extra libraries to build (optional, comma separated)
7892
type: string
@@ -86,6 +100,14 @@ on:
86100
build-fpm:
87101
description: Build fpm binary
88102
type: boolean
103+
build-frankenphp:
104+
description: Build frankenphp binary (requires ZTS)
105+
type: boolean
106+
default: false
107+
enable-zts:
108+
description: Enable ZTS
109+
type: boolean
110+
default: false
89111
prefer-pre-built:
90112
description: Prefer pre-built binaries (reduce build time)
91113
type: boolean
@@ -152,8 +174,19 @@ jobs:
152174
RUNS_ON="macos-15"
153175
;;
154176
esac
155-
DOWN_CMD="$DOWN_CMD --with-php=${{ inputs.php-version }} --for-extensions=${{ inputs.extensions }} --ignore-cache-sources=php-src"
156-
BUILD_CMD="$BUILD_CMD ${{ inputs.extensions }}"
177+
STATIC_EXTS="${{ inputs.extensions }}"
178+
SHARED_EXTS="${{ inputs['shared-extensions'] }}"
179+
BUILD_FRANKENPHP="${{ inputs['build-frankenphp'] }}"
180+
ENABLE_ZTS="${{ inputs['enable-zts'] }}"
181+
ALL_EXTS="$STATIC_EXTS"
182+
if [ -n "$SHARED_EXTS" ]; then
183+
ALL_EXTS="$ALL_EXTS,$SHARED_EXTS"
184+
fi
185+
DOWN_CMD="$DOWN_CMD --with-php=${{ inputs.php-version }} --for-extensions=$ALL_EXTS --ignore-cache-sources=php-src"
186+
BUILD_CMD="$BUILD_CMD $STATIC_EXTS"
187+
if [ -n "$SHARED_EXTS" ]; then
188+
BUILD_CMD="$BUILD_CMD --build-shared=$SHARED_EXTS"
189+
fi
157190
if [ -n "${{ inputs.extra-libs }}" ]; then
158191
DOWN_CMD="$DOWN_CMD --for-libs=${{ inputs.extra-libs }}"
159192
BUILD_CMD="$BUILD_CMD --with-libs=${{ inputs.extra-libs }}"
@@ -177,6 +210,12 @@ jobs:
177210
if [ ${{ inputs.build-fpm }} == true ]; then
178211
BUILD_CMD="$BUILD_CMD --build-fpm"
179212
fi
213+
if [ "$BUILD_FRANKENPHP" = "true" ]; then
214+
BUILD_CMD="$BUILD_CMD --build-frankenphp"
215+
fi
216+
if [ "$ENABLE_ZTS" = "true" ]; then
217+
BUILD_CMD="$BUILD_CMD --enable-zts"
218+
fi
180219
echo 'download='"$DOWN_CMD" >> "$GITHUB_OUTPUT"
181220
echo 'build='"$BUILD_CMD" >> "$GITHUB_OUTPUT"
182221
echo 'run='"$RUNS_ON" >> "$GITHUB_OUTPUT"
@@ -199,6 +238,27 @@ jobs:
199238
env:
200239
phpts: nts
201240

241+
- if: ${{ inputs['build-frankenphp'] == true }}
242+
name: "Install go-xcaddy for FrankenPHP"
243+
run: |
244+
case "${{ inputs.os }}" in
245+
linux-x86_64|linux-aarch64)
246+
./bin/spc-alpine-docker install-pkg go-xcaddy
247+
;;
248+
linux-x86_64-glibc|linux-aarch64-glibc)
249+
./bin/spc-gnu-docker install-pkg go-xcaddy
250+
;;
251+
macos-x86_64|macos-aarch64)
252+
composer update --no-dev --classmap-authoritative
253+
./bin/spc doctor --auto-fix
254+
./bin/spc install-pkg go-xcaddy
255+
;;
256+
*)
257+
echo "Unsupported OS for go-xcaddy install: ${{ inputs.os }}"
258+
exit 1
259+
;;
260+
esac
261+
202262
# Cache downloaded source
203263
- id: cache-download
204264
uses: actions/cache@v4
@@ -245,7 +305,22 @@ jobs:
245305
name: php-fpm-${{ inputs.php-version }}-${{ inputs.os }}
246306
path: buildroot/bin/php-fpm
247307

308+
# Upload frankenphp executable
309+
- if: ${{ inputs['build-frankenphp'] == true }}
310+
name: "Upload FrankenPHP SAPI"
311+
uses: actions/upload-artifact@v4
312+
with:
313+
name: php-frankenphp-${{ inputs.php-version }}-${{ inputs.os }}
314+
path: buildroot/bin/frankenphp
315+
248316
# Upload extensions metadata
317+
- if: ${{ inputs['shared-extensions'] != '' }}
318+
name: "Upload shared extensions"
319+
uses: actions/upload-artifact@v4
320+
with:
321+
name: php-shared-ext-${{ inputs.php-version }}-${{ inputs.os }}
322+
path: |
323+
buildroot/modules/*.so
249324
- uses: actions/upload-artifact@v4
250325
name: "Upload License Files"
251326
with:

config/env.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-
148148
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
149149
; EXTRA_CFLAGS for `configure` and `make` php
150150
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie -Werror=unknown-warning-option ${SPC_DEFAULT_C_FLAGS}"
151+
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so
152+
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
151153
; minimum compatible macOS version (LLVM vars, availability not guaranteed)
152154
MACOSX_DEPLOYMENT_TARGET=12.0
153155

docs/en/guide/action-build.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ while also defining the extensions to compile.
1616

1717
1. Fork project.
1818
2. Go to the Actions of the project and select `CI`.
19-
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`)
20-
4. After waiting for about a period of time, enter the corresponding task and get `Artifacts`.
19+
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`)
20+
4. If you need shared extensions (for example `xdebug`), set `shared-extensions` (comma separated, e.g. `xdebug`).
21+
5. If you need FrankenPHP, enable `build-frankenphp` and also enable `enable-zts`.
22+
6. After waiting for about a period of time, enter the corresponding task and get `Artifacts`.
2123

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

docs/zh/guide/action-build.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ Action 构建指的是直接使用 GitHub Action 进行编译。
1414
1. Fork 本项目。
1515
2. 进入项目的 Actions,选择 CI 开头的 Workflow(根据你需要的操作系统选择)。
1616
3. 选择 `Run workflow`,填入你要编译的 PHP 版本、目标类型、扩展列表。(扩展列表使用英文逗号分割,例如 `bcmath,curl,mbstring`
17-
4. 等待大约一段时间后,进入对应的任务中,获取 `Artifacts`
17+
4. 如果需要共享扩展(例如 `xdebug`),请设置 `shared-extensions`(使用英文逗号分割,例如 `xdebug`)。
18+
5. 如果需要 FrankenPHP,请启用 `build-frankenphp`,同时也需要启用 `enable-zts`
19+
6. 等待大约一段时间后,进入对应的任务中,获取 `Artifacts`
1820

1921
如果你选择了 `debug`,则会在构建时输出所有日志,包括编译的日志,以供排查错误。
2022

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
162162
throw new WrongUsageException(
163163
"You're building against musl libc statically (the default on Linux), but you're trying to build shared extensions.\n" .
164164
'Static musl libc does not implement `dlopen`, so your php binary is not able to load shared extensions.' . "\n" .
165-
'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`.'
165+
'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.'
166166
);
167167
}
168168
logger()->info('Building shared extensions...');

0 commit comments

Comments
 (0)