musl paths in zig toolchain are hogwash, of course

This commit is contained in:
DubbleClick 2025-07-01 17:08:19 +07:00
parent 88f9172866
commit fd89e83798
2 changed files with 10 additions and 23 deletions

View File

@ -12,17 +12,11 @@ class ZigToolchain implements ToolchainInterface
{ {
public function initEnv(): void public function initEnv(): void
{ {
$arch = getenv('GNU_ARCH'); // Set environment variables for zig toolchain
// Set environment variables for musl toolchain
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=zig-cc'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=zig-cc');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld'); GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld');
GlobalEnvManager::addPathIfNotExists('/usr/local/musl/bin');
GlobalEnvManager::addPathIfNotExists("/usr/local/musl/{$arch}-linux-musl/bin");
GlobalEnvManager::putenv("SPC_LD_LIBRARY_PATH=/usr/local/musl/lib:/usr/local/musl/{$arch}-linux-musl/lib");
GlobalEnvManager::putenv("SPC_LIBRARY_PATH=/usr/local/musl/lib:/usr/local/musl/{$arch}-linux-musl/lib");
} }
public function afterInit(): void public function afterInit(): void

View File

@ -24,9 +24,6 @@ class SPCTarget
public static function isStatic(): bool public static function isStatic(): bool
{ {
// 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 (getenv('SPC_LIBC') === 'musl') {
return true;
}
if ($target = getenv('SPC_TARGET')) { if ($target = getenv('SPC_TARGET')) {
if (str_contains($target, '-macos') || str_contains($target, '-native') && PHP_OS_FAMILY === 'Darwin') { if (str_contains($target, '-macos') || str_contains($target, '-native') && PHP_OS_FAMILY === 'Darwin') {
return false; return false;
@ -39,6 +36,9 @@ class SPCTarget
} }
return true; return true;
} }
if (getenv('SPC_LIBC') === 'musl') {
return true;
}
return false; return false;
} }
@ -47,10 +47,6 @@ class SPCTarget
*/ */
public static function getLibc(): ?string public static function getLibc(): ?string
{ {
$libc = getenv('SPC_LIBC');
if ($libc !== false) {
return $libc;
}
$target = getenv('SPC_TARGET'); $target = getenv('SPC_TARGET');
if (str_contains($target, '-gnu')) { if (str_contains($target, '-gnu')) {
return 'glibc'; return 'glibc';
@ -64,6 +60,10 @@ class SPCTarget
if (PHP_OS_FAMILY === 'Linux' && str_contains($target, '-native')) { if (PHP_OS_FAMILY === 'Linux' && str_contains($target, '-native')) {
return 'musl'; return 'musl';
} }
$libc = getenv('SPC_LIBC');
if ($libc !== false) {
return $libc;
}
return null; return null;
} }
@ -72,15 +72,8 @@ class SPCTarget
*/ */
public static function getLibcVersion(): ?string public static function getLibcVersion(): ?string
{ {
$env = getenv('SPC_TARGET'); $libc = self::getLibc();
$libc = getenv('SPC_LIBC'); return SystemUtil::getLibcVersionIfExists($libc);
if ($libc !== false) {
// legacy method: get a version from system
return SystemUtil::getLibcVersionIfExists($libc);
}
// TODO: zig target parser
return null;
} }
/** /**