From 5bc4504e37b08286d9efd08b56eb3f570f6034cf Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 17:53:35 +0700 Subject: [PATCH 1/2] fix g++ not found error --- src/SPC/toolchain/ClangNativeToolchain.php | 19 ++++++++++++------- src/SPC/toolchain/GccNativeToolchain.php | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/SPC/toolchain/ClangNativeToolchain.php b/src/SPC/toolchain/ClangNativeToolchain.php index c5186521..061bb517 100644 --- a/src/SPC/toolchain/ClangNativeToolchain.php +++ b/src/SPC/toolchain/ClangNativeToolchain.php @@ -22,12 +22,17 @@ class ClangNativeToolchain implements ToolchainInterface 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 . '.'), - }; + foreach (['CC', 'CXX', 'AR', 'LD'] as $env) { + $command = getenv($env); + if (is_file($command)) { + continue; + } + 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 . '.'), + }; + } } } diff --git a/src/SPC/toolchain/GccNativeToolchain.php b/src/SPC/toolchain/GccNativeToolchain.php index bd8cc868..21d103ab 100644 --- a/src/SPC/toolchain/GccNativeToolchain.php +++ b/src/SPC/toolchain/GccNativeToolchain.php @@ -22,12 +22,17 @@ class GccNativeToolchain implements ToolchainInterface public function afterInit(): void { - // check gcc exists - match (PHP_OS_FAMILY) { - '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.'), - default => throw new \RuntimeException('GCC is not supported on ' . PHP_OS_FAMILY . '.'), - }; + foreach (['CC', 'CXX', 'AR', 'LD'] as $env) { + $command = getenv($env); + if (is_file($command)) { + continue; + } + 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 . '.'), + }; + } } } From e5ea32e9c03bd3b764a889de71ee09681ed5e8d4 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 1 Jul 2025 17:57:36 +0700 Subject: [PATCH 2/2] fix in case it's not set --- src/SPC/toolchain/ClangNativeToolchain.php | 2 +- src/SPC/toolchain/GccNativeToolchain.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SPC/toolchain/ClangNativeToolchain.php b/src/SPC/toolchain/ClangNativeToolchain.php index 061bb517..fb0bea46 100644 --- a/src/SPC/toolchain/ClangNativeToolchain.php +++ b/src/SPC/toolchain/ClangNativeToolchain.php @@ -24,7 +24,7 @@ class ClangNativeToolchain implements ToolchainInterface { foreach (['CC', 'CXX', 'AR', 'LD'] as $env) { $command = getenv($env); - if (is_file($command)) { + if (!$command || is_file($command)) { continue; } match (PHP_OS_FAMILY) { diff --git a/src/SPC/toolchain/GccNativeToolchain.php b/src/SPC/toolchain/GccNativeToolchain.php index 21d103ab..1e97b50e 100644 --- a/src/SPC/toolchain/GccNativeToolchain.php +++ b/src/SPC/toolchain/GccNativeToolchain.php @@ -24,7 +24,7 @@ class GccNativeToolchain implements ToolchainInterface { foreach (['CC', 'CXX', 'AR', 'LD'] as $env) { $command = getenv($env); - if (is_file($command)) { + if (!$command || is_file($command)) { continue; } match (PHP_OS_FAMILY) {