Skip to content

Commit 3af40a6

Browse files
authored
Merge pull request #772 from crazywhalecc/sapi/frankenphp
Sapi/frankenphp
2 parents ba0ea5b + 6e70f16 commit 3af40a6

22 files changed

+344
-49
lines changed

.github/pull_request_template.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
> If your PR involves the changes mentioned below and completed the action, please tick the corresponding option.
88
> If a modification is not involved, please skip it directly.
99
10-
- [ ] If you modified `*.php`, run `composer cs-fix` at local machine.
11-
- [ ] If it's an extension or dependency update, make sure adding related extensions in `src/global/test-extensions.php`.
12-
- [ ] If you changed the behavior of static-php-cli, update docs in `./docs/`.
13-
- [ ] If you updated `config/xxx.json` content, run `bin/spc dev:sort-config xxx`.
10+
- If you modified `*.php` or `*.json`, run them locally to ensure your changes are valid:
11+
- [ ] `PHP_CS_FIXER_IGNORE_ENV=1 composer cs-fix`
12+
- [ ] `composer analyse`
13+
- [ ] `composer test`
14+
- [ ] `bin/spc dev:sort-config`
15+
- If it's an extension or dependency update, please ensure the following:
16+
- [ ] Add your test combination to `src/globals/test-extensions.php`.
17+
- [ ] If adding new or fixing bugs, add commit message containing `extension test` or `test extensions` to trigger full test suite.

.github/workflows/ext-matrix-tests.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
name: "Extension matrix tests"
1+
name: "Extension Matrix Tests"
22

33
on:
44
workflow_dispatch:
5-
pull_request:
6-
branches: [ "main" ]
7-
paths:
8-
- '.github/workflows/ext-matrix-tests.yml'
5+
push:
96

107
jobs:
118
test:
129
name: "${{ matrix.extension }} (PHP ${{ matrix.php-version }} on ${{ matrix.operating-system }})"
1310
runs-on: ${{ matrix.operating-system }}
11+
if: contains(github.event.head_commit.message, 'extension test') || contains(github.event.head_commit.message, 'test extensions')
1412
strategy:
1513
fail-fast: false
1614
matrix:

bin/spc-gnu-docker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ ENV PATH="/app/bin:/cmake/bin:$PATH"
9494
ENV SPC_LIBC=glibc
9595
9696
ADD ./config/env.ini /app/config/env.ini
97-
RUN bin/spc doctor --auto-fix --debug
97+
RUN CC=gcc bin/spc doctor --auto-fix --debug
9898
9999
RUN curl -o make.tgz -fsSL https://ftp.gnu.org/gnu/make/make-4.4.tar.gz && \
100100
tar -zxvf make.tgz && \

config/env.ini

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ SPC_CONCURRENCY=${CPU_COUNT}
4242
SPC_SKIP_PHP_VERSION_CHECK="no"
4343
; Ignore some check item for bin/spc doctor command, comma separated (e.g. SPC_SKIP_DOCTOR_CHECK_ITEMS="if homebrew has installed")
4444
SPC_SKIP_DOCTOR_CHECK_ITEMS=""
45+
; extra modules that xcaddy will include in the FrankenPHP build
46+
SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES="--with github.com/dunglas/frankenphp/caddy --with github.com/dunglas/mercure/caddy --with github.com/dunglas/vulcain/caddy --with github.com/dunglas/caddy-cbrotli"
47+
4548
; EXTENSION_DIR where the built php will look for extension when a .ini instructs to load them
4649
; only useful for builds targeting not pure-static linking
4750
; default paths
@@ -68,8 +71,8 @@ CXX=${SPC_LINUX_DEFAULT_CXX}
6871
AR=${SPC_LINUX_DEFAULT_AR}
6972
LD=ld.gold
7073
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
71-
SPC_DEFAULT_C_FLAGS="-fpic -Os"
72-
SPC_DEFAULT_CXX_FLAGS="-fpic -Os"
74+
SPC_DEFAULT_C_FLAGS="-fPIC -Os"
75+
SPC_DEFAULT_CXX_FLAGS="-fPIC -Os"
7376
; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated)
7477
SPC_EXTRA_LIBS=
7578
; upx executable path
@@ -89,15 +92,15 @@ SPC_CMD_VAR_PHP_EMBED_TYPE="static"
8992

