Skip to content

Commit 0d5c94d

Browse files
authored
Patch VS installation reference on Windows
Patch VS installation reference on Windows
2 parents 23022a0 + 3f13278 commit 0d5c94d

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

.github/workflows/llvm-binaries.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,13 @@ jobs:
380380
- name: Install LLVM
381381
run: cmake --build ${{ github.workspace }}/BinaryCache/1 --target ${{ matrix.install_target }}
382382

383+
- name: Patch VS path in LLVMExports.cmake (Windows only)
384+
if: ${{ matrix.os == 'windows-2025' }}
385+
shell: pwsh
386+
working-directory: ${{ github.workspace }}/BuildRoot/${{ env.PACKAGE_NAME }}
387+
run: |
388+
pwsh -File ${{ github.workspace }}/SourceCache/llvm-build/scripts/fix-vs.ps1
389+
383390
- name: Package LLVM
384391
working-directory: ${{ github.workspace }}/BuildRoot/
385392
run: >-

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ Swift compatibility is mostly irrelevant except when it comes to
1919
Windows, where these builds of LLVM always link against a release-mode
2020
multithreaded DLL C runtime and have iterator debugging disabled
2121
(`_ITERATOR_DEBUG_LEVEL=0`) for C++.
22+
23+
> Note: On Windows, make sure to set the environment variable `VSINSTALLDIR` to something like `C:/Program Files/Microsoft Visual Studio/2022/Community`, without `/` at the end. This is needed for LLVM to locate the DIA SDK.

scripts/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ The files in this directory were written for testing and diagnosing
22
the functionality of this project, but they are not used by the actual
33
workflow run. Don't expect them to be accurate, portable, or anything
44
else.
5+
6+
- fix-vs.ps1: PowerShell script to patch hardcoded Visual Studio paths in LLVMExports.cmake after install (Windows only, not shipped in tarballs)

scripts/fix-vs.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# fix-vs.ps1
2+
# This script replaces any hardcoded Visual Studio path in LLVMExports.cmake
3+
# with the literal string $ENV{VSINSTALLDIR} for portability across systems.
4+
# Usage: Run this script in PowerShell after LLVM installation, inside the LLVM folder.
5+
# This is a fix for https://github.com/hylo-lang/llvm-build/issues/15 and https://discourse.llvm.org/t/llvm-assumes-specific-visual-studio-installation-after-build/79857/4
6+
7+
# Path to the LLVMExports.cmake file (relative to LLVM install root)
8+
$llvmExportsPath = "./lib/cmake/llvm/LLVMExports.cmake"
9+
10+
# Check if the LLVMExports.cmake file exists
11+
if (-Not (Test-Path $llvmExportsPath)) {
12+
Write-Error "The file $llvmExportsPath does not exist."
13+
exit 1
14+
}
15+
16+
# Regex to match typical VS install paths (e.g., C:/Program Files/Microsoft Visual Studio/2022/Enterprise/)
17+
$vsPathPattern = "C:[\\/]Program Files[\\/]Microsoft Visual Studio[\\/]([0-9]+)[\\/]([A-Za-z]+)[\\/]"
18+
# Read the contents of the LLVMExports.cmake file
19+
$fileContent = Get-Content -Path $llvmExportsPath -Raw
20+
21+
# Replace all matching VS paths with the literal $ENV{VSINSTALLDIR}
22+
$newContent = [regex]::Replace($fileContent, $vsPathPattern, '$ENV{VSINSTALLDIR}/')
23+
24+
if ($fileContent -eq $newContent) {
25+
Write-Output "No replacements were made in $llvmExportsPath."
26+
exit 1
27+
} else {
28+
Set-Content -Path $llvmExportsPath -Value $newContent
29+
Write-Output "Patched $llvmExportsPath to use $ENV{VSINSTALLDIR} instead of hardcoded VS path."
30+
}

0 commit comments

Comments
 (0)