Skip to content

Commit d219801

Browse files
committed
bring back openmp for musl, add TODO to add it back in on glibc
1 parent 16d8221 commit d219801

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/SPC/builder/extension/imagick.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
namespace SPC\builder\extension;
66

77
use SPC\builder\Extension;
8-
use SPC\exception\FileSystemException;
9-
use SPC\store\FileSystem;
108
use SPC\util\CustomExt;
119

1210
#[CustomExt('imagick')]
1311
class imagick extends Extension
1412
{
15-
/**
16-
* @throws FileSystemException
17-
*/
1813
public function patchBeforeMake(): bool
1914
{
20-
// replace php_config.h HAVE_OMP_PAUSE_RESOURCE_ALL line to #define HAVE_OMP_PAUSE_RESOURCE_ALL 0
21-
FileSystem::replaceFileLineContainsString(SOURCE_PATH . '/php-src/main/php_config.h', 'HAVE_OMP_PAUSE_RESOURCE_ALL', '#define HAVE_OMP_PAUSE_RESOURCE_ALL 0');
15+
if (getenv('SPC_LIBC') !== 'musl') {
16+
return false;
17+
}
18+
// imagick with calls omp_pause_all which requires -lgomp, on non-musl we build imagick without openmp
19+
$extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -lgomp');
20+
f_putenv('SPC_EXTRA_LIBS=' . $extra_libs);
2221
return true;
2322
}
2423

2524
public function getUnixConfigureArg(): string
2625
{
27-
return '--with-imagick=' . BUILD_ROOT_PATH;
26+
$disable_omp = getenv('SPC_LIBC') === 'musl' ? '' : ' ac_cv_func_omp_pause_resource_all=no';
27+
return '--with-imagick=' . BUILD_ROOT_PATH . $disable_omp;
2828
}
2929
}

src/SPC/builder/unix/library/imagemagick.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ trait imagemagick
1818
*/
1919
protected function build(): void
2020
{
21-
// TODO: imagemagick build with bzip2 failed with bugs, we need to fix it in the future
22-
$extra = '--without-jxl --without-x --disable-openmp ';
21+
// TODO: glibc rh 10 toolset's libgomp.a was built without -fPIC -fPIE so we can't use openmp without depending on libgomp.so
22+
$openmp = getenv('SPC_LIBC') === 'musl' ? '--enable-openmp' : '--disable-openmp';
23+
$extra = "--without-jxl --without-x {$openmp} ";
2324
$required_libs = '';
2425
$optional_libs = [
2526
'libzip' => 'zip',

src/SPC/util/SPCConfigUtil.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ private function getLibsString(array $libraries): string
9090
}
9191
}
9292
}
93+
// patch: imagick (imagemagick wrapper) for linux needs libgomp
94+
if (in_array('imagemagick', $libraries) && PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') {
95+
$short_name[] = '-lgomp';
96+
}
9397
return implode(' ', $short_name);
9498
}
9599

0 commit comments

Comments
 (0)