remove SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS, use eu-strip (#966)

This commit is contained in:
Marc
2025-11-12 20:51:06 +01:00
committed by GitHub
6 changed files with 48 additions and 27 deletions

View File

@@ -110,9 +110,7 @@ SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --disable
; *** default build vars for building php *** ; *** default build vars for building php ***
; embed type for php, static (libphp.a) or shared (libphp.so) ; embed type for php, static (libphp.a) or shared (libphp.so)
SPC_CMD_VAR_PHP_EMBED_TYPE="static" SPC_CMD_VAR_PHP_EMBED_TYPE="static"
; CFLAGS for configuring php ; EXTRA_CFLAGS for `configure` and `make` php
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -fPIE"
; EXTRA_CFLAGS for `make` php
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}" SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}"
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so ; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS="" SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
@@ -142,10 +140,8 @@ SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-
; *** default build vars for building php *** ; *** default build vars for building php ***
; embed type for php, static (libphp.a) or shared (libphp.dylib) ; embed type for php, static (libphp.a) or shared (libphp.dylib)
SPC_CMD_VAR_PHP_EMBED_TYPE="static" SPC_CMD_VAR_PHP_EMBED_TYPE="static"
; CFLAGS for configuring php ; EXTRA_CFLAGS for `configure` and `make` php
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -Werror=unknown-warning-option" SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie -Werror=unknown-warning-option ${SPC_DEFAULT_C_FLAGS}"
; EXTRA_CFLAGS for `make` php
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie ${SPC_DEFAULT_C_FLAGS}"
[freebsd] [freebsd]
; compiler environments ; compiler environments

View File

