Skip to content

Commit 00050f4

Browse files
authored
Merge branch 'main' into feat/no-strip
2 parents 987ad4b + 4ae4165 commit 00050f4

File tree

8 files changed

+176
-15
lines changed

8 files changed

+176
-15
lines changed

bin/spc-alpine-docker

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,47 @@ if [ ! -z "$GITHUB_TOKEN" ]; then
162162
ENV_LIST="$ENV_LIST -e GITHUB_TOKEN=$GITHUB_TOKEN"
163163
fi
164164

165+
# Intercept and rewrite --with-frankenphp-app option, and mount host path to /app/app
166+
FRANKENPHP_APP_PATH=""
167+
NEW_ARGS=()
168+
while [ $# -gt 0 ]; do
169+
case "$1" in
170+
--with-frankenphp-app=*)
171+
FRANKENPHP_APP_PATH="${1#*=}"
172+
NEW_ARGS+=("--with-frankenphp-app=/app/app")
173+
shift
174+
;;
175+
--with-frankenphp-app)
176+
if [ -n "${2:-}" ]; then
177+
FRANKENPHP_APP_PATH="$2"
178+
NEW_ARGS+=("--with-frankenphp-app=/app/app")
179+
shift 2
180+
else
181+
NEW_ARGS+=("$1")
182+
shift
183+
fi
184+
;;
185+
*)
186+
NEW_ARGS+=("$1")
187+
shift
188+
;;
189+
esac
190+
done
191+
192+
# Normalize the path and add mount if provided
193+
if [ -n "$FRANKENPHP_APP_PATH" ]; then
194+
# expand ~ to $HOME
195+
if [ "${FRANKENPHP_APP_PATH#~}" != "$FRANKENPHP_APP_PATH" ]; then
196+
FRANKENPHP_APP_PATH="$HOME${FRANKENPHP_APP_PATH#~}"
197+
fi
198+
# make absolute if relative
199+
case "$FRANKENPHP_APP_PATH" in
200+
/*) ABS_APP_PATH="$FRANKENPHP_APP_PATH" ;;
201+
*) ABS_APP_PATH="$(pwd)/$FRANKENPHP_APP_PATH" ;;
202+
esac
203+
MOUNT_LIST="$MOUNT_LIST -v $ABS_APP_PATH:/app/app"
204+
fi
205+
165206
# Run docker
166207
# shellcheck disable=SC2068
167208
# shellcheck disable=SC2086
@@ -183,5 +224,5 @@ if [ "$SPC_DOCKER_DEBUG" = "yes" ]; then
183224
set -ex
184225
$DOCKER_EXECUTABLE run $PLATFORM_ARG --rm $INTERACT $ENV_LIST $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION /bin/bash
185226
else
186-
$DOCKER_EXECUTABLE run $PLATFORM_ARG --rm $INTERACT $ENV_LIST $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION bin/spc $@
227+
$DOCKER_EXECUTABLE run $PLATFORM_ARG --rm $INTERACT $ENV_LIST $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION bin/spc "${NEW_ARGS[@]}"
187228
fi

bin/spc-gnu-docker

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,47 @@ if [ ! -z "$GITHUB_TOKEN" ]; then
174174
ENV_LIST="$ENV_LIST -e GITHUB_TOKEN=$GITHUB_TOKEN"
175175
fi
176176

177+
# Intercept and rewrite --with-frankenphp-app option, and mount host path to /app/app
178+
FRANKENPHP_APP_PATH=""
179+
NEW_ARGS=()
180+
while [ $# -gt 0 ]; do
181+
case "$1" in
182+
--with-frankenphp-app=*)
183+
FRANKENPHP_APP_PATH="${1#*=}"
184+
NEW_ARGS+=("--with-frankenphp-app=/app/app")
185+
shift
186+
;;
187+
--with-frankenphp-app)
188+
if [ -n "${2:-}" ]; then
189+
FRANKENPHP_APP_PATH="$2"
190+
NEW_ARGS+=("--with-frankenphp-app=/app/app")
191+
shift 2
192+
else
193+
NEW_ARGS+=("$1")
194+
shift
195+
fi
196+
;;
197+
*)
198+
NEW_ARGS+=("$1")
199+
shift
200+
;;
201+
esac
202+
done
203+
204+
# Normalize the path and add mount if provided
205+
if [ -n "$FRANKENPHP_APP_PATH" ]; then
206+
# expand ~ to $HOME
207+
if [ "${FRANKENPHP_APP_PATH#~}" != "$FRANKENPHP_APP_PATH" ]; then
208+
FRANKENPHP_APP_PATH="$HOME${FRANKENPHP_APP_PATH#~}"
209+
fi
210+
# make absolute if relative
211+
case "$FRANKENPHP_APP_PATH" in
212+
/*) ABS_APP_PATH="$FRANKENPHP_APP_PATH" ;;
213+
*) ABS_APP_PATH="$(pwd)/$FRANKENPHP_APP_PATH" ;;
214+
esac
215+
MOUNT_LIST="$MOUNT_LIST -v $ABS_APP_PATH:/app/app"
216+
fi
217+
177218
# Run docker
178219
# shellcheck disable=SC2068
179220
# shellcheck disable=SC2086
@@ -196,5 +237,5 @@ if [ "$SPC_DOCKER_DEBUG" = "yes" ]; then
196237
set -ex
197238
$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
198239
else
199-
$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 $@
240+
$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[@]}"
200241
fi

config/env.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ SPC_SKIP_PHP_VERSION_CHECK="no"
4545
; Ignore some check item for bin/spc doctor command, comma separated (e.g. SPC_SKIP_DOCTOR_CHECK_ITEMS="if homebrew has installed")
4646
SPC_SKIP_DOCTOR_CHECK_ITEMS=""
4747
; extra modules that xcaddy will include in the FrankenPHP build
48-
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"
48+
SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES="--with github.com/dunglas/mercure/caddy --with github.com/dunglas/vulcain/caddy --with github.com/dunglas/caddy-cbrotli"
4949
; The display message for php version output (PHP >= 8.4 available)
5050
PHP_BUILD_PROVIDER="static-php-cli ${SPC_VERSION}"
5151

config/lib.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"source": "php-src",
88
"lib-depends": [
99
"lib-base",
10-
"micro"
10+
"micro",
11+
"frankenphp"
1112
],
1213
"lib-depends-macos": [
1314
"lib-base",
@@ -968,5 +969,24 @@
968969
"zstd.h",
969970
"zstd_errors.h"
970971
]
972+
},
973+
"liburing": {
974+
"source": "liburing",
975+
"pkg-configs": [
976+
"liburing",
977+
"liburing-ffi"
978+
],
979+
"static-libs-linux": [
980+
"liburing.a",
981+
"liburing-ffi.a"
982+
],
983+
"headers-linux": [
984+
"liburing/",
985+
"liburing.h"
986+
]
987+
},
988+
"frankenphp": {
989+
"source": "frankenphp",
990+
"type": "target"
971991
}
972992
}

config/source.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@
302302
}
303303
},
304304
"freetype": {
305-
"type": "git",
306-
"rev": "VER-2-13-2",
307-
"url": "https://github.com/freetype/freetype",
305+
"type": "ghtagtar",
306+
"repo": "freetype/freetype",
307+
"match": "VER-2-\\d+-\\d+",
308308
"license": {
309309
"type": "file",
310310
"path": "LICENSE.TXT"
@@ -363,6 +363,16 @@
363363
"path": "LICENSE"
364364
}
365365
},
366+
"frankenphp": {
367+
"type": "ghtar",
368+
"repo": "php/frankenphp",
369+
"prefer-stable": true,
370+
"provide-pre-build": false,
371+
"license": {
372+
"type": "file",
373+
"path": "LICENSE"
374+
}
375+
},
366376
"icu-static-win": {
367377
"type": "url",
368378
"url": "https://dl.static-php.dev/static-php-cli/deps/icu-static-windows-x64/icu-static-windows-x64.zip",

src/SPC/builder/unix/UnixBuilderBase.php

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use SPC\store\Config;
1414
use SPC\store\FileSystem;
1515
use SPC\store\pkg\GoXcaddy;
16+
use SPC\store\SourceManager;
1617
use SPC\toolchain\GccNativeToolchain;
1718
use SPC\toolchain\ToolchainManager;
1819
use SPC\util\DependencyUtil;
@@ -344,22 +345,69 @@ protected function patchPhpScripts(): void
344345
}
345346
}
346347

348+
/**
349+
* Process the --with-frankenphp-app option
350+
* Creates app.tar and app.checksum in source/frankenphp directory
351+
*/
352+
protected function processFrankenphpApp(): void
353+
{
354+
$frankenphpSourceDir = SOURCE_PATH . '/frankenphp';
355+
SourceManager::initSource(['frankenphp'], ['frankenphp']);
356+
$frankenphpAppPath = $this->getOption('with-frankenphp-app');
357+
358+
if ($frankenphpAppPath) {
359+
if (!is_dir($frankenphpAppPath)) {
360+
throw new WrongUsageException("The path provided to --with-frankenphp-app is not a valid directory: {$frankenphpAppPath}");
361+
}
362+
$appTarPath = $frankenphpSourceDir . '/app.tar';
363+
logger()->info("Creating app.tar from {$frankenphpAppPath}");
364+
365+
shell()->exec('tar -cf ' . escapeshellarg($appTarPath) . ' -C ' . escapeshellarg($frankenphpAppPath) . ' .');
366+
367+
$checksum = hash_file('md5', $appTarPath);
368+
file_put_contents($frankenphpSourceDir . '/app_checksum.txt', $checksum);
369+
} else {
370+
FileSystem::removeFileIfExists($frankenphpSourceDir . '/app.tar');
371+
FileSystem::removeFileIfExists($frankenphpSourceDir . '/app_checksum.txt');
372+
file_put_contents($frankenphpSourceDir . '/app.tar', '');
373+
file_put_contents($frankenphpSourceDir . '/app_checksum.txt', '');
374+
}
375+
}
376+
377+
protected function getFrankenPHPVersion(): string
378+
{
379+
$goModPath = SOURCE_PATH . '/frankenphp/caddy/go.mod';
380+
381+
if (!file_exists($goModPath)) {
382+
throw new SPCInternalException("FrankenPHP caddy/go.mod file not found at {$goModPath}, why did we not download FrankenPHP?");
383+
}
384+
385+
$content = file_get_contents($goModPath);
386+
if (preg_match('/github\.com\/dunglas\/frankenphp\s+v?(\d+\.\d+\.\d+)/', $content, $matches)) {
387+
return $matches[1];
388+
}
389+
390+
throw new SPCInternalException('Could not find FrankenPHP version in caddy/go.mod');
391+
}
392+
347393
protected function buildFrankenphp(): void
348394
{
349395
GlobalEnvManager::addPathIfNotExists(GoXcaddy::getPath());
396+
$this->processFrankenphpApp();
350397
$nobrotli = $this->getLib('brotli') === null ? ',nobrotli' : '';
351398
$nowatcher = $this->getLib('watcher') === null ? ',nowatcher' : '';
352399
$xcaddyModules = getenv('SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES');
353-
// make it possible to build from a different frankenphp directory!
354-
if (!str_contains($xcaddyModules, '--with github.com/dunglas/frankenphp')) {
355-
$xcaddyModules = '--with github.com/dunglas/frankenphp ' . $xcaddyModules;
356-
}
400+
$frankenphpSourceDir = SOURCE_PATH . '/frankenphp';
401+
402+
$xcaddyModules = preg_replace('#--with github.com/dunglas/frankenphp\S*#', '', $xcaddyModules);
403+
$xcaddyModules = "--with github.com/dunglas/frankenphp={$frankenphpSourceDir} " .
404+
"--with github.com/dunglas/frankenphp/caddy={$frankenphpSourceDir}/caddy {$xcaddyModules}";
357405
if ($this->getLib('brotli') === null && str_contains($xcaddyModules, '--with github.com/dunglas/caddy-cbrotli')) {
358406
logger()->warning('caddy-cbrotli module is enabled, but brotli library is not built. Disabling caddy-cbrotli.');
359407
$xcaddyModules = str_replace('--with github.com/dunglas/caddy-cbrotli', '', $xcaddyModules);
360408
}
361-
[, $out] = shell()->execWithResult('go list -m github.com/dunglas/frankenphp@latest');
362-
$frankenPhpVersion = str_replace('github.com/dunglas/frankenphp v', '', $out[0]);
409+
410+
$frankenPhpVersion = $this->getFrankenPHPVersion();
363411
$libphpVersion = $this->getPHPVersion();
364412
$dynamic_exports = '';
365413
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') {
@@ -369,7 +417,7 @@ protected function buildFrankenphp(): void
369417
$dynamic_exports = ' ' . $dynamicSymbolsArgument;
370418
}
371419
}
372-
$debugFlags = $this->getOption('no-strip') ? '-w -s ' : '';
420+
$debugFlags = $this->getOption('no-strip') ? '' : '-w -s ';
373421
$extLdFlags = "-extldflags '-pie{$dynamic_exports} {$this->arch_ld_flags}'";
374422
$muslTags = '';
375423
$staticFlags = '';

