Skip to content

Commit dbdf10c

Browse files
committed
support for dynamic linking of musl libc
1 parent 2564da2 commit dbdf10c

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

config/env.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime
6565
[linux]
6666
; include PATH for musl libc.
6767
SPC_LIBC=musl
68+
SPC_LIBC_VERSION=
69+
SPC_LIBC_LINKAGE=-static
6870
; compiler environments
6971
CC=${SPC_LINUX_DEFAULT_CC}
7072
CXX=${SPC_LINUX_DEFAULT_CXX}

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ 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') {
142+
if ($embed_type !== 'static' && getenv('SPC_LIBC') === 'musl' && getenv('SPC_LIBC_LINKAGE') === '-static') {
143143
throw new WrongUsageException('Musl libc does not support dynamic linking of PHP embed!');
144144
}
145145
shell()->cd(SOURCE_PATH . '/php-src')

src/SPC/builder/unix/UnixBuilderBase.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ protected function sanityCheck(int $build_target): void
202202
$util = new SPCConfigUtil($this);
203203
$config = $util->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
204204
$lens = "{$config['cflags']} {$config['ldflags']} {$config['libs']}";
205-
if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') {
206-
$lens .= ' -static';
207-
}
205+
$lens .= ' ' . getenv('SPC_LIBC_LINKAGE');
208206
// if someone changed to EMBED_TYPE=shared, we need to add LD_LIBRARY_PATH
209207
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') {
210208
$ext_path = 'LD_LIBRARY_PATH=' . BUILD_LIB_PATH . ':$LD_LIBRARY_PATH ';

src/SPC/command/BuildPHPCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function handle(): int
6363

6464
// check dynamic extension build env
6565
// linux must build with glibc
66-
if (!empty($shared_extensions) && PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') !== 'glibc') {
66+
if (!empty($shared_extensions) && PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') !== 'glibc' && getenv('SPC_LIBC_LINKAGE') === '-static') {
6767
$this->output->writeln('Linux does not support dynamic extension loading with musl-libc full-static build, please build with glibc!');
6868
return static::FAILURE;
6969
}

0 commit comments

Comments
 (0)