From 8d47e560100348b1385e2e2700a5e4fd426867f6 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 18:22:05 +0700 Subject: [PATCH] sanity check after toolset init --- src/SPC/builder/linux/SystemUtil.php | 7 +++++-- src/SPC/toolchain/ToolchainManager.php | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/SPC/builder/linux/SystemUtil.php b/src/SPC/builder/linux/SystemUtil.php index 6c1037ba..0d808f9d 100644 --- a/src/SPC/builder/linux/SystemUtil.php +++ b/src/SPC/builder/linux/SystemUtil.php @@ -8,6 +8,7 @@ use SPC\builder\traits\UnixSystemUtilTrait; use SPC\exception\RuntimeException; use SPC\toolchain\ToolchainManager; use SPC\toolchain\ZigToolchain; +use SPC\util\SPCTarget; class SystemUtil { @@ -215,10 +216,12 @@ class SystemUtil return null; } if ($libc === 'musl') { - if (self::isMuslDist()) { + if (SPCTarget::getLibc() === 'musl') { $result = shell()->execWithResult('ldd 2>&1', false); - } else { + } elseif (is_file('/usr/local/musl/lib/libc.so')) { $result = shell()->execWithResult('/usr/local/musl/lib/libc.so 2>&1', false); + } else { + $result = shell()->execWithResult('/lib/ld-musl-x86_64.so.1 2>&1', false); } // Match Version * line // match ldd version: "Version 1.2.3" match 1.2.3 diff --git a/src/SPC/toolchain/ToolchainManager.php b/src/SPC/toolchain/ToolchainManager.php index 8192175b..bb5fd08e 100644 --- a/src/SPC/toolchain/ToolchainManager.php +++ b/src/SPC/toolchain/ToolchainManager.php @@ -5,8 +5,10 @@ declare(strict_types=1); namespace SPC\toolchain; use SPC\builder\linux\SystemUtil; +use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\util\GlobalEnvManager; +use SPC\util\SPCTarget; class ToolchainManager { @@ -47,7 +49,13 @@ class ToolchainManager public static function afterInitToolchain(): void { if (!getenv('SPC_TOOLCHAIN')) { - throw new WrongUsageException('SPC_TOOLCHAIN not set'); + throw new WrongUsageException('SPC_TOOLCHAIN was not properly set. Please contact the developers.'); + } + if (SPCTarget::getLibc() === 'musl' && !SPCTarget::isStatic() && !file_exists('/lib/ld-musl-x86_64.so.1')) { + 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`'); + } + if (SPCTarget::getLibc() === 'glibc' && SystemUtil::isMuslDist()) { + throw new RuntimeException('You are linking against glibc libc dynamically, which is only supported on glibc distros.'); } $toolchain = getenv('SPC_TOOLCHAIN'); /* @var ToolchainInterface $toolchain */