Skip to content

Commit 0c22a11

Browse files
committed
fix(ci): even more robust LLVM detection in setup_llvm_windows.ps1
1 parent 0c78928 commit 0c22a11

1 file changed

Lines changed: 73 additions & 52 deletions

File tree

scripts/setup_llvm_windows.ps1

Lines changed: 73 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,53 @@ function Resolve-LLVMLayout {
88
if ($env:LLVM_ROOT -and (Test-Path $env:LLVM_ROOT)) { $candidateRoots.Add($env:LLVM_ROOT) }
99
if ($env:LLVM_DIR -and (Test-Path $env:LLVM_DIR)) {
1010
$dir = $env:LLVM_DIR
11+
$candidateRoots.Add($dir)
12+
# Try to backtrack to root if LLVM_DIR points to cmake dir
1113
$candidateRoots.Add((Split-Path (Split-Path (Split-Path $dir)))) # lib/cmake/llvm -> root
1214
$candidateRoots.Add((Split-Path (Split-Path $dir))) # cmake -> root
1315
}
1416

15-
# 2. Check known paths for llvm-config.exe explicitly
16-
$llvmConfigPaths = @(
17-
"C:\LLVM\bin\llvm-config.exe",
18-
"C:\Program Files\LLVM\bin\llvm-config.exe",
19-
"C:\ProgramData\chocolatey\lib\llvm\tools\llvm\bin\llvm-config.exe"
17+
# 2. Check known paths for llvm-config.exe or clang.exe explicitly
18+
$checkFiles = @(
19+
"bin\llvm-config.exe",
20+
"bin\clang.exe",
21+
"bin\lld.exe"
2022
)
21-
foreach ($p in $llvmConfigPaths) {
22-
if (Test-Path $p) {
23-
Write-Host "Found llvm-config at: $p"
24-
$root = Split-Path (Split-Path $p)
25-
$cmakeDir = & $p --cmakedir 2>$null
26-
if ($cmakeDir -and (Test-Path $cmakeDir)) {
27-
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = Join-Path $root "bin" }
23+
$searchBases = @(
24+
"C:\LLVM",
25+
"C:\Program Files\LLVM",
26+
"C:\ProgramData\chocolatey\lib\llvm\tools\llvm",
27+
"C:\tools\llvm"
28+
)
29+
30+
foreach ($base in $searchBases) {
31+
if (-not (Test-Path $base)) { continue }
32+
foreach ($file in $checkFiles) {
33+
$p = Join-Path $base $file
34+
if (Test-Path $p) {
35+
Write-Host "Found LLVM component at: $p"
36+
$root = $base
37+
$binDir = Join-Path $root "bin"
38+
39+
# Try to find cmake dir via llvm-config if it exists
40+
if ($p -like "*llvm-config.exe") {
41+
$cmakeDir = & $p --cmakedir 2>$null
42+
if ($cmakeDir -and (Test-Path $cmakeDir)) {
43+
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = $binDir }
44+
}
45+
}
46+
47+
# Otherwise search for LLVMConfig.cmake in this root
48+
$cmakeSuffixes = @("lib\cmake\llvm", "lib\llvm\cmake", "share\llvm\cmake", "cmake", "lib\cmake", "share\cmake\llvm")
49+
foreach ($suffix in $cmakeSuffixes) {
50+
$cmakeDir = Join-Path $root $suffix
51+
if (Test-Path (Join-Path $cmakeDir "LLVMConfig.cmake")) {
52+
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = $binDir }
53+
}
54+
if (Test-Path (Join-Path $cmakeDir "llvm-config.cmake")) {
55+
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = $binDir }
56+
}
57+
}
2858
}
2959
}
3060
}
@@ -40,58 +70,37 @@ function Resolve-LLVMLayout {
4070
}
4171
}
4272

43-
# 4. Known installation paths with suffix search
73+
# 4. Aggressive search for LLVMConfig.cmake or llvm-config.cmake in candidate roots
4474
$candidateRoots.Add("C:\LLVM")
4575
$candidateRoots.Add("C:\Program Files\LLVM")
46-
$candidateRoots.Add("C:\Program Files (x86)\LLVM")
47-
$candidateRoots.Add("C:\ProgramData\chocolatey\lib\llvm\tools\llvm")
48-
$candidateRoots.Add("C:\tools\llvm")
49-
50-
$cmakeSuffixes = @("lib\cmake\llvm", "lib\llvm\cmake", "share\llvm\cmake", "cmake", "lib\cmake")
51-
$uniqueRoots = $candidateRoots | Where-Object { $_ -ne $null -and $_ -ne "" } | Select-Object -Unique
76+
$candidateRoots.Add("C:\ProgramData\chocolatey")
5277

