Skip to content

Commit 40f89d1

Browse files
committed
is shared_libadd enough?
1 parent fa2e041 commit 40f89d1

File tree

1 file changed

+4
-29
lines changed

1 file changed

+4
-29
lines changed

src/SPC/builder/Extension.php

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

77
use SPC\exception\EnvironmentException;
8-
use SPC\exception\FileSystemException;
98
use SPC\exception\SPCException;
109
use SPC\exception\ValidationException;
1110
use SPC\exception\WrongUsageException;
1211
use SPC\store\Config;
1312
use SPC\store\FileSystem;
14-
use SPC\toolchain\ClangNativeToolchain;
15-
use SPC\toolchain\GccNativeToolchain;
16-
use SPC\toolchain\ToolchainManager;
17-
use SPC\toolchain\ZigToolchain;
1813
use SPC\util\SPCConfigUtil;
1914
use SPC\util\SPCTarget;
2015

@@ -226,11 +221,11 @@ public function patchBeforeSharedConfigure(): bool
226221
public function patchBeforeSharedMake(): bool
227222
{
228223
$config = (new SPCConfigUtil($this->builder))->config([$this->getName()], array_map(fn ($l) => $l->getName(), $this->builder->getLibs()));
229-
[$staticLibs] = $this->splitLibsIntoStaticAndShared($config['libs']);
224+
[$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']);
230225
FileSystem::replaceFileRegex(
231226
$this->source_dir . '/Makefile',
232227
'/^(.*_SHARED_LIBADD\s*=.*)$/m',
233-
'$1 ' . trim($staticLibs)
228+
clean_spaces("$1 {$staticLibs} {$sharedLibs}")
234229
);
235230
if ($objs = getenv('SPC_EXTRA_RUNTIME_OBJECTS')) {
236231
FileSystem::replaceFileRegex(
@@ -406,26 +401,6 @@ public function buildShared(array $visited = []): void
406401
public function buildUnixShared(): void
407402
{
408403
$env = $this->getSharedExtensionEnv();
409-
if (str_contains($env['LIBS'], '-lstdc++') && SPCTarget::getTargetOS() === 'Linux') {
410-
if (ToolchainManager::getToolchainClass() === ZigToolchain::class) {
411-
$env['SPC_COMPILER_EXTRA'] = '-lstdc++';
412-
} elseif (ToolchainManager::getToolchainClass() === GccNativeToolchain::class || ToolchainManager::getToolchainClass() === ClangNativeToolchain::class) {
413-
try {
414-
$content = FileSystem::readFile($this->source_dir . '/config.m4');
415-
if ($content && !str_contains($content, 'PHP_ADD_LIBRARY(stdc++')) {
416-
$pattern = '/(PHP_NEW_EXTENSION\(' . $this->name . ',.*\))/m';
417-
$replacement = "$1\nPHP_ADD_LIBRARY(stdc++, 1, " . strtoupper($this->name) . '_SHARED_LIBADD)';
418-
FileSystem::replaceFileRegex(
419-
$this->source_dir . '/config.m4',
420-
$pattern,
421-
$replacement
422-
);
423-
}
424-
} catch (FileSystemException) {
425-
}
426-
}
427-
}
428-
429404
if ($this->patchBeforeSharedPhpize()) {
430405
logger()->info("Extension [{$this->getName()}] patched before shared phpize");
431406
}
@@ -593,12 +568,12 @@ protected function getLibraryDependencies(bool $recursive = false): array
593568
$added = 0;
594569
foreach ($ret as $depName => $dep) {
595570
foreach ($dep->getDependencies(true) as $depdepName => $depdep) {
596-
if (!in_array($depdepName, array_keys($deps), true)) {
571+
if (!array_key_exists($depdepName, $deps)) {
597572
$deps[$depdepName] = $depdep;
598573
++$added;
599574
}
600575
}
601-
if (!in_array($depName, array_keys($deps), true)) {
576+
if (!array_key_exists($depName, $deps)) {
602577
$deps[$depName] = $dep;
603578
}
604579
}

0 commit comments

Comments
 (0)