55namespace SPC \builder \unix ;
66
77use SPC \builder \BuilderBase ;
8+ use SPC \builder \linux \SystemUtil ;
89use SPC \builder \linux \SystemUtil as LinuxSystemUtil ;
910use SPC \exception \SPCException ;
1011use SPC \exception \SPCInternalException ;
@@ -105,9 +106,15 @@ public function extractDebugInfo(string $binary_path): string
105106 if (PHP_OS_FAMILY === 'Darwin ' ) {
106107 shell ()->exec ("dsymutil -f {$ binary_path } -o {$ debug_file }" );
107108 } 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 }" );
109+ if ($ eu_strip = SystemUtil::findCommand ('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 }
@@ -121,9 +128,6 @@ public function deployBinary(string $src, string $dst, bool $executable = true):
121128 {
122129 logger ()->debug ('Deploying binary from ' . $ src . ' to ' . $ dst );
123130
124- // UPX for linux
125- $ upx_option = (bool ) $ this ->getOption ('with-upx-pack ' , false );
126-
127131 // file must exists
128132 if (!file_exists ($ src )) {
129133 throw new SPCInternalException ("Deploy failed. Cannot find file: {$ src }" );
@@ -145,13 +149,14 @@ public function deployBinary(string $src, string $dst, bool $executable = true):
145149 $ this ->extractDebugInfo ($ dst );
146150
147151 // strip
148- if (!$ this ->getOption ('no-strip ' , false )) {
152+ if (!$ this ->getOption ('no-strip ' )) {
149153 $ this ->stripBinary ($ dst );
150154 }
151155
152- // Compress binary with UPX if needed (only for Linux)
156+ // UPX for linux
157+ $ upx_option = $ this ->getOption ('with-upx-pack ' );
153158 if ($ upx_option && PHP_OS_FAMILY === 'Linux ' && $ executable ) {
154- if ($ this ->getOption ('no-strip ' , false )) {
159+ if ($ this ->getOption ('no-strip ' )) {
155160 logger ()->warning ('UPX compression is not recommended when --no-strip is enabled. ' );
156161 }
157162 logger ()->info ("Compressing {$ dst } with UPX " );
@@ -351,8 +356,10 @@ protected function patchPhpScripts(): void
351356 */
352357 protected function processFrankenphpApp (): void
353358 {
354- $ frankenphpSourceDir = SOURCE_PATH . '/frankenphp ' ;
355- SourceManager::initSource (['frankenphp ' ], ['frankenphp ' ]);
359+ $ frankenphpSourceDir = getenv ('FRANKENPHP_SOURCE_PATH ' ) ?: SOURCE_PATH . '/frankenphp ' ;
360+ if (!is_dir ($ frankenphpSourceDir )) {
361+ SourceManager::initSource (['frankenphp ' ], ['frankenphp ' ]);
362+ }
356363 $ frankenphpAppPath = $ this ->getOption ('with-frankenphp-app ' );
357364
358365 if ($ frankenphpAppPath ) {
@@ -376,7 +383,11 @@ protected function processFrankenphpApp(): void
376383
377384 protected function getFrankenPHPVersion (): string
378385 {
379- $ goModPath = SOURCE_PATH . '/frankenphp/caddy/go.mod ' ;
386+ if ($ version = getenv ('FRANKENPHP_VERSION ' )) {
387+ return $ version ;
388+ }
389+ $ frankenphpSourceDir = getenv ('FRANKENPHP_SOURCE_PATH ' ) ?: SOURCE_PATH . '/frankenphp ' ;
390+ $ goModPath = $ frankenphpSourceDir . '/caddy/go.mod ' ;
380391
381392 if (!file_exists ($ goModPath )) {
382393 throw new SPCInternalException ("FrankenPHP caddy/go.mod file not found at {$ goModPath }, why did we not download FrankenPHP? " );
@@ -397,7 +408,7 @@ protected function buildFrankenphp(): void
397408 $ nobrotli = $ this ->getLib ('brotli ' ) === null ? ',nobrotli ' : '' ;
398409 $ nowatcher = $ this ->getLib ('watcher ' ) === null ? ',nowatcher ' : '' ;
399410 $ xcaddyModules = getenv ('SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES ' );
400- $ frankenphpSourceDir = SOURCE_PATH . '/frankenphp ' ;
411+ $ frankenphpSourceDir = getenv ( ' FRANKENPHP_SOURCE_PATH ' ) ?: SOURCE_PATH . '/frankenphp ' ;
401412
402413 $ xcaddyModules = preg_replace ('#--with github.com/dunglas/frankenphp\S*# ' , '' , $ xcaddyModules );
403414 $ xcaddyModules = "--with github.com/dunglas/frankenphp= {$ frankenphpSourceDir } " .
@@ -417,7 +428,6 @@ protected function buildFrankenphp(): void
417428 $ dynamic_exports = ' ' . $ dynamicSymbolsArgument ;
418429 }
419430 }
420- $ debugFlags = $ this ->getOption ('no-strip ' ) ? '' : '-w -s ' ;
421431 $ extLdFlags = "-extldflags '-pie {$ dynamic_exports } {$ this ->arch_ld_flags }' " ;
422432 $ muslTags = '' ;
423433 $ staticFlags = '' ;
@@ -442,7 +452,7 @@ protected function buildFrankenphp(): void
442452 'CGO_CFLAGS ' => clean_spaces ($ cflags ),
443453 'CGO_LDFLAGS ' => "{$ this ->arch_ld_flags } {$ staticFlags } {$ config ['ldflags ' ]} {$ libs }" ,
444454 'XCADDY_GO_BUILD_FLAGS ' => '-buildmode=pie ' .
445- '-ldflags \"-linkmode=external ' . $ extLdFlags . ' ' . $ debugFlags .
455+ '-ldflags \"-linkmode=external ' . $ extLdFlags . ' ' .
446456 '-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' .
447457 "v {$ frankenPhpVersion } PHP {$ libphpVersion } Caddy' \\\" " .
448458 "-tags= {$ muslTags }nobadger,nomysql,nopgx {$ nobrotli }{$ nowatcher }" ,
0 commit comments