Skip to content

Commit a5d26d6

Browse files
authored
Merge pull request #813 from crazywhalecc/fix-native
fix g++ not found error
2 parents 4cb4c9c + e5ea32e commit a5d26d6

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

src/SPC/toolchain/ClangNativeToolchain.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ public function initEnv(): void
2222

2323
public function afterInit(): void
2424
{
25-
// check clang exists
26-
match (PHP_OS_FAMILY) {
27-
'Linux' => LinuxSystemUtil::findCommand('clang++') ?? throw new WrongUsageException('Clang++ not found, please install it or manually set CC/CXX to a valid path.'),
28-
'Darwin' => MacOSSystemUtil::findCommand('clang++') ?? throw new WrongUsageException('Clang++ not found, please install it or set CC/CXX to a valid path.'),
29-
'BSD' => FreeBSDSystemUtil::findCommand('clang++') ?? throw new WrongUsageException('Clang++ not found, please install it or set CC/CXX to a valid path.'),
30-
default => throw new WrongUsageException('Clang is not supported on ' . PHP_OS_FAMILY . '.'),
31-
};
25+
foreach (['CC', 'CXX', 'AR', 'LD'] as $env) {
26+
$command = getenv($env);
27+
if (!$command || is_file($command)) {
28+
continue;
29+
}
30+
match (PHP_OS_FAMILY) {
31+
'Linux' => LinuxSystemUtil::findCommand($command) ?? throw new WrongUsageException("{$command} not found, please install it or set {$env} to a valid path."),
32+
'Darwin' => MacOSSystemUtil::findCommand($command) ?? throw new WrongUsageException("{$command} not found, please install it or set {$env} to a valid path."),
33+
'BSD' => FreeBSDSystemUtil::findCommand($command) ?? throw new WrongUsageException("{$command} not found, please install it or set {$env} to a valid path."),
34+
default => throw new \RuntimeException(__CLASS__ . ' is not supported on ' . PHP_OS_FAMILY . '.'),
35+
};
36+
}
3237
}
3338
}

src/SPC/toolchain/GccNativeToolchain.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ public function initEnv(): void
2222

2323
public function afterInit(): void
2424
{
25-
// check gcc exists
26-
match (PHP_OS_FAMILY) {
27-
'Linux' => LinuxSystemUtil::findCommand('g++') ?? throw new WrongUsageException('g++ not found, please install it or set CC/CXX to a valid path.'),
28-
'Darwin' => MacOSSystemUtil::findCommand('g++') ?? throw new WrongUsageException('g++ not found, please install it or set CC/CXX to a valid path.'),
29-
'BSD' => FreeBSDSystemUtil::findCommand('g++') ?? throw new WrongUsageException('g++ not found, please install it or set CC/CXX to a valid path.'),
30-
default => throw new \RuntimeException('GCC is not supported on ' . PHP_OS_FAMILY . '.'),
31-
};
25+
foreach (['CC', 'CXX', 'AR', 'LD'] as $env) {
26+
$command = getenv($env);
27+
if (!$command || is_file($command)) {
28+
continue;
29+
}
30+
match (PHP_OS_FAMILY) {
31+
'Linux' => LinuxSystemUtil::findCommand($command) ?? throw new WrongUsageException("{$command} not found, please install it or set {$env} to a valid path."),
32+
'Darwin' => MacOSSystemUtil::findCommand($command) ?? throw new WrongUsageException("{$command} not found, please install it or set {$env} to a valid path."),
33+
'BSD' => FreeBSDSystemUtil::findCommand($command) ?? throw new WrongUsageException("{$command} not found, please install it or set {$env} to a valid path."),
34+
default => throw new \RuntimeException(__CLASS__ . ' is not supported on ' . PHP_OS_FAMILY . '.'),
35+
};
36+
}
3237
}
3338
}

0 commit comments

Comments
 (0)