From dbdf10c75a673b0c4eec41f99bbe6db42f4edf5f Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 29 Jun 2025 18:24:25 +0700 Subject: [PATCH] support for dynamic linking of musl libc --- config/env.ini | 2 ++ src/SPC/builder/linux/LinuxBuilder.php | 2 +- src/SPC/builder/unix/UnixBuilderBase.php | 4 +--- src/SPC/command/BuildPHPCommand.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/env.ini b/config/env.ini index c00aafc3..54996148 100644 --- a/config/env.ini +++ b/config/env.ini @@ -65,6 +65,8 @@ SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime [linux] ; include PATH for musl libc. SPC_LIBC=musl +SPC_LIBC_VERSION= +SPC_LIBC_LINKAGE=-static ; compiler environments CC=${SPC_LINUX_DEFAULT_CC} CXX=${SPC_LINUX_DEFAULT_CXX} diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 1de5a41c..4e30460c 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -139,7 +139,7 @@ class LinuxBuilder extends UnixBuilderBase } $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; - if ($embed_type !== 'static' && getenv('SPC_LIBC') === 'musl') { + if ($embed_type !== 'static' && getenv('SPC_LIBC') === 'musl' && getenv('SPC_LIBC_LINKAGE') === '-static') { throw new WrongUsageException('Musl libc does not support dynamic linking of PHP embed!'); } shell()->cd(SOURCE_PATH . '/php-src') diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 435f0b9b..7a0ed139 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -202,9 +202,7 @@ abstract class UnixBuilderBase extends BuilderBase $util = new SPCConfigUtil($this); $config = $util->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs')); $lens = "{$config['cflags']} {$config['ldflags']} {$config['libs']}"; - if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') { - $lens .= ' -static'; - } + $lens .= ' ' . getenv('SPC_LIBC_LINKAGE'); // if someone changed to EMBED_TYPE=shared, we need to add LD_LIBRARY_PATH if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { $ext_path = 'LD_LIBRARY_PATH=' . BUILD_LIB_PATH . ':$LD_LIBRARY_PATH '; diff --git a/src/SPC/command/BuildPHPCommand.php b/src/SPC/command/BuildPHPCommand.php index 21a848a5..63a5ef72 100644 --- a/src/SPC/command/BuildPHPCommand.php +++ b/src/SPC/command/BuildPHPCommand.php @@ -63,7 +63,7 @@ class BuildPHPCommand extends BuildCommand // check dynamic extension build env // linux must build with glibc - if (!empty($shared_extensions) && PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') !== 'glibc') { + if (!empty($shared_extensions) && PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') !== 'glibc' && getenv('SPC_LIBC_LINKAGE') === '-static') { $this->output->writeln('Linux does not support dynamic extension loading with musl-libc full-static build, please build with glibc!'); return static::FAILURE; }