mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
34 lines
1.4 KiB
PHP
34 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace SPC\toolchain;
|
|
|
|
use SPC\builder\freebsd\SystemUtil as FreeBSDSystemUtil;
|
|
use SPC\builder\linux\SystemUtil as LinuxSystemUtil;
|
|
use SPC\builder\macos\SystemUtil as MacOSSystemUtil;
|
|
use SPC\exception\WrongUsageException;
|
|
use SPC\util\GlobalEnvManager;
|
|
|
|
class ClangNativeToolchain implements ToolchainInterface
|
|
{
|
|
public function initEnv(): void
|
|
{
|
|
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=clang');
|
|
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=clang++');
|
|
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar');
|
|
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld');
|
|
}
|
|
|
|
public function afterInit(): void
|
|
{
|
|
// check clang exists
|
|
match (PHP_OS_FAMILY) {
|
|
'Linux' => LinuxSystemUtil::findCommand('clang++') ?? throw new WrongUsageException('Clang++ not found, please install it or manually set CC/CXX to a valid path.'),
|
|
'Darwin' => MacOSSystemUtil::findCommand('clang++') ?? throw new WrongUsageException('Clang++ not found, please install it or set CC/CXX to a valid path.'),
|
|
'BSD' => FreeBSDSystemUtil::findCommand('clang++') ?? throw new WrongUsageException('Clang++ not found, please install it or set CC/CXX to a valid path.'),
|
|
default => throw new WrongUsageException('Clang is not supported on ' . PHP_OS_FAMILY . '.'),
|
|
};
|
|
}
|
|
}
|