add zig to libc/static target parsing

This commit is contained in:
DubbleClick 2025-07-01 12:55:32 +07:00
parent c43a10027b
commit ad8322b6a6
2 changed files with 27 additions and 12 deletions

View File

@ -529,8 +529,7 @@ class Extension
$sharedLibString = ''; $sharedLibString = '';
$staticLibString = ''; $staticLibString = '';
$staticLibs = $this->getLibFilesString(); $staticLibs = $this->getLibFilesString();
$staticLibs = str_replace(BUILD_LIB_PATH . '/lib', '-l', $staticLibs); $staticLibs = str_replace([BUILD_LIB_PATH . '/lib', '.a'], ['-l', ''], $staticLibs);
$staticLibs = str_replace('.a', '', $staticLibs);
$staticLibs = explode('-l', $staticLibs . ' ' . $config['libs']); $staticLibs = explode('-l', $staticLibs . ' ' . $config['libs']);
foreach ($staticLibs as $lib) { foreach ($staticLibs as $lib) {
$lib = trim($lib); $lib = trim($lib);
@ -546,11 +545,6 @@ class Extension
$sharedLibString .= '-l' . $lib . ' '; $sharedLibString .= '-l' . $lib . ' ';
} }
} }
// move static libstdc++ to shared if we are on non-full-static build target
if (!SPCTarget::isStatic() && in_array(SPCTarget::getLibc(), SPCTarget::LIBC_LIST)) {
$staticLibString .= ' -lstdc++';
$sharedLibString = str_replace('-lstdc++', '', $sharedLibString);
}
return [trim($staticLibString), trim($sharedLibString)]; return [trim($staticLibString), trim($sharedLibString)];
} }

View File

@ -19,17 +19,27 @@ class SPCTarget
]; ];
/** /**
* Returns whether the target is a full-static target. * Returns whether we link the C runtime in statically.
*/ */
public static function isStatic(): bool public static function isStatic(): bool
{ {
$env = getenv('SPC_TARGET');
$libc = getenv('SPC_LIBC'); $libc = getenv('SPC_LIBC');
// if SPC_LIBC is set, it means the target is static, remove it when 3.0 is released // if SPC_LIBC is set, it means the target is static, remove it when 3.0 is released
if ($libc === 'musl') { if ($libc === 'musl') {
return true; return true;
} }
// TODO: add zig target parser here if ($target = getenv('SPC_TARGET')) {
if (str_contains($target, '-macos') || str_contains($target, '-native') && PHP_OS_FAMILY === 'Darwin') {
return false;
}
if (str_contains($target, '-gnu')) {
return false;
}
if (str_contains($target, '-dynamic')) {
return false;
}
return true;
}
return false; return false;
} }
@ -38,12 +48,23 @@ class SPCTarget
*/ */
public static function getLibc(): ?string public static function getLibc(): ?string
{ {
$env = getenv('SPC_TARGET');
$libc = getenv('SPC_LIBC'); $libc = getenv('SPC_LIBC');
if ($libc !== false) { if ($libc !== false) {
return $libc; return $libc;
} }
// TODO: zig target parser $target = getenv('SPC_TARGET');
if (str_contains($target, '-gnu')) {
return 'glibc';
}
if (str_contains($target, '-musl')) {
return 'musl';
}
if (str_contains($target, '-linux')) {
return 'musl';
}
if (PHP_OS_FAMILY === 'Linux' && str_contains($target, '-native')) {
return 'musl';
}
return null; return null;
} }