44function Resolve-LLVMLayout {
55 $candidateRoots = New-Object System.Collections.Generic.List[string ]
66
7- # Check if llvm-config is already in PATH
7+ # 1. Direct LLVM_ROOT or LLVM_DIR environment variables
8+ if ($env: LLVM_ROOT -and (Test-Path $env: LLVM_ROOT )) { $candidateRoots.Add ($env: LLVM_ROOT ) }
9+ if ($env: LLVM_DIR -and (Test-Path $env: LLVM_DIR )) {
10+ # If LLVM_DIR points to cmake dir, root is likely 2 or 3 levels up
11+ $dir = $env: LLVM_DIR
12+ $candidateRoots.Add ((Split-Path (Split-Path (Split-Path $dir )))) # lib/cmake/llvm -> lib/cmake -> lib -> root
13+ $candidateRoots.Add ((Split-Path (Split-Path $dir ))) # cmake -> root
14+ }
15+
16+ # 2. Check if llvm-config is in PATH
817 $llvmConfig = Get-Command llvm- config - ErrorAction SilentlyContinue
918 if ($llvmConfig ) {
1019 $binPath = $llvmConfig.Source
@@ -13,11 +22,12 @@ function Resolve-LLVMLayout {
1322 $candidateRoots.Add ($root )
1423 }
1524
16- # Common installation paths
25+ # 3. Known installation paths
1726 $candidateRoots.Add (" C:\Program Files\LLVM" )
1827 $candidateRoots.Add (" C:\Program Files (x86)\LLVM" )
1928 $candidateRoots.Add (" C:\ProgramData\chocolatey\lib\llvm\tools\llvm" )
2029 $candidateRoots.Add (" C:\ProgramData\chocolatey\lib\llvm" )
30+ $candidateRoots.Add (" C:\tools\llvm" )
2131
2232 if ($env: ChocolateyInstall ) {
2333 $candidateRoots.Add ((Join-Path $env: ChocolateyInstall " lib\llvm\tools\llvm" ))
@@ -28,11 +38,13 @@ function Resolve-LLVMLayout {
2838 " lib\cmake\llvm" ,
2939 " lib\llvm\cmake" ,
3040 " share\llvm\cmake" ,
31- " cmake"
41+ " cmake" ,
42+ " lib\cmake"
3243 )
3344
34- foreach ($root in ($candidateRoots | Select-Object - Unique)) {
35- if (-not $root -or -not (Test-Path $root )) { continue }
45+ $uniqueRoots = $candidateRoots | Where-Object { $_ -ne $null -and $_ -ne " " } | Select-Object - Unique
46+ foreach ($root in $uniqueRoots ) {
47+ if (-not (Test-Path $root )) { continue }
3648
3749 Write-Host " Checking LLVM root candidate: $root "
3850 foreach ($suffix in $cmakeSuffixes ) {
@@ -47,28 +59,30 @@ function Resolve-LLVMLayout {
4759 }
4860 }
4961
50- # Fallback: Recursive search in Program Files if still not found
62+ # 4. Fallback: Recursive search in common areas
5163 Write-Host " Performing exhaustive search for LLVMConfig.cmake..."
52- $searchRoots = @ (" C:\Program Files" , " C:\Program Files (x86)" , " C:\ProgramData\chocolatey\lib " )
64+ $searchRoots = @ (" C:\Program Files" , " C:\Program Files (x86)" , " C:\ProgramData\chocolatey" , " C:\tools " )
5365 foreach ($sr in $searchRoots ) {
5466 if (-not (Test-Path $sr )) { continue }
55- $configFile = Get-ChildItem - Path $sr - Filter " LLVMConfig.cmake" - Recurse - ErrorAction SilentlyContinue | Select-Object - First 1
67+ $configFile = Get-ChildItem - Path $sr - Filter " LLVMConfig.cmake" - Recurse - Depth 4 - ErrorAction SilentlyContinue | Select-Object - First 1
5668 if ($configFile ) {
5769 $cmakeDir = $configFile.DirectoryName
5870 Write-Host " Found LLVMConfig.cmake at: $cmakeDir "
59- # Try to find the root by going up from cmake dir
71+
72+ # Try to find the root by looking for 'bin' nearby
6073 $root = $cmakeDir
6174 for ($i = 0 ; $i -lt 4 ; $i ++ ) {
62- if (Test-Path (Join-Path $root " bin" )) { break }
75+ if (Test-Path (Join-Path $root " bin" )) {
76+ return @ {
77+ Root = $root
78+ CMakeDir = $cmakeDir
79+ BinDir = Join-Path $root " bin"
80+ }
81+ }
6382 $parent = Split-Path - Parent $root
6483 if ($parent -eq $root ) { break }
6584 $root = $parent
6685 }
67- return @ {
68- Root = $root
69- CMakeDir = $cmakeDir
70- BinDir = Join-Path $root " bin"
71- }
7286 }
7387 }
7488 return $null
@@ -80,7 +94,8 @@ $layout = Resolve-LLVMLayout
8094# 2. Install if not found
8195if (-not $layout ) {
8296 Write-Host " LLVM not initially found. Installing via Chocolatey..."
83- choco install llvm - y -- version 17.0 .6 -- allow- downgrade -- no- progress -- limit-output
97+ # Using --params to add LLVM to PATH
98+ choco install llvm - y -- version 17.0 .6 -- allow- downgrade -- no- progress -- limit-output -- package- parameters= " \" / InstallDir:C:\LLVM\" "
8499
85100 # Refresh PATH for the current session
86101 Write-Host " Refreshing PATH..."
@@ -106,6 +121,7 @@ if ($layout) {
106121
107122 Write-Host " Resolved LLVM root: $llvmRoot "
108123 Write-Host " Resolved LLVM_DIR: $cmakeDir "
124+ Write-Host " Resolved BinDir: $binDir "
109125
110126 if ($env: GITHUB_ENV ) {
111127 Add-Content $env: GITHUB_ENV " LLVM_DIR=$cmakeDir "
@@ -117,9 +133,17 @@ if ($layout) {
117133 Add-Content $env: GITHUB_PATH $binDir
118134 }
119135} else {
120- Write-Host " DUMPING COMMON LOCATIONS FOR DEBUG:"
121- Get-ChildItem " C:\Program Files" - ErrorAction SilentlyContinue | Select-Object Name
122- Get-ChildItem " C:\ProgramData\chocolatey\lib" - ErrorAction SilentlyContinue | Select-Object Name
123- Write-Error " Failed to detect LLVM after installation."
136+ Write-Host " `n --- DEBUG INFO: SEARCH FAILED ---"
137+ Write-Host " Listing top-level directories for clues:"
138+ $debugPaths = @ (" C:\Program Files" , " C:\Program Files (x86)" , " C:\ProgramData\chocolatey\lib" , " C:\LLVM" , " C:\tools" )
139+ foreach ($dp in $debugPaths ) {
140+ if (Test-Path $dp ) {
141+ Write-Host " `n Contents of $dp `:"
142+ Get-ChildItem $dp - ErrorAction SilentlyContinue | Select-Object Name | Format-Table - HideTableHeaders
143+ }
144+ }
145+
146+ Write-Error " Failed to detect LLVM after installation. Check logs above for directory contents."
124147 exit 1
125148}
149+
0 commit comments