mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-08 17:35:36 +08:00
set lcompiler_rt only when building shared extensions
This commit is contained in:
@@ -11,6 +11,9 @@ use SPC\exception\ValidationException;
|
|||||||
use SPC\exception\WrongUsageException;
|
use SPC\exception\WrongUsageException;
|
||||||
use SPC\store\Config;
|
use SPC\store\Config;
|
||||||
use SPC\store\FileSystem;
|
use SPC\store\FileSystem;
|
||||||
|
use SPC\toolchain\ToolchainManager;
|
||||||
|
use SPC\toolchain\ZigToolchain;
|
||||||
|
use SPC\util\GlobalEnvManager;
|
||||||
use SPC\util\SPCConfigUtil;
|
use SPC\util\SPCConfigUtil;
|
||||||
use SPC\util\SPCTarget;
|
use SPC\util\SPCTarget;
|
||||||
|
|
||||||
@@ -543,6 +546,11 @@ class Extension
|
|||||||
*/
|
*/
|
||||||
protected function getSharedExtensionEnv(): array
|
protected function getSharedExtensionEnv(): array
|
||||||
{
|
{
|
||||||
|
$compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: '';
|
||||||
|
if (!str_contains($compiler_extra, '-lcompiler_rt') && ToolchainManager::getToolchainClass() === ZigToolchain::class) {
|
||||||
|
$compiler_extra = trim($compiler_extra . ' -lcompiler_rt');
|
||||||
|
GlobalEnvManager::putenv("SPC_COMPILER_EXTRA={$compiler_extra}");
|
||||||
|
}
|
||||||
$config = (new SPCConfigUtil($this->builder, ['no_php' => true]))->getExtensionConfig($this);
|
$config = (new SPCConfigUtil($this->builder, ['no_php' => true]))->getExtensionConfig($this);
|
||||||
[$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']);
|
[$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']);
|
||||||
$preStatic = PHP_OS_FAMILY === 'Darwin' ? '' : '-Wl,--start-group ';
|
$preStatic = PHP_OS_FAMILY === 'Darwin' ? '' : '-Wl,--start-group ';
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ use SPC\store\Config;
|
|||||||
use SPC\store\DirDiff;
|
use SPC\store\DirDiff;
|
||||||
use SPC\store\FileSystem;
|
use SPC\store\FileSystem;
|
||||||
use SPC\store\SourcePatcher;
|
use SPC\store\SourcePatcher;
|
||||||
|
use SPC\toolchain\ToolchainManager;
|
||||||
|
use SPC\toolchain\ZigToolchain;
|
||||||
use SPC\util\GlobalEnvManager;
|
use SPC\util\GlobalEnvManager;
|
||||||
use SPC\util\SPCConfigUtil;
|
use SPC\util\SPCConfigUtil;
|
||||||
use SPC\util\SPCTarget;
|
use SPC\util\SPCTarget;
|
||||||
@@ -267,6 +269,11 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
*/
|
*/
|
||||||
protected function buildEmbed(): void
|
protected function buildEmbed(): void
|
||||||
{
|
{
|
||||||
|
$compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: '';
|
||||||
|
if (!str_contains($compiler_extra, '-lcompiler_rt') && ToolchainManager::getToolchainClass() === ZigToolchain::class) {
|
||||||
|
$compiler_extra = trim($compiler_extra . ' -lcompiler_rt');
|
||||||
|
GlobalEnvManager::putenv("SPC_COMPILER_EXTRA={$compiler_extra}");
|
||||||
|
}
|
||||||
$sharedExts = array_filter($this->exts, static fn ($ext) => $ext->isBuildShared());
|
$sharedExts = array_filter($this->exts, static fn ($ext) => $ext->isBuildShared());
|
||||||
$sharedExts = array_filter($sharedExts, static function ($ext) {
|
$sharedExts = array_filter($sharedExts, static function ($ext) {
|
||||||
return Config::getExt($ext->getName(), 'build-with-php') === true;
|
return Config::getExt($ext->getName(), 'build-with-php') === true;
|
||||||
|
|||||||
@@ -64,12 +64,6 @@ class ZigToolchain implements ToolchainInterface
|
|||||||
$extra_libs = trim($extra_libs . ' -lunwind');
|
$extra_libs = trim($extra_libs . ' -lunwind');
|
||||||
GlobalEnvManager::putenv("SPC_EXTRA_LIBS={$extra_libs}");
|
GlobalEnvManager::putenv("SPC_EXTRA_LIBS={$extra_libs}");
|
||||||
}
|
}
|
||||||
$compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: '';
|
|
||||||
if (!str_contains($compiler_extra, '-lcompiler_rt')) {
|
|
||||||
// Add unwind library if not already present
|
|
||||||
$compiler_extra = trim($compiler_extra . ' -lcompiler_rt');
|
|
||||||
GlobalEnvManager::putenv("SPC_COMPILER_EXTRA={$compiler_extra}");
|
|
||||||
}
|
|
||||||
$cflags = getenv('SPC_DEFAULT_C_FLAGS') ?: getenv('CFLAGS') ?: '';
|
$cflags = getenv('SPC_DEFAULT_C_FLAGS') ?: getenv('CFLAGS') ?: '';
|
||||||
$has_avx512 = str_contains($cflags, '-mavx512') || str_contains($cflags, '-march=x86-64-v4');
|
$has_avx512 = str_contains($cflags, '-mavx512') || str_contains($cflags, '-march=x86-64-v4');
|
||||||
if (!$has_avx512) {
|
if (!$has_avx512) {
|
||||||
|
|||||||
Reference in New Issue
Block a user