diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index e71376dd..fef4855c 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -529,8 +529,7 @@ class Extension $sharedLibString = ''; $staticLibString = ''; $staticLibs = $this->getLibFilesString(); - $staticLibs = str_replace(BUILD_LIB_PATH . '/lib', '-l', $staticLibs); - $staticLibs = str_replace('.a', '', $staticLibs); + $staticLibs = str_replace([BUILD_LIB_PATH . '/lib', '.a'], ['-l', ''], $staticLibs); $staticLibs = explode('-l', $staticLibs . ' ' . $config['libs']); foreach ($staticLibs as $lib) { $lib = trim($lib); @@ -546,11 +545,6 @@ class Extension $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)]; } diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index 071f2620..7968c508 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -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 { - $env = getenv('SPC_TARGET'); $libc = getenv('SPC_LIBC'); // if SPC_LIBC is set, it means the target is static, remove it when 3.0 is released if ($libc === 'musl') { 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; } @@ -38,12 +48,23 @@ class SPCTarget */ public static function getLibc(): ?string { - $env = getenv('SPC_TARGET'); $libc = getenv('SPC_LIBC'); if ($libc !== false) { 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; }