From d21980170ed062c26abcfb28c5d9d3fb9bbd5c54 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 30 Mar 2025 22:07:56 +0700 Subject: [PATCH] bring back openmp for musl, add TODO to add it back in on glibc --- src/SPC/builder/extension/imagick.php | 16 ++++++++-------- src/SPC/builder/unix/library/imagemagick.php | 5 +++-- src/SPC/util/SPCConfigUtil.php | 4 ++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index e452a98a..c3a96c3b 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -5,25 +5,25 @@ declare(strict_types=1); namespace SPC\builder\extension; use SPC\builder\Extension; -use SPC\exception\FileSystemException; -use SPC\store\FileSystem; use SPC\util\CustomExt; #[CustomExt('imagick')] class imagick extends Extension { - /** - * @throws FileSystemException - */ public function patchBeforeMake(): bool { - // replace php_config.h HAVE_OMP_PAUSE_RESOURCE_ALL line to #define HAVE_OMP_PAUSE_RESOURCE_ALL 0 - FileSystem::replaceFileLineContainsString(SOURCE_PATH . '/php-src/main/php_config.h', 'HAVE_OMP_PAUSE_RESOURCE_ALL', '#define HAVE_OMP_PAUSE_RESOURCE_ALL 0'); + if (getenv('SPC_LIBC') !== 'musl') { + return false; + } + // imagick with calls omp_pause_all which requires -lgomp, on non-musl we build imagick without openmp + $extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -lgomp'); + f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); return true; } public function getUnixConfigureArg(): string { - return '--with-imagick=' . BUILD_ROOT_PATH; + $disable_omp = getenv('SPC_LIBC') === 'musl' ? '' : ' ac_cv_func_omp_pause_resource_all=no'; + return '--with-imagick=' . BUILD_ROOT_PATH . $disable_omp; } } diff --git a/src/SPC/builder/unix/library/imagemagick.php b/src/SPC/builder/unix/library/imagemagick.php index 19238f7b..13f7f4cd 100644 --- a/src/SPC/builder/unix/library/imagemagick.php +++ b/src/SPC/builder/unix/library/imagemagick.php @@ -18,8 +18,9 @@ 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 --disable-openmp '; + // TODO: glibc rh 10 toolset's libgomp.a was built without -fPIC -fPIE so we can't use openmp without depending on libgomp.so + $openmp = getenv('SPC_LIBC') === 'musl' ? '--enable-openmp' : '--disable-openmp'; + $extra = "--without-jxl --without-x {$openmp} "; $required_libs = ''; $optional_libs = [ 'libzip' => 'zip', diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index b65dc1c6..8f676d3f 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -90,6 +90,10 @@ class SPCConfigUtil } } } + // patch: imagick (imagemagick wrapper) for linux needs libgomp + if (in_array('imagemagick', $libraries) && PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') { + $short_name[] = '-lgomp'; + } return implode(' ', $short_name); }