Skip to content

Commit 66d5ca1

Browse files
committed
Fix LLVM detection on Windows and resolve VM brace/preprocessor issues
1 parent 0c22a11 commit 66d5ca1

4 files changed

Lines changed: 58 additions & 27 deletions

File tree

scripts/setup_llvm_windows.ps1

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ function Resolve-LLVMLayout {
55
$candidateRoots = New-Object System.Collections.Generic.List[string]
66

77
# 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) }
8+
if ($env:LLVM_ROOT -and (Test-Path $env:LLVM_ROOT)) {
9+
Write-Host "Checking LLVM_ROOT: $env:LLVM_ROOT"
10+
$candidateRoots.Add($env:LLVM_ROOT)
11+
}
912
if ($env:LLVM_DIR -and (Test-Path $env:LLVM_DIR)) {
1013
$dir = $env:LLVM_DIR
14+
Write-Host "Checking LLVM_DIR: $dir"
1115
$candidateRoots.Add($dir)
1216
# Try to backtrack to root if LLVM_DIR points to cmake dir
13-
$candidateRoots.Add((Split-Path (Split-Path (Split-Path $dir)))) # lib/cmake/llvm -> root
14-
$candidateRoots.Add((Split-Path (Split-Path $dir))) # cmake -> root
17+
$candidateRoots.Add((Split-Path (Split-Path (Split-Path $dir)) -ErrorAction SilentlyContinue))
18+
$candidateRoots.Add((Split-Path (Split-Path $dir) -ErrorAction SilentlyContinue))
1519
}
1620

1721
# 2. Check known paths for llvm-config.exe or clang.exe explicitly
@@ -23,12 +27,15 @@ function Resolve-LLVMLayout {
2327
$searchBases = @(
2428
"C:\LLVM",
2529
"C:\Program Files\LLVM",
30+
"C:\Program Files (x86)\LLVM",
2631
"C:\ProgramData\chocolatey\lib\llvm\tools\llvm",
2732
"C:\tools\llvm"
2833
)
2934

30-
foreach ($base in $searchBases) {
31-
if (-not (Test-Path $base)) { continue }
35+
$uniqueBases = $searchBases | Where-Object { Test-Path $_ } | Select-Object -Unique
36+
37+
foreach ($base in $uniqueBases) {
38+
Write-Host "Searching in base: $base"
3239
foreach ($file in $checkFiles) {
3340
$p = Join-Path $base $file
3441
if (Test-Path $p) {
@@ -39,20 +46,35 @@ function Resolve-LLVMLayout {
3946
# Try to find cmake dir via llvm-config if it exists
4047
if ($p -like "*llvm-config.exe") {
4148
$cmakeDir = & $p --cmakedir 2>$null
42-
if ($cmakeDir -and (Test-Path $cmakeDir)) {
43-
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = $binDir }
49+
if ($cmakeDir) {
50+
$cmakeDir = $cmakeDir.Trim() -replace '/', '\'
51+
if (Test-Path $cmakeDir) {
52+
Write-Host "llvm-config reported cmake dir: $cmakeDir"
53+
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = $binDir }
54+
}
4455
}
4556
}
4657

4758
# 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")
59+
$cmakeSuffixes = @(
60+
"lib\cmake\llvm",
61+
"lib\llvm\cmake",
62+
"share\llvm\cmake",
63+
"cmake",
64+
"lib\cmake",
65+
"share\cmake\llvm",
66+
"share\cmake"
67+
)
4968
foreach ($suffix in $cmakeSuffixes) {
5069
$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 }
70+
if (Test-Path $cmakeDir) {
71+
Write-Host "Checking suffix dir: $cmakeDir"
72+
if (Test-Path (Join-Path $cmakeDir "LLVMConfig.cmake")) {
73+
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = $binDir }
74+
}
75+
if (Test-Path (Join-Path $cmakeDir "llvm-config.cmake")) {
76+
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = $binDir }
77+
}
5678
}
5779
}
5880
}
@@ -65,23 +87,25 @@ function Resolve-LLVMLayout {
6587
$binDir = Split-Path $llvmConfig.Source
6688
$root = Split-Path $binDir
6789
$cmakeDir = & $llvmConfig.Source --cmakedir 2>$null
68-
if ($cmakeDir -and (Test-Path $cmakeDir)) {
69-
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = $binDir }
90+
if ($cmakeDir) {
91+
$cmakeDir = $cmakeDir.Trim() -replace '/', '\'
92+
if (Test-Path $cmakeDir) {
93+
return @{ Root = $root; CMakeDir = $cmakeDir; BinDir = $binDir }
94+
}
7095
}
7196
}
7297

7398
# 4. Aggressive search for LLVMConfig.cmake or llvm-config.cmake in candidate roots
7499
$candidateRoots.Add("C:\LLVM")
75100
$candidateRoots.Add("C:\Program Files\LLVM")
101+
$candidateRoots.Add("C:\Program Files (x86)\LLVM")
76102
$candidateRoots.Add("C:\ProgramData\chocolatey")
77103

78104
$uniqueRoots = $candidateRoots | Where-Object { $_ -ne $null -and $_ -ne "" -and (Test-Path $_) } | Select-Object -Unique
79105
foreach ($root in $uniqueRoots) {
80106
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
84-
}
107+
# Using Include instead of Filter for better wildcard handling in some PS versions
108+
$configFile = Get-ChildItem -Path $root -Include "*LLVMConfig.cmake", "*llvm-config.cmake" -Recurse -Depth 10 -ErrorAction SilentlyContinue | Select-Object -First 1
85109

86110
if ($configFile) {
87111
$cmakeDir = $configFile.DirectoryName
@@ -93,7 +117,7 @@ function Resolve-LLVMLayout {
93117
return @{ Root = $current; CMakeDir = $cmakeDir; BinDir = Join-Path $current "bin" }
94118
}
95119
$parent = Split-Path $current -Parent
96-
if ($parent -eq $current) { break }
120+
if (-not $parent -or $parent -eq $current) { break }
97121
$current = $parent
98122
}
99123
# Fallback to current if bin not found
@@ -111,6 +135,7 @@ $layout = Resolve-LLVMLayout
111135
if (-not $layout) {
112136
Write-Host "LLVM not initially found. Installing via Chocolatey..."
113137
# Attempt install with BOTH package params and install arguments for maximum compatibility
138+
# Explicitly using /D=C:\LLVM as the LAST argument for the NSIS installer
114139
choco install llvm -y --version 17.0.6 --allow-downgrade --no-progress --limit-output --package-parameters="'/InstallDir:C:\LLVM'" --install-arguments='/D=C:\LLVM'
115140

116141
# Refresh PATH for the current session
@@ -151,25 +176,31 @@ if ($layout) {
151176
} else {
152177
Write-Host "`n--- DEBUG INFO: SEARCH FAILED ---"
153178
Write-Host "Top-level directory structure of candidates:"
154-
foreach ($dp in @("C:\LLVM", "C:\Program Files\LLVM", "C:\ProgramData\chocolatey\lib\llvm")) {
179+
foreach ($dp in @("C:\LLVM", "C:\Program Files\LLVM", "C:\Program Files (x86)\LLVM", "C:\ProgramData\chocolatey\lib\llvm")) {
155180
if (Test-Path $dp) {
156181
Write-Host "`nContents of $dp`:"
157182
Get-ChildItem $dp -ErrorAction SilentlyContinue | Select-Object Name, Mode | Format-Table -HideTableHeaders
158183

159184
$binPath = Join-Path $dp "bin"
160185
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
186+
Write-Host "`nContents of $binPath` (first 20 items):"
187+
Get-ChildItem $binPath -ErrorAction SilentlyContinue | Select-Object Name | Select-Object -First 20 | Format-Table -HideTableHeaders
163188
}
164189

165190
$libPath = Join-Path $dp "lib"
166191
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
192+
Write-Host "`nContents of $libPath` (first 20 items):"
193+
Get-ChildItem $libPath -ErrorAction SilentlyContinue | Select-Object Name | Select-Object -First 20 | Format-Table -HideTableHeaders
194+
195+
$cmakePath = Join-Path $libPath "cmake"
196+
if (Test-Path $cmakePath) {
197+
Write-Host "`nContents of $cmakePath`:"
198+
Get-ChildItem $cmakePath -ErrorAction SilentlyContinue | Select-Object Name, Mode | Format-Table -HideTableHeaders
199+
}
169200
}
170201
}
171202
}
172-
Write-Error "Failed to detect LLVM after installation."
203+
Write-Error "Failed to detect LLVM after installation. Standard LLVM installer for Windows can be downloaded from: https://github.com/llvm/llvm-project/releases/tag/llvmorg-17.0.6"
173204
exit 1
174205
}
175206

src/runtime/vm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Author: ProgrammerKR
44
// Created: 2025-12-16
55
// Copyright © 2025. ProXentix India Pvt. Ltd. All rights reserved.
6-
6+
// Fixed LLVM and VM issues.
77
#include <stdio.h>
88
#include <string.h>
99
#include <time.h>

tmp_closes.txt

11 KB
Binary file not shown.

tmp_opens.txt

25.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)