src/SPC/command/BuildPHPCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function configure(): void
4848
$this->addOption('with-upx-pack', null, null, 'Compress / pack binary using UPX tool (linux/windows only)');
4949
$this->addOption('with-micro-logo', null, InputOption::VALUE_REQUIRED, 'Use custom .ico for micro.sfx (windows only)');
5050
$this->addOption('enable-micro-win32', null, null, 'Enable win32 mode for phpmicro (Windows only)');
51+
$this->addOption('with-frankenphp-app', null, InputOption::VALUE_REQUIRED, 'Path to a folder to be embedded in FrankenPHP');
5152
}
5253

5354
public function handle(): int

src/SPC/store/source/PhpSource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function fetch(bool $force = false, ?array $config = null, int $lock_as =
1616
{
1717
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.4';
1818
if ($major === '8.5') {
19-
Downloader::downloadSource('php-src', ['type' => 'url', 'url' => 'https://downloads.php.net/~daniels/php-8.5.0RC3.tar.xz'], $force);
19+
Downloader::downloadSource('php-src', ['type' => 'url', 'url' => 'https://downloads.php.net/~edorian/php-8.5.0RC4.tar.xz'], $force);
2020
} elseif ($major === 'git') {
2121
Downloader::downloadSource('php-src', ['type' => 'git', 'url' => 'https://github.com/php/php-src.git', 'rev' => 'master'], $force);
2222
} else {

0 commit comments

Comments
 (0)