From 4d3501118e0a062767dcc625157754524971b9be Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 5 Sep 2025 21:36:25 +0700 Subject: [PATCH 1/8] add --with-frankenphp-app option to embed an app --- config/env.ini | 2 +- config/lib.json | 7 ++- config/source.json | 10 ++++ src/SPC/builder/unix/UnixBuilderBase.php | 63 +++++++++++++++++++++--- src/SPC/command/BuildPHPCommand.php | 1 + 5 files changed, 74 insertions(+), 9 deletions(-) diff --git a/config/env.ini b/config/env.ini index 4b9f294ad..8b5a58d41 100644 --- a/config/env.ini +++ b/config/env.ini @@ -43,7 +43,7 @@ SPC_SKIP_PHP_VERSION_CHECK="no" ; Ignore some check item for bin/spc doctor command, comma separated (e.g. SPC_SKIP_DOCTOR_CHECK_ITEMS="if homebrew has installed") SPC_SKIP_DOCTOR_CHECK_ITEMS="" ; extra modules that xcaddy will include in the FrankenPHP build -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" +SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES="--with github.com/dunglas/mercure/caddy --with github.com/dunglas/vulcain/caddy --with github.com/dunglas/caddy-cbrotli" ; The display message for php version output (PHP >= 8.4 available) PHP_BUILD_PROVIDER="static-php-cli ${SPC_VERSION}" diff --git a/config/lib.json b/config/lib.json index bda0baad2..eccda3043 100644 --- a/config/lib.json +++ b/config/lib.json @@ -7,7 +7,8 @@ "source": "php-src", "lib-depends": [ "lib-base", - "micro" + "micro", + "frankenphp" ], "lib-suggests-linux": [ "libacl", @@ -940,5 +941,9 @@ "liburing/", "liburing.h" ] + }, + "frankenphp": { + "source": "frankenphp", + "type": "target" } } diff --git a/config/source.json b/config/source.json index 4a0e0fdb5..f020ae06e 100644 --- a/config/source.json +++ b/config/source.json @@ -343,6 +343,16 @@ "path": "LICENSE" } }, + "frankenphp": { + "type": "ghtar", + "repo": "php/frankenphp", + "prefer-stable": true, + "provide-pre-build": false, + "license": { + "type": "file", + "path": "LICENSE" + } + }, "icu-static-win": { "type": "url", "url": "https://dl.static-php.dev/static-php-cli/deps/icu-static-windows-x64/icu-static-windows-x64.zip", diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 5309636fc..341a15bc1 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -12,6 +12,7 @@ use SPC\store\Config; use SPC\store\FileSystem; use SPC\store\pkg\GoXcaddy; +use SPC\store\SourceManager; use SPC\toolchain\GccNativeToolchain; use SPC\toolchain\ToolchainManager; use SPC\util\DependencyUtil; @@ -264,22 +265,70 @@ protected function patchPhpScripts(): void } } + /** + * Process the --with-frankenphp-app option + * Creates app.tar and app.checksum in source/frankenphp directory + */ + protected function processFrankenphpApp(): void + { + $frankenphpSourceDir = SOURCE_PATH . '/frankenphp'; + SourceManager::initSource(['frankenphp'], ['frankenphp']); + $frankenphpAppPath = $this->getOption('with-frankenphp-app'); + + if ($frankenphpAppPath) { + if (!is_dir($frankenphpAppPath)) { + throw new WrongUsageException("The path provided to --with-frankenphp-app is not a valid directory: {$frankenphpAppPath}"); + } + $appTarPath = $frankenphpSourceDir . '/app.tar'; + logger()->info("Creating app.tar from {$frankenphpAppPath}"); + + shell()->exec('tar -cf ' . escapeshellarg($appTarPath) . ' -C ' . escapeshellarg($frankenphpAppPath) . ' .'); + + $checksum = hash_file('md5', $appTarPath); + file_put_contents($frankenphpSourceDir . '/app_checksum.txt', $checksum); + } else { + FileSystem::removeFileIfExists($frankenphpSourceDir . '/app.tar'); + FileSystem::removeFileIfExists($frankenphpSourceDir . '/app_checksum.txt'); + file_put_contents($frankenphpSourceDir . '/app.tar', ''); + file_put_contents($frankenphpSourceDir . '/app_checksum.txt', ''); + } + } + + protected function getFrankenPHPVersion(): string + { + $goModPath = SOURCE_PATH . '/frankenphp/caddy/go.mod'; + + if (!file_exists($goModPath)) { + throw new SPCInternalException("FrankenPHP caddy/go.mod file not found at {$goModPath}, why did we not download FrankenPHP?"); + } + + $content = file_get_contents($goModPath); + if (preg_match('/github\.com\/dunglas\/frankenphp\s+v?(\d+\.\d+\.\d+)/', $content, $matches)) { + return $matches[1]; + } + + throw new SPCInternalException('Could not find FrankenPHP version in caddy/go.mod'); + } + protected function buildFrankenphp(): void { GlobalEnvManager::addPathIfNotExists(GoXcaddy::getEnvironment()['PATH']); + $this->processFrankenphpApp(); $nobrotli = $this->getLib('brotli') === null ? ',nobrotli' : ''; $nowatcher = $this->getLib('watcher') === null ? ',nowatcher' : ''; $xcaddyModules = getenv('SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES'); - // make it possible to build from a different frankenphp directory! - if (!str_contains($xcaddyModules, '--with github.com/dunglas/frankenphp')) { - $xcaddyModules = '--with github.com/dunglas/frankenphp ' . $xcaddyModules; - } + $frankenphpSourceDir = SOURCE_PATH . '/frankenphp'; + + $xcaddyModules = preg_replace('#--with github.com/dunglas/frankenphp(=\S+)?#', '', $xcaddyModules); + $xcaddyModules = preg_replace('#--with github.com/dunglas/frankenphp/caddy(=\S+)?#', '', $xcaddyModules); + $xcaddyModules = "--with github.com/dunglas/frankenphp={$frankenphpSourceDir} " . + "--with github.com/dunglas/frankenphp/caddy={$frankenphpSourceDir}/caddy {$xcaddyModules}"; if ($this->getLib('brotli') === null && str_contains($xcaddyModules, '--with github.com/dunglas/caddy-cbrotli')) { logger()->warning('caddy-cbrotli module is enabled, but brotli library is not built. Disabling caddy-cbrotli.'); $xcaddyModules = str_replace('--with github.com/dunglas/caddy-cbrotli', '', $xcaddyModules); } - [, $out] = shell()->execWithResult('go list -m github.com/dunglas/frankenphp@latest'); - $frankenPhpVersion = str_replace('github.com/dunglas/frankenphp v', '', $out[0]); + + $frankenPhpVersion = $this->getFrankenPHPVersion(); $libphpVersion = $this->getPHPVersion(); $dynamic_exports = ''; if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { @@ -317,7 +366,7 @@ protected function buildFrankenphp(): void 'XCADDY_GO_BUILD_FLAGS' => '-buildmode=pie ' . '-ldflags \"-linkmode=external ' . $extLdFlags . ' ' . $debugFlags . '-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' . - "{$frankenPhpVersion} PHP {$libphpVersion} Caddy'\\\" " . + "v{$frankenPhpVersion} PHP {$libphpVersion} Caddy'\\\" " . "-tags={$muslTags}nobadger,nomysql,nopgx{$nobrotli}{$nowatcher}", 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, ]; diff --git a/src/SPC/command/BuildPHPCommand.php b/src/SPC/command/BuildPHPCommand.php index 3ffc54cef..f8ab384b0 100644 --- a/src/SPC/command/BuildPHPCommand.php +++ b/src/SPC/command/BuildPHPCommand.php @@ -48,6 +48,7 @@ public function configure(): void $this->addOption('with-upx-pack', null, null, 'Compress / pack binary using UPX tool (linux/windows only)'); $this->addOption('with-micro-logo', null, InputOption::VALUE_REQUIRED, 'Use custom .ico for micro.sfx (windows only)'); $this->addOption('enable-micro-win32', null, null, 'Enable win32 mode for phpmicro (Windows only)'); + $this->addOption('with-frankenphp-app', null, InputOption::VALUE_REQUIRED, 'Path to a folder to be embedded in FrankenPHP'); } public function handle(): int From 9a2d94cc3398975fae60a4e6b7bc1923a310f878 Mon Sep 17 00:00:00 2001 From: henderkes Date: Tue, 28 Oct 2025 18:50:16 +0100 Subject: [PATCH 2/8] fix debugflags being backwards --- src/SPC/builder/unix/UnixBuilderBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 85fb61517..6249274c6 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -339,7 +339,7 @@ protected function buildFrankenphp(): void $dynamic_exports = ' ' . $dynamicSymbolsArgument; } } - $debugFlags = $this->getOption('no-strip') ? '-w -s ' : ''; + $debugFlags = $this->getOption('no-strip') ? '' : '-w -s '; $extLdFlags = "-extldflags '-pie{$dynamic_exports} {$this->arch_ld_flags}'"; $muslTags = ''; $staticFlags = ''; From ed4978bb893bfc67109157f1b7c89a072d750a2c Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 3 Nov 2025 20:40:50 +0100 Subject: [PATCH 3/8] add frankenphp version --- src/SPC/builder/unix/UnixBuilderBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 6249274c6..46f4cb433 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -350,7 +350,7 @@ protected function buildFrankenphp(): void } $config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list); - $cflags = "{$this->arch_c_flags} {$config['cflags']} " . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'); + $cflags = "{$this->arch_c_flags} {$config['cflags']} " . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -DFRANKENPHP_VERSION=' . $frankenPhpVersion; $libs = $config['libs']; // Go's gcc driver doesn't automatically link against -lgcov or -lrt. Ugly, but necessary fix. if ((str_contains((string) getenv('SPC_DEFAULT_C_FLAGS'), '-fprofile') || From 4198ddd5d1ae8f41fe036354a0a4209a8ce603b9 Mon Sep 17 00:00:00 2001 From: henderkes Date: Fri, 7 Nov 2025 11:06:50 +0100 Subject: [PATCH 4/8] make --with-frankenphp-app=dir work with docker scripts --- bin/spc-alpine-docker | 43 ++++++++++++++++++++++++++++++++++++++++++- bin/spc-gnu-docker | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/bin/spc-alpine-docker b/bin/spc-alpine-docker index 6365233c5..0d618743e 100755 --- a/bin/spc-alpine-docker +++ b/bin/spc-alpine-docker @@ -162,6 +162,47 @@ if [ ! -z "$GITHUB_TOKEN" ]; then ENV_LIST="$ENV_LIST -e GITHUB_TOKEN=$GITHUB_TOKEN" fi +# Intercept and rewrite --with-frankenphp-app option, and mount host path to /app/app +FRANKENPHP_APP_PATH="" +NEW_ARGS=() +while [ $# -gt 0 ]; do + case "$1" in + --with-frankenphp-app=*) + FRANKENPHP_APP_PATH="${1#*=}" + NEW_ARGS+=("--with-frankenphp-app=/app/app") + shift + ;; + --with-frankenphp-app) + if [ -n "${2:-}" ]; then + FRANKENPHP_APP_PATH="$2" + NEW_ARGS+=("--with-frankenphp-app=/app/app") + shift 2 + else + NEW_ARGS+=("$1") + shift + fi + ;; + *) + NEW_ARGS+=("$1") + shift + ;; + esac +done + +# Normalize the path and add mount if provided +if [ -n "$FRANKENPHP_APP_PATH" ]; then + # expand ~ to $HOME + if [ "${FRANKENPHP_APP_PATH#~}" != "$FRANKENPHP_APP_PATH" ]; then + FRANKENPHP_APP_PATH="$HOME${FRANKENPHP_APP_PATH#~}" + fi + # make absolute if relative + case "$FRANKENPHP_APP_PATH" in + /*) ABS_APP_PATH="$FRANKENPHP_APP_PATH" ;; + *) ABS_APP_PATH="$(pwd)/$FRANKENPHP_APP_PATH" ;; + esac + MOUNT_LIST="$MOUNT_LIST -v \"$ABS_APP_PATH\":/app/app" +fi + # Run docker # shellcheck disable=SC2068 # shellcheck disable=SC2086 @@ -183,5 +224,5 @@ if [ "$SPC_DOCKER_DEBUG" = "yes" ]; then set -ex $DOCKER_EXECUTABLE run $PLATFORM_ARG --rm $INTERACT $ENV_LIST $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION /bin/bash else - $DOCKER_EXECUTABLE run $PLATFORM_ARG --rm $INTERACT $ENV_LIST $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION bin/spc $@ + $DOCKER_EXECUTABLE run $PLATFORM_ARG --rm $INTERACT $ENV_LIST $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION bin/spc "${NEW_ARGS[@]}" fi diff --git a/bin/spc-gnu-docker b/bin/spc-gnu-docker index 7fcf5d410..29c68adef 100755 --- a/bin/spc-gnu-docker +++ b/bin/spc-gnu-docker @@ -174,6 +174,47 @@ if [ ! -z "$GITHUB_TOKEN" ]; then ENV_LIST="$ENV_LIST -e GITHUB_TOKEN=$GITHUB_TOKEN" fi +# Intercept and rewrite --with-frankenphp-app option, and mount host path to /app/app +FRANKENPHP_APP_PATH="" +NEW_ARGS=() +while [ $# -gt 0 ]; do + case "$1" in + --with-frankenphp-app=*) + FRANKENPHP_APP_PATH="${1#*=}" + NEW_ARGS+=("--with-frankenphp-app=/app/app") + shift + ;; + --with-frankenphp-app) + if [ -n "${2:-}" ]; then + FRANKENPHP_APP_PATH="$2" + NEW_ARGS+=("--with-frankenphp-app=/app/app") + shift 2 + else + NEW_ARGS+=("$1") + shift + fi + ;; + *) + NEW_ARGS+=("$1") + shift + ;; + esac +done + +# Normalize the path and add mount if provided +if [ -n "$FRANKENPHP_APP_PATH" ]; then + # expand ~ to $HOME + if [ "${FRANKENPHP_APP_PATH#~}" != "$FRANKENPHP_APP_PATH" ]; then + FRANKENPHP_APP_PATH="$HOME${FRANKENPHP_APP_PATH#~}" + fi + # make absolute if relative + case "$FRANKENPHP_APP_PATH" in + /*) ABS_APP_PATH="$FRANKENPHP_APP_PATH" ;; + *) ABS_APP_PATH="$(pwd)/$FRANKENPHP_APP_PATH" ;; + esac + MOUNT_LIST="$MOUNT_LIST -v \"$ABS_APP_PATH\":/app/app" +fi + # Run docker # shellcheck disable=SC2068 # shellcheck disable=SC2086 @@ -196,5 +237,5 @@ if [ "$SPC_DOCKER_DEBUG" = "yes" ]; then set -ex $DOCKER_EXECUTABLE run $PLATFORM_ARG --privileged --rm -it $INTERACT $ENV_LIST --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH-$SPC_DOCKER_VERSION /bin/bash else - $DOCKER_EXECUTABLE run $PLATFORM_ARG --rm $INTERACT $ENV_LIST --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH-$SPC_DOCKER_VERSION bin/spc $@ + $DOCKER_EXECUTABLE run $PLATFORM_ARG --rm $INTERACT $ENV_LIST --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH-$SPC_DOCKER_VERSION bin/spc "${NEW_ARGS[@]}" fi From 09b7159119e15ed6fb68b216f71a77ce9fc5923c Mon Sep 17 00:00:00 2001 From: henderkes Date: Sat, 8 Nov 2025 09:40:16 +0100 Subject: [PATCH 5/8] update freetype download to get latest version --- config/source.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/source.json b/config/source.json index 4a1990815..ca1edfb02 100644 --- a/config/source.json +++ b/config/source.json @@ -302,9 +302,9 @@ } }, "freetype": { - "type": "git", - "rev": "VER-2-13-2", - "url": "https://github.com/freetype/freetype", + "type": "ghtagtar", + "repo": "freetype/freetype", + "match": "VER-2-\\d+-\\d+", "license": { "type": "file", "path": "LICENSE.TXT" From d6de01d05c2eeb26d3693a7bf79916fbbc225acd Mon Sep 17 00:00:00 2001 From: henderkes Date: Sun, 9 Nov 2025 10:01:19 +0100 Subject: [PATCH 6/8] update to rc4 --- src/SPC/store/source/PhpSource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/store/source/PhpSource.php b/src/SPC/store/source/PhpSource.php index 1c0be85fb..e0b3ba279 100644 --- a/src/SPC/store/source/PhpSource.php +++ b/src/SPC/store/source/PhpSource.php @@ -16,7 +16,7 @@ public function fetch(bool $force = false, ?array $config = null, int $lock_as = { $major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.4'; if ($major === '8.5') { - Downloader::downloadSource('php-src', ['type' => 'url', 'url' => 'https://downloads.php.net/~daniels/php-8.5.0RC3.tar.xz'], $force); + Downloader::downloadSource('php-src', ['type' => 'url', 'url' => 'https://downloads.php.net/~edorian/php-8.5.0RC4.tar.xz'], $force); } elseif ($major === 'git') { Downloader::downloadSource('php-src', ['type' => 'git', 'url' => 'https://github.com/php/php-src.git', 'rev' => 'master'], $force); } else { From 1575016885b7bede22cd4255567478a2afe3a6d8 Mon Sep 17 00:00:00 2001 From: henderkes Date: Sun, 9 Nov 2025 23:35:49 +0100 Subject: [PATCH 7/8] simplify regex --- src/SPC/builder/unix/UnixBuilderBase.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 46f4cb433..2a9bcb9bb 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -320,8 +320,7 @@ protected function buildFrankenphp(): void $xcaddyModules = getenv('SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES'); $frankenphpSourceDir = SOURCE_PATH . '/frankenphp'; - $xcaddyModules = preg_replace('#--with github.com/dunglas/frankenphp(=\S+)?#', '', $xcaddyModules); - $xcaddyModules = preg_replace('#--with github.com/dunglas/frankenphp/caddy(=\S+)?#', '', $xcaddyModules); + $xcaddyModules = preg_replace('#--with github.com/dunglas/frankenphp\S*#', '', $xcaddyModules); $xcaddyModules = "--with github.com/dunglas/frankenphp={$frankenphpSourceDir} " . "--with github.com/dunglas/frankenphp/caddy={$frankenphpSourceDir}/caddy {$xcaddyModules}"; if ($this->getLib('brotli') === null && str_contains($xcaddyModules, '--with github.com/dunglas/caddy-cbrotli')) { From e441a575eaedf1cfc4f9084878bd5306134fcb30 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 10 Nov 2025 13:26:17 +0800 Subject: [PATCH 8/8] Remove escape backslashes --- bin/spc-alpine-docker | 2 +- bin/spc-gnu-docker | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/spc-alpine-docker b/bin/spc-alpine-docker index 0d618743e..2790a5c34 100755 --- a/bin/spc-alpine-docker +++ b/bin/spc-alpine-docker @@ -200,7 +200,7 @@ if [ -n "$FRANKENPHP_APP_PATH" ]; then /*) ABS_APP_PATH="$FRANKENPHP_APP_PATH" ;; *) ABS_APP_PATH="$(pwd)/$FRANKENPHP_APP_PATH" ;; esac - MOUNT_LIST="$MOUNT_LIST -v \"$ABS_APP_PATH\":/app/app" + MOUNT_LIST="$MOUNT_LIST -v $ABS_APP_PATH:/app/app" fi # Run docker diff --git a/bin/spc-gnu-docker b/bin/spc-gnu-docker index 29c68adef..68f85109f 100755 --- a/bin/spc-gnu-docker +++ b/bin/spc-gnu-docker @@ -212,7 +212,7 @@ if [ -n "$FRANKENPHP_APP_PATH" ]; then /*) ABS_APP_PATH="$FRANKENPHP_APP_PATH" ;; *) ABS_APP_PATH="$(pwd)/$FRANKENPHP_APP_PATH" ;; esac - MOUNT_LIST="$MOUNT_LIST -v \"$ABS_APP_PATH\":/app/app" + MOUNT_LIST="$MOUNT_LIST -v $ABS_APP_PATH:/app/app" fi # Run docker