diff --git a/config/ext.json b/config/ext.json index 5dc86c625..a906daf6f 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", diff --git a/config/lib.json b/config/lib.json index 0dae815fc..a68d242e1 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/docs/en/guide/extension-notes.md b/docs/en/guide/extension-notes.md index 1d9209c99..734658ab8 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 diff --git a/docs/zh/guide/extension-notes.md b/docs/zh/guide/extension-notes.md index c13deeeab..6ff2dfc0b 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. 目前,这还处于实验阶段,但建议在线程环境中使用。 diff --git a/src/SPC/builder/extension/imagick.php b/src/SPC/builder/extension/imagick.php index 7becb143b..c3a96c3b6 100644 --- a/src/SPC/builder/extension/imagick.php +++ b/src/SPC/builder/extension/imagick.php @@ -5,7 +5,6 @@ namespace SPC\builder\extension; use SPC\builder\Extension; -use SPC\builder\linux\LinuxBuilder; use SPC\util\CustomExt; #[CustomExt('imagick')] @@ -13,17 +12,18 @@ 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 '; + 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 53f7953e9..13f7f4cd1 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 --enable-openmp --without-bzlib '; + // 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', @@ -31,6 +32,7 @@ protected function build(): void '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/store/FileSystem.php b/src/SPC/store/FileSystem.php index 67b21ec43..16047427b 100644 --- a/src/SPC/store/FileSystem.php +++ b/src/SPC/store/FileSystem.php @@ -461,6 +461,23 @@ public static function removeFileIfExists(string $string): void } } + /** + * @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 diff --git a/src/SPC/util/SPCConfigUtil.php b/src/SPC/util/SPCConfigUtil.php index f4a121eb7..8f676d3f5 100644 --- a/src/SPC/util/SPCConfigUtil.php +++ b/src/SPC/util/SPCConfigUtil.php @@ -90,8 +90,8 @@ private function getLibsString(array $libraries): string } } } - // patch: imagick (imagemagick wrapper) for linux needs -lgomp - if (in_array('imagemagick', $libraries) && PHP_OS_FAMILY === 'Linux') { + // 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); diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index c8e2f8cb1..e0904d401 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -21,8 +21,8 @@ // test os (macos-13, macos-14, ubuntu-latest, windows-latest are available) $test_os = [ - // 'macos-13', - // 'macos-14', + 'macos-13', + 'macos-14', 'ubuntu-latest', 'ubuntu-22.04', 'ubuntu-22.04-arm', @@ -35,10 +35,10 @@ $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) {