@@ -19,6 +19,7 @@ $RequiredVersion = "21.1"
1919$Asset = " clang+llvm-$Version -x86_64-pc-windows-msvc.tar.xz"
2020$Url = " https://github.com/llvm/llvm-project/releases/download/llvmorg-$Version /$Asset "
2121$LlvmConfig = Join-Path $InstallDir " bin\llvm-config.exe"
22+ $LlvmConfigReal = Join-Path $InstallDir " bin\llvm-config.real.exe"
2223
2324function Find-SevenZip {
2425 foreach ($Name in @ (" 7z.exe" , " 7zz.exe" , " 7za.exe" )) {
@@ -66,9 +67,44 @@ function Get-Sha256Hex {
6667 }
6768}
6869
70+ function Install-LlvmConfigWrapper {
71+ $WrapperSource = Join-Path $PSScriptRoot " llvm-config-wrapper.rs"
72+ if (-not (Test-Path $WrapperSource )) {
73+ throw " LLVM config wrapper source not found: $WrapperSource "
74+ }
75+
76+ if (-not (Test-Path $LlvmConfigReal )) {
77+ if (-not (Test-Path $LlvmConfig )) {
78+ throw " llvm-config.exe not found at $LlvmConfig "
79+ }
80+ Move-Item - Force - Path $LlvmConfig - Destination $LlvmConfigReal
81+ }
82+ elseif (Test-Path $LlvmConfig ) {
83+ Remove-Item - Force $LlvmConfig
84+ }
85+
86+ $Rustc = Get-Command rustc.exe - ErrorAction SilentlyContinue
87+ if (-not $Rustc ) {
88+ throw " rustc.exe is required to repair the LLVM Windows llvm-config system library output"
89+ }
90+
91+ Write-Host " Installing PECOS llvm-config wrapper"
92+ & $Rustc.Source -- edition= 2021 - O - o $LlvmConfig $WrapperSource
93+ if ($LASTEXITCODE -ne 0 ) {
94+ throw " rustc failed to build llvm-config wrapper with exit code $LASTEXITCODE "
95+ }
96+
97+ $SystemLibs = (& $LlvmConfig -- system- libs -- link- static ).Trim()
98+ $Libxml2Static = Join-Path $InstallDir " lib\libxml2s.lib"
99+ if ((-not (Test-Path $Libxml2Static )) -and $SystemLibs -match " (^|\s)libxml2s\.lib($|\s)" ) {
100+ throw " LLVM config wrapper did not filter missing libxml2s.lib from --system-libs"
101+ }
102+ }
103+
69104if (Test-Path $LlvmConfig ) {
70105 $FoundVersion = (& $LlvmConfig -- version).Trim()
71106 if ($FoundVersion.StartsWith ($RequiredVersion )) {
107+ Install-LlvmConfigWrapper
72108 Write-Host " LLVM $FoundVersion already installed at $InstallDir "
73109 exit 0
74110 }
@@ -134,6 +170,7 @@ try {
134170
135171 & $LlvmConfig -- version
136172 & $LlvmConfig -- shared- mode
173+ Install-LlvmConfigWrapper
137174 Write-Host " Installed LLVM $Version to $InstallDir "
138175}
139176finally {
0 commit comments