@@ -54,16 +54,43 @@ jobs:
5454 shell : pwsh
5555 run : |
5656 function Find-LLVM {
57- $searchPaths = @("C:\Program Files\LLVM", "C:\Program Files (x86)\LLVM", "C:\ProgramData\chocolatey", "C:\tools\llvm")
57+ $possiblePaths = @(
58+ "C:\Program Files\LLVM",
59+ "C:\Program Files (x86)\LLVM",
60+ "C:\ProgramData\chocolatey\lib\llvm\tools\llvm",
61+ "C:\tools\llvm",
62+ "$env:ProgramFiles\LLVM",
63+ "$env:ProgramFiles(x86)\LLVM"
64+ )
65+
66+ Write-Host "Searching for LLVM in standard locations..."
5867
5968 # 1. Try to find llvm-config.exe
6069 $config = Get-Command llvm-config -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
6170 if (-not $config) {
62- $config = Get-ChildItem -Path $searchPaths -Filter "llvm-config.exe" -Recurse -Depth 4 -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
71+ foreach ($path in $possiblePaths) {
72+ if (Test-Path "$path\bin\llvm-config.exe") {
73+ $config = "$path\bin\llvm-config.exe"
74+ break
75+ }
76+ # Fallback recursive search if not in bin
77+ $found = Get-ChildItem -Path $path -Filter "llvm-config.exe" -Recurse -Depth 4 -ErrorAction SilentlyContinue | Select-Object -First 1
78+ if ($found) {
79+ $config = $found.FullName
80+ break
81+ }
82+ }
6383 }
6484
6585 # 2. Try to find LLVMConfig.cmake
66- $cmake = Get-ChildItem -Path $searchPaths -Filter "LLVMConfig.cmake" -Recurse -Depth 6 -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
86+ $cmake = $null
87+ foreach ($path in $possiblePaths) {
88+ $found = Get-ChildItem -Path $path -Filter "LLVMConfig.cmake" -Recurse -Depth 6 -ErrorAction SilentlyContinue | Select-Object -First 1
89+ if ($found) {
90+ $cmake = $found.FullName
91+ break
92+ }
93+ }
6794
6895 return @{ Config = $config; CMake = $cmake }
6996 }
7299 if (-not $res.Config -and -not $res.CMake) {
73100 Write-Host "LLVM not found. Attempting to install LLVM 17.0.6 via Chocolatey..."
74101 choco install llvm -y --version 17.0.6 --allow-downgrade --limit-output
102+
103+ # Refresh environment to pick up PATH changes
104+ $env:PATH = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
105+
75106 $res = Find-LLVM
76107 }
77108
@@ -80,23 +111,47 @@ jobs:
80111 Write-Host "Found llvm-config at: $($res.Config)"
81112 $llvmBin = Split-Path -Parent $res.Config
82113 $llvmRoot = Split-Path -Parent $llvmBin
83- $cmakeDir = & $res.Config --cmakedir
114+
115+ # Try to get cmake dir from llvm-config
116+ try {
117+ $cmakeDir = & $res.Config --cmakedir
118+ Write-Host "Detected LLVM_DIR from llvm-config: $cmakeDir"
119+ } catch {
120+ # Fallback if --cmakedir fails
121+ $cmakeDir = Join-Path $llvmRoot "lib\cmake\llvm"
122+ }
123+
124+ if (-not (Test-Path $cmakeDir)) {
125+ # Second fallback
126+ $foundCmake = Get-ChildItem -Path $llvmRoot -Filter "LLVMConfig.cmake" -Recurse -Depth 5 -ErrorAction SilentlyContinue | Select-Object -First 1
127+ if ($foundCmake) { $cmakeDir = $foundCmake.DirectoryName }
128+ }
129+
84130 echo "LLVM_DIR=$cmakeDir" >> $env:GITHUB_ENV
85131 echo "CMAKE_PREFIX_PATH=$llvmRoot" >> $env:GITHUB_ENV
86132 echo "$llvmBin" >> $env:GITHUB_PATH
87133 } elseif ($res.CMake) {
88134 Write-Host "Found LLVMConfig.cmake at: $($res.CMake)"
89135 $cmakeDir = Split-Path -Parent $res.CMake
90- $llvmRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $cmakeDir))
136+ # Heuristic to find root from cmake dir (typically lib/cmake/llvm)
137+ $llvmRoot = $cmakeDir
138+ for ($i=0; $i -lt 3; $i++) { $llvmRoot = Split-Path -Parent $llvmRoot }
139+
91140 echo "LLVM_DIR=$cmakeDir" >> $env:GITHUB_ENV
92141 echo "CMAKE_PREFIX_PATH=$llvmRoot" >> $env:GITHUB_ENV
142+
143+ $binDir = Join-Path $llvmRoot "bin"
144+ if (Test-Path $binDir) {
145+ echo "$binDir" >> $env:GITHUB_PATH
146+ }
93147 }
94148 } else {
95- Write-Error "Exhaustive LLVM detection failed!"
149+ Write-Error "Exhaustive LLVM detection failed after installation !"
96150 exit 1
97151 }
98152
99153
154+
100155 - name : Configure (Unix)
101156 if : matrix.os != 'windows-latest'
102157 shell : bash
0 commit comments