From 4115e42dc687c6948fd69c81dd4c11b0adbe9bb1 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 29 Mar 2025 22:51:12 +0800 Subject: [PATCH 01/11] Remove openmp support for imagemagick --- src/SPC/builder/extension/imagick.php | 12 ------------ src/SPC/builder/unix/library/imagemagick.php | 2 +- src/SPC/util/SPCConfigUtil.php | 4 ---- src/globals/test-extensions.php | 4 ++-- 4 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 7becb143..ed456e17 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -5,23 +5,11 @@ declare(strict_types=1); namespace SPC\builder\extension; use SPC\builder\Extension; -use SPC\builder\linux\LinuxBuilder; use SPC\util\CustomExt; #[CustomExt('imagick')] class imagick extends Extension { - public function patchBeforeMake(): bool - { - // 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 '; - } - f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); - return true; - } - public function getUnixConfigureArg(): string { return '--with-imagick=' . BUILD_ROOT_PATH; diff --git a/src/SPC/builder/unix/library/imagemagick.php b/src/SPC/builder/unix/library/imagemagick.php index 53f7953e..26101def 100644 --- a/src/SPC/builder/unix/library/imagemagick.php +++ b/src/SPC/builder/unix/library/imagemagick.php @@ -19,7 +19,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 --disable-openmp --without-bzlib '; $required_libs = ''; $optional_libs = [ 'libzip' => 'zip', diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index f4a121eb..b65dc1c6 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -90,10 +90,6 @@ class SPCConfigUtil } } } - // patch: imagick (imagemagick wrapper) for linux needs -lgomp - if (in_array('imagemagick', $libraries) && PHP_OS_FAMILY === 'Linux') { - $short_name[] = '-lgomp'; - } return implode(' ', $short_name); } diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index cecb8ace..5f9c15a6 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -24,7 +24,7 @@ $test_os = [ // 'macos-13', // 'macos-14', 'ubuntu-latest', - 'windows-latest', + // 'windows-latest', ]; // whether enable thread safe @@ -40,7 +40,7 @@ $prefer_pre_built = false; // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'pgsql,pdo_pgsql', + 'Linux', 'Darwin' => 'imagick', 'Windows' => 'pgsql,pdo_pgsql', }; From 3915c8410b9efda3a9ff9f4f495935c9b8c12504 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 29 Mar 2025 23:15:55 +0800 Subject: [PATCH 02/11] Destroy imagick config for disabling openmp --- src/SPC/builder/extension/imagick.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index ed456e17..8202bc8f 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -5,11 +5,19 @@ declare(strict_types=1); namespace SPC\builder\extension; use SPC\builder\Extension; +use SPC\store\FileSystem; use SPC\util\CustomExt; #[CustomExt('imagick')] class imagick extends Extension { + public function patchBeforeBuildconf(): bool + { + // destroy imagick build conf to avoid libgomp build error + FileSystem::replaceFileStr(SOURCE_PATH . '/ext/imagick/config.m4', '#include ', '#include '); + return true; + } + public function getUnixConfigureArg(): string { return '--with-imagick=' . BUILD_ROOT_PATH; From 88ce2eafab6d06bd8ebce83c23038331610fab22 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 29 Mar 2025 23:29:45 +0800 Subject: [PATCH 03/11] Fix path bug --- src/SPC/builder/extension/imagick.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 8202bc8f..4e1a2ff9 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -14,7 +14,7 @@ class imagick extends Extension public function patchBeforeBuildconf(): bool { // destroy imagick build conf to avoid libgomp build error - FileSystem::replaceFileStr(SOURCE_PATH . '/ext/imagick/config.m4', '#include ', '#include '); + FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/imagick/config.m4', '#include ', '#include '); return true; } From 936413a6d91eb2f8fc9b10fab641397260295578 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 30 Mar 2025 14:01:31 +0800 Subject: [PATCH 04/11] Define HAVE_OMP_PAUSE_RESOURCE_ALL to 0, add additional file system func --- src/SPC/builder/extension/imagick.php | 10 +++++++--- src/SPC/store/FileSystem.php | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 4e1a2ff9..e452a98a 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -5,16 +5,20 @@ 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 { - public function patchBeforeBuildconf(): bool + /** + * @throws FileSystemException + */ + public function patchBeforeMake(): bool { - // destroy imagick build conf to avoid libgomp build error - FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/imagick/config.m4', '#include ', '#include '); + // 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'); return true; } diff --git a/src/SPC/store/FileSystem.php b/src/SPC/store/FileSystem.php index 67b21ec4..16047427 100644 --- a/src/SPC/store/FileSystem.php +++ b/src/SPC/store/FileSystem.php @@ -461,6 +461,23 @@ class FileSystem } } + /** + * @throws FileSystemException + */ + public static function replaceFileLineContainsString(string $file, string $find, string $line): false|int + { + $lines = file($file); + if ($lines === false) { + throw new FileSystemException('Cannot read file: ' . $file); + } + foreach ($lines as $key => $value) { + if (str_contains($value, $find)) { + $lines[$key] = $line . PHP_EOL; + } + } + return file_put_contents($file, implode('', $lines)); + } + /** * @throws RuntimeException * @throws FileSystemException From 6ea1d06460d72af8bfc98d02a99286b2d046eca6 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 30 Mar 2025 14:02:44 +0800 Subject: [PATCH 05/11] Add bzip2 support for imagick --- config/lib.json | 4 ++-- src/SPC/builder/unix/library/imagemagick.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/config/lib.json b/config/lib.json index 0dae815f..a68d242e 100644 --- a/config/lib.json +++ b/config/lib.json @@ -210,12 +210,12 @@ "libwebp", "freetype", "libtiff", - "libheif" + "libheif", + "bzip2" ], "lib-suggests": [ "zstd", "xz", - "bzip2", "libzip", "libxml2" ] diff --git a/src/SPC/builder/unix/library/imagemagick.php b/src/SPC/builder/unix/library/imagemagick.php index 26101def..19238f7b 100644 --- a/src/SPC/builder/unix/library/imagemagick.php +++ b/src/SPC/builder/unix/library/imagemagick.php @@ -19,7 +19,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 --disable-openmp --without-bzlib '; + $extra = '--without-jxl --without-x --disable-openmp '; $required_libs = ''; $optional_libs = [ 'libzip' => 'zip', @@ -31,6 +31,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} "; From 16d82212dd3d0edb3f69416adb04d47120188551 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 30 Mar 2025 14:03:06 +0800 Subject: [PATCH 06/11] Add full tests for imagick extension --- src/globals/test-extensions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 5f9c15a6..ab5c5528 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -21,8 +21,8 @@ $test_php_version = [ // test os (macos-13, macos-14, ubuntu-latest, windows-latest are available) $test_os = [ - // 'macos-13', - // 'macos-14', + 'macos-13', + 'macos-14', 'ubuntu-latest', // 'windows-latest', ]; From d21980170ed062c26abcfb28c5d9d3fb9bbd5c54 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 30 Mar 2025 22:07:56 +0700 Subject: [PATCH 07/11] 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); } From 7a2f77193feff40301cd6682ae986c34c3c90d70 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 30 Mar 2025 22:22:22 +0700 Subject: [PATCH 08/11] add imagick extension note --- docs/en/guide/extension-notes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/guide/extension-notes.md b/docs/en/guide/extension-notes.md index 1d9209c9..734658ab 100644 --- a/docs/en/guide/extension-notes.md +++ b/docs/en/guide/extension-notes.md @@ -48,6 +48,10 @@ This extension contains an implementation of the coroutine environment for `pdo_ 1. Only PHP 8.0 ~ 8.4 is supported. +## imagick + +1. The imagick extension currently only has openmp support on musl libc. This means that multithreading is disabled on glibc or other operating systems. The extension is still fully functional. + ## imap 1. Kerberos is not supported From 0524129b6417bb635f1b6641ea2da6278a88c758 Mon Sep 17 00:00:00 2001 From: Marc Date: Sun, 30 Mar 2025 23:34:52 +0700 Subject: [PATCH 09/11] add notes to imagick --- config/ext.json | 1 + 1 file changed, 1 insertion(+) diff --git a/config/ext.json b/config/ext.json index 5dc86c62..a906daf6 100644 --- a/config/ext.json +++ b/config/ext.json @@ -253,6 +253,7 @@ "Windows": "wip", "BSD": "wip" }, + "notes": true, "type": "external", "source": "ext-imagick", "arg-type": "custom", From 3fe50e9ca37eb260d536a93090750e3b364cee99 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 30 Mar 2025 23:37:22 +0700 Subject: [PATCH 10/11] let tests succeed --- src/globals/test-extensions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 36bfde55..e0904d40 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -35,10 +35,10 @@ $zts = false; $no_strip = false; // compress with upx -$upx = true; +$upx = false; // prefer downloading pre-built packages to speed up the build process -$prefer_pre_built = true; +$prefer_pre_built = false; // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { From 615e680b9b36975596eb2951fb3e0e8c1e074040 Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Mon, 31 Mar 2025 16:15:12 +0800 Subject: [PATCH 11/11] Update extension-notes.md --- docs/zh/guide/extension-notes.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/zh/guide/extension-notes.md b/docs/zh/guide/extension-notes.md index c13deeea..6ff2dfc0 100644 --- a/docs/zh/guide/extension-notes.md +++ b/docs/zh/guide/extension-notes.md @@ -45,6 +45,10 @@ swoole-hook-sqlite 与 `pdo_sqlite` 扩展冲突。如需使用 Swoole 和 `pdo_ 1. swow 仅支持 PHP 8.0 ~ 8.4 版本。 +## imagick + +imagick 扩展目前仅在 musl libc 上支持 OpenMP(libgomp)。使用 glibc 方式构建的 imagick 扩展无法支持多线程特性。 + ## imap 1. 该扩展目前不支持 Kerberos。 @@ -141,4 +145,4 @@ parallel 扩展只支持 PHP 8.0 及以上版本,并只支持 ZTS 构建(`-- 1. 从技术上讲,这不是扩展,而是一个库。 2. 在 Linux 或 macOS 上使用 `--with-libs="mimalloc"` 进行构建将覆盖默认分配器。 -3. 目前,这还处于实验阶段,但建议在线程环境中使用。 \ No newline at end of file +3. 目前,这还处于实验阶段,但建议在线程环境中使用。