Skip to content

Commit ea49d55

Browse files
committed
fix: attempt 3 - exhaustive search for LLVMConfig.cmake and llvm-config.exe
1 parent f8dda67 commit ea49d55

1 file changed

Lines changed: 32 additions & 43 deletions

File tree

.github/workflows/build.yml

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -53,57 +53,46 @@ jobs:
5353
if: matrix.os == 'windows-latest'
5454
shell: pwsh
5555
run: |
56-
# Try to find llvm-config first
57-
$llvmConfig = Get-Command llvm-config -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
58-
59-
if (-not $llvmConfig) {
60-
Write-Host "LLVM not in PATH. Checking common locations..."
61-
$commonPaths = @(
62-
"C:\Program Files\LLVM\bin\llvm-config.exe",
63-
"C:\Program Files (x86)\LLVM\bin\llvm-config.exe",
64-
"C:\ProgramData\chocolatey\bin\llvm-config.exe",
65-
"C:\ProgramData\chocolatey\lib\llvm\tools\llvm\bin\llvm-config.exe",
66-
"C:\tools\llvm\bin\llvm-config.exe"
67-
)
68-
foreach ($path in $commonPaths) {
69-
if (Test-Path $path) {
70-
$llvmConfig = $path
71-
Write-Host "Found llvm-config at: $path"
72-
break
73-
}
56+
function Find-LLVM {
57+
$searchPaths = @("C:\Program Files\LLVM", "C:\Program Files (x86)\LLVM", "C:\ProgramData\chocolatey", "C:\tools\llvm")
58+
59+
# 1. Try to find llvm-config.exe
60+
$config = Get-Command llvm-config -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
61+
if (-not $config) {
62+
$config = Get-ChildItem -Path $searchPaths -Filter "llvm-config.exe" -Recurse -Depth 4 -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
7463
}
64+
65+
# 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
67+
68+
return @{ Config = $config; CMake = $cmake }
7569
}
7670
77-
# If still not found, try to install/reinstall
78-
if (-not $llvmConfig) {
71+
$res = Find-LLVM
72+
if (-not $res.Config -and -not $res.CMake) {
7973
Write-Host "LLVM not found. Attempting to install LLVM 17.0.6 via Chocolatey..."
80-
# Use --allow-downgrade in case a newer version is partially present or we want to pin 17
8174
choco install llvm -y --version 17.0.6 --allow-downgrade --limit-output
82-
83-
# Refresh path to find newly installed llvm-config
84-
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
85-
$llvmConfig = Get-Command llvm-config -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
86-
87-
if (-not $llvmConfig) {
88-
# Last ditch effort: search the choco lib dir specifically
89-
$llvmConfig = Get-ChildItem -Path "C:\ProgramData\chocolatey\lib\llvm" -Filter "llvm-config.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
90-
}
75+
$res = Find-LLVM
9176
}
9277
93-
if ($llvmConfig) {
94-
Write-Host "Using llvm-config at: $llvmConfig"
95-
$llvmBin = Split-Path -Parent $llvmConfig
96-
$llvmRoot = Split-Path -Parent $llvmBin
97-
$cmakeDir = & $llvmConfig --cmakedir
98-
99-
Write-Host "LLVM Root: $llvmRoot"
100-
Write-Host "LLVM CMake dir: $cmakeDir"
101-
102-
echo "LLVM_DIR=$cmakeDir" >> $env:GITHUB_ENV
103-
echo "CMAKE_PREFIX_PATH=$llvmRoot" >> $env:GITHUB_ENV
104-
echo "$llvmBin" >> $env:GITHUB_PATH
78+
if ($res.Config -or $res.CMake) {
79+
if ($res.Config) {
80+
Write-Host "Found llvm-config at: $($res.Config)"
81+
$llvmBin = Split-Path -Parent $res.Config
82+
$llvmRoot = Split-Path -Parent $llvmBin
83+
$cmakeDir = & $res.Config --cmakedir
84+
echo "LLVM_DIR=$cmakeDir" >> $env:GITHUB_ENV
85+
echo "CMAKE_PREFIX_PATH=$llvmRoot" >> $env:GITHUB_ENV
86+
echo "$llvmBin" >> $env:GITHUB_PATH
87+
} elseif ($res.CMake) {
88+
Write-Host "Found LLVMConfig.cmake at: $($res.CMake)"
89+
$cmakeDir = Split-Path -Parent $res.CMake
90+
$llvmRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $cmakeDir))
91+
echo "LLVM_DIR=$cmakeDir" >> $env:GITHUB_ENV
92+
echo "CMAKE_PREFIX_PATH=$llvmRoot" >> $env:GITHUB_ENV
93+
}
10594
} else {
106-
Write-Error "LLVM detection and installation failed!"
95+
Write-Error "Exhaustive LLVM detection failed!"
10796
exit 1
10897
}
10998

0 commit comments

Comments
 (0)