Skip to content

Commit 574960a

Browse files
committed
fix: attempt 2 - exhaustive LLVM detection with better logging and broader search
1 parent 8bc4a6a commit 574960a

1 file changed

Lines changed: 83 additions & 58 deletions

File tree

.github/workflows/build.yml

Lines changed: 83 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -54,104 +54,126 @@ jobs:
5454
shell: pwsh
5555
run: |
5656
function Find-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-
)
57+
Write-Host "--- Starting LLVM Detection ---"
58+
$possiblePaths = New-Object System.Collections.Generic.List[string]
59+
$possiblePaths.Add("C:\Program Files\LLVM")
60+
$possiblePaths.Add("C:\Program Files (x86)\LLVM")
61+
$possiblePaths.Add("C:\ProgramData\chocolatey\lib\llvm\tools\llvm")
62+
$possiblePaths.Add("C:\tools\llvm")
6563
66-
Write-Host "Searching for LLVM in standard locations..."
67-
68-
# 1. Try to find llvm-config.exe
69-
$config = Get-Command llvm-config -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
70-
if (-not $config) {
71-
foreach ($path in $possiblePaths) {
64+
if ($env:ProgramFiles) { $possiblePaths.Add((Join-Path $env:ProgramFiles "LLVM")) }
65+
if ($env:{"ProgramFiles(x86)"}) { $possiblePaths.Add((Join-Path $env:{"ProgramFiles(x86)"} "LLVM")) }
66+
67+
# Broaden search to ANY LLVM-like folder in Program Files
68+
foreach ($pf in @($env:ProgramFiles, $env:{"ProgramFiles(x86)"}, "C:\Program Files", "C:\Program Files (x86)")) {
69+
if ($pf -and (Test-Path $pf)) {
70+
Get-ChildItem -Path $pf -Filter "LLVM*" -ErrorAction SilentlyContinue | ForEach-Object { $possiblePaths.Add($_.FullName) }
71+
}
72+
}
73+
74+
$uniquePaths = $possiblePaths | Select-Object -Unique
75+
$config = $null
76+
$cmake = $null
77+
78+
Write-Host "Checking candidate paths..."
79+
foreach ($path in $uniquePaths) {
80+
if ($path -and (Test-Path $path)) {
81+
Write-Host " Checking: $path"
7282
if (Test-Path "$path\bin\llvm-config.exe") {
7383
$config = "$path\bin\llvm-config.exe"
84+
Write-Host " >> Found llvm-config: $config"
7485
break
7586
}
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
87+
}
88+
}
89+
90+
if (-not $config) {
91+
Write-Host " Checking PATH for llvm-config..."
92+
$config = Get-Command llvm-config -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
93+
if ($config) { Write-Host " >> Found llvm-config in PATH: $config" }
94+
}
95+
96+
# Search for LLVMConfig.cmake
97+
Write-Host "Searching for LLVMConfig.cmake..."
98+
foreach ($path in $uniquePaths) {
99+
if ($path -and (Test-Path $path)) {
100+
$found = Get-ChildItem -Path $path -Filter "LLVMConfig.cmake" -Recurse -Depth 10 -ErrorAction SilentlyContinue | Select-Object -First 1
78101
if ($found) {
79-
$config = $found.FullName
102+
$cmake = $found.FullName
103+
Write-Host " >> Found LLVMConfig.cmake: $cmake"
80104
break
81105
}
82106
}
83107
}
84-
85-
# 2. Try to find LLVMConfig.cmake
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-
}
94-
108+
95109
return @{ Config = $config; CMake = $cmake }
96110
}
97111
98112
$res = Find-LLVM
99113
if (-not $res.Config -and -not $res.CMake) {
100-
Write-Host "LLVM not found. Attempting to install LLVM 17.0.6 via Chocolatey..."
114+
Write-Host "LLVM not initially found. Installing via Chocolatey..."
101115
choco install llvm -y --version 17.0.6 --allow-downgrade --limit-output
102116
103-
# Refresh environment to pick up PATH changes
117+
Write-Host "Refreshing PATH..."
104118
$env:PATH = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
105119
106120
$res = Find-LLVM
107121
}
108122
109123
if ($res.Config -or $res.CMake) {
124+
$llvmRoot = $null
125+
$cmakeDir = $null
126+
$binDir = $null
127+
110128
if ($res.Config) {
111-
Write-Host "Found llvm-config at: $($res.Config)"
112-
$llvmBin = Split-Path -Parent $res.Config
113-
$llvmRoot = Split-Path -Parent $llvmBin
114-
115-
# Try to get cmake dir from llvm-config
129+
$binDir = Split-Path -Parent $res.Config
130+
$llvmRoot = Split-Path -Parent $binDir
116131
try {
117132
$cmakeDir = & $res.Config --cmakedir
118-
Write-Host "Detected LLVM_DIR from llvm-config: $cmakeDir"
133+
Write-Host "llvm-config reported cmakedir: $cmakeDir"
119134
} 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 }
135+
Write-Host "llvm-config --cmakedir failed. Using fallbacks."
128136
}
137+
}
129138
130-
echo "LLVM_DIR=$cmakeDir" >> $env:GITHUB_ENV
131-
echo "CMAKE_PREFIX_PATH=$llvmRoot" >> $env:GITHUB_ENV
132-
echo "$llvmBin" >> $env:GITHUB_PATH
133-
} elseif ($res.CMake) {
134-
Write-Host "Found LLVMConfig.cmake at: $($res.CMake)"
139+
if (-not $cmakeDir -and $res.CMake) {
135140
$cmakeDir = Split-Path -Parent $res.CMake
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-
141+
if (-not $llvmRoot) {
142+
# Heuristic: lib/cmake/llvm -> root
143+
$llvmRoot = $cmakeDir
144+
for ($i=0; $i -lt 3; $i++) { $llvmRoot = Split-Path -Parent $llvmRoot }
145+
}
146+
}
147+
148+
# Final check for cmakeDir if still null
149+
if (-not $cmakeDir -and $llvmRoot) {
150+
$found = Get-ChildItem -Path $llvmRoot -Filter "LLVMConfig.cmake" -Recurse -Depth 6 -ErrorAction SilentlyContinue | Select-Object -First 1
151+
if ($found) { $cmakeDir = $found.DirectoryName }
152+
}
153+
154+
if ($llvmRoot) {
155+
Write-Host "Setting GITHUB_ENV: LLVM_DIR=$cmakeDir"
156+
Write-Host "Setting GITHUB_ENV: CMAKE_PREFIX_PATH=$llvmRoot"
140157
echo "LLVM_DIR=$cmakeDir" >> $env:GITHUB_ENV
141158
echo "CMAKE_PREFIX_PATH=$llvmRoot" >> $env:GITHUB_ENV
142-
143-
$binDir = Join-Path $llvmRoot "bin"
144-
if (Test-Path $binDir) {
159+
if ($binDir) {
160+
Write-Host "Adding to GITHUB_PATH: $binDir"
145161
echo "$binDir" >> $env:GITHUB_PATH
162+
} elseif (Test-Path "$llvmRoot\bin") {
163+
Write-Host "Adding to GITHUB_PATH: $llvmRoot\bin"
164+
echo "$llvmRoot\bin" >> $env:GITHUB_PATH
146165
}
166+
} else {
167+
Write-Error "Could not resolve LLVM Root!"
168+
exit 1
147169
}
148170
} else {
171+
Write-Host "DUMPING C:\ PROGRAM FILES TO DEBUG:"
172+
Get-ChildItem "C:\Program Files" -ErrorAction SilentlyContinue | Select-Object Name
149173
Write-Error "Exhaustive LLVM detection failed after installation!"
150174
exit 1
151175
}
152176
153-
154-
155177
- name: Configure (Unix)
156178
if: matrix.os != 'windows-latest'
157179
shell: bash
@@ -165,6 +187,8 @@ jobs:
165187
if: matrix.os == 'windows-latest'
166188
shell: pwsh
167189
run: |
190+
Write-Host "LLVM_DIR is: $env:LLVM_DIR"
191+
Write-Host "CMAKE_PREFIX_PATH is: $env:CMAKE_PREFIX_PATH"
168192
cmake -S . -B build `
169193
-G "Visual Studio 17 2022" -A x64 `
170194
-DLLVM_DIR="$env:LLVM_DIR" `
@@ -173,6 +197,7 @@ jobs:
173197
-DBUILD_TESTS=OFF `
174198
-DBUILD_BENCH=OFF
175199
200+
176201
- name: Build
177202
shell: bash
178203
run: cmake --build build --config Release --verbose

0 commit comments

Comments
 (0)