mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-07 16:55:38 +08:00
Add homebrew llvm version toolchain support
This commit is contained in:
@@ -134,6 +134,8 @@ OPENSSLDIR=""
|
|||||||
; build target: macho or macho (possibly we could support macho-universal in the future)
|
; build target: macho or macho (possibly we could support macho-universal in the future)
|
||||||
; Currently we do not support universal and cross-compilation for macOS.
|
; Currently we do not support universal and cross-compilation for macOS.
|
||||||
SPC_TARGET=native-macos
|
SPC_TARGET=native-macos
|
||||||
|
; Whether to use brew version of llvm or system version (valid options: 'system', 'brew', default: 'system')
|
||||||
|
SPC_USE_LLVM=system
|
||||||
; compiler environments (default value is defined by selected toolchain)
|
; compiler environments (default value is defined by selected toolchain)
|
||||||
CC=${SPC_DEFAULT_CC}
|
CC=${SPC_DEFAULT_CC}
|
||||||
CXX=${SPC_DEFAULT_CXX}
|
CXX=${SPC_DEFAULT_CXX}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace StaticPHP\Doctor\Item;
|
|||||||
use StaticPHP\Attribute\Doctor\CheckItem;
|
use StaticPHP\Attribute\Doctor\CheckItem;
|
||||||
use StaticPHP\Attribute\Doctor\FixItem;
|
use StaticPHP\Attribute\Doctor\FixItem;
|
||||||
use StaticPHP\Doctor\CheckResult;
|
use StaticPHP\Doctor\CheckResult;
|
||||||
|
use StaticPHP\Runtime\SystemTarget;
|
||||||
use StaticPHP\Util\System\MacOSUtil;
|
use StaticPHP\Util\System\MacOSUtil;
|
||||||
|
|
||||||
class MacOSToolCheck
|
class MacOSToolCheck
|
||||||
@@ -58,6 +59,20 @@ class MacOSToolCheck
|
|||||||
return CheckResult::ok();
|
return CheckResult::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[CheckItem('if homebrew llvm are installed', limit_os: 'Darwin')]
|
||||||
|
public function checkBrewLLVM(): ?CheckResult
|
||||||
|
{
|
||||||
|
if (getenv('SPC_USE_LLVM') === 'brew') {
|
||||||
|
$homebrew_prefix = getenv('HOMEBREW_PREFIX') ?: (SystemTarget::getTargetArch() === 'aarch64' ? '/opt/homebrew' : '/usr/local/homebrew');
|
||||||
|
|
||||||
|
if (MacOSUtil::findCommand('clang', ["{$homebrew_prefix}/opt/llvm/bin"]) === null) {
|
||||||
|
return CheckResult::fail('Homebrew llvm is not installed', 'brew', ['missing' => ['llvm']]);
|
||||||
|
}
|
||||||
|
return CheckResult::ok();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
#[CheckItem('if bison version is 3.0 or later', limit_os: 'Darwin')]
|
#[CheckItem('if bison version is 3.0 or later', limit_os: 'Darwin')]
|
||||||
public function checkBisonVersion(array $command_path = []): ?CheckResult
|
public function checkBisonVersion(array $command_path = []): ?CheckResult
|
||||||
{
|
{
|
||||||
|
|||||||
21
src/StaticPHP/Toolchain/ClangBrewToolchain.php
Normal file
21
src/StaticPHP/Toolchain/ClangBrewToolchain.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace StaticPHP\Toolchain;
|
||||||
|
|
||||||
|
use StaticPHP\Runtime\SystemTarget;
|
||||||
|
use StaticPHP\Util\GlobalEnvManager;
|
||||||
|
|
||||||
|
class ClangBrewToolchain extends ClangNativeToolchain
|
||||||
|
{
|
||||||
|
public function initEnv(): void
|
||||||
|
{
|
||||||
|
$homebrew_prefix = getenv('HOMEBREW_PREFIX') ?: (SystemTarget::getTargetArch() === 'aarch64' ? '/opt/homebrew' : '/usr/local/homebrew');
|
||||||
|
GlobalEnvManager::putenv("SPC_DEFAULT_CC={$homebrew_prefix}/opt/llvm/bin/clang");
|
||||||
|
GlobalEnvManager::putenv("SPC_DEFAULT_CXX={$homebrew_prefix}/opt/llvm/bin/clang++");
|
||||||
|
GlobalEnvManager::putenv("SPC_DEFAULT_AR={$homebrew_prefix}/opt/llvm/bin/llvm-ar");
|
||||||
|
GlobalEnvManager::putenv('SPC_DEFAULT_LD=ld');
|
||||||
|
GlobalEnvManager::addPathIfNotExists("{$homebrew_prefix}/opt/llvm/bin");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,7 +39,10 @@ class ToolchainManager
|
|||||||
return match (PHP_OS_FAMILY) {
|
return match (PHP_OS_FAMILY) {
|
||||||
'Linux' => ZigToolchain::class,
|
'Linux' => ZigToolchain::class,
|
||||||
'Windows' => MSVCToolchain::class,
|
'Windows' => MSVCToolchain::class,
|
||||||
'Darwin' => ClangNativeToolchain::class,
|
'Darwin' => match (getenv('SPC_USE_LLVM') ?: 'system') {
|
||||||
|
'brew' => ClangBrewToolchain::class,
|
||||||
|
default => ClangNativeToolchain::class,
|
||||||
|
},
|
||||||
default => throw new WrongUsageException('Unsupported OS family: ' . PHP_OS_FAMILY),
|
default => throw new WrongUsageException('Unsupported OS family: ' . PHP_OS_FAMILY),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user