Skip to content

Commit df8b2db

Browse files
committed
better patching for libstdc++ when extensions forget they need it
1 parent 30e174a commit df8b2db

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

config/ext.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,17 @@
414414
"libmemcached",
415415
"fastlz"
416416
],
417+
"lib-suggests": [
418+
"zstd"
419+
],
417420
"ext-depends": [
418421
"session",
419422
"zlib"
423+
],
424+
"ext-suggests": [
425+
"igbinary",
426+
"msgpack",
427+
"session"
420428
]
421429
},
422430
"mongodb": {

src/SPC/builder/Extension.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
namespace SPC\builder;
66

77
use SPC\exception\EnvironmentException;
8+
use SPC\exception\FileSystemException;
89
use SPC\exception\SPCException;
910
use SPC\exception\ValidationException;
1011
use SPC\exception\WrongUsageException;
1112
use SPC\store\Config;
1213
use SPC\store\FileSystem;
14+
use SPC\toolchain\ClangNativeToolchain;
15+
use SPC\toolchain\GccNativeToolchain;
1316
use SPC\toolchain\ToolchainManager;
1417
use SPC\toolchain\ZigToolchain;
1518
use SPC\util\SPCConfigUtil;
@@ -418,8 +421,24 @@ public function buildUnixShared(): void
418421
'LIBS' => clean_spaces("{$preStatic} {$staticLibs} {$postStatic} {$sharedLibs}"),
419422
'LD_LIBRARY_PATH' => BUILD_LIB_PATH,
420423
];
421-
if (ToolchainManager::getToolchainClass() === ZigToolchain::class && SPCTarget::getTargetOS() === 'Linux') {
422-
$env['SPC_COMPILER_EXTRA'] = '-lstdc++';
424+
if (str_contains($env['LIBS'], '-lstdc++') && SPCTarget::getTargetOS() === 'Linux') {
425+
if (ToolchainManager::getToolchainClass() === ZigToolchain::class) {
426+
$env['SPC_COMPILER_EXTRA'] = '-lstdc++';
427+
} elseif (ToolchainManager::getToolchainClass() === GccNativeToolchain::class || ToolchainManager::getToolchainClass() === ClangNativeToolchain::class) {
428+
try {
429+
$content = FileSystem::readFile($this->source_dir . '/config.m4');
430+
if ($content && !str_contains($content, 'PHP_ADD_LIBRARY(stdc++')) {
431+
$pattern = '/(PHP_NEW_EXTENSION\(' . $this->name . ',.*\))/m';
432+
$replacement = "$1\nPHP_ADD_LIBRARY(stdc++, 1, " . strtoupper($this->name) . '_SHARED_LIBADD)';
433+
FileSystem::replaceFileRegex(
434+
$this->source_dir . '/config.m4',
435+
$pattern,
436+
$replacement
437+
);
438+
}
439+
} catch (FileSystemException) {
440+
}
441+
}
423442
}
424443

425444
if ($this->patchBeforeSharedPhpize()) {

src/SPC/builder/extension/memcached.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public function getUnixConfigureArg(bool $shared = false): string
1717
'--with-libmemcached-dir=' . BUILD_ROOT_PATH . ' ' .
1818
'--disable-memcached-sasl ' .
1919
'--enable-memcached-json ' .
20+
($this->builder->getLib('zstd') ? '--with-zstd ' : '') .
21+
($this->builder->getExt('igbinary') ? '--enable-memcached-igbinary ' : '') .
22+
($this->builder->getExt('session') ? '--enable-memcached-session ' : '') .
23+
($this->builder->getExt('msgpack') ? '--enable-memcached-msgpack ' : '') .
2024
'--with-system-fastlz';
2125
}
2226
}

0 commit comments

Comments
 (0)