9093
; *** default build vars for building php ***
9194
; CFLAGS for configuring php
92-
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -fpie"
95+
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -fPIE"
9396
; CPPFLAGS for configuring php
9497
SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}"
9598
; LDFLAGS for configuring php
9699
SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}"
97100
; LIBS for configuring php
98101
SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lpthread -lm"
99102
; EXTRA_CFLAGS for `make` php
100-
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fpie ${SPC_DEFAULT_C_FLAGS}"
103+
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}"
101104
; EXTRA_LIBS for `make` php
102105
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm"
103106
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so

config/pkg.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,17 @@
4242
"extract-files": {
4343
"upx-*-win64/upx.exe": "{pkg_root_path}/bin/upx.exe"
4444
}
45+
},
46+
"go-mod-frankenphp-x86_64-linux": {
47+
"type": "custom"
48+
},
49+
"go-mod-frankenphp-aarch64-linux": {
50+
"type": "custom"
51+
},
52+
"go-mod-frankenphp-x86_64-macos": {
53+
"type": "custom"
54+
},
55+
"go-mod-frankenphp-aarch64-macos": {
56+
"type": "custom"
4557
}
4658
}

docs/deps-craft-yml.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ build-options:
4242
# Set micro SAPI as win32 mode, without this, micro SAPI will be compiled as a console application (only for Windows, default: false)
4343
enable-micro-win32: false
4444

45+
# Build options for shared extensions (list or comma-separated are both accepted)
46+
shared-extensions: [ ]
47+
4548
# Download options
4649
download-options:
4750
# Use custom url for specified sources, format: "{source-name}:{url}" (e.g. "php-src:https://example.com/php-8.4.0.tar.gz")

src/SPC/builder/BuilderBase.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ public function getBuildTypeName(int $type): string
401401
if (($type & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED) {
402402
$ls[] = 'embed';
403403
}
404+
if (($type & BUILD_TARGET_FRANKENPHP) === BUILD_TARGET_FRANKENPHP) {
405+
$ls[] = 'frankenphp';
406+
}
404407
return implode(', ', $ls);
405408
}
406409

@@ -507,6 +510,26 @@ public function emitPatchPoint(string $point_name): void
507510
}
508511
}
509512

513+
public function checkBeforeBuildPHP(int $rule): void
514+
{
515+
if (($rule & BUILD_TARGET_FRANKENPHP) === BUILD_TARGET_FRANKENPHP) {
516+
// frankenphp only support linux and macOS
517+
if (!in_array(PHP_OS_FAMILY, ['Linux', 'Darwin'])) {
518+
throw new WrongUsageException('FrankenPHP SAPI is only available on Linux and macOS!');
519+
}
520+
// frankenphp needs package go-mod-frankenphp installed
521+
$pkg_dir = PKG_ROOT_PATH . '/go-mod-frankenphp-' . arch2gnu(php_uname('m')) . '-' . osfamily2shortname();
522+
if (!file_exists("{$pkg_dir}/bin/go") || !file_exists("{$pkg_dir}/bin/xcaddy")) {
523+
global $argv;
524+
throw new WrongUsageException("FrankenPHP SAPI requires go-mod-frankenphp package, please install it first: {$argv[0]} install-pkg go-mod-frankenphp");
525+
}
526+
// frankenphp needs libxml2 libs
527+
if (PHP_OS_FAMILY === 'Darwin' && !$this->getLib('libxml2')) {
528+
throw new WrongUsageException('FrankenPHP SAPI for macOS requires libxml2 library, please include `xml` extension in your build.');
529+
}
530+
}
531+
}
532+
510533
/**
511534
* Generate micro extension test php code.
512535
*/

src/SPC/builder/freebsd/BSDBuilder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
9696
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
9797
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
9898
$enableEmbed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED;
99+
$enableFrankenphp = ($build_target & BUILD_TARGET_FRANKENPHP) === BUILD_TARGET_FRANKENPHP;
99100

100101
shell()->cd(SOURCE_PATH . '/php-src')
101102
->exec(
@@ -143,6 +144,10 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
143144
}
144145
$this->buildEmbed();
145146
}
147+
if ($enableFrankenphp) {
148+
logger()->info('building frankenphp');
149+
$this->buildFrankenphp();
150+
}
146151
}
147152