78+
$uniqueRoots = $candidateRoots | Where-Object { $_ -ne $null -and $_ -ne "" -and (Test-Path $_) } | Select-Object -Unique
5379
foreach ($root in $uniqueRoots) {
54-
if (-not (Test-Path $root)) { continue }
55-
Write-Host "Checking LLVM root candidate: $root"
56-
foreach ($suffix in $cmakeSuffixes) {
57-
$cmakeDir = Join-Path $root $suffix
58-
if (Test-Path (Join-Path $cmakeDir "LLVMConfig.cmake")) {
59-
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = Join-Path $root "bin" }
60-
}
61-
}
62-
}
63-
64-
# 5. Deep exhaustive search in C:\LLVM specifically
65-
if (Test-Path "C:\LLVM") {
66-
Write-Host "Performing deep search in C:\LLVM..."
67-
$configFile = Get-ChildItem -Path "C:\LLVM" -Filter "LLVMConfig.cmake" -Recurse -Depth 10 -ErrorAction SilentlyContinue | Select-Object -First 1
68-
if ($configFile) {
69-
$cmakeDir = $configFile.DirectoryName
70-
$root = "C:\LLVM"
71-
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = Join-Path $root "bin" }
80+
Write-Host "Aggressively searching for LLVM CMake files in: $root"
81+
$configFile = Get-ChildItem -Path $root -Filter "*LLVMConfig.cmake" -Recurse -Depth 10 -ErrorAction SilentlyContinue | Select-Object -First 1
82+
if (-not $configFile) {
83+
$configFile = Get-ChildItem -Path $root -Filter "*llvm-config.cmake" -Recurse -Depth 10 -ErrorAction SilentlyContinue | Select-Object -First 1
7284
}
73-
}
74-
75-
# 6. Fallback: Recursive search in common areas
76-
Write-Host "Performing exhaustive search for LLVMConfig.cmake (Depth 8)..."
77-
$searchRoots = @("C:\Program Files", "C:\Program Files (x86)", "C:\ProgramData\chocolatey", "C:\tools")
78-
foreach ($sr in $searchRoots) {
79-
if (-not (Test-Path $sr)) { continue }
80-
$configFile = Get-ChildItem -Path $sr -Filter "LLVMConfig.cmake" -Recurse -Depth 8 -ErrorAction SilentlyContinue | Select-Object -First 1
85+
8186
if ($configFile) {
8287
$cmakeDir = $configFile.DirectoryName
83-
Write-Host "Found LLVMConfig.cmake at: $cmakeDir"
84-
$root = $cmakeDir
88+
Write-Host "Found config file at: $($configFile.FullName)"
89+
# Try to find root by looking for 'bin' up the tree
90+
$current = $cmakeDir
8591
for ($i = 0; $i -lt 5; $i++) {
86-
if (Test-Path (Join-Path $root "bin")) {
87-
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = Join-Path $root "bin" }
92+
if (Test-Path (Join-Path $current "bin")) {
93+
return @{ Root = $current; CMakeDir = $cmakeDir; BinDir = Join-Path $current "bin" }
8894
}
89-
$parent = Split-Path -Parent $root
90-
if ($parent -eq $root) { break }
91-
$root = $parent
95+
$parent = Split-Path $current -Parent
96+
if ($parent -eq $current) { break }
97+
$current = $parent
9298
}
99+
# Fallback to current if bin not found
100+
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = Join-Path $root "bin" }
93101
}
94102
}
103+
95104
return $null
96105
}
97106

@@ -146,6 +155,18 @@ if ($layout) {
146155
if (Test-Path $dp) {
147156
Write-Host "`nContents of $dp`:"
148157
Get-ChildItem $dp -ErrorAction SilentlyContinue | Select-Object Name, Mode | Format-Table -HideTableHeaders
158+
159+
$binPath = Join-Path $dp "bin"
160+
if (Test-Path $binPath) {
161+
Write-Host "`nContents of $binPath` (first 10 items):"
162+
Get-ChildItem $binPath -ErrorAction SilentlyContinue | Select-Object Name | Select-Object -First 10 | Format-Table -HideTableHeaders
163+
}
164+
165+
$libPath = Join-Path $dp "lib"
166+
if (Test-Path $libPath) {
167+
Write-Host "`nContents of $libPath` (first 10 items):"
168+
Get-ChildItem $libPath -ErrorAction SilentlyContinue | Select-Object Name | Select-Object -First 10 | Format-Table -HideTableHeaders
169+
}
149170
}
150171
}
151172
Write-Error "Failed to detect LLVM after installation."

0 commit comments

Comments
 (0)