Skip to content

Commit dc83282

Browse files
authored
remove SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS, use eu-strip (#966)
2 parents 00050f4 + 23c0d6f commit dc83282

File tree

6 files changed

+48
-27
lines changed

6 files changed

+48
-27
lines changed

config/env.ini

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --disable
110110
; *** default build vars for building php ***
111111
; embed type for php, static (libphp.a) or shared (libphp.so)
112112
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
113-
; CFLAGS for configuring php
114-
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -fPIE"
115-
; EXTRA_CFLAGS for `make` php
113+
; EXTRA_CFLAGS for `configure` and `make` php
116114
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}"
117115
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so
118116
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
@@ -142,10 +140,8 @@ SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-
142140
; *** default build vars for building php ***
143141
; embed type for php, static (libphp.a) or shared (libphp.dylib)
144142
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
145-
; CFLAGS for configuring php
146-
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -Werror=unknown-warning-option"
147-
; EXTRA_CFLAGS for `make` php
148-
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie ${SPC_DEFAULT_C_FLAGS}"
143+
; EXTRA_CFLAGS for `configure` and `make` php
144+
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie -Werror=unknown-warning-option ${SPC_DEFAULT_C_FLAGS}"
149145

150146
[freebsd]
151147
; compiler environments

config/lib.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"lib-depends-macos": [
1414
"lib-base",
1515
"micro",
16-
"libxml2"
16+
"libxml2",
17+
"frankenphp"
1718
],
1819
"lib-suggests-linux": [
1920
"libacl",
@@ -25,6 +26,10 @@
2526
"watcher"
2627
]
2728
},
29+
"frankenphp": {
30+
"source": "frankenphp",
31+
"type": "target"
32+
},
2833
"micro": {
2934
"type": "target",
3035
"source": "micro"

config/source.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@
301301
"path": "LICENSE.MIT"
302302
}
303303
},
304+
"frankenphp": {
305+
"type": "ghtar",
306+
"repo": "php/frankenphp",
307+
"prefer-stable": true,
308+
"provide-pre-built": false,
309+
"license": {
310+
"type": "file",
311+
"path": "LICENSE"
312+
}
313+
},
304314
"freetype": {
305315
"type": "ghtagtar",
306316
"repo": "freetype/freetype",

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
9191
// prepare build php envs
9292
// $musl_flag = SPCTarget::getLibc() === 'musl' ? ' -D__MUSL__' : ' -U__MUSL__';
9393
$php_configure_env = SystemUtil::makeEnvVarString([
94-
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
94+
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
9595
'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, // . ' -Dsomethinghere', // . $musl_flag,
9696
'LDFLAGS' => '-L' . BUILD_LIB_PATH,
9797
// 'LIBS' => SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions!
@@ -284,10 +284,10 @@ protected function buildEmbed(): void
284284
// process libphp.so for shared embed
285285
$libphpSo = BUILD_LIB_PATH . '/libphp.so';
286286
if (file_exists($libphpSo)) {
287-
// deploy libphp.so
288-
$this->deployBinary($libphpSo, $libphpSo, false);
289287
// post actions: rename libphp.so to libphp-<release>.so if -release is set in LDFLAGS
290288
$this->processLibphpSoFile($libphpSo);
289+
// deploy libphp.so
290+
$this->deployBinary($libphpSo, $libphpSo, false);
291291
}
292292

293293
// process shared extensions build-with-php

src/SPC/builder/macos/MacOSBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
106106

107107
// prepare build php envs
108108
$envs_build_php = SystemUtil::makeEnvVarString([
109-
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
109+
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
110110
'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH,
111111
'LDFLAGS' => '-L' . BUILD_LIB_PATH,
112112
]);

src/SPC/builder/unix/UnixBuilderBase.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace SPC\builder\unix;
66

77
use SPC\builder\BuilderBase;
8+
use SPC\builder\linux\SystemUtil;
89
use SPC\builder\linux\SystemUtil as LinuxSystemUtil;
910
use SPC\exception\SPCException;
1011
use 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

Comments
 (0)