2025-12-08 10:57:51 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace StaticPHP\Doctor\Item;
|
|
|
|
|
|
|
|
|
|
use StaticPHP\Attribute\Doctor\CheckItem;
|
|
|
|
|
use StaticPHP\Attribute\Doctor\FixItem;
|
|
|
|
|
use StaticPHP\Attribute\Doctor\OptionalCheck;
|
|
|
|
|
use StaticPHP\DI\ApplicationContext;
|
|
|
|
|
use StaticPHP\Doctor\CheckResult;
|
|
|
|
|
use StaticPHP\Package\PackageInstaller;
|
|
|
|
|
use StaticPHP\Toolchain\Interface\ToolchainInterface;
|
|
|
|
|
use StaticPHP\Toolchain\ZigToolchain;
|
|
|
|
|
|
|
|
|
|
#[OptionalCheck([self::class, 'optionalCheck'])]
|
|
|
|
|
class ZigCheck
|
|
|
|
|
{
|
|
|
|
|
public static function optionalCheck(): bool
|
|
|
|
|
{
|
|
|
|
|
return ApplicationContext::get(ToolchainInterface::class) instanceof ZigToolchain;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @noinspection PhpUnused */
|
|
|
|
|
#[CheckItem('if zig is installed', level: 800)]
|
|
|
|
|
public function checkZig(): CheckResult
|
|
|
|
|
{
|
2026-02-04 15:28:10 +08:00
|
|
|
if (new PackageInstaller()->addInstallPackage('zig')->isPackageInstalled('zig')) {
|
2026-05-12 10:38:33 +07:00
|
|
|
return CheckResult::ok(PKG_ROOT_PATH . '/zig/zig');
|
2025-12-08 10:57:51 +08:00
|
|
|
}
|
|
|
|
|
return CheckResult::fail('zig is not installed', 'install-zig');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[FixItem('install-zig')]
|
|
|
|
|
public function installZig(): bool
|
|
|
|
|
{
|
2026-03-09 11:04:18 +08:00
|
|
|
$installer = new PackageInstaller(interactive: false);
|
2025-12-08 10:57:51 +08:00
|
|
|
$installer->addInstallPackage('zig');
|
2026-03-09 11:04:18 +08:00
|
|
|
$installer->run(true);
|
2025-12-08 10:57:51 +08:00
|
|
|
return $installer->isPackageInstalled('zig');
|
|
|
|
|
}
|
2026-05-18 10:55:39 +08:00
|
|
|
|
|
|
|
|
/** @noinspection PhpUnused */
|
|
|
|
|
#[CheckItem('if clang runtime bits are built', limit_os: 'Linux', level: 799)]
|
|
|
|
|
public function checkClangRuntimeBits(): ?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';
|
|
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[FixItem('build-clang-runtime-bits')]
|
|
|
|
|
public function fixClangRuntimeBits(): bool
|
|
|
|
|
{
|
|
|
|
|
$installer = new PackageInstaller(interactive: false);
|
|
|
|
|
$installer->addInstallPackage('clang-runtime-bits');
|
|
|
|
|
$installer->run(true);
|
|
|
|
|
$libDir = PKG_ROOT_PATH . '/zig/lib';
|
|
|
|
|
return file_exists("{$libDir}/libclang_rt.profile.a")
|
|
|
|
|
&& file_exists("{$libDir}/clang_rt.crtbegin.o")
|
|
|
|
|
&& file_exists("{$libDir}/clang_rt.crtend.o");
|
|
|
|
|
}
|
2025-12-08 10:57:51 +08:00
|
|
|
}
|