Files
punktfunk/scripts/ci/provision-windows-wdk.ps1
enricobuehler b24c10a723
apple / swift (push) Failing after 1s
apple / screenshots (push) Has been skipped
windows-drivers-provision / provision (push) Successful in 1m26s
windows-drivers / probe-and-proto (push) Successful in 16s
windows-drivers / driver-build (push) Successful in 56s
ci / rust (push) Successful in 1m16s
ci / web (push) Successful in 40s
android / android (push) Successful in 3m12s
ci / docs-site (push) Successful in 58s
deb / build-publish (push) Successful in 3m22s
decky / build-publish (push) Successful in 13s
docker / build-push (--build-arg FEDORA_VERSION=44, ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora44-rpm) (push) Successful in 4s
docker / build-push (., web/Dockerfile, punktfunk-web) (push) Successful in 4s
docker / build-push (ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora-rpm) (push) Successful in 4s
docker / build-push (ci, ci/rust-ci.Dockerfile, punktfunk-rust-ci) (push) Successful in 4s
docker / build-push (docs-site, docs-site/Dockerfile, punktfunk-docs) (push) Successful in 3s
ci / bench (push) Successful in 4m44s
rpm / build-publish (bazzite, punktfunk-fedora-rpm) (push) Successful in 8m36s
rpm / build-publish (fedora-44, punktfunk-fedora44-rpm) (push) Successful in 8m24s
docker / deploy-docs (push) Successful in 6s
ci(windows-drivers): LLVM via portable tar.xz + self-provision driver-build
The LLVM NSIS .exe /S silent install HANGS in the headless SYSTEM CI session
(stuck >15min after download, blocking the single runner). Switch to the portable
clang+llvm-21.1.2-x86_64-pc-windows-msvc.tar.xz (curl + Win11 tar -xf, strip 1) —
deterministic, no installer. And make driver-build run the provision script itself
(idempotent) so it self-provisions LLVM and never races a separate provision run.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 09:27:42 +00:00

109 lines
6.8 KiB
PowerShell

