bring back openmp for musl, add TODO to add it back in on glibc

This commit is contained in:
DubbleClick
2025-03-30 22:07:56 +07:00
parent 16d82212dd
commit d21980170e
3 changed files with 15 additions and 10 deletions

View File

@@ -5,25 +5,25 @@ declare(strict_types=1);
namespace SPC\builder\extension; namespace SPC\builder\extension;
use SPC\builder\Extension; use SPC\builder\Extension;
use SPC\exception\FileSystemException;
use SPC\store\FileSystem;
use SPC\util\CustomExt; use SPC\util\CustomExt;
#[CustomExt('imagick')] #[CustomExt('imagick')]
class imagick extends Extension class imagick extends Extension
{ {
/**
* @throws FileSystemException
*/
public function patchBeforeMake(): bool public function patchBeforeMake(): bool
{ {
// replace php_config.h HAVE_OMP_PAUSE_RESOURCE_ALL line to #define HAVE_OMP_PAUSE_RESOURCE_ALL 0 if (getenv('SPC_LIBC') !== 'musl') {
FileSystem::replaceFileLineContainsString(SOURCE_PATH . '/php-src/main/php_config.h', 'HAVE_OMP_PAUSE_RESOURCE_ALL', '#define HAVE_OMP_PAUSE_RESOURCE_ALL 0'); 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; return true;
} }
public function getUnixConfigureArg(): string 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;
} }
} }

View File

@@ -18,8 +18,9 @@ trait imagemagick
*/ */
protected function build(): void protected function build(): void
{ {
// TODO: imagemagick build with bzip2 failed with bugs, we need to fix it in the future // TODO: glibc rh 10 toolset's libgomp.a was built without -fPIC -fPIE so we can't use openmp without depending on libgomp.so
$extra = '--without-jxl --without-x --disable-openmp '; $openmp = getenv('SPC_LIBC') === 'musl' ? '--enable-openmp' : '--disable-openmp';
$extra = "--without-jxl --without-x {$openmp} ";
$required_libs = ''; $required_libs = '';
$optional_libs = [ $optional_libs = [
'libzip' => 'zip', 'libzip' => 'zip',

View File

@@ -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); return implode(' ', $short_name);
} }