2025-06-28 16:36:05 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\util\toolchain;
|
|
|
|
|
|
|
|
|
|
use SPC\builder\freebsd\SystemUtil as FreeBSDSystemUtil;
|
|
|
|
|
use SPC\builder\linux\SystemUtil as LinuxSystemUtil;
|
|
|
|
|
use SPC\builder\macos\SystemUtil as MacOSSystemUtil;
|
2025-06-28 16:45:20 +08:00
|
|
|
use SPC\exception\WrongUsageException;
|
2025-06-28 16:36:05 +08:00
|
|
|
use SPC\util\GlobalEnvManager;
|
2025-06-28 23:11:26 +08:00
|
|
|
use SPC\util\SPCTarget;
|
2025-06-28 16:36:05 +08:00
|
|
|
|
|
|
|
|
class GccNativeToolchain implements ToolchainInterface
|
|
|
|
|
{
|
|
|
|
|
public function initEnv(string $target): void
|
|
|
|
|
{
|
2025-06-28 23:11:26 +08:00
|
|
|
// native toolchain does not support versioning
|
|
|
|
|
if (SPCTarget::getTargetSuffix() !== null) {
|
|
|
|
|
throw new WrongUsageException('gcc native toolchain does not support versioning.');
|
|
|
|
|
}
|
2025-06-28 16:36:05 +08:00
|
|
|
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=gcc');
|
|
|
|
|
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=g++');
|
|
|
|
|
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar');
|
|
|
|
|
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld.gold');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function afterInit(string $target): void
|
|
|
|
|
{
|
|
|
|
|
// check gcc exists
|
|
|
|
|
match (PHP_OS_FAMILY) {
|
2025-06-28 16:45:20 +08:00
|
|
|
'Linux' => LinuxSystemUtil::findCommand('g++') ?? throw new WrongUsageException('g++ not found, please install it or set CC/CXX to a valid path.'),
|
|
|
|
|
'Darwin' => MacOSSystemUtil::findCommand('g++') ?? throw new WrongUsageException('g++ not found, please install it or set CC/CXX to a valid path.'),
|
|
|
|
|
'BSD' => FreeBSDSystemUtil::findCommand('g++') ?? throw new WrongUsageException('g++ not found, please install it or set CC/CXX to a valid path.'),
|
2025-06-28 16:36:05 +08:00
|
|
|
default => throw new \RuntimeException('GCC is not supported on ' . PHP_OS_FAMILY . '.'),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|