Skip to content

Commit 43dc04b

Browse files
committed
building shared libphp.so on musl is really pointless and should be an error, since static compilations cannot load it
1 parent e92f043 commit 43dc04b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
139139
}
140140

141141
$embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static';
142+
if ($embed_type !== 'static' && getenv('SPC_LIBC') === 'musl') {
143+
throw new RuntimeException('Musl libc does not support dynamic linking of PHP embed!');
144+
}
142145
shell()->cd(SOURCE_PATH . '/php-src')
143146
->exec(
144147
getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
@@ -335,6 +338,9 @@ protected function buildEmbed(): void
335338
}
336339
chdir($cwd);
337340
}
341+
if (!$this->getOption('no-strip', false)) {
342+
shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-all php');
343+
}
338344
$this->patchPhpScripts();
339345
}
340346

src/SPC/builder/unix/UnixBuilderBase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,19 @@ protected function buildFrankenphp(): void
327327
$debugFlags = $this->getOption('no-strip') ? "'-w -s' " : '';
328328
$extLdFlags = "-extldflags '-pie'";
329329
$muslTags = '';
330+
$staticFlags = '';
330331
if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') {
331332
$extLdFlags = "-extldflags '-static-pie -Wl,-z,stack-size=0x80000'";
332333
$muslTags = 'static_build,';
334+
$staticFlags = '-static -static-pie';
333335
}
334336

335337
$config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list, with_dependencies: true);
336338

337339
$env = [
338340
'CGO_ENABLED' => '1',
339341
'CGO_CFLAGS' => $config['cflags'],
340-
'CGO_LDFLAGS' => "{$config['ldflags']} {$config['libs']} {$lrt}",
342+
'CGO_LDFLAGS' => "$staticFlags {$config['ldflags']} {$config['libs']} {$lrt}",
341343
'XCADDY_GO_BUILD_FLAGS' => '-buildmode=pie ' .
342344
'-ldflags \"-linkmode=external ' . $extLdFlags . ' ' . $debugFlags .
343345
'-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' .

0 commit comments

Comments
 (0)