@@ -13,7 +13,8 @@
"lib-depends-macos": [ "lib-depends-macos": [
"lib-base", "lib-base",
"micro", "micro",
"libxml2" "libxml2",
"frankenphp"
], ],
"lib-suggests-linux": [ "lib-suggests-linux": [
"libacl", "libacl",
@@ -25,6 +26,10 @@
"watcher" "watcher"
] ]
}, },
"frankenphp": {
"source": "frankenphp",
"type": "target"
},
"micro": { "micro": {
"type": "target", "type": "target",
"source": "micro" "source": "micro"

View File

@@ -301,6 +301,16 @@
"path": "LICENSE.MIT" "path": "LICENSE.MIT"
} }
}, },
"frankenphp": {
"type": "ghtar",
"repo": "php/frankenphp",
"prefer-stable": true,
"provide-pre-built": false,
"license": {
"type": "file",
"path": "LICENSE"
}
},
"freetype": { "freetype": {
"type": "ghtagtar", "type": "ghtagtar",
"repo": "freetype/freetype", "repo": "freetype/freetype",

View File

@@ -91,7 +91,7 @@ class LinuxBuilder extends UnixBuilderBase
// prepare build php envs // prepare build php envs
// $musl_flag = SPCTarget::getLibc() === 'musl' ? ' -D__MUSL__' : ' -U__MUSL__'; // $musl_flag = SPCTarget::getLibc() === 'musl' ? ' -D__MUSL__' : ' -U__MUSL__';
$php_configure_env = SystemUtil::makeEnvVarString([ $php_configure_env = SystemUtil::makeEnvVarString([
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'), 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, // . ' -Dsomethinghere', // . $musl_flag, 'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, // . ' -Dsomethinghere', // . $musl_flag,
'LDFLAGS' => '-L' . BUILD_LIB_PATH, 'LDFLAGS' => '-L' . BUILD_LIB_PATH,
// 'LIBS' => SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions! // 'LIBS' => SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions!
@@ -284,10 +284,10 @@ class LinuxBuilder extends UnixBuilderBase
// process libphp.so for shared embed // process libphp.so for shared embed
$libphpSo = BUILD_LIB_PATH . '/libphp.so'; $libphpSo = BUILD_LIB_PATH . '/libphp.so';
if (file_exists($libphpSo)) { if (file_exists($libphpSo)) {
// deploy libphp.so
$this->deployBinary($libphpSo, $libphpSo, false);
// post actions: rename libphp.so to libphp-<release>.so if -release is set in LDFLAGS // post actions: rename libphp.so to libphp-<release>.so if -release is set in LDFLAGS
$this->processLibphpSoFile($libphpSo); $this->processLibphpSoFile($libphpSo);
// deploy libphp.so
$this->deployBinary($libphpSo, $libphpSo, false);
} }
// process shared extensions build-with-php // process shared extensions build-with-php

View File

@@ -106,7 +106,7 @@ class MacOSBuilder extends UnixBuilderBase
// prepare build php envs // prepare build php envs
$envs_build_php = SystemUtil::makeEnvVarString([ $envs_build_php = SystemUtil::makeEnvVarString([
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'), 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, 'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH,
'LDFLAGS' => '-L' . BUILD_LIB_PATH, 'LDFLAGS' => '-L' . BUILD_LIB_PATH,
]); ]);

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace SPC\builder\unix; namespace SPC\builder\unix;
use SPC\builder\BuilderBase; use SPC\builder\BuilderBase;
use SPC\builder\linux\SystemUtil;
use SPC\builder\linux\SystemUtil as LinuxSystemUtil; use SPC\builder\linux\SystemUtil as LinuxSystemUtil;
use SPC\exception\SPCException; use SPC\exception\SPCException;
use SPC\exception\SPCInternalException; use SPC\exception\SPCInternalException;
@@ -105,9 +106,15 @@ abstract class UnixBuilderBase extends BuilderBase
if (PHP_OS_FAMILY === 'Darwin') { if (PHP_OS_FAMILY === 'Darwin') {
shell()->exec("dsymutil -f {$binary_path} -o {$debug_file}"); shell()->exec("dsymutil -f {$binary_path} -o {$debug_file}");
} elseif (PHP_OS_FAMILY === 'Linux') { } elseif (PHP_OS_FAMILY === 'Linux') {
shell() if ($eu_strip = SystemUtil::findCommand('eu-strip')) {
->exec("objcopy --only-keep-debug {$binary_path} {$debug_file}") shell()
->exec("objcopy --add-gnu-debuglink={$debug_file} {$binary_path}"); ->exec("{$eu_strip} -f {$debug_file} {$binary_path}")
->exec("objcopy --add-gnu-debuglink={$debug_file} {$binary_path}");
} else {
shell()
->exec("objcopy --only-keep-debug {$binary_path} {$debug_file}")
->exec("objcopy --add-gnu-debuglink={$debug_file} {$binary_path}");
}
} else { } else {
throw new SPCInternalException('extractDebugInfo is only supported on Linux and macOS'); throw new SPCInternalException('extractDebugInfo is only supported on Linux and macOS');
} }
@@ -121,9 +128,6 @@ abstract class UnixBuilderBase extends BuilderBase
{ {
logger()->debug('Deploying binary from ' . $src . ' to ' . $dst); logger()->debug('Deploying binary from ' . $src . ' to ' . $dst);
// UPX for linux
$upx_option = (bool) $this->getOption('with-upx-pack', false);
// file must exists // file must exists
if (!file_exists($src)) { if (!file_exists($src)) {
throw new SPCInternalException("Deploy failed. Cannot find file: {$src}"); throw new SPCInternalException("Deploy failed. Cannot find file: {$src}");
@@ -145,13 +149,14 @@ abstract class UnixBuilderBase extends BuilderBase
$this->extractDebugInfo($dst); $this->extractDebugInfo($dst);
// strip // strip
if (!$this->getOption('no-strip', false)) { if (!$this->getOption('no-strip')) {
$this->stripBinary($dst); $this->stripBinary($dst);
} }
// Compress binary with UPX if needed (only for Linux) // UPX for linux
$upx_option = $this->getOption('with-upx-pack');
if ($upx_option && PHP_OS_FAMILY === 'Linux' && $executable) { if ($upx_option && PHP_OS_FAMILY === 'Linux' && $executable) {
if ($this->getOption('no-strip', false)) { if ($this->getOption('no-strip')) {
logger()->warning('UPX compression is not recommended when --no-strip is enabled.'); logger()->warning('UPX compression is not recommended when --no-strip is enabled.');
} }
logger()->info("Compressing {$dst} with UPX"); logger()->info("Compressing {$dst} with UPX");
@@ -351,8 +356,10 @@ abstract class UnixBuilderBase extends BuilderBase
*/ */
protected function processFrankenphpApp(): void protected function processFrankenphpApp(): void
{ {
$frankenphpSourceDir = SOURCE_PATH . '/frankenphp'; $frankenphpSourceDir = getenv('FRANKENPHP_SOURCE_PATH') ?: SOURCE_PATH . '/frankenphp';
SourceManager::initSource(['frankenphp'], ['frankenphp']); if (!is_dir($frankenphpSourceDir)) {
SourceManager::initSource(['frankenphp'], ['frankenphp']);
}
$frankenphpAppPath = $this->getOption('with-frankenphp-app'); $frankenphpAppPath = $this->getOption('with-frankenphp-app');
if ($frankenphpAppPath) { if ($frankenphpAppPath) {
@@ -376,7 +383,11 @@ abstract class UnixBuilderBase extends BuilderBase
protected function getFrankenPHPVersion(): string protected function getFrankenPHPVersion(): string
{ {
$goModPath = SOURCE_PATH . '/frankenphp/caddy/go.mod'; if ($version = getenv('FRANKENPHP_VERSION')) {
return $version;
}
$frankenphpSourceDir = getenv('FRANKENPHP_SOURCE_PATH') ?: SOURCE_PATH . '/frankenphp';
$goModPath = $frankenphpSourceDir . '/caddy/go.mod';
if (!file_exists($goModPath)) { if (!file_exists($goModPath)) {
throw new SPCInternalException("FrankenPHP caddy/go.mod file not found at {$goModPath}, why did we not download FrankenPHP?"); throw new SPCInternalException("FrankenPHP caddy/go.mod file not found at {$goModPath}, why did we not download FrankenPHP?");
@@ -397,7 +408,7 @@ abstract class UnixBuilderBase extends BuilderBase
$nobrotli = $this->getLib('brotli') === null ? ',nobrotli' : ''; $nobrotli = $this->getLib('brotli') === null ? ',nobrotli' : '';
$nowatcher = $this->getLib('watcher') === null ? ',nowatcher' : ''; $nowatcher = $this->getLib('watcher') === null ? ',nowatcher' : '';
$xcaddyModules = getenv('SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES'); $xcaddyModules = getenv('SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES');
$frankenphpSourceDir = SOURCE_PATH . '/frankenphp'; $frankenphpSourceDir = getenv('FRANKENPHP_SOURCE_PATH') ?: SOURCE_PATH . '/frankenphp';
$xcaddyModules = preg_replace('#--with github.com/dunglas/frankenphp\S*#', '', $xcaddyModules); $xcaddyModules = preg_replace('#--with github.com/dunglas/frankenphp\S*#', '', $xcaddyModules);
$xcaddyModules = "--with github.com/dunglas/frankenphp={$frankenphpSourceDir} " . $xcaddyModules = "--with github.com/dunglas/frankenphp={$frankenphpSourceDir} " .
@@ -417,7 +428,6 @@ abstract class UnixBuilderBase extends BuilderBase
$dynamic_exports = ' ' . $dynamicSymbolsArgument; $dynamic_exports = ' ' . $dynamicSymbolsArgument;
} }
} }
$debugFlags = $this->getOption('no-strip') ? '' : '-w -s ';
$extLdFlags = "-extldflags '-pie{$dynamic_exports} {$this->arch_ld_flags}'"; $extLdFlags = "-extldflags '-pie{$dynamic_exports} {$this->arch_ld_flags}'";
$muslTags = ''; $muslTags = '';
$staticFlags = ''; $staticFlags = '';
@@ -442,7 +452,7 @@ abstract class UnixBuilderBase extends BuilderBase
'CGO_CFLAGS' => clean_spaces($cflags), 'CGO_CFLAGS' => clean_spaces($cflags),
'CGO_LDFLAGS' => "{$this->arch_ld_flags} {$staticFlags} {$config['ldflags']} {$libs}", 'CGO_LDFLAGS' => "{$this->arch_ld_flags} {$staticFlags} {$config['ldflags']} {$libs}",
'XCADDY_GO_BUILD_FLAGS' => '-buildmode=pie ' . 'XCADDY_GO_BUILD_FLAGS' => '-buildmode=pie ' .
'-ldflags \"-linkmode=external ' . $extLdFlags . ' ' . $debugFlags . '-ldflags \"-linkmode=external ' . $extLdFlags . ' ' .
'-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' . '-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' .
"v{$frankenPhpVersion} PHP {$libphpVersion} Caddy'\\\" " . "v{$frankenPhpVersion} PHP {$libphpVersion} Caddy'\\\" " .
"-tags={$muslTags}nobadger,nomysql,nopgx{$nobrotli}{$nowatcher}", "-tags={$muslTags}nobadger,nomysql,nopgx{$nobrotli}{$nowatcher}",