mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
move to systemutil
This commit is contained in:
parent
9a3a536479
commit
b142610800
@ -108,9 +108,6 @@ SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
|
|||||||
; EXTRA_LDFLAGS_PROGRAM for `make` php
|
; EXTRA_LDFLAGS_PROGRAM for `make` php
|
||||||
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-all-static -pie"
|
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-all-static -pie"
|
||||||
|
|
||||||
# Zig
|
|
||||||
ZIG_SHARED_EXTENSION_EXTRA_OBJECTS="/usr/lib/gcc/x86_64-redhat-linux/14/crtbeginS.o /usr/lib/gcc/x86_64-redhat-linux/14/crtendS.o"
|
|
||||||
|
|
||||||
[macos]
|
[macos]
|
||||||
; compiler environments
|
; compiler environments
|
||||||
CC=clang
|
CC=clang
|
||||||
|
|||||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace SPC\builder;
|
namespace SPC\builder;
|
||||||
|
|
||||||
|
use SPC\builder\linux\SystemUtil;
|
||||||
use SPC\exception\FileSystemException;
|
use SPC\exception\FileSystemException;
|
||||||
use SPC\exception\RuntimeException;
|
use SPC\exception\RuntimeException;
|
||||||
use SPC\exception\WrongUsageException;
|
use SPC\exception\WrongUsageException;
|
||||||
@ -215,13 +216,13 @@ class Extension
|
|||||||
*/
|
*/
|
||||||
public function patchBeforeSharedMake(): bool
|
public function patchBeforeSharedMake(): bool
|
||||||
{
|
{
|
||||||
if (!str_contains(getenv('CC'), 'zig')) {
|
$extra = SystemUtil::getExtraRuntimeObjects();
|
||||||
|
if (!$extra) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$extra = getenv('ZIG_SHARED_EXTENSION_EXTRA_OBJECTS');
|
|
||||||
FileSystem::replaceFileRegex(
|
FileSystem::replaceFileRegex(
|
||||||
$this->source_dir . '/Makefile',
|
$this->source_dir . '/Makefile',
|
||||||
"/^(shared_objects_{$this->getName()}\s*=.*)$/m",
|
"/^(shared_objects_{$this->getName()}\\s*=.*)$/m",
|
||||||
"$1 {$extra}",
|
"$1 {$extra}",
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -13,6 +13,8 @@ class SystemUtil
|
|||||||
|
|
||||||
public static ?string $libc_version = null;
|
public static ?string $libc_version = null;
|
||||||
|
|
||||||
|
private static ?string $extra_runtime_objects = null;
|
||||||
|
|
||||||
/** @noinspection PhpMissingBreakStatementInspection */
|
/** @noinspection PhpMissingBreakStatementInspection */
|
||||||
public static function getOSRelease(): array
|
public static function getOSRelease(): array
|
||||||
{
|
{
|
||||||
@ -226,4 +228,38 @@ class SystemUtil
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getExtraRuntimeObjects(): string
|
||||||
|
{
|
||||||
|
$cc = getenv('CC');
|
||||||
|
if (!$cc || !str_contains($cc, 'zig')) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self::$extra_runtime_objects !== null) {
|
||||||
|
return self::$extra_runtime_objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
$paths = ['/usr/lib/gcc', '/usr/local/lib/gcc'];
|
||||||
|
$objects = ['crtbeginS.o', 'crtendS.o'];
|
||||||
|
$found = [];
|
||||||
|
|
||||||
|
foreach ($objects as $obj) {
|
||||||
|
$located = null;
|
||||||
|
foreach ($paths as $base) {
|
||||||
|
$output = shell_exec("find {$base} -name {$obj} -print -quit 2>/dev/null");
|
||||||
|
$line = trim((string) $output);
|
||||||
|
if ($line !== '') {
|
||||||
|
$located = $line;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($located) {
|
||||||
|
$found[] = escapeshellarg($located);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$extra_runtime_objects = implode(' ', $found);
|
||||||
|
return implode(' ', $found);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user