Skip to content

Commit 8d47e56

Browse files
committed
sanity check after toolset init
1 parent a6d68b9 commit 8d47e56

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/SPC/builder/linux/SystemUtil.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use SPC\exception\RuntimeException;
99
use SPC\toolchain\ToolchainManager;
1010
use SPC\toolchain\ZigToolchain;
11+
use SPC\util\SPCTarget;
1112

1213
class SystemUtil
1314
{
@@ -215,10 +216,12 @@ public static function getLibcVersionIfExists(?string $libc = null): ?string
215216
return null;
216217
}
217218
if ($libc === 'musl') {
218-
if (self::isMuslDist()) {
219+
if (SPCTarget::getLibc() === 'musl') {
219220
$result = shell()->execWithResult('ldd 2>&1', false);
220-
} else {
221+
} elseif (is_file('/usr/local/musl/lib/libc.so')) {
221222
$result = shell()->execWithResult('/usr/local/musl/lib/libc.so 2>&1', false);
223+
} else {
224+
$result = shell()->execWithResult('/lib/ld-musl-x86_64.so.1 2>&1', false);
222225
}
223226
// Match Version * line
224227
// match ldd version: "Version 1.2.3" match 1.2.3

src/SPC/toolchain/ToolchainManager.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
namespace SPC\toolchain;
66

77
use SPC\builder\linux\SystemUtil;
8+
use SPC\exception\RuntimeException;
89
use SPC\exception\WrongUsageException;
910
use SPC\util\GlobalEnvManager;
11+
use SPC\util\SPCTarget;
1012

1113
class ToolchainManager
1214
{
@@ -47,7 +49,13 @@ public static function initToolchain(): void
4749
public static function afterInitToolchain(): void
4850
{
4951
if (!getenv('SPC_TOOLCHAIN')) {
50-
throw new WrongUsageException('SPC_TOOLCHAIN not set');
52+
throw new WrongUsageException('SPC_TOOLCHAIN was not properly set. Please contact the developers.');
53+
}
54+
if (SPCTarget::getLibc() === 'musl' && !SPCTarget::isStatic() && !file_exists('/lib/ld-musl-x86_64.so.1')) {
55+
throw new RuntimeException('You are linking against musl libc dynamically, but musl libc is not installed. Please install it with `sudo dnf install musl-libc` or `sudo apt install musl`');
56+
}
57+
if (SPCTarget::getLibc() === 'glibc' && SystemUtil::isMuslDist()) {
58+
throw new RuntimeException('You are linking against glibc libc dynamically, which is only supported on glibc distros.');
5159
}
5260
$toolchain = getenv('SPC_TOOLCHAIN');
5361
/* @var ToolchainInterface $toolchain */

0 commit comments

Comments
 (0)