Skip to content

Commit f8dda67

Browse files
committed
fix: attempt 2 - robust LLVM detection with downgrade support
1 parent 79ada9c commit f8dda67

1 file changed

Lines changed: 34 additions & 22 deletions

File tree

.github/workflows/build.yml

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,45 @@ jobs:
5353
if: matrix.os == 'windows-latest'
5454
shell: pwsh
5555
run: |
56-
# Install LLVM via Chocolatey if not present
57-
if (-not (Get-Command llvm-config -ErrorAction SilentlyContinue)) {
58-
Write-Host "LLVM not found. Installing via Chocolatey..."
59-
choco install llvm -y --version 17.0.6 # Pin version for stability
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+
}
74+
}
6075
}
6176
62-
# Robust detection logic
63-
$llvmConfig = Get-Command llvm-config -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
77+
# If still not found, try to install/reinstall
6478
if (-not $llvmConfig) {
65-
$commonPaths = @(
66-
"C:\Program Files\LLVM\bin\llvm-config.exe",
67-
"C:\Program Files (x86)\LLVM\bin\llvm-config.exe",
68-
"C:\ProgramData\chocolatey\bin\llvm-config.exe",
69-
"C:\ProgramData\chocolatey\lib\llvm\tools\llvm\bin\llvm-config.exe"
70-
)
71-
foreach ($path in $commonPaths) {
72-
if (Test-Path $path) {
73-
$llvmConfig = $path
74-
break
75-
}
76-
}
79+
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
81+
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+
}
7791
}
7892
7993
if ($llvmConfig) {
80-
Write-Host "Found llvm-config at: $llvmConfig"
94+
Write-Host "Using llvm-config at: $llvmConfig"
8195
$llvmBin = Split-Path -Parent $llvmConfig
8296
$llvmRoot = Split-Path -Parent $llvmBin
8397
$cmakeDir = & $llvmConfig --cmakedir
@@ -87,11 +101,9 @@ jobs:
87101
88102
echo "LLVM_DIR=$cmakeDir" >> $env:GITHUB_ENV
89103
echo "CMAKE_PREFIX_PATH=$llvmRoot" >> $env:GITHUB_ENV
90-
91-
# Add bin to path for subsequent steps if needed
92104
echo "$llvmBin" >> $env:GITHUB_PATH
93105
} else {
94-
Write-Error "LLVM installation failed or llvm-config.exe not found in common paths!"
106+
Write-Error "LLVM detection and installation failed!"
95107
exit 1
96108
}
97109

0 commit comments

Comments
 (0)