link libgomp statically on glibc

This commit is contained in:
DubbleClick
2025-03-27 08:48:52 +07:00
parent ee54b6d347
commit 9a7889e46b
3 changed files with 15 additions and 6 deletions

View File

@@ -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;

View File

@@ -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} ";

View File

@@ -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);
}