Skip to content

Commit 0a3c56b

Browse files
committed
set lcompiler_rt only when building shared extensions
1 parent b1a77b0 commit 0a3c56b

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/SPC/builder/Extension.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use SPC\exception\WrongUsageException;
1212
use SPC\store\Config;
1313
use SPC\store\FileSystem;
14+
use SPC\toolchain\ToolchainManager;
15+
use SPC\toolchain\ZigToolchain;
16+
use SPC\util\GlobalEnvManager;
1417
use SPC\util\SPCConfigUtil;
1518
use SPC\util\SPCTarget;
1619

@@ -543,6 +546,11 @@ public function getLibraryDependencies(bool $recursive = false): array
543546
*/
544547
protected function getSharedExtensionEnv(): array
545548
{
549+
$compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: '';
550+
if (!str_contains($compiler_extra, '-lcompiler_rt') && ToolchainManager::getToolchainClass() === ZigToolchain::class) {
551+
$compiler_extra = trim($compiler_extra . ' -lcompiler_rt');
552+
GlobalEnvManager::putenv("SPC_COMPILER_EXTRA={$compiler_extra}");
553+
}
546554
$config = (new SPCConfigUtil($this->builder, ['no_php' => true]))->getExtensionConfig($this);
547555
[$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']);
548556
$preStatic = PHP_OS_FAMILY === 'Darwin' ? '' : '-Wl,--start-group ';

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use SPC\store\DirDiff;
1212
use SPC\store\FileSystem;
1313
use SPC\store\SourcePatcher;
14+
use SPC\toolchain\ToolchainManager;
15+
use SPC\toolchain\ZigToolchain;
1416
use SPC\util\GlobalEnvManager;
1517
use SPC\util\SPCConfigUtil;
1618
use SPC\util\SPCTarget;
@@ -267,6 +269,11 @@ protected function buildFpm(): void
267269
*/
268270
protected function buildEmbed(): void
269271
{
272+
$compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: '';
273+
if (!str_contains($compiler_extra, '-lcompiler_rt') && ToolchainManager::getToolchainClass() === ZigToolchain::class) {
274+
$compiler_extra = trim($compiler_extra . ' -lcompiler_rt');
275+
GlobalEnvManager::putenv("SPC_COMPILER_EXTRA={$compiler_extra}");
276+
}
270277
$sharedExts = array_filter($this->exts, static fn ($ext) => $ext->isBuildShared());
271278
$sharedExts = array_filter($sharedExts, static function ($ext) {
272279
return Config::getExt($ext->getName(), 'build-with-php') === true;

src/SPC/toolchain/ZigToolchain.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ public function afterInit(): void
6464
$extra_libs = trim($extra_libs . ' -lunwind');
6565
GlobalEnvManager::putenv("SPC_EXTRA_LIBS={$extra_libs}");
6666
}
67-
$compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: '';
68-
if (!str_contains($compiler_extra, '-lcompiler_rt')) {
69-
// Add unwind library if not already present
70-
$compiler_extra = trim($compiler_extra . ' -lcompiler_rt');
71-
GlobalEnvManager::putenv("SPC_COMPILER_EXTRA={$compiler_extra}");
72-
}
7367
$cflags = getenv('SPC_DEFAULT_C_FLAGS') ?: getenv('CFLAGS') ?: '';
7468
$has_avx512 = str_contains($cflags, '-mavx512') || str_contains($cflags, '-march=x86-64-v4');
7569
if (!$has_avx512) {

0 commit comments

Comments
 (0)