148153
public function testPHP(int $build_target = BUILD_TARGET_NONE)

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
110110
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
111111
('--with-config-file-scan-dir=' . $this->getOption('with-config-file-scan-dir') . ' ') : '';
112112

113-
$enable_cli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
114-
$enable_fpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
115-
$enable_micro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
116-
$enable_embed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED;
113+
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
114+
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
115+
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
116+
$enableEmbed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED;
117+
$enableFrankenphp = ($build_target & BUILD_TARGET_FRANKENPHP) === BUILD_TARGET_FRANKENPHP;
117118

118119
$mimallocLibs = $this->getLib('mimalloc') !== null ? BUILD_LIB_PATH . '/mimalloc.o ' : '';
119120
// prepare build php envs
@@ -125,7 +126,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
125126
]);
126127

127128
// process micro upx patch if micro sapi enabled
128-
if ($enable_micro) {
129+
if ($enableMicro) {
129130
if (version_compare($this->getMicroVersion(), '0.2.0') < 0) {
130131
// for phpmicro 0.1.x
131132
$this->processMicroUPXLegacy();
@@ -137,10 +138,10 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
137138
shell()->cd(SOURCE_PATH . '/php-src')
138139
->exec(
139140
getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
140-
($enable_cli ? '--enable-cli ' : '--disable-cli ') .
141-
($enable_fpm ? '--enable-fpm ' . ($this->getLib('libacl') !== null ? '--with-fpm-acl ' : '') : '--disable-fpm ') .
142-
($enable_embed ? "--enable-embed={$embed_type} " : '--disable-embed ') .
143-
($enable_micro ? '--enable-micro=all-static ' : '--disable-micro ') .
141+
($enableCli ? '--enable-cli ' : '--disable-cli ') .
142+
($enableFpm ? '--enable-fpm ' . ($this->getLib('libacl') !== null ? '--with-fpm-acl ' : '') : '--disable-fpm ') .
143+
($enableEmbed ? "--enable-embed={$embed_type} " : '--disable-embed ') .
144+
($enableMicro ? '--enable-micro=all-static ' : '--disable-micro ') .
144145
$config_file_path .
145146
$config_file_scan_dir .
146147
$disable_jit .
@@ -156,25 +157,29 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
156157

157158
$this->cleanMake();
158159

159-
if ($enable_cli) {
160+
if ($enableCli) {
160161
logger()->info('building cli');
161162
$this->buildCli();
162163
}
163-
if ($enable_fpm) {
164+
if ($enableFpm) {
164165
logger()->info('building fpm');
165166
$this->buildFpm();
166167
}
167-
if ($enable_micro) {
168+
if ($enableMicro) {
168169
logger()->info('building micro');
169170
$this->buildMicro();
170171
}
171-
if ($enable_embed) {
172+
if ($enableEmbed) {
172173
logger()->info('building embed');
173-
if ($enable_micro) {
174+
if ($enableMicro) {
174175
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/Makefile', 'OVERALL_TARGET =', 'OVERALL_TARGET = libphp.la');
175176
}
176177
$this->buildEmbed();
177178
}
179+
if ($enableFrankenphp) {
180+
logger()->info('building frankenphp');
181+
$this->buildFrankenphp();
182+
}
178183
}
179184

180185
public function testPHP(int $build_target = BUILD_TARGET_NONE)

src/SPC/builder/macos/MacOSBuilder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
122122
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
123123
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
124124
$enableEmbed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED;
125+
$enableFrankenphp = ($build_target & BUILD_TARGET_FRANKENPHP) === BUILD_TARGET_FRANKENPHP;
125126

126127
// prepare build php envs
127128
$mimallocLibs = $this->getLib('mimalloc') !== null ? BUILD_LIB_PATH . '/mimalloc.o ' : '';
@@ -180,6 +181,10 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
180181
}
181182
$this->buildEmbed();
182183
}
184+
if ($enableFrankenphp) {
185+
logger()->info('building frankenphp');
186+
$this->buildFrankenphp();
187+
}
183188
}
184189

185190
public function testPHP(int $build_target = BUILD_TARGET_NONE)

0 commit comments

Comments
 (0)