# Provision the Windows Driver Kit (WDK) + cargo-wdk on the self-hosted windows-amd64 runner, so the
# all-Rust UMDF drivers (pf-vdisplay + the gamepad drivers, unified on microsoft/windows-drivers-rs)
# can build there. See docs/windows-host-rewrite.md (M0).
#
# The runner already has the base Windows SDK 10.0.26100 (um/ headers) + MSVC + LLVM + Rust, but NOT the
# WDK — no km/ + wdf/ + um/iddcx headers, no inf2cat/stampinf/devgen. wdk-sys's bindgen needs those.
# Idempotent: skips the WDK install if the km/wdf headers are already present, and cargo-wdk if already
# installed. Safe to run repeatedly. Runs non-interactively (/q /norestart) — never auto-reboots.
#
# Invoked by .gitea/workflows/windows-drivers-provision.yml (workflow_dispatch) and referenced by
# scripts/ci/setup-windows-runner.ps1. Run as the runner's account (SYSTEM) with admin rights.
[CmdletBinding()]
param(
# WDK 26100 standalone bootstrapper. Source: https://learn.microsoft.com/windows-hardware/drivers/download-the-wdk
# (bump this when the runner's base SDK version changes; must match an installed Windows SDK version).
[string]$WdkSetupUrl = 'https://download.microsoft.com/download/41fb59c2-1723-45f9-a270-96b73ad58233/KIT_BUNDLE_WDK_MEDIACREATION/wdksetup.exe',
[string]$SdkVersion = '10.0.26100.0'
)
$ErrorActionPreference = 'Stop'
function info($m) { Write-Host "[provision-wdk] $m" }
$kitRoot = 'C:\Program Files (x86)\Windows Kits\10'
$iddcxInc = Join-Path $kitRoot "Include\$SdkVersion\um\iddcx" # iddcx ships ONLY with the WDK -> reliable "installed" signal
$kmDir = Join-Path $kitRoot "Include\$SdkVersion\km" # kernel-mode SDK headers (ntddk/wdm) — also WDK-only
# ---- 1. WDK ---- (iddcx presence is the reliable "WDK installed" signal)
if (Test-Path $iddcxInc) {
info "WDK already present (iddcx headers at $iddcxInc) — skipping install."
} else {
$tmp = Join-Path $env:TEMP 'wdksetup.exe'
info "Downloading WDK bootstrapper -> $tmp"
Invoke-WebRequest -Uri $WdkSetupUrl -OutFile $tmp -UseBasicParsing
info ("downloaded {0:N1} MB" -f ((Get-Item $tmp).Length / 1MB))
info "Installing WDK silently (/q /norestart) — this can take several minutes..."
$p = Start-Process -FilePath $tmp -ArgumentList '/q','/norestart' -Wait -PassThru
info "wdksetup exit code = $($p.ExitCode)"
if ($p.ExitCode -ne 0 -and $p.ExitCode -ne 3010) {
# 3010 = success, reboot required (acceptable for headers/libs/tools; no reboot done).
throw "WDK install failed (exit $($p.ExitCode))"
}
}
# ---- 2. cargo-wdk (the windows-drivers-rs build+package tool: cargo build -> stampinf/inf2cat/signtool) ----
$haveCargoWdk = $false
try { & cargo wdk --version *> $null; if ($LASTEXITCODE -eq 0) { $haveCargoWdk = $true } } catch {}
if ($haveCargoWdk) {
info "cargo-wdk already installed."
} else {
info "Installing cargo-wdk (cargo install --locked cargo-wdk)..."
& cargo install --locked cargo-wdk
if ($LASTEXITCODE -ne 0) { throw "cargo install cargo-wdk failed ($LASTEXITCODE)" }
}
# ---- 2b. LLVM 21.1.2 (libclang for wdk-sys bindgen) ----
# wdk-sys's bindgen layout tests overflow (E0080 on threadlocaleinfostruct etc.) with LLVM ToT / dev
# (22+) builds — the runner's default C:\Program Files\LLVM. The windows-drivers-rs maintainers confirm
# the RELEASED LLVM 21.1.2 builds clean (discussion #591). Install it to a dedicated path so the client
# builds' LLVM is untouched; the driver-build CI job points LIBCLANG_PATH here.
$llvmDir = 'C:\llvm-21'
$libclang = Join-Path $llvmDir 'bin\libclang.dll'
if (Test-Path $libclang) {
info "LLVM 21.1.2 already present ($libclang) — skipping."
} else {
# Use the portable .tar.xz, NOT the NSIS .exe: the .exe /S silent install HANGS in the headless SYSTEM
# CI session (observed stuck >15 min after download, blocking the runner). Win11's bundled tar
# (bsdtar/libarchive) extracts .tar.xz; the tarball has one top-level dir, so --strip-components=1
# lands bin/ at $llvmDir\bin. We only need libclang.dll + the clang resource dir for bindgen.
$url = 'https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.2/clang+llvm-21.1.2-x86_64-pc-windows-msvc.tar.xz'
$tmp = Join-Path $env:TEMP 'llvm-21.1.2-msvc.tar.xz'
info "Downloading LLVM 21.1.2 portable archive (~898 MB) -> $tmp"
& curl.exe -L --fail --retry 3 -o $tmp $url
if ($LASTEXITCODE -ne 0) { throw "LLVM archive download failed ($LASTEXITCODE)" }
info ("downloaded {0:N0} MB; extracting to $llvmDir (tar, strip 1)..." -f ((Get-Item $tmp).Length / 1MB))
New-Item -ItemType Directory -Force -Path $llvmDir | Out-Null
& tar -xf $tmp -C $llvmDir --strip-components=1
if ($LASTEXITCODE -ne 0) { throw "tar extract of LLVM failed ($LASTEXITCODE) — runner tar may lack .xz support" }
if (-not (Test-Path $libclang)) { throw "LLVM extract did not produce $libclang" }
}
# ---- 3. Verify (enumerate the REAL layout; fail only on build-essential absences) ----
Write-Host ""
Write-Host "===== post-provision verification ====="
function found($label, $val) { Write-Host ("{0,-26} {1}" -f $label, $val) }
# WDF UMDF headers live under Include\wdf\umdf\<ver>\ (NOT under the SDK-version dir).
$umdfRoot = Join-Path $kitRoot 'Include\wdf\umdf'
$umdfVers = (Get-ChildItem $umdfRoot -Directory -ErrorAction SilentlyContinue | ForEach-Object { $_.Name }) -join ','
$umdfHdr = Get-ChildItem -Path $umdfRoot -Filter 'wdf.h' -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
$iddcxVers = (Get-ChildItem $iddcxInc -Directory -ErrorAction SilentlyContinue | ForEach-Object { $_.Name }) -join ','
found 'Include\wdf\umdf vers' "[$umdfVers]"
found 'wdf.h' ($(if ($umdfHdr) { $umdfHdr } else { 'MISSING' }))
found 'km SDK headers' ($(if (Test-Path $kmDir) { $kmDir } else { 'MISSING' }))
found 'um/iddcx versions' "[$iddcxVers]"
foreach ($t in 'inf2cat.exe','stampinf.exe','signtool.exe','makecat.exe','InfVerif.exe') {
$hit = Get-ChildItem -Path $kitRoot -Filter $t -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
found $t ($(if ($hit) { $hit } else { 'MISSING' }))
}
try { $cw = (& cargo wdk --version 2>&1) -join ' ' } catch { $cw = '' }
found 'cargo-wdk' $cw
found 'LLVM 21.1.2 libclang' ($(if (Test-Path $libclang) { $libclang } else { 'MISSING' }))
# Block only on the genuinely build-essential pieces (headers + iddcx + cargo-wdk + the pinned libclang).
# inf2cat arch quirks are non-fatal — cargo-wdk locates the WDK tools itself.
$essential = ($null -ne $umdfHdr) -and (Test-Path $kmDir) -and ($iddcxVers -ne '') -and ($cw -match 'wdk') -and (Test-Path $libclang)
if (-not $essential) { throw "provisioning incomplete: need wdf.h + km headers + iddcx + cargo-wdk + LLVM 21.1.2 (see above)" }
info "WDK + cargo-wdk + LLVM 21.1.2 provisioned OK. Driver builds pin Version_Number=$SdkVersion + LIBCLANG_PATH=$llvmDir\bin."