Skip to content

Commit e2b80e7

Browse files
committed
update building of frankenphp
1 parent 09073c5 commit e2b80e7

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/SPC/builder/unix/UnixBuilderBase.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,16 @@ public function extractDebugInfo(string $binary_path): string
105105
if (PHP_OS_FAMILY === 'Darwin') {
106106
shell()->exec("dsymutil -f {$binary_path} -o {$debug_file}");
107107
} elseif (PHP_OS_FAMILY === 'Linux') {
108-
shell()
109-
->exec("objcopy --only-keep-debug {$binary_path} {$debug_file}")
110-
->exec("objcopy --add-gnu-debuglink={$debug_file} {$binary_path}");
108+
$has_eu_strip = shell()->execWithResult('which eu-strip')[0] === 0;
109+
if ($has_eu_strip) {
110+
shell()
111+
->exec("eu-strip -f {$debug_file} {$binary_path}")
112+
->exec("objcopy --add-gnu-debuglink={$debug_file} {$binary_path}");
113+
} else {
114+
shell()
115+
->exec("objcopy --only-keep-debug {$binary_path} {$debug_file}")
116+
->exec("objcopy --add-gnu-debuglink={$debug_file} {$binary_path}");
117+
}
111118
} else {
112119
throw new SPCInternalException('extractDebugInfo is only supported on Linux and macOS');
113120
}
@@ -351,8 +358,10 @@ protected function patchPhpScripts(): void
351358
*/
352359
protected function processFrankenphpApp(): void
353360
{
354-
$frankenphpSourceDir = SOURCE_PATH . '/frankenphp';
355-
SourceManager::initSource(['frankenphp'], ['frankenphp']);
361+
$frankenphpSourceDir = getenv('FRANKENPHP_SOURCE_PATH') ?: SOURCE_PATH . '/frankenphp';
362+
if (!is_dir($frankenphpSourceDir)) {
363+
SourceManager::initSource(['frankenphp'], ['frankenphp']);
364+
}
356365
$frankenphpAppPath = $this->getOption('with-frankenphp-app');
357366

358367
if ($frankenphpAppPath) {
@@ -376,7 +385,11 @@ protected function processFrankenphpApp(): void
376385

377386
protected function getFrankenPHPVersion(): string
378387
{
379-
$goModPath = SOURCE_PATH . '/frankenphp/caddy/go.mod';
388+
if ($version = getenv('FRANKENPHP_VERSION')) {
389+
return $version;
390+
}
391+
$frankenphpSourceDir = getenv('FRANKENPHP_SOURCE_PATH') ?: SOURCE_PATH . '/frankenphp';
392+
$goModPath = $frankenphpSourceDir . '/caddy/go.mod';
380393

381394
if (!file_exists($goModPath)) {
382395
throw new SPCInternalException("FrankenPHP caddy/go.mod file not found at {$goModPath}, why did we not download FrankenPHP?");
@@ -397,7 +410,7 @@ protected function buildFrankenphp(): void
397410
$nobrotli = $this->getLib('brotli') === null ? ',nobrotli' : '';
398411
$nowatcher = $this->getLib('watcher') === null ? ',nowatcher' : '';
399412
$xcaddyModules = getenv('SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES');
400-
$frankenphpSourceDir = SOURCE_PATH . '/frankenphp';
413+
$frankenphpSourceDir = getenv('FRANKENPHP_SOURCE_PATH') ?: SOURCE_PATH . '/frankenphp';
401414

402415
$xcaddyModules = preg_replace('#--with github.com/dunglas/frankenphp\S*#', '', $xcaddyModules);
403416
$xcaddyModules = "--with github.com/dunglas/frankenphp={$frankenphpSourceDir} " .
@@ -417,7 +430,6 @@ protected function buildFrankenphp(): void
417430
$dynamic_exports = ' ' . $dynamicSymbolsArgument;
418431
}
419432
}
420-
$debugFlags = $this->getOption('no-strip') ? '' : '-w -s ';
421433
$extLdFlags = "-extldflags '-pie{$dynamic_exports} {$this->arch_ld_flags}'";
422434
$muslTags = '';
423435
$staticFlags = '';
@@ -442,7 +454,7 @@ protected function buildFrankenphp(): void
442454
'CGO_CFLAGS' => clean_spaces($cflags),
443455
'CGO_LDFLAGS' => "{$this->arch_ld_flags} {$staticFlags} {$config['ldflags']} {$libs}",
444456
'XCADDY_GO_BUILD_FLAGS' => '-buildmode=pie ' .
445-
'-ldflags \"-linkmode=external ' . $extLdFlags . ' ' . $debugFlags .
457+
'-ldflags \"-linkmode=external ' . $extLdFlags . ' ' .
446458
'-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' .
447459
"v{$frankenPhpVersion} PHP {$libphpVersion} Caddy'\\\" " .
448460
"-tags={$muslTags}nobadger,nomysql,nopgx{$nobrotli}{$nowatcher}",

0 commit comments

Comments
 (0)