diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 9077269e5..63dc31d04 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -11,6 +11,9 @@ use SPC\exception\WrongUsageException; use SPC\store\Config; use SPC\store\FileSystem; +use SPC\toolchain\ToolchainManager; +use SPC\toolchain\ZigToolchain; +use SPC\util\GlobalEnvManager; use SPC\util\SPCConfigUtil; use SPC\util\SPCTarget; @@ -231,7 +234,7 @@ public function patchBeforeSharedMake(): bool if (preg_match('/^(.*_SHARED_LIBADD\s*=\s*)(.*)$/m', $makefileContent, $matches)) { $prefix = $matches[1]; $currentLibs = trim($matches[2]); - $newLibs = trim("{$currentLibs} {$staticLibs} {$lstdcpp}"); + $newLibs = clean_spaces("{$currentLibs} {$staticLibs} {$lstdcpp}"); $deduplicatedLibs = deduplicate_flags($newLibs); FileSystem::replaceFileRegex( @@ -543,6 +546,11 @@ public function getLibraryDependencies(bool $recursive = false): 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); [$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']); $preStatic = PHP_OS_FAMILY === 'Darwin' ? '' : '-Wl,--start-group '; diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index d959aade6..ed26d64f3 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -11,6 +11,8 @@ use SPC\store\DirDiff; use SPC\store\FileSystem; use SPC\store\SourcePatcher; +use SPC\toolchain\ToolchainManager; +use SPC\toolchain\ZigToolchain; use SPC\util\GlobalEnvManager; use SPC\util\SPCConfigUtil; use SPC\util\SPCTarget; @@ -65,7 +67,8 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void // php 8.5 contains opcache extension by default, // if opcache_jit is enabled for 8.5 or opcache enabled, // we need to disable undefined behavior sanitizer. - f_putenv('SPC_COMPILER_EXTRA=-fno-sanitize=undefined'); + $compiler_extra = getenv('SPC_COMPILER_EXTRA') ?: ''; + f_putenv('SPC_COMPILER_EXTRA=' . trim($compiler_extra . ' -fno-sanitize=undefined')); } if ($this->getOption('enable-zts', false)) { @@ -266,6 +269,11 @@ protected function buildFpm(): 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($sharedExts, static function ($ext) { return Config::getExt($ext->getName(), 'build-with-php') === true; diff --git a/src/globals/common-tests/embed.c b/src/globals/common-tests/embed.c index 38d8f39fc..c6ba0b260 100644 --- a/src/globals/common-tests/embed.c +++ b/src/globals/common-tests/embed.c @@ -1,17 +1,12 @@ #include -int main(int argc,char **argv){ - - PHP_EMBED_START_BLOCK(argc,argv) - +int main(int argc, char **argv) { + PHP_EMBED_START_BLOCK(argc, argv) zend_file_handle file_handle; - - zend_stream_init_filename(&file_handle,"embed.php"); - - if(!php_execute_script(&file_handle)){ + zend_stream_init_filename(&file_handle, "embed.php"); + if(!php_execute_script(&file_handle)) { php_printf("Failed to execute PHP script.\n"); } - PHP_EMBED_END_BLOCK() return 0; }