upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/scripts/build_llvm_mc.ps1
diff options
context:
space:
mode:
authorDiesel <dev.diesel@proton.me>2026-11-21 22:44:07 +0100
committerDiesel <dev.diesel@proton.me>2026-11-21 22:44:07 +0100
commit5c1a1fbb6bf6f609eb4e61baa4961ce382743a4e (patch)
treeac8ad90058b97ab241fdc65edae3d4628d20ee1e /scripts/build_llvm_mc.ps1
parentc45309e29f21c1d5b75678db0e2dc2dd11cff25b (diff)
parent4e390e0871d7265e629b51aca8ff99a15a6a6845 (diff)
Merge main to include the compute Y/Z harness test fix
Diffstat (limited to 'scripts/build_llvm_mc.ps1')
-rw-r--r--scripts/build_llvm_mc.ps182
1 files changed, 82 insertions, 0 deletions
diff --git a/scripts/build_llvm_mc.ps1 b/scripts/build_llvm_mc.ps1
new file mode 100644
index 000000000..ea72db26f
--- /dev/null
+++ b/scripts/build_llvm_mc.ps1
@@ -0,0 +1,82 @@
1# Builds a native Windows llvm-mc.exe with the AMDGPU target, for the shader disassembler, without WSL.
2# The official Windows LLVM build ships no llvm-mc.exe and no AMDGPU target. This fetches only the LLVM sources the
3# tool needs (sparse, shallow), builds llvm-mc alone with AMDGPU as the only target, keeps llvm-mc.exe (static CRT,
4# so it runs without the VC++ redistributable) and deletes the rest. Needs git, Python 3 and Visual Studio with the
5# C++ x64 tools; uses VS's CMake + Ninja, or the ones on PATH. About 2 GB of temporary space, 20-40 minutes.
6#
7# powershell -ExecutionPolicy Bypass -File scripts\build_llvm_mc.ps1
8# powershell -ExecutionPolicy Bypass -File scripts\build_llvm_mc.ps1 -Dest D:\tools\llvm-mc -NoEnv
9param(
10 [string]$Version = "21.1.8",
11 [string]$Dest = (Join-Path $env:LOCALAPPDATA "Leonida\llvm-mc"),
12 [string]$Temp = (Join-Path $env:TEMP "leonida-llvm-mc"),
13 [switch]$NoEnv, # don't set LLVM_MC for the current user
14 [switch]$Keep # keep the sources and build folder (faster rebuilds)
15)
16$ErrorActionPreference = "Stop"
17
18foreach ($t in "git", "python") {
19 if (-not (Get-Command $t -ErrorAction SilentlyContinue)) { throw "$t wasn't found on PATH." }
20}
21$installer = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer"
22$vs = & "$installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
23if (-not $vs) { throw "Visual Studio with the C++ x64 tools wasn't found." }
24$vcvars = Join-Path $vs "VC\Auxiliary\Build\vcvars64.bat"
25$jobs = [Math]::Max(1, [int]([Environment]::ProcessorCount / 2))
26
27$cmakeDir = Join-Path $vs "Common7\IDE\CommonExtensions\Microsoft\CMake"
28$cmake = Join-Path $cmakeDir "CMake\bin\cmake.exe"
29$ninja = Join-Path $cmakeDir "Ninja\ninja.exe"
30if (-not ((Test-Path $cmake) -and (Test-Path $ninja))) {
31 $cmake = (Get-Command cmake -ErrorAction SilentlyContinue).Source
32 $ninja = (Get-Command ninja -ErrorAction SilentlyContinue).Source
33 if (-not ($cmake -and $ninja)) { throw "CMake and Ninja weren't found (install VS's 'C++ CMake tools' or put them on PATH)." }
34}
35
36$src = Join-Path $Temp "src"
37$out = Join-Path $Temp "build"
38if (-not (Test-Path (Join-Path $src "llvm\CMakeLists.txt"))) {
39 if (Test-Path $src) { Remove-Item -Recurse -Force $src }
40 New-Item -ItemType Directory -Force $Temp | Out-Null
41 & git clone --quiet --depth 1 --branch "llvmorg-$Version" --filter=blob:none --sparse https://github.com/llvm/llvm-project $src
42 if ($LASTEXITCODE -ne 0) { throw "git clone of llvmorg-$Version failed." }
43 & git -C $src sparse-checkout set llvm cmake third-party
44 if ($LASTEXITCODE -ne 0) { throw "git sparse-checkout failed." }
45}
46
47# DIA SDK off: its headers need ATL, which the C++ build tools don't always include, and llvm-mc doesn't use it.
48$body = @"
49"$cmake" -S "$src\llvm" -B "$out" -G Ninja "-DCMAKE_MAKE_PROGRAM=$ninja" -DCMAKE_BUILD_TYPE=Release ^
50 -DLLVM_TARGETS_TO_BUILD=AMDGPU -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DLLVM_ENABLE_DIA_SDK=OFF ^
51 -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_DOCS=OFF ^
52 -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_ZSTD=OFF -DLLVM_ENABLE_LIBXML2=OFF || exit /b 1
53"$cmake" --build "$out" --target llvm-mc -j $jobs || exit /b 1
54"@
55New-Item -ItemType Directory -Force $out | Out-Null
56# A .cmd file avoids cmd.exe's quote stripping on paths with spaces.
57$bat = Join-Path $Temp "_build.cmd"
58"@echo off`r`nset `"PATH=$installer;%PATH%`"`r`ncall `"$vcvars`" >nul || exit /b 1`r`n$body" | Set-Content -Encoding ascii $bat
59
60$p = Start-Process cmd.exe -ArgumentList "/c", "`"$bat`"" -NoNewWindow -PassThru
61$null = $p.Handle # keeps the exit code readable after WaitForExit
62try { $p.PriorityClass = "BelowNormal" } catch {}
63$p.WaitForExit()
64if ($p.ExitCode -ne 0) { throw "build failed ($($p.ExitCode)); the build folder is kept in $out" }
65
66# Same check shader_disasm.py makes before a run: one s_endpgm on the console's GPU.
67$exe = Join-Path $out "bin\llvm-mc.exe"
68# Through a file: a PowerShell pipe can prepend a BOM, which llvm-mc rejects as an invalid token.
69$probeFile = Join-Path $Temp "probe.txt"
70[IO.File]::WriteAllText($probeFile, "0x00 0x00 0x81 0xbf`n")
71$probe = & $exe --disassemble -triple=amdgcn -mcpu=gfx1013 $probeFile
72if ($LASTEXITCODE -ne 0 -or -not ($probe -match "s_endpgm")) { throw "the built llvm-mc didn't disassemble an s_endpgm" }
73
74New-Item -ItemType Directory -Force $Dest | Out-Null
75$final = Join-Path $Dest "llvm-mc.exe"
76Copy-Item -Force $exe $final
77if (-not $Keep) { Remove-Item -Recurse -Force $Temp }
78if (-not $NoEnv) {
79 [Environment]::SetEnvironmentVariable("LLVM_MC", $final, "User")
80 Write-Host "LLVM_MC set for this user (open a new terminal to pick it up)."
81}
82Write-Host "built $final"