fix g++ not found error

This commit is contained in:
DubbleClick 2025-07-01 17:53:35 +07:00
parent 4cb4c9c6a5
commit 5bc4504e37
2 changed files with 24 additions and 14 deletions

View File

@ -22,12 +22,17 @@ class ClangNativeToolchain implements ToolchainInterface
public function afterInit(): void public function afterInit(): void
{ {
// check clang exists foreach (['CC', 'CXX', 'AR', 'LD'] as $env) {
match (PHP_OS_FAMILY) { $command = getenv($env);
'Linux' => LinuxSystemUtil::findCommand('clang++') ?? throw new WrongUsageException('Clang++ not found, please install it or manually set CC/CXX to a valid path.'), if (is_file($command)) {
'Darwin' => MacOSSystemUtil::findCommand('clang++') ?? throw new WrongUsageException('Clang++ not found, please install it or set CC/CXX to a valid path.'), continue;
'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 . '.'), match (PHP_OS_FAMILY) {
}; 'Linux' => LinuxSystemUtil::findCommand($command) ?? throw new WrongUsageException("{$command} not found, please install it or set {$env} to a valid path."),
'Darwin' => MacOSSystemUtil::findCommand($command) ?? throw new WrongUsageException("{$command} not found, please install it or set {$env} to a valid path."),
'BSD' => FreeBSDSystemUtil::findCommand($command) ?? throw new WrongUsageException("{$command} not found, please install it or set {$env} to a valid path."),
default => throw new \RuntimeException(__CLASS__ . ' is not supported on ' . PHP_OS_FAMILY . '.'),
};
}
} }
} }

View File

@ -22,12 +22,17 @@ class GccNativeToolchain implements ToolchainInterface
public function afterInit(): void public function afterInit(): void
{ {
// check gcc exists foreach (['CC', 'CXX', 'AR', 'LD'] as $env) {
match (PHP_OS_FAMILY) { $command = getenv($env);
'Linux' => LinuxSystemUtil::findCommand('g++') ?? throw new WrongUsageException('g++ not found, please install it or set CC/CXX to a valid path.'), if (is_file($command)) {
'Darwin' => MacOSSystemUtil::findCommand('g++') ?? throw new WrongUsageException('g++ not found, please install it or set CC/CXX to a valid path.'), continue;
'BSD' => FreeBSDSystemUtil::findCommand('g++') ?? throw new WrongUsageException('g++ not found, please install it or set CC/CXX to a valid path.'), }
default => throw new \RuntimeException('GCC is not supported on ' . PHP_OS_FAMILY . '.'), match (PHP_OS_FAMILY) {
}; 'Linux' => LinuxSystemUtil::findCommand($command) ?? throw new WrongUsageException("{$command} not found, please install it or set {$env} to a valid path."),
'Darwin' => MacOSSystemUtil::findCommand($command) ?? throw new WrongUsageException("{$command} not found, please install it or set {$env} to a valid path."),
'BSD' => FreeBSDSystemUtil::findCommand($command) ?? throw new WrongUsageException("{$command} not found, please install it or set {$env} to a valid path."),
default => throw new \RuntimeException(__CLASS__ . ' is not supported on ' . PHP_OS_FAMILY . '.'),
};
}
} }
} }