turn llvm-tools into a doctor check. llvm-runtime is a target now

This commit is contained in:
henderkes
2026-05-19 20:01:50 +07:00
parent 3eca044895
commit 7bb4a09a3c
12 changed files with 326 additions and 51 deletions

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Doctor\Item;
use Package\Artifact\llvm_tools;
use StaticPHP\Attribute\Doctor\CheckItem;
use StaticPHP\Attribute\Doctor\FixItem;
use StaticPHP\Doctor\CheckResult;
use StaticPHP\Package\PackageInstaller;
class LlvmToolsCheck
{
/** @noinspection PhpUnused */
#[CheckItem('if llvm-tools (objcopy/strip/profdata) are built', limit_os: 'Linux', level: 798)]
public function checkLlvmTools(): CheckResult
{
$binDir = PKG_ROOT_PATH . '/llvm-tools/bin';
if (new llvm_tools()->allBuilt($binDir)) {
return CheckResult::ok($binDir);
}
return CheckResult::fail('llvm-tools are not built', 'build-llvm-tools');
}
#[FixItem('build-llvm-tools')]
public function fixLlvmTools(): bool
{
$installer = new PackageInstaller(interactive: false);
$installer->addInstallPackage('llvm-tools');
$installer->run(true);
new llvm_tools()->buildForHost();
return new llvm_tools()->allBuilt(PKG_ROOT_PATH . '/llvm-tools/bin');
}
}

View File

@@ -10,6 +10,7 @@ use StaticPHP\Attribute\Doctor\OptionalCheck;
use StaticPHP\DI\ApplicationContext;
use StaticPHP\Doctor\CheckResult;
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Toolchain\Interface\ToolchainInterface;
use StaticPHP\Toolchain\ZigToolchain;
@@ -41,30 +42,31 @@ class ZigCheck
}
/** @noinspection PhpUnused */
#[CheckItem('if clang runtime bits are built', limit_os: 'Linux', level: 799)]
public function checkClangRuntimeBits(): ?CheckResult
#[CheckItem('if llvm compiler-rt bits are built', limit_os: 'Linux', level: 799)]
public function checkCompilerRtBits(): ?CheckResult
{
// Skip if zig is not installed yet (zig check runs at level 800)
if (!new PackageInstaller()->addInstallPackage('zig')->isPackageInstalled('zig')) {
return null;
}
$libDir = PKG_ROOT_PATH . '/zig/lib';
$libDir = PKG_ROOT_PATH . '/zig/lib/' . SystemTarget::getCanonicalTriple();
if (file_exists("{$libDir}/libclang_rt.profile.a")
&& file_exists("{$libDir}/clang_rt.crtbegin.o")
&& file_exists("{$libDir}/clang_rt.crtend.o")
) {
return CheckResult::ok("{$libDir}/libclang_rt.profile.a");
}
return CheckResult::fail('clang runtime bits are not built', 'build-clang-runtime-bits');
return CheckResult::fail('llvm compiler-rt bits are not built for ' . SystemTarget::getCanonicalTriple(), 'build-llvm-compiler-rt');
}
#[FixItem('build-clang-runtime-bits')]
public function fixClangRuntimeBits(): bool
#[FixItem('build-llvm-compiler-rt')]
public function fixCompilerRtBits(): bool
{
$installer = new PackageInstaller(interactive: false);
$installer->addInstallPackage('clang-runtime-bits');
$installer->addInstallPackage('llvm-compiler-rt');
$installer->run(true);
$libDir = PKG_ROOT_PATH . '/zig/lib';
new \Package\Artifact\llvm_compiler_rt()->buildForCurrentTarget();
$libDir = PKG_ROOT_PATH . '/zig/lib/' . SystemTarget::getCanonicalTriple();
return file_exists("{$libDir}/libclang_rt.profile.a")
&& file_exists("{$libDir}/clang_rt.crtbegin.o")
&& file_exists("{$libDir}/clang_rt.crtend.o");