From b265d6dd5625665a0477047f367e7a20673e313a Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Fri, 13 Jun 2025 16:25:31 +0700 Subject: [PATCH] don't set unknown linker flags on macos --- src/SPC/builder/Extension.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 5b35aade..d0448389 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -368,11 +368,16 @@ class Extension { $config = (new SPCConfigUtil($this->builder))->config([$this->getName()], with_dependencies: true); [$staticLibString, $sharedLibString] = $this->getStaticAndSharedLibs(); + + // macOS ld64 doesn't understand these, while Linux and BSD do + // use them to make sure that all symbols are picked up, even if a library has already been visited before + $preStatic = PHP_OS_FAMILY !== 'Darwin' ? '-Wl,-Bstatic -Wl,--start-group ' : ''; + $postStatic = PHP_OS_FAMILY !== 'Darwin' ? ' -Wl,--end-group -Wl,-Bdynamic ' : ' '; $env = [ 'CFLAGS' => $config['cflags'], 'CXXFLAGS' => $config['cflags'], 'LDFLAGS' => $config['ldflags'], - 'LIBS' => '-Wl,-Bstatic -Wl,--start-group ' . $staticLibString . ' -Wl,--end-group -Wl,-Bdynamic ' . $sharedLibString, + 'LIBS' => $preStatic . $staticLibString . $postStatic . $sharedLibString, 'LD_LIBRARY_PATH' => BUILD_LIB_PATH, ]; @@ -393,6 +398,7 @@ class Extension '--enable-shared --disable-static' ); + // some extensions don't define their dependencies well, this patch is only needed for a few FileSystem::replaceFileRegex( $this->source_dir . '/Makefile', '/^(.*_SHARED_LIBADD\s*=.*)$/m',