From 4ddc137eae85b031fee16e4189f8d3d86e2bb871 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 12 Apr 2026 23:17:33 +0800 Subject: [PATCH] Add clang finder for Windows --- src/StaticPHP/Util/System/WindowsUtil.php | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/StaticPHP/Util/System/WindowsUtil.php b/src/StaticPHP/Util/System/WindowsUtil.php index 150730c0..40637262 100644 --- a/src/StaticPHP/Util/System/WindowsUtil.php +++ b/src/StaticPHP/Util/System/WindowsUtil.php @@ -85,6 +85,44 @@ class WindowsUtil return intval($result); } + /** + * Find Clang compiler from the Visual Studio LLVM toolchain. + * + * Checks the CC environment variable first (user override), then searches + * the VS2022/VS2019 installation via vswhere. + * + * @return array{clang: string, clangpp: string}|false False if not found + */ + public static function findClang(): array|false + { + // Allow user to override via CC environment variable + if ($cc = getenv('CC')) { + if (file_exists($cc)) { + $clangpp = dirname($cc) . DIRECTORY_SEPARATOR . 'clang++.exe'; + return [ + 'clang' => $cc, + 'clangpp' => file_exists($clangpp) ? $clangpp : $cc, + ]; + } + } + + $vs = self::findVisualStudio(); + if ($vs === false) { + return false; + } + + $clang = $vs['dir'] . '\VC\Tools\Llvm\x64\bin\clang.exe'; + $clangpp = $vs['dir'] . '\VC\Tools\Llvm\x64\bin\clang++.exe'; + if (!file_exists($clang)) { + return false; + } + + return [ + 'clang' => $clang, + 'clangpp' => file_exists($clangpp) ? $clangpp : $clang, + ]; + } + /** * Create CMake toolchain file. *