From 4eac953c71b19ad85db6ca273bc65c7cef3488d8 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 26 Aug 2025 14:07:49 +0700 Subject: [PATCH] ensure liburing is only pulled in by suggested libs when glibc >= 2.30 (or musl) --- config/lib.json | 3 ++- src/SPC/builder/extension/swoole.php | 6 ++++-- src/SPC/builder/linux/library/liburing.php | 10 +++++++++- src/SPC/util/DependencyUtil.php | 16 ++++++++++++++++ src/SPC/util/SPCTarget.php | 4 ++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/config/lib.json b/config/lib.json index 079ebc1e..ffedd938 100644 --- a/config/lib.json +++ b/config/lib.json @@ -939,6 +939,7 @@ "headers-linux": [ "liburing/", "liburing.h" - ] + ], + "glibc-min": "2.30" } } diff --git a/src/SPC/builder/extension/swoole.php b/src/SPC/builder/extension/swoole.php index 34dd6233..e3f8c105 100644 --- a/src/SPC/builder/extension/swoole.php +++ b/src/SPC/builder/extension/swoole.php @@ -69,8 +69,10 @@ class swoole extends Extension $arg .= $this->builder->getExt('swoole-hook-mysql') ? ' --enable-mysqlnd' : ' --disable-mysqlnd'; $arg .= $this->builder->getExt('swoole-hook-sqlite') ? ' --enable-swoole-sqlite' : ' --disable-swoole-sqlite'; - $config = (new SPCConfigUtil($this->builder, ['libs_only_deps' => true]))->config([], ['unixodbc']); - $arg .= $this->builder->getExt('swoole-hook-odbc') ? ' --with-swoole-odbc=unixODBC,' . BUILD_ROOT_PATH . ' SWOOLE_ODBC_LIBS="' . $config['libs'] . '"' : ''; + if ($this->builder->getExt('swoole-hook-odbc')) { + $config = (new SPCConfigUtil($this->builder, ['libs_only_deps' => true]))->config([], ['unixodbc']); + $arg .= ' --with-swoole-odbc=unixODBC,' . BUILD_ROOT_PATH . ' SWOOLE_ODBC_LIBS="' . $config['libs'] . '"'; + } return $arg; } } diff --git a/src/SPC/builder/linux/library/liburing.php b/src/SPC/builder/linux/library/liburing.php index 62e32f88..08d871f4 100644 --- a/src/SPC/builder/linux/library/liburing.php +++ b/src/SPC/builder/linux/library/liburing.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace SPC\builder\linux\library; +use SPC\exception\WrongUsageException; use SPC\util\executor\UnixAutoconfExecutor; +use SPC\util\SPCTarget; class liburing extends LinuxLibraryBase { @@ -12,8 +14,14 @@ class liburing extends LinuxLibraryBase protected function build(): void { - // Build liburing with static linking via autoconf + if (SPCTarget::getLibc() === 'glibc' && SPCTarget::getLibcVersion() < 2.30) { + throw new WrongUsageException('liburing requires glibc >= 2.30'); + } + UnixAutoconfExecutor::create($this) + ->appendEnv([ + 'CFLAGS' => '-D_GNU_SOURCE' + ]) ->removeConfigureArgs( '--disable-shared', '--enable-static', diff --git a/src/SPC/util/DependencyUtil.php b/src/SPC/util/DependencyUtil.php index 83123f65..9d1aa0f6 100644 --- a/src/SPC/util/DependencyUtil.php +++ b/src/SPC/util/DependencyUtil.php @@ -76,6 +76,14 @@ class DependencyUtil $del_list = []; foreach ($obj['suggests'] as $id => $suggest) { if (!str_starts_with($suggest, 'ext@')) { + $glibcMin = Config::getLib($suggest, 'glibc-min'); + if ($glibcMin !== null) { + $libc = SPCTarget::getLibc(); + $ver = SPCTarget::getLibcVersion(); + if ($libc === 'glibc' && version_compare($ver, (string) $glibcMin, '<')) { + continue; + } + } $dep_list[$name]['depends'][] = $suggest; $del_list[] = $id; } @@ -134,6 +142,14 @@ class DependencyUtil $del_list = []; foreach ($obj['suggests'] as $id => $suggest) { if (!str_starts_with($suggest, 'ext@')) { + $glibcMin = Config::getLib($suggest, 'glibc-min'); + if ($glibcMin !== null) { + $libc = SPCTarget::getLibc(); + $ver = SPCTarget::getLibcVersion(); + if ($libc === 'glibc' && version_compare($ver, (string) $glibcMin, '<')) { + continue; + } + } $dep_list[$name]['depends'][] = $suggest; $del_list[] = $id; } diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index c6519a9a..981f51cd 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -100,6 +100,10 @@ class SPCTarget public static function getLibcVersion(): ?string { if (PHP_OS_FAMILY === 'Linux') { + $target = getenv('SPC_TARGET'); + if (str_contains($target, '-gnu.2.')) { + return preg_match('/-gnu\.(2\.\d+)/', $target, $matches) ? $matches[1] : null; + } $libc = self::getLibc(); return SystemUtil::getLibcVersionIfExists($libc); }