mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-14 04:15:35 +08:00
turn llvm-tools into a doctor check. llvm-runtime is a target now
This commit is contained in:
35
src/StaticPHP/Doctor/Item/LlvmToolsCheck.php
Normal file
35
src/StaticPHP/Doctor/Item/LlvmToolsCheck.php
Normal 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');
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user