Skip to content

Commit ad8322b

Browse files
committed
add zig to libc/static target parsing
1 parent c43a100 commit ad8322b

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/SPC/builder/Extension.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,7 @@ protected function getStaticAndSharedLibs(): array
529529
$sharedLibString = '';
530530
$staticLibString = '';
531531
$staticLibs = $this->getLibFilesString();
532-
$staticLibs = str_replace(BUILD_LIB_PATH . '/lib', '-l', $staticLibs);
533-
$staticLibs = str_replace('.a', '', $staticLibs);
532+
$staticLibs = str_replace([BUILD_LIB_PATH . '/lib', '.a'], ['-l', ''], $staticLibs);
534533
$staticLibs = explode('-l', $staticLibs . ' ' . $config['libs']);
535534
foreach ($staticLibs as $lib) {
536535
$lib = trim($lib);
@@ -546,11 +545,6 @@ protected function getStaticAndSharedLibs(): array
546545
$sharedLibString .= '-l' . $lib . ' ';
547546
}
548547
}
549-
// move static libstdc++ to shared if we are on non-full-static build target
550-
if (!SPCTarget::isStatic() && in_array(SPCTarget::getLibc(), SPCTarget::LIBC_LIST)) {
551-
$staticLibString .= ' -lstdc++';
552-
$sharedLibString = str_replace('-lstdc++', '', $sharedLibString);
553-
}
554548
return [trim($staticLibString), trim($sharedLibString)];
555549
}
556550

src/SPC/util/SPCTarget.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,27 @@ class SPCTarget
1919
];
2020

2121
/**
22-
* Returns whether the target is a full-static target.
22+
* Returns whether we link the C runtime in statically.
2323
*/
2424
public static function isStatic(): bool
2525
{
26-
$env = getenv('SPC_TARGET');
2726
$libc = getenv('SPC_LIBC');
2827
// if SPC_LIBC is set, it means the target is static, remove it when 3.0 is released
2928
if ($libc === 'musl') {
3029
return true;
3130
}
32-
// TODO: add zig target parser here
31+
if ($target = getenv('SPC_TARGET')) {
32+
if (str_contains($target, '-macos') || str_contains($target, '-native') && PHP_OS_FAMILY === 'Darwin') {
33+
return false;
34+
}
35+
if (str_contains($target, '-gnu')) {
36+
return false;
37+
}
38+
if (str_contains($target, '-dynamic')) {
39+
return false;
40+
}
41+
return true;
42+
}
3343
return false;
3444
}
3545

@@ -38,12 +48,23 @@ public static function isStatic(): bool
3848
*/
3949
public static function getLibc(): ?string
4050
{
41-
$env = getenv('SPC_TARGET');
4251
$libc = getenv('SPC_LIBC');
4352
if ($libc !== false) {
4453
return $libc;
4554
}
46-
// TODO: zig target parser
55+
$target = getenv('SPC_TARGET');
56+
if (str_contains($target, '-gnu')) {
57+
return 'glibc';
58+
}
59+
if (str_contains($target, '-musl')) {
60+
return 'musl';
61+
}
62+
if (str_contains($target, '-linux')) {
63+
return 'musl';
64+
}
65+
if (PHP_OS_FAMILY === 'Linux' && str_contains($target, '-native')) {
66+
return 'musl';
67+
}
4768
return null;
4869
}
4970

0 commit comments

Comments
 (0)