Skip to content

Commit 52da048

Browse files
committed
Fix Windows LLVM extraction
1 parent bcacb19 commit 52da048

1 file changed

Lines changed: 54 additions & 7 deletions

File tree

scripts/ci/install-llvm-21-windows.ps1

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,34 @@ $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"
2222

23+
function Find-SevenZip {
24+
foreach ($Name in @("7z.exe", "7zz.exe", "7za.exe")) {
25+
$Command = Get-Command $Name -ErrorAction SilentlyContinue
26+
if ($Command) {
27+
return $Command.Source
28+
}
29+
}
30+
31+
$Candidates = @()
32+
if ($env:ProgramFiles) {
33+
$Candidates += Join-Path $env:ProgramFiles "7-Zip\7z.exe"
34+
}
35+
if (${env:ProgramFiles(x86)}) {
36+
$Candidates += Join-Path ${env:ProgramFiles(x86)} "7-Zip\7z.exe"
37+
}
38+
if ($env:ChocolateyInstall) {
39+
$Candidates += Join-Path $env:ChocolateyInstall "bin\7z.exe"
40+
}
41+
42+
foreach ($Candidate in $Candidates) {
43+
if ($Candidate -and (Test-Path $Candidate)) {
44+
return $Candidate
45+
}
46+
}
47+
48+
return $null
49+
}
50+
2351
function Get-Sha256Hex {
2452
param([string]$Path)
2553

@@ -48,9 +76,11 @@ if (Test-Path $LlvmConfig) {
4876

4977
$TempDir = Join-Path ([System.IO.Path]::GetTempPath()) "pecos-llvm-$([System.Guid]::NewGuid())"
5078
$Archive = Join-Path $TempDir $Asset
79+
$TarDir = Join-Path $TempDir "tar"
5180
$ExtractDir = Join-Path $TempDir "extract"
5281

5382
New-Item -ItemType Directory -Force -Path $TempDir | Out-Null
83+
New-Item -ItemType Directory -Force -Path $TarDir | Out-Null
5484
New-Item -ItemType Directory -Force -Path $ExtractDir | Out-Null
5585

5686
try {
@@ -68,22 +98,39 @@ try {
6898
throw "SHA256 mismatch for $Asset. Expected $ExpectedSha256, got $ActualSha256"
6999
}
70100

71-
$Tar = Join-Path $env:SystemRoot "System32\tar.exe"
72-
if (-not (Test-Path $Tar)) {
73-
$Tar = "tar.exe"
101+
$SevenZip = Find-SevenZip
102+
if (-not $SevenZip) {
103+
throw "7-Zip is required to extract $Asset on Windows. Windows tar.exe can hang for hours on this archive in CI; install 7-Zip or provide an existing LLVM 21.1 install."
74104
}
75105

76-
Write-Host "Extracting LLVM archive with $Tar"
77-
& $Tar -xf $Archive -C $ExtractDir --strip-components=1
106+
Write-Host "Extracting compressed LLVM archive with $SevenZip"
107+
& $SevenZip x -y -bb0 "-o$TarDir" $Archive
78108
if ($LASTEXITCODE -ne 0) {
79-
throw "tar failed with exit code $LASTEXITCODE"
109+
throw "7-Zip failed to decompress $Asset with exit code $LASTEXITCODE"
110+
}
111+
112+
$TarArchive = Get-ChildItem -Path $TarDir -File -Filter "*.tar" | Select-Object -First 1
113+
if (-not $TarArchive) {
114+
throw "7-Zip did not produce a .tar payload from $Asset"
115+
}
116+
117+
Write-Host "Extracting LLVM payload with $SevenZip"
118+
& $SevenZip x -y -bb0 "-o$ExtractDir" $TarArchive.FullName
119+
if ($LASTEXITCODE -ne 0) {
120+
throw "7-Zip failed to extract $($TarArchive.Name) with exit code $LASTEXITCODE"
121+
}
122+
123+
$PayloadRoots = @(Get-ChildItem -Path $ExtractDir -Directory)
124+
if ($PayloadRoots.Count -ne 1) {
125+
throw "Expected one LLVM payload directory in $ExtractDir, found $($PayloadRoots.Count)"
80126
}
127+
$PayloadDir = $PayloadRoots[0].FullName
81128

82129
if (Test-Path $InstallDir) {
83130
Remove-Item -Recurse -Force $InstallDir
84131
}
85132
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $InstallDir) | Out-Null
86-
Move-Item $ExtractDir $InstallDir
133+
Move-Item -Path $PayloadDir -Destination $InstallDir
87134

88135
& $LlvmConfig --version
89136
& $LlvmConfig --shared-mode

0 commit comments

Comments
 (0)