From 9a7889e46b4a8b0009823b7bda068fd9bc87c068 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 27 Mar 2025 08:48:52 +0700 Subject: [PATCH] link libgomp statically on glibc --- src/SPC/builder/extension/imagick.php | 11 ++++++++--- src/SPC/builder/unix/library/imagemagick.php | 4 ++-- src/SPC/util/SPCConfigUtil.php | 6 +++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 7becb143..941498c6 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace SPC\builder\extension; use SPC\builder\Extension; -use SPC\builder\linux\LinuxBuilder; use SPC\util\CustomExt; #[CustomExt('imagick')] @@ -13,10 +12,16 @@ class imagick extends Extension { public function patchBeforeMake(): bool { + if (PHP_OS_FAMILY !== 'Linux') { + return false; + } // imagick may call omp_pause_all which requires -lgomp $extra_libs = getenv('SPC_EXTRA_LIBS') ?: ''; - if ($this->builder instanceof LinuxBuilder) { - $extra_libs .= (empty($extra_libs) ? '' : ' ') . '-lgomp '; + if (getenv('SPC_LIBC') === 'musl') { + $extra_libs = trim($extra_libs . ' -lgomp'); + } + if (getenv('SPC_LIBC') === 'glibc') { + $extra_libs = trim($extra_libs . ' -l:libgomp.a'); } f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); return true; diff --git a/src/SPC/builder/unix/library/imagemagick.php b/src/SPC/builder/unix/library/imagemagick.php index 53f7953e..a8658f46 100644 --- a/src/SPC/builder/unix/library/imagemagick.php +++ b/src/SPC/builder/unix/library/imagemagick.php @@ -18,8 +18,7 @@ trait imagemagick */ protected function build(): void { - // TODO: imagemagick build with bzip2 failed with bugs, we need to fix it in the future - $extra = '--without-jxl --without-x --enable-openmp --without-bzlib '; + $extra = '--without-jxl --without-x --enable-openmp '; $required_libs = ''; $optional_libs = [ 'libzip' => 'zip', @@ -31,6 +30,7 @@ trait imagemagick 'xz' => 'lzma', 'zstd' => 'zstd', 'freetype' => 'freetype', + 'bzip2' => 'bzlib', ]; foreach ($optional_libs as $lib => $option) { $extra .= $this->builder->getLib($lib) ? "--with-{$option} " : "--without-{$option} "; diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index f4a121eb..769da60e 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -92,7 +92,11 @@ class SPCConfigUtil } // patch: imagick (imagemagick wrapper) for linux needs -lgomp if (in_array('imagemagick', $libraries) && PHP_OS_FAMILY === 'Linux') { - $short_name[] = '-lgomp'; + if (getenv('SPC_LIBC') === 'glibc') { + $short_name[] = '-l:libgomp.a'; + } else { + $short_name[] = '-lgomp'; + } } return implode(' ', $short_name); }