diff --git a/config/env.ini b/config/env.ini index 3143efaf..94797118 100644 --- a/config/env.ini +++ b/config/env.ini @@ -134,6 +134,8 @@ OPENSSLDIR="" ; 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. 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) CC=${SPC_DEFAULT_CC} CXX=${SPC_DEFAULT_CXX} diff --git a/src/StaticPHP/Doctor/Item/MacOSToolCheck.php b/src/StaticPHP/Doctor/Item/MacOSToolCheck.php index b69528ad..9d51b83a 100644 --- a/src/StaticPHP/Doctor/Item/MacOSToolCheck.php +++ b/src/StaticPHP/Doctor/Item/MacOSToolCheck.php @@ -7,6 +7,7 @@ namespace StaticPHP\Doctor\Item; use StaticPHP\Attribute\Doctor\CheckItem; use StaticPHP\Attribute\Doctor\FixItem; use StaticPHP\Doctor\CheckResult; +use StaticPHP\Runtime\SystemTarget; use StaticPHP\Util\System\MacOSUtil; class MacOSToolCheck @@ -58,6 +59,20 @@ class MacOSToolCheck 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')] public function checkBisonVersion(array $command_path = []): ?CheckResult { diff --git a/src/StaticPHP/Toolchain/ClangBrewToolchain.php b/src/StaticPHP/Toolchain/ClangBrewToolchain.php new file mode 100644 index 00000000..5d8963ef --- /dev/null +++ b/src/StaticPHP/Toolchain/ClangBrewToolchain.php @@ -0,0 +1,21 @@ + ZigToolchain::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), }; }