]>
| Commit | Line | Data |
|---|---|---|
| 3c096107 MV |
1 | #Requires -RunAsAdministrator\r |
| 2 | <#\r | |
| 3 | setup-windows-with-uac.ps1\r | |
| 452f525c | 4 | Elevated portion of the Windows provisioning. Invoked by setup-windows.bat\r |
| 3c096107 MV |
5 | via Start-Process -Verb RunAs, or run manually from an Administrator prompt.\r |
| 6 | \r | |
| 7 | What this installs / configures:\r | |
| b8144088 MV |
8 | - OpenSSH Client capability (the ssh.exe rsync shells out to, and the\r |
| 9 | System32 libcrypto.dll the release's own ssh.exe links against)\r | |
| 3c096107 | 10 | - ssh-agent set to automatic + started\r |
| 452f525c | 11 | - OpenSSH Server (sshd) capability: automatic + started + inbound TCP 22\r |
| b8144088 MV |
12 | - rsync for Windows (nuket/rsync-windows) in C:\Tools\rsync, on the machine\r |
| 13 | PATH: rsync.exe plus the ssh.exe it runs, out of the release zip for this\r | |
| f51da37a MV |
14 | architecture - x86, x64 and arm64 are all published, so both binaries are\r |
| 15 | native everywhere. The ssh.exe is kept only if it actually starts.\r | |
| 649b04df | 16 | - Visual Studio Community (C++ desktop workload, x86/x64 AND ARM64 build\r |
| 7840e3c2 MV |
17 | tools, Spectre libs, Win11 SDK 26100, and - on x64 only - the WDK VSIX,\r |
| 18 | Clang/LLVM, and the v141 + Windows XP targeting toolset). VS 2022 on x64,\r | |
| 19 | VS 2026 on ARM64; see $VsChannel.\r | |
| 20 | - Windows Driver Kit 10.0.26100 (x64 only)\r | |
| 99725a30 MV |
21 | - Windows Performance Toolkit - xperf, wpr and Windows Performance Analyzer\r |
| 22 | (wpa.exe) - on the machine PATH\r | |
| 3c096107 | 23 | \r |
| 649b04df MV |
24 | Change $VsEdition below to Professional or Enterprise if needed. $VsChannel\r |
| 25 | picks the Visual Studio generation and is architecture-split by default:\r | |
| 26 | 17 (VS 2022) on x64, where the v141 / Windows XP toolset is wanted, and\r | |
| 27 | 18 (VS 2026) on ARM64, where that toolset cannot exist anyway.\r | |
| 28 | \r | |
| 29 | ARCHITECTURE. Runs on x64 and on ARM64 (Windows 11 on Arm). On ARM64 the\r | |
| 7840e3c2 MV |
30 | Visual Studio installer and MSVC are native ARM64 and cross-compile\r |
| 31 | ARM64/x64/x86 targets.\r | |
| 32 | \r | |
| 33 | The two architectures deliberately provision DIFFERENT things. x64 is the full\r | |
| 34 | workstation; ARM64 is a constrained VM set up as a single-compiler build box -\r | |
| 35 | MSVC only, with clang-cl and the WDK dropped there. Neither is dropped for lack\r | |
| 36 | of an ARM64 build; see the comments on $ClangComponents and the WDK step.\r | |
| 37 | What changes is called out at each step, and $HostArch below is what drives it.\r | |
| 3c096107 MV |
38 | #>\r |
| 39 | \r | |
| 40 | $ErrorActionPreference = 'Stop'\r | |
| 41 | \r | |
| 649b04df MV |
42 | # ---------------------------------------------------------------------------\r |
| 43 | # Host architecture\r | |
| 44 | #\r | |
| 7840e3c2 MV |
45 | # Read from the machine environment in the registry, because this script can be\r |
| 46 | # launched by a 32-bit or an emulated x64 PowerShell and BOTH of the obvious\r | |
| 47 | # sources report the emulated architecture in that case. Measured on this box,\r | |
| 48 | # from the x64 PowerShell an x64 shell resolves to:\r | |
| 49 | # [RuntimeInformation]::OSArchitecture X64 <- wrong\r | |
| 50 | # $env:PROCESSOR_ARCHITECTURE AMD64 <- wrong\r | |
| 51 | # HKLM\...\Session Manager\Environment ARM64 <- right\r | |
| 52 | # OSArchitecture is documented as the OS's architecture, and on .NET Core it is;\r | |
| 53 | # under .NET Framework on Prism it is not, so it is kept only as a fallback.\r | |
| 649b04df MV |
54 | #\r |
| 55 | # $IsArm64 gates:\r | |
| f51da37a | 56 | # - which rsync-windows release zip is fetched (x86 / x64 / arm64, all native)\r |
| 649b04df | 57 | # - which Visual Studio generation is driven ($VsChannel: 18 on Arm, 17 on x64)\r |
| 7840e3c2 MV |
58 | # - the Visual Studio component groups: ARM64 build tools in; the v141/XP\r |
| 59 | # toolset out because it has no ARM64-hosted compiler and Microsoft does not\r | |
| 60 | # ship Windows XP targeting for Arm hosts; Clang/LLVM and the WDK VSIX out by\r | |
| 61 | # policy rather than by limitation - both are available and native on Arm\r | |
| 62 | # - whether the Windows Driver Kit is installed at all\r | |
| 649b04df MV |
63 | # - what the VTune and WPT steps report\r |
| 64 | # ---------------------------------------------------------------------------\r | |
| 7840e3c2 MV |
65 | $rawArch = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -ErrorAction SilentlyContinue).PROCESSOR_ARCHITECTURE\r |
| 66 | if (-not $rawArch) { $rawArch = [Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString() }\r | |
| 67 | $IsArm64 = ($rawArch -eq 'ARM64')\r | |
| 68 | $HostArch = if ($IsArm64) { 'Arm64' } elseif ($rawArch -eq 'AMD64') { 'X64' } else { $rawArch }\r | |
| 649b04df | 69 | \r |
| 3c096107 MV |
70 | function Write-Step([string]$Msg) {\r |
| 71 | Write-Host "`n==> $Msg" -ForegroundColor Cyan\r | |
| 72 | }\r | |
| 73 | \r | |
| 74 | function Assert-ExitCode([int]$Code, [string]$Step) {\r | |
| 75 | # 0 = success, 3010 = success + reboot required\r | |
| 76 | if ($Code -notin @(0, 3010)) {\r | |
| 77 | throw "$Step failed with exit code $Code"\r | |
| 78 | }\r | |
| 79 | if ($Code -eq 3010) {\r | |
| 80 | Write-Host " [reboot required after $Step]" -ForegroundColor Yellow\r | |
| 81 | }\r | |
| 82 | }\r | |
| 83 | \r | |
| 84 | function Show-VsSetupLogs {\r | |
| 85 | # The VS Installer writes dd_*.log to the invoking user's %TEMP%. Because\r | |
| 86 | # this script runs elevated, that %TEMP% belongs to the elevated user and is\r | |
| 87 | # readable here even when it is NOT readable by the non-elevated caller. Fold\r | |
| 88 | # only the NEWEST installer + bootstrapper log into the transcript (the setup\r | |
| 89 | # engine log is where per-component / product errors actually appear) and\r | |
| 90 | # keep it short so the transcript stays readable.\r | |
| 91 | Write-Host "`n==> Collecting VS Installer logs from $env:TEMP" -ForegroundColor Cyan\r | |
| 92 | $recent = Get-ChildItem $env:TEMP -Filter 'dd_*.log' -ErrorAction SilentlyContinue |\r | |
| 93 | Where-Object { $_.LastWriteTime -gt (Get-Date).AddMinutes(-15) }\r | |
| 94 | $picks = @()\r | |
| 95 | $picks += $recent | Where-Object { $_.Name -like 'dd_installer_*' } | Sort-Object LastWriteTime | Select-Object -Last 1\r | |
| 96 | $picks += $recent | Where-Object { $_.Name -like 'dd_bootstrapper_*' } | Sort-Object LastWriteTime | Select-Object -Last 1\r | |
| 97 | $picks = $picks | Where-Object { $_ }\r | |
| 98 | if (-not $picks) {\r | |
| 99 | Write-Host ' (no VS Installer logs modified in the last 15 minutes)' -ForegroundColor Yellow\r | |
| 100 | return\r | |
| 101 | }\r | |
| 102 | foreach ($l in $picks) {\r | |
| 103 | Write-Host "`n----- $($l.Name) (tail) -----" -ForegroundColor Yellow\r | |
| 104 | Get-Content $l.FullName -Tail 40\r | |
| 105 | }\r | |
| 106 | }\r | |
| 107 | \r | |
| 649b04df MV |
108 | function Get-VsInstallPath {\r |
| 109 | # The install path of a Visual Studio matching $script:VsChannel, or $null.\r | |
| 110 | #\r | |
| 111 | # -version is the point. A bare `vswhere -products *` returns EVERY Visual\r | |
| 112 | # Studio on the box, newest first, and handing that path to a bootstrapper of\r | |
| 113 | # a different generation is not a no-op: `vs_community.exe` (17.x) told to\r | |
| 114 | # `modify --installPath <a VS 2026 install>` is a 17.x engine pointed at an\r | |
| 115 | # 18.x product. On a box that already has VS 2026 - increasingly the default -\r | |
| 116 | # every pass below would target the wrong install. Scope the query to the\r | |
| 117 | # generation this script is actually driving.\r | |
| 118 | if (-not (Test-Path $script:VsWhere)) { return $null }\r | |
| 119 | $range = "[$script:VsChannel.0,$($script:VsChannel + 1).0)"\r | |
| 120 | & $script:VsWhere -products '*' -version $range -property installationPath -format value |\r | |
| 121 | Select-Object -First 1\r | |
| 122 | }\r | |
| 123 | \r | |
| 3c096107 MV |
124 | function Invoke-VsModify {\r |
| 125 | # Run one VS install/modify pass for a named group of components. Splitting\r | |
| 126 | # the install into separate passes makes it obvious WHICH group fails: each\r | |
| 127 | # call prints its label and exit code before Assert-ExitCode throws.\r | |
| 649b04df MV |
128 | #\r |
| 129 | # -Optional downgrades a failure to a warning. Used for groups that are not\r | |
| 130 | # available on every host architecture (the v141/XP toolset on ARM64) or that\r | |
| 131 | # the rest of the box does not depend on, so one unavailable component cannot\r | |
| 132 | # cost you the toolchain.\r | |
| 3c096107 MV |
133 | param(\r |
| 134 | [string] $Label,\r | |
| 649b04df MV |
135 | [string[]] $Ids,\r |
| 136 | [switch] $Optional\r | |
| 3c096107 | 137 | )\r |
| 649b04df MV |
138 | Write-Step "Visual Studio: $Label"\r |
| 139 | if (-not $Ids) {\r | |
| 140 | Write-Host ' (no components in this group for this architecture - skipping)' -ForegroundColor DarkGray\r | |
| 141 | return\r | |
| 142 | }\r | |
| 3c096107 MV |
143 | $addStr = ($Ids | ForEach-Object { "--add $_" }) -join ' '\r |
| 144 | # --installPath must be quoted: it contains spaces ("C:\Program Files\...").\r | |
| 145 | # Windows PowerShell 5.1's Start-Process does not quote array elements, so we\r | |
| 146 | # hand-build a single string. Component IDs / flags have no spaces.\r | |
| 147 | $common = '--includeRecommended --quiet --norestart --wait'\r | |
| 148 | if ($script:InstallPath) {\r | |
| 149 | $argString = "modify --installPath `"$script:InstallPath`" $addStr $common --force"\r | |
| 150 | } else {\r | |
| 151 | # No existing install yet -> this first pass performs the base install.\r | |
| 152 | $argString = "$addStr $common"\r | |
| 153 | }\r | |
| 154 | Write-Host " > $script:VsBootstrapper $argString" -ForegroundColor DarkGray\r | |
| 155 | $p = Start-Process -FilePath $script:VsBootstrapper -ArgumentList $argString -Wait -PassThru -NoNewWindow\r | |
| 156 | Write-Host " exit code: $($p.ExitCode)"\r | |
| 649b04df MV |
157 | if ($Optional -and $p.ExitCode -notin @(0, 3010)) {\r |
| 158 | Write-Warning "Visual Studio ($Label) failed with exit code $($p.ExitCode); continuing (this group is optional)."\r | |
| 159 | } else {\r | |
| 160 | Assert-ExitCode $p.ExitCode "Visual Studio ($Label)"\r | |
| 161 | }\r | |
| 3c096107 MV |
162 | \r |
| 163 | # After the first (fresh) install, re-detect the install path so subsequent\r | |
| 164 | # passes use `modify`.\r | |
| 649b04df | 165 | if (-not $script:InstallPath) { $script:InstallPath = Get-VsInstallPath }\r |
| 3c096107 MV |
166 | }\r |
| 167 | \r | |
| 168 | # ---------------------------------------------------------------------------\r | |
| 169 | # This runs in a separate elevated window that closes the moment it exits, so\r | |
| 170 | # the non-elevated caller (setup-windows.bat) can't see what happened. Mirror\r | |
| 171 | # all output to a log next to the script and exit with a real code so the\r | |
| 172 | # caller can detect success/failure and show the log.\r | |
| 173 | # ---------------------------------------------------------------------------\r | |
| 174 | $LogFile = Join-Path $PSScriptRoot 'setup-windows-uac.log'\r | |
| 175 | $ExitCode = 0\r | |
| 176 | try { Start-Transcript -Path $LogFile -Force | Out-Null } catch {}\r | |
| 177 | \r | |
| 178 | try {\r | |
| 179 | \r | |
| 649b04df MV |
180 | Write-Step "Host architecture: $HostArch"\r |
| 181 | if ($IsArm64) {\r | |
| 182 | # x64 emulation ("Prism") is what carries every x64-only tool this script\r | |
| 183 | # installs - rsync.exe, the WDK and ADK installers, BinSkim in the\r | |
| 184 | # non-elevated half. It is present on Windows 11 on Arm and absent on\r | |
| 185 | # Windows 10 on Arm (x86-only there) and on some Server images, so check\r | |
| 186 | # rather than assume: without it those steps install binaries that cannot\r | |
| 187 | # start, and the failure would otherwise surface much later.\r | |
| 188 | $Prism = Join-Path $env:WINDIR 'System32\xtajit64.dll'\r | |
| 189 | if (Test-Path $Prism) {\r | |
| 190 | Write-Host ' x64 emulation (Prism) present - x64-only tools will run.' -ForegroundColor Green\r | |
| 191 | } else {\r | |
| 192 | Write-Warning "x64 emulation not found ($Prism is missing). rsync.exe, the WDK/ADK installers and BinSkim have no ARM64 build and will not run on this box."\r | |
| 193 | }\r | |
| 194 | }\r | |
| 195 | \r | |
| 3c096107 MV |
196 | # ---------------------------------------------------------------------------\r |
| 197 | # Base tools via winget\r | |
| 198 | # ---------------------------------------------------------------------------\r | |
| b8144088 MV |
199 | \r |
| 200 | # ---------------------------------------------------------------------------\r | |
| 201 | # OpenSSH Client\r | |
| 202 | #\r | |
| 203 | # Present by default on Windows 10 1809+ / Windows 11, but removable, and absent\r | |
| 204 | # from some Server images. Two things below want it: rsync does not speak ssh\r | |
| 205 | # itself, it execs an ssh binary, and the release's own ssh.exe links against the\r | |
| 206 | # libcrypto.dll this capability puts in System32. It also owns the ssh-agent\r | |
| 207 | # service configured next, so a missing client is why that step would fail.\r | |
| 208 | #\r | |
| 209 | # Non-fatal, like the server half below: a box that cannot have it should still\r | |
| 210 | # finish provisioning.\r | |
| 211 | # ---------------------------------------------------------------------------\r | |
| 212 | Write-Step 'OpenSSH Client'\r | |
| 213 | try {\r | |
| 214 | $sshc = Get-WindowsCapability -Online -Name 'OpenSSH.Client*' |\r | |
| 215 | Select-Object -First 1\r | |
| 216 | if (-not $sshc) {\r | |
| 217 | Write-Warning 'OpenSSH.Client capability not offered by this Windows image - skipping.'\r | |
| 218 | } elseif ($sshc.State -eq 'Installed') {\r | |
| 219 | Write-Host " OK: $($sshc.Name) already installed"\r | |
| 220 | } else {\r | |
| 221 | Write-Host " Installing $($sshc.Name) ..."\r | |
| 222 | $r = Add-WindowsCapability -Online -Name $sshc.Name\r | |
| 223 | if ($r.RestartNeeded) { Write-Host ' [reboot required after OpenSSH Client]' -ForegroundColor Yellow }\r | |
| 224 | }\r | |
| 225 | } catch {\r | |
| 226 | Write-Warning "OpenSSH Client setup failed: $($_.Exception.Message)"\r | |
| 227 | }\r | |
| 228 | \r | |
| 3c096107 MV |
229 | # ---------------------------------------------------------------------------\r |
| 230 | # SSH agent\r | |
| 231 | # ---------------------------------------------------------------------------\r | |
| 232 | Write-Step 'Enabling ssh-agent'\r | |
| 233 | Set-Service -Name ssh-agent -StartupType Automatic\r | |
| 234 | if ((Get-Service ssh-agent).Status -ne 'Running') { Start-Service ssh-agent }\r | |
| 235 | \r | |
| 452f525c MV |
236 | # ---------------------------------------------------------------------------\r |
| 237 | # OpenSSH Server (sshd)\r | |
| 238 | #\r | |
| 239 | # Used to reach the test VMs (VirtualBox) from the host: remote shell plus the\r | |
| 240 | # transport rsync rides on when seeding test data in. Ships with Windows 10\r | |
| 241 | # 1809+ / Windows 11 as an on-demand capability, so no third-party install.\r | |
| 242 | #\r | |
| 243 | # The capability normally adds the "OpenSSH Server (sshd)" inbound firewall\r | |
| 244 | # rule; we verify and create it if missing (it is absent on some images).\r | |
| 245 | #\r | |
| 246 | # Non-fatal: a box that can't run sshd should still finish provisioning.\r | |
| 247 | # ---------------------------------------------------------------------------\r | |
| 248 | Write-Step 'OpenSSH Server (sshd)'\r | |
| 249 | try {\r | |
| 250 | $sshd = Get-WindowsCapability -Online -Name 'OpenSSH.Server*' |\r | |
| 251 | Select-Object -First 1\r | |
| 252 | if (-not $sshd) {\r | |
| 253 | Write-Warning 'OpenSSH.Server capability not offered by this Windows image - skipping.'\r | |
| 254 | } else {\r | |
| 255 | if ($sshd.State -ne 'Installed') {\r | |
| 256 | Write-Host " Installing $($sshd.Name) ..."\r | |
| 257 | $r = Add-WindowsCapability -Online -Name $sshd.Name\r | |
| 258 | if ($r.RestartNeeded) { Write-Host ' [reboot required after OpenSSH Server]' -ForegroundColor Yellow }\r | |
| 259 | } else {\r | |
| 260 | Write-Host " OK: $($sshd.Name) already installed"\r | |
| 261 | }\r | |
| 262 | \r | |
| 263 | Set-Service -Name sshd -StartupType Automatic\r | |
| 264 | if ((Get-Service sshd).Status -ne 'Running') { Start-Service sshd }\r | |
| 265 | Write-Host ' sshd: Automatic + running'\r | |
| 266 | \r | |
| 267 | # Firewall: allow inbound 22 on all profiles. VirtualBox host-only and\r | |
| 268 | # bridged adapters are frequently classified Public, and the capability's\r | |
| 269 | # own rule is Private-only on some images, which is what leaves a plainly\r | |
| 270 | # running sshd plainly unreachable.\r | |
| 271 | #\r | |
| 272 | # OpenSSH-Server-In-TCP is the name the capability itself uses, so this\r | |
| 273 | # WIDENS that rule rather than adding a second one next to it. Creating\r | |
| 274 | # our own under a different name would leave the narrow rule in place and\r | |
| 275 | # the box still unreachable on a Public-classified adapter; creating one\r | |
| 276 | # under the same name would collide. Adopt it if present, create it if not.\r | |
| 277 | $ruleName = 'OpenSSH-Server-In-TCP'\r | |
| 278 | if (Get-NetFirewallRule -Name $ruleName -ErrorAction SilentlyContinue) {\r | |
| 279 | Set-NetFirewallRule -Name $ruleName -Enabled True -Profile Any\r | |
| 280 | Write-Host " Widened firewall rule $ruleName to all profiles"\r | |
| 281 | } else {\r | |
| 282 | New-NetFirewallRule -Name $ruleName -DisplayName 'OpenSSH SSH Server (sshd)' `\r | |
| 283 | -Enabled True -Direction Inbound -Protocol TCP -Action Allow `\r | |
| 284 | -LocalPort 22 -Profile Any | Out-Null\r | |
| 285 | Write-Host " Added firewall rule $ruleName (TCP 22, all profiles)"\r | |
| 286 | }\r | |
| 287 | }\r | |
| 288 | } catch {\r | |
| 289 | Write-Warning "OpenSSH Server setup failed: $($_.Exception.Message)"\r | |
| 290 | }\r | |
| 291 | \r | |
| 292 | # ---------------------------------------------------------------------------\r | |
| 293 | # rsync for Windows (github.com/nuket/rsync-windows)\r | |
| 294 | #\r | |
| 295 | # Windows' OpenSSH ships the transport only - no rsync - so pushing test data\r | |
| 296 | # from a Linux box needs an rsync.exe on the Windows side.\r | |
| 297 | #\r | |
| b8144088 MV |
298 | # The release is one zip per architecture - rsync-windows-x64.zip and\r |
| 299 | # rsync-windows-x86.zip - each holding rsync.exe, the ssh.exe it runs, and the\r | |
| 300 | # licence texts under exactly those names. Both exes are installed, together:\r | |
| 301 | # rsync.exe prefers an ssh.exe in its own directory, and the release's build is\r | |
| 302 | # what makes a push FROM this box run at line rate. The ssh.exe Windows ships\r | |
| 303 | # reads its stdin 3KB at a time, which holds a send at ~17MB/s however fast the\r | |
| 304 | # link is. Nothing else about it differs - same ~/.ssh, same ssh-agent, same\r | |
| 305 | # known_hosts - and a bare `ssh` still resolves to the in-box client, which sits\r | |
| 306 | # ahead of C:\Tools\rsync on the machine PATH.\r | |
| 307 | #\r | |
| 308 | # That ssh.exe links against the libcrypto.dll the OpenSSH Client capability\r | |
| 309 | # above puts in System32: Windows' own LibreSSL, and the fast one, since it uses\r | |
| 310 | # AES-NI. No copy of it ships in the zip, so where the capability is missing we\r | |
| 311 | # unpack rsync alone rather than an ssh.exe that will not start.\r | |
| 312 | #\r | |
| 452f525c MV |
313 | # Installed to C:\Tools\rsync (NOT under "Program Files"): the remote end is\r |
| 314 | # invoked as `rsync --server ...` through cmd.exe, and a path with spaces makes\r | |
| 315 | # the client-side --rsync-path escape hatch painful to quote. Added to the\r | |
| 316 | # MACHINE PATH so it resolves for every account, including the non-interactive\r | |
| 317 | # sshd session, which builds its environment from the machine + user registry\r | |
| 318 | # PATH rather than from a login shell.\r | |
| 319 | #\r | |
| 320 | # Non-fatal: a download failure only warns.\r | |
| 321 | # ---------------------------------------------------------------------------\r | |
| 322 | Write-Step 'rsync for Windows'\r | |
| b8144088 | 323 | $RsyncRepo = 'nuket/rsync-windows'\r |
| f51da37a MV |
324 | # The release publishes x86, x64 and - since v3.5.0-gdeeda96f - arm64, so every\r |
| 325 | # architecture this script runs on gets a native build. ARM64 used to take the\r | |
| 326 | # x64 zip under emulation, which was defensible (a transfer is bound by the\r | |
| 327 | # socket, not by emulated CPU) but cost the release's ssh.exe: that x64 binary\r | |
| 328 | # could not load the ARM64 libcrypto.dll in System32 and had to be deleted on\r | |
| 329 | # every run. The arm64 asset ships an ARM64 rsync.exe AND an ARM64 ssh.exe, so\r | |
| 330 | # both halves are now native and the fast client survives.\r | |
| 331 | #\r | |
| 332 | # Selected off $HostArch rather than Is64BitOperatingSystem, which answers "true"\r | |
| 333 | # on ARM64 and so cannot tell the two 64-bit cases apart.\r | |
| 649b04df MV |
334 | $RsyncAsset = switch ($HostArch) {\r |
| 335 | 'X64' { 'rsync-windows-x64.zip' }\r | |
| f51da37a | 336 | 'Arm64' { 'rsync-windows-arm64.zip' }\r |
| 649b04df MV |
337 | default { 'rsync-windows-x86.zip' }\r |
| 338 | }\r | |
| 339 | if ($IsArm64) {\r | |
| f51da37a | 340 | Write-Host ' ARM64: using the native arm64 asset (rsync.exe and ssh.exe both ARM64).' -ForegroundColor Green\r |
| 649b04df | 341 | }\r |
| b8144088 MV |
342 | # The /releases/latest/download/ redirect rather than the API: unauthenticated\r |
| 343 | # API calls are rate-limited to 60/hour per IP, which a provisioning run behind a\r | |
| 344 | # shared NAT can genuinely exhaust, and the redirect costs none of that budget.\r | |
| 345 | # To hold a box on a known build, pin the tag instead:\r | |
| 346 | # .../releases/download/v3.5.0-gABCDEF0/$RsyncAsset\r | |
| 347 | $RsyncUrl = "https://github.com/$RsyncRepo/releases/latest/download/$RsyncAsset"\r | |
| 348 | $RsyncDir = 'C:\Tools\rsync'\r | |
| 452f525c MV |
349 | try {\r |
| 350 | New-Item -ItemType Directory -Force -Path $RsyncDir | Out-Null\r | |
| 351 | $RsyncExe = Join-Path $RsyncDir 'rsync.exe'\r | |
| b8144088 MV |
352 | \r |
| 353 | # Does the release's ssh.exe have the libcrypto it needs? Decided before the\r | |
| 649b04df MV |
354 | # download so the answer can also gate what comes out of the zip. This is a\r |
| 355 | # cheap pre-filter only - the authoritative check is running the thing, which\r | |
| 356 | # happens after the unpack below.\r | |
| b8144088 MV |
357 | $SysCrypto = Join-Path $env:WINDIR 'System32\libcrypto.dll'\r |
| 358 | $WantSsh = Test-Path $SysCrypto\r | |
| 359 | if (-not $WantSsh) {\r | |
| 360 | Write-Warning "$SysCrypto is missing - the OpenSSH Client capability is not installed - and the release's ssh.exe needs it. Installing rsync.exe only; rsync will use the ssh on the PATH."\r | |
| 361 | } else {\r | |
| 362 | $v = (Get-Item $SysCrypto).VersionInfo.FileVersion\r | |
| 363 | if ($v -and ([version]($v -replace '[^0-9.]', '')) -lt [version]'3.8.2') {\r | |
| 364 | Write-Warning "$SysCrypto is LibreSSL $v; the release's ssh.exe is built against 3.8.2 (Windows OpenSSH Client 9.5). Update Windows, or expect ssh.exe not to start."\r | |
| 365 | }\r | |
| f51da37a MV |
366 | # No architecture special-case here any more: the asset chosen above\r |
| 367 | # matches the host, so the release's ssh.exe and System32's libcrypto.dll\r | |
| 368 | # are the same architecture on every box. The run-it check below still\r | |
| 369 | # happens on all of them - it is cheap, and it is what caught the ARM64\r | |
| 370 | # mismatch back when this took the x64 zip.\r | |
| b8144088 MV |
371 | }\r |
| 372 | \r | |
| 373 | # Download and unpack beside the targets, not over them, so an interrupted\r | |
| 374 | # transfer can't leave a truncated rsync.exe sitting on the PATH. The scratch\r | |
| 375 | # name still has to END in .zip: Windows PowerShell 5.1's Expand-Archive\r | |
| 376 | # refuses any other extension outright ("*.download is not a supported\r | |
| 377 | # archive file format"), where PowerShell 7 just reads the file.\r | |
| 452f525c | 378 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\r |
| b8144088 MV |
379 | $tmpZip = Join-Path $RsyncDir "download-$RsyncAsset"\r |
| 380 | Invoke-WebRequest -Uri $RsyncUrl -OutFile $tmpZip -UseBasicParsing\r | |
| 381 | Write-Host " Downloaded $RsyncAsset ($([math]::Round((Get-Item $tmpZip).Length / 1MB, 2)) MB)"\r | |
| 382 | \r | |
| 383 | # Verify against the .sha256 published beside it. Same origin, so this is an\r | |
| 384 | # integrity check on the transfer rather than a defence against a hostile\r | |
| 385 | # release - but a truncated or proxy-mangled download is the failure that\r | |
| 386 | # actually happens, and it fails here instead of mid-transfer later.\r | |
| 387 | #\r | |
| 388 | # -OutFile, not .Content: GitHub serves the .sha256 as\r | |
| 389 | # application/octet-stream, and Invoke-WebRequest hands back a byte[] rather\r | |
| 390 | # than a string for any non-text content type, so .Content would compare the\r | |
| 391 | # first BYTE against the hash and fail on every correct download.\r | |
| 392 | $tmpSha = "$tmpZip.sha256"\r | |
| 393 | Invoke-WebRequest -Uri "$RsyncUrl.sha256" -OutFile $tmpSha -UseBasicParsing\r | |
| 394 | $want = (((Get-Content $tmpSha -Raw) -split '\s+')[0]).Trim().ToLower()\r | |
| 395 | Remove-Item $tmpSha -Force -ErrorAction SilentlyContinue\r | |
| 396 | $got = (Get-FileHash $tmpZip -Algorithm SHA256).Hash.ToLower()\r | |
| 397 | if ($want -and $want -ne $got) {\r | |
| 398 | Remove-Item $tmpZip -Force\r | |
| 399 | throw "SHA-256 mismatch for ${RsyncAsset}: expected $want, got $got"\r | |
| 400 | }\r | |
| 401 | Write-Host " SHA-256 verified: $got"\r | |
| 402 | \r | |
| 403 | # Unpack to a scratch directory and move out the files we asked for, rather\r | |
| 404 | # than expanding straight over the install directory: the zip is the unit\r | |
| 405 | # that was checksummed, and this way a future release adding something to it\r | |
| 406 | # cannot quietly drop that something onto the machine PATH.\r | |
| 407 | $unpack = Join-Path $RsyncDir '.unpack'\r | |
| 408 | if (Test-Path $unpack) { Remove-Item -Recurse -Force $unpack }\r | |
| 409 | Expand-Archive -Path $tmpZip -DestinationPath $unpack -Force\r | |
| 410 | Remove-Item $tmpZip -Force\r | |
| 411 | foreach ($f in 'rsync.exe', 'ssh.exe', 'COPYING.txt', 'NOTICE-ssh.txt') {\r | |
| 412 | $src = Join-Path $unpack $f\r | |
| 413 | if (-not (Test-Path $src)) { continue }\r | |
| 414 | if ($f -eq 'ssh.exe' -and -not $WantSsh) { continue }\r | |
| 415 | Move-Item -Path $src -Destination (Join-Path $RsyncDir $f) -Force\r | |
| 416 | }\r | |
| 417 | Remove-Item -Recurse -Force $unpack\r | |
| 649b04df MV |
418 | \r |
| 419 | # Prove the unpacked ssh.exe actually starts, and DELETE it if it does not.\r | |
| 420 | #\r | |
| 421 | # This matters more than it looks. rsync.exe prefers an ssh.exe sitting in its\r | |
| 422 | # own directory, so a present-but-unstartable one does not degrade to the\r | |
| 423 | # in-box client - it breaks rsync outright, and the error you get is a remote\r | |
| f51da37a MV |
424 | # shell that died rather than anything naming ssh.exe. The way to land there\r |
| 425 | # is a missing or too-old System32 libcrypto.dll. Removing it is the repair:\r | |
| 426 | # rsync then falls back to the ssh on the PATH, which is the in-box client.\r | |
| 427 | #\r | |
| 428 | # This also used to fire on every ARM64 run, when the x64 asset was the only\r | |
| 429 | # 64-bit one published and its ssh.exe could not load the ARM64 libcrypto\r | |
| 430 | # (exit 0xC0000135, STATUS_DLL_NOT_FOUND). The arm64 asset fixed that at the\r | |
| 431 | # source; the check stays because it is how that was found in the first place.\r | |
| 649b04df MV |
432 | #\r |
| 433 | # EAP back to Continue for the call: ssh -V writes its version to STDERR, and\r | |
| 434 | # under $ErrorActionPreference = 'Stop' a native command's stderr becomes a\r | |
| 435 | # terminating error, so a WORKING client would look like a broken one.\r | |
| 436 | # $global:LASTEXITCODE is cleared first because an exe that cannot start at\r | |
| 437 | # all throws without setting one, and the stale 0 from the previous native\r | |
| 438 | # command would otherwise read as success.\r | |
| 4658d6dd MV |
439 | #\r |
| 440 | # DRAIN THE OUTPUT BEFORE READING $LASTEXITCODE. `... | Select-Object -First 1`\r | |
| 441 | # was the original spelling here, and it is a trap: Select-Object stops the\r | |
| 442 | # pipeline the instant it has its one object, and that is when ssh.exe has\r | |
| 443 | # WRITTEN its banner - not when it has exited. PowerShell then tears the\r | |
| 444 | # pipeline down, kills the still-running process, and reports -1. Measured on a\r | |
| 445 | # healthy binary on an x64 box: 24 of 25 runs reported exit -1 through\r | |
| 446 | # Select-Object, and 25 of 25 reported 0 when the output was collected first.\r | |
| 447 | #\r | |
| 448 | # So this check was deleting a perfectly good ssh.exe on almost every run, on\r | |
| 449 | # every architecture, and the resulting fallback to the in-box client - the\r | |
| 450 | # ~17MB/s one this whole step exists to avoid - looked like a property of the\r | |
| 451 | # release rather than a bug in the test. Collect, THEN take the first line.\r | |
| 649b04df MV |
452 | $SshExe = Join-Path $RsyncDir 'ssh.exe'\r |
| 453 | if ($WantSsh -and (Test-Path $SshExe)) {\r | |
| 454 | $prevEap = $ErrorActionPreference\r | |
| 455 | $ErrorActionPreference = 'Continue'\r | |
| 456 | $global:LASTEXITCODE = $null\r | |
| 457 | $sshVer = $null\r | |
| 4658d6dd | 458 | try { $sshOut = (& $SshExe -V 2>&1); $sshVer = $sshOut | Select-Object -First 1 } catch { }\r |
| 649b04df MV |
459 | finally { $ErrorActionPreference = $prevEap }\r |
| 460 | if ($LASTEXITCODE -eq 0) {\r | |
| 461 | Write-Host " ssh.exe runs: $sshVer"\r | |
| 462 | } else {\r | |
| 463 | $why = if ($null -eq $LASTEXITCODE) { 'it would not start' } else { "exit $LASTEXITCODE" }\r | |
| 464 | Write-Warning "The release's ssh.exe does not run here ($why)$(if ($sshVer) { ": $sshVer" }). Removing it so rsync.exe falls back to the ssh on the PATH instead of failing on it."\r | |
| 465 | Remove-Item $SshExe -Force -ErrorAction SilentlyContinue\r | |
| 466 | $WantSsh = $false\r | |
| 467 | }\r | |
| 468 | }\r | |
| b8144088 | 469 | Write-Host " Installed $RsyncExe$(if ($WantSsh) { ' and the ssh.exe it runs' })"\r |
| 452f525c MV |
470 | \r |
| 471 | # Machine PATH (HKLM environment). Idempotent: only appends if absent.\r | |
| 472 | $m = [Environment]::GetEnvironmentVariable('Path', 'Machine')\r | |
| 473 | if (-not $m) { $m = '' }\r | |
| 474 | if (($m -split ';') -notcontains $RsyncDir) {\r | |
| 475 | $new = if ($m.Trim()) { $m.TrimEnd(';') + ';' + $RsyncDir } else { $RsyncDir }\r | |
| 476 | [Environment]::SetEnvironmentVariable('Path', $new, 'Machine')\r | |
| 477 | Write-Host " Added $RsyncDir to the machine PATH (restart shells / sshd to pick it up)."\r | |
| 478 | # sshd caches the environment it was started with, so an already-running\r | |
| 479 | # service would not see the new PATH until restarted.\r | |
| 480 | if ((Get-Service sshd -ErrorAction SilentlyContinue).Status -eq 'Running') {\r | |
| 481 | Restart-Service sshd\r | |
| 482 | Write-Host ' Restarted sshd so it inherits the updated machine PATH.'\r | |
| 483 | }\r | |
| 484 | } else {\r | |
| 485 | Write-Host " OK: $RsyncDir already in the machine PATH"\r | |
| 486 | }\r | |
| 487 | \r | |
| 488 | & $RsyncExe --version | Select-Object -First 1\r | |
| 489 | } catch {\r | |
| 490 | Write-Warning "rsync install failed: $($_.Exception.Message)"\r | |
| b8144088 MV |
491 | Write-Warning "Download $RsyncAsset from https://github.com/$RsyncRepo/releases manually"\r |
| 492 | Write-Warning "and unpack it into $RsyncDir, keeping rsync.exe and ssh.exe together."\r | |
| 452f525c MV |
493 | }\r |
| 494 | \r | |
| 3c096107 MV |
495 | # ---------------------------------------------------------------------------\r |
| 496 | # Visual Studio 2022 Community\r | |
| 497 | # ---------------------------------------------------------------------------\r | |
| 498 | $TempDir = Join-Path $env:TEMP 'dev_install'\r | |
| 499 | New-Item -ItemType Directory -Force -Path $TempDir | Out-Null\r | |
| 500 | \r | |
| 501 | # Component IDs split into independent groups so each can be installed in its\r | |
| 502 | # own pass. The base group is the known-good set; Clang and the Windows XP\r | |
| 503 | # toolset are layered on afterwards so a failure clearly identifies the culprit.\r | |
| 504 | # Component reference: https://learn.microsoft.com/visualstudio/install/workload-component-id-vs-community\r | |
| 505 | $BaseComponents = @(\r | |
| 506 | # Core C++ desktop workload\r | |
| 507 | 'Microsoft.VisualStudio.Workload.NativeDesktop'\r | |
| 508 | \r | |
| 649b04df MV |
509 | # MSVC build tools. Named explicitly rather than left to --includeRecommended,\r |
| 510 | # because what that pulls in depends on the host: on an ARM64 machine the\r | |
| 511 | # workload's recommended set is the ARM64-hosted toolchain targeting ARM64,\r | |
| 512 | # and the x64 cross-compiler is NOT implied. Ask for both and the box builds\r | |
| 513 | # every target it can, whichever architecture it is:\r | |
| 514 | # on x64 -> x64-hosted, targeting x86/x64 and ARM64\r | |
| 515 | # on ARM64 -> ARM64-hosted, targeting ARM64 and x86/x64\r | |
| 516 | # Both are native toolchains; neither cross-compile runs under emulation.\r | |
| 517 | 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'\r | |
| 518 | 'Microsoft.VisualStudio.Component.VC.Tools.ARM64'\r | |
| 519 | \r | |
| 520 | # Spectre-mitigated MSVC runtime libs, for each target above\r | |
| 3c096107 MV |
521 | 'Microsoft.VisualStudio.Component.VC.Runtimes.x86.x64.Spectre'\r |
| 522 | 'Microsoft.VisualStudio.Component.VC.Runtimes.ARM64.Spectre'\r | |
| 523 | \r | |
| 649b04df MV |
524 | # Spectre-mitigated ATL (needed for many driver/COM projects). The x86/x64 and\r |
| 525 | # ARM64 ATL libraries are separate components; a driver or COM project built\r | |
| 526 | # for ARM64 wants the second one, and it is not implied by the first.\r | |
| 3c096107 | 527 | 'Microsoft.VisualStudio.Component.VC.ATL.Spectre'\r |
| 649b04df | 528 | 'Microsoft.VisualStudio.Component.VC.ATL.ARM64.Spectre'\r |
| 3c096107 MV |
529 | \r |
| 530 | # Windows 11 SDK — build number must match the WDK below\r | |
| 531 | 'Microsoft.VisualStudio.Component.Windows11SDK.26100'\r | |
| 3c096107 MV |
532 | )\r |
| 533 | \r | |
| 7840e3c2 MV |
534 | # WDK Visual Studio extension (VSIX). The silent wdksetup.exe /quiet does NOT\r |
| 535 | # install this (it only prompts interactively), so it has to be asked for here.\r | |
| 536 | #\r | |
| 537 | # Follows the WDK itself: x64 only. On ARM64 the kit is not installed (see the\r | |
| 538 | # WDK step for why), and this VSIX on its own is just the driver project\r | |
| 539 | # templates and property pages with no headers, libs or tools behind them.\r | |
| 540 | if (-not $IsArm64) {\r | |
| 541 | $BaseComponents += 'Component.Microsoft.Windows.DriverKit'\r | |
| 542 | }\r | |
| 543 | \r | |
| 3c096107 MV |
544 | # Clang/LLVM toolset (ClangCL, used in CMakePresets.json). Two parts: the Clang\r |
| 545 | # compiler itself, plus the MSBuild integration providing the "ClangCL" toolset.\r | |
| 649b04df | 546 | #\r |
| 7840e3c2 | 547 | # x64 ONLY, and NOT because ARM64 cannot have it - it can, natively. The VSIX is\r |
| 649b04df | 548 | # productArch=neutral with no chip/machineArch restriction, so the Arm installer\r |
| 7840e3c2 MV |
549 | # offers it, and MSVC's VC\Tools\Llvm tree is partitioned by HOST architecture\r |
| 550 | # (bin = x86, x64\bin = x64, ARM64\bin = ARM64) with genuine ARM64 binaries in\r | |
| 551 | # ARM64\bin, which is where clang-cl.exe lands. It was installed and working here\r | |
| 552 | # before this split.\r | |
| 649b04df | 553 | #\r |
| 7840e3c2 MV |
554 | # It is dropped on ARM64 because that machine is a constrained VM provisioned as\r |
| 555 | # a single-compiler build box: MSVC and nothing else. Compiler diversity - MSVC,\r | |
| 556 | # VS clang-cl and upstream LLVM over the same sources - now lives entirely on the\r | |
| 557 | # x64 machine, which is the one with room for three toolchains. Empty here means\r | |
| 558 | # Invoke-VsModify is never called for this group.\r | |
| 559 | $ClangComponents = if ($IsArm64) { @() } else {\r | |
| 560 | @(\r | |
| 561 | 'Microsoft.VisualStudio.Component.VC.Llvm.Clang'\r | |
| 562 | 'Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset'\r | |
| 563 | )\r | |
| 564 | }\r | |
| 3c096107 MV |
565 | \r |
| 566 | # Windows XP targeting (v141_xp toolset, used in CMakePresets.json). The v141\r | |
| 567 | # (VS2017) build tools provide the 14.16 compiler that the XP toolset wraps;\r | |
| 568 | # WinXP layers the XP-compatible CRT/SDK on top of it.\r | |
| 649b04df MV |
569 | #\r |
| 570 | # NOT USED ON ARM64, and left empty there. The components are still listed in the\r | |
| 571 | # catalog on Arm, so this is not strictly "unavailable" - but the 14.16 toolset\r | |
| 572 | # predates Windows on Arm as a host and ships HostX86/HostX64 compilers only, so\r | |
| 573 | # the best you could get is an x86-emulated compiler, and Microsoft does not\r | |
| 574 | # support XP targeting from an Arm host. Nothing is lost that this box could have\r | |
| 575 | # used: Windows XP never ran on ARM64, so an XP-targeting build from an ARM64\r | |
| 576 | # host has no purpose beyond producing x86 binaries, which the current toolset\r | |
| 577 | # does natively via -A Win32. On x64 the group is installed exactly as before.\r | |
| 578 | $XpComponents = if ($IsArm64) { @() } else {\r | |
| 579 | @(\r | |
| 580 | 'Microsoft.VisualStudio.Component.VC.v141.x86.x64'\r | |
| 581 | 'Microsoft.VisualStudio.Component.WinXP'\r | |
| 582 | )\r | |
| 583 | }\r | |
| 3c096107 | 584 | \r |
| 649b04df MV |
585 | # Which Visual Studio generation to drive: 17 = VS 2022, 18 = VS 2026. Both have\r |
| 586 | # native ARM64 installers and ARM64-hosted MSVC. This picks the bootstrapper URL,\r | |
| 587 | # and - just as importantly - scopes the vswhere lookup below, so a box that\r | |
| 588 | # already has a DIFFERENT generation installed is not mistaken for this one.\r | |
| 589 | #\r | |
| 590 | # Split by architecture on purpose:\r | |
| 591 | # x64 -> 17. The v141 / Windows XP targeting toolset in $XpComponents is the\r | |
| 592 | # reason; that group is the whole point of pinning a generation here.\r | |
| 593 | # ARM64 -> 18. The XP group is skipped on Arm regardless (no ARM64-hosted 14.16\r | |
| 594 | # compiler), so nothing holds this back to 17, and VS 2026 brings the\r | |
| 595 | # newer MSVC. Together with the native ARM64 clang-cl from\r | |
| 596 | # $ClangComponents above, that is the compiler diversity on this box.\r | |
| 597 | $VsChannel = if ($IsArm64) { 18 } else { 17 }\r | |
| 598 | $VsEdition = 'community' # community | professional | enterprise\r | |
| 599 | \r | |
| 600 | # aka.ms path segment per generation. NOT the same word for both: VS 2022 is\r | |
| 601 | # published under /release/, VS 2026 under /stable/. This is not cosmetic -\r | |
| 602 | # https://aka.ms/vs/18/release/vs_community.exe is not a 404, it silently\r | |
| 603 | # redirects to Bing and returns 200 with an HTML body, so a wrong guess here\r | |
| 604 | # downloads a web page, names it vs_community.exe, and fails at Start-Process\r | |
| 605 | # with something that looks nothing like a bad URL.\r | |
| 606 | $VsChannelPath = if ($VsChannel -ge 18) { 'stable' } else { 'release' }\r | |
| 607 | \r | |
| 608 | # Detect an existing VS install via vswhere (ships with the VS Installer). Note\r | |
| 609 | # that vswhere itself lives under the 32-bit Program Files on every architecture,\r | |
| 610 | # ARM64 included - the VS Installer is x86-registered there by contract even\r | |
| 611 | # though the installer binaries themselves are native.\r | |
| 3c096107 MV |
612 | # These are referenced by Invoke-VsModify via $script: scope.\r |
| 613 | $VsWhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'\r | |
| 649b04df MV |
614 | $InstallPath = Get-VsInstallPath\r |
| 615 | \r | |
| 616 | # Report any OTHER Visual Studio generations on the box. They are left alone -\r | |
| 617 | # the passes below only ever touch $InstallPath - but when none of them matches\r | |
| 618 | # $VsChannel this script is about to download and install a second, largely\r | |
| 619 | # redundant toolchain, and that should be a visible decision rather than a\r | |
| 620 | # surprise 10GB. (On ARM64, where $VsChannel is 18, an existing VS 2026 IS the\r | |
| 621 | # match and gets modified in place rather than duplicated.)\r | |
| 3c096107 | 622 | if (Test-Path $VsWhere) {\r |
| 649b04df MV |
623 | $others = & $VsWhere -products '*' -format value -property installationPath |\r |
| 624 | Where-Object { $_ -and $_ -ne $InstallPath }\r | |
| 625 | if ($others) {\r | |
| 626 | Write-Step 'Other Visual Studio installations detected'\r | |
| 627 | foreach ($o in $others) { Write-Host " $o" -ForegroundColor Yellow }\r | |
| 628 | Write-Host " Not modified. This script drives VS generation $VsChannel only." -ForegroundColor Yellow\r | |
| 629 | Write-Host " To use one of the above instead, set `$VsChannel at the top of this step." -ForegroundColor Yellow\r | |
| 630 | }\r | |
| 3c096107 MV |
631 | }\r |
| 632 | \r | |
| 649b04df MV |
633 | Write-Step "Downloading VS $VsChannel $VsEdition bootstrapper (host: $HostArch)"\r |
| 634 | # aka.ms serves the bootstrapper for the requesting machine's architecture, so on\r | |
| 635 | # ARM64 this is the native ARM64 installer - no --arch flag needed or offered.\r | |
| 636 | $VsInstallerUrl = "https://aka.ms/vs/$VsChannel/$VsChannelPath/vs_$VsEdition.exe"\r | |
| 637 | $VsBootstrapper = Join-Path $TempDir "vs_$VsEdition.exe"\r | |
| 638 | Write-Host " $VsInstallerUrl" -ForegroundColor DarkGray\r | |
| 3c096107 MV |
639 | Invoke-WebRequest -Uri $VsInstallerUrl -OutFile $VsBootstrapper -UseBasicParsing\r |
| 640 | \r | |
| 649b04df MV |
641 | # Prove we got an installer and not a web page. The Bing redirect described above\r |
| 642 | # returns 200 with HTML, and every other aka.ms typo behaves the same way, so a\r | |
| 643 | # bad channel/edition combination is otherwise only discovered when the "exe"\r | |
| 644 | # fails to start. 'MZ' is the DOS header every PE begins with.\r | |
| 645 | $vsHead = [IO.File]::ReadAllBytes($VsBootstrapper) | Select-Object -First 2\r | |
| 646 | if (-not ($vsHead.Count -eq 2 -and $vsHead[0] -eq 0x4D -and $vsHead[1] -eq 0x5A)) {\r | |
| 647 | throw "Visual Studio: $VsInstallerUrl did not return an executable (no MZ header; $((Get-Item $VsBootstrapper).Length) bytes). Check `$VsChannel / `$VsChannelPath / `$VsEdition."\r | |
| 648 | }\r | |
| 649 | Write-Host " OK: bootstrapper is a PE ($([math]::Round((Get-Item $VsBootstrapper).Length / 1MB, 2)) MB)"\r | |
| 650 | \r | |
| 3c096107 MV |
651 | # Install in three sequential passes. The base set is installed first (this is\r |
| 652 | # the configuration that previously worked); Clang and the XP toolset are added\r | |
| 653 | # afterwards. If one fails, its label pinpoints which group is responsible.\r | |
| 649b04df MV |
654 | #\r |
| 655 | # The last two are -Optional: neither the Clang toolset nor XP targeting is\r | |
| 656 | # needed to build with MSVC, and on a host where one of them is simply not\r | |
| 657 | # offered a hard failure here would cost you the whole toolchain over a component\r | |
| 658 | # you can add later from the installer UI.\r | |
| 3c096107 | 659 | Invoke-VsModify -Label 'base toolset + workload' -Ids $BaseComponents\r |
| 7840e3c2 MV |
660 | if ($IsArm64) {\r |
| 661 | Write-Step 'Visual Studio: Clang / LLVM'\r | |
| 662 | Write-Host ' Skipped on ARM64 by choice, not by limitation: a native ARM64 clang-cl is' -ForegroundColor Yellow\r | |
| 663 | Write-Host ' offered here and works. This box is provisioned with MSVC alone; the' -ForegroundColor Yellow\r | |
| 664 | Write-Host ' multi-compiler builds belong on the x64 machine.' -ForegroundColor Yellow\r | |
| 665 | } else {\r | |
| 666 | Invoke-VsModify -Label 'Clang / LLVM' -Ids $ClangComponents -Optional\r | |
| 667 | }\r | |
| 649b04df MV |
668 | if ($IsArm64) {\r |
| 669 | Write-Step 'Visual Studio: Windows XP (v141 + WinXP)'\r | |
| 670 | Write-Host ' Skipped on ARM64: the v141 (14.16) toolset ships x86/x64-hosted compilers only,' -ForegroundColor Yellow\r | |
| 671 | Write-Host ' and Windows XP targeting is not offered for Arm hosts. Build x86 with the' -ForegroundColor Yellow\r | |
| 672 | Write-Host ' current toolset instead (cmake -A Win32), which is native here.' -ForegroundColor Yellow\r | |
| 673 | } else {\r | |
| 674 | Invoke-VsModify -Label 'Windows XP (v141 + WinXP)' -Ids $XpComponents -Optional\r | |
| 675 | }\r | |
| 3c096107 MV |
676 | \r |
| 677 | # ---------------------------------------------------------------------------\r | |
| 649b04df MV |
678 | # Verify what actually landed, on disk. Earlier runs silently skipped the v141\r |
| 679 | # toolset and the failure only surfaced at build time, so check here and say so\r | |
| 680 | # loudly instead. Widened from that one check to every toolset worth naming,\r | |
| 681 | # because the same "installed something, but not the thing you needed" failure is\r | |
| 682 | # now possible per host architecture: this reports which MSVC host toolchains are\r | |
| 683 | # present (HostARM64 is what proves the compiler is native rather than emulated),\r | |
| 684 | # whether clang-cl is there, and - on x64 only - whether v141 is.\r | |
| 685 | #\r | |
| 686 | # Reporting, not throwing. A missing optional component is something to fix from\r | |
| 687 | # the installer UI, not a reason to fail a provisioning run that installed a\r | |
| 688 | # working compiler.\r | |
| 3c096107 | 689 | # ---------------------------------------------------------------------------\r |
| 649b04df MV |
690 | Write-Step 'Verifying the installed toolsets'\r |
| 691 | $InstallPath = Get-VsInstallPath\r | |
| 692 | if (-not $InstallPath) {\r | |
| 693 | Write-Warning "No Visual Studio $VsChannel installation found after the passes above; cannot verify toolsets."\r | |
| 3c096107 | 694 | } else {\r |
| 649b04df MV |
695 | Write-Host " Install path: $InstallPath"\r |
| 696 | \r | |
| 697 | # What MSVC versions landed, and which host toolchains each one carries.\r | |
| 698 | # HostARM64 is the directory that proves the native ARM64 compiler is here\r | |
| 699 | # rather than an x64 one that would run under emulation.\r | |
| 700 | $msvcRoot = Join-Path $InstallPath 'VC\Tools\MSVC'\r | |
| 701 | foreach ($v in (Get-ChildItem $msvcRoot -Directory -ErrorAction SilentlyContinue | Sort-Object Name)) {\r | |
| 702 | $hosts = Get-ChildItem (Join-Path $v.FullName 'bin') -Directory -ErrorAction SilentlyContinue |\r | |
| 703 | ForEach-Object { $_.Name }\r | |
| 704 | Write-Host " MSVC $($v.Name): $(if ($hosts) { $hosts -join ', ' } else { '(no bin dir)' })"\r | |
| 705 | }\r | |
| 706 | if ($IsArm64) {\r | |
| 707 | $armHost = Test-Path (Join-Path $msvcRoot '*\bin\HostARM64\ARM64\cl.exe')\r | |
| 708 | if ($armHost) {\r | |
| 709 | Write-Host ' OK: native ARM64-hosted cl.exe present.' -ForegroundColor Green\r | |
| 710 | } else {\r | |
| 711 | Write-Warning 'No HostARM64 cl.exe found - MSVC would run under x64 emulation. Add "MSVC v14x - VS 2022 C++ ARM64/ARM64EC build tools" in the installer.'\r | |
| 712 | }\r | |
| 713 | }\r | |
| 714 | \r | |
| 715 | # clang-cl, for the ClangCL toolset in CMakePresets.json. Checked per host\r | |
| 716 | # directory, because the Llvm tree is partitioned by HOST architecture and\r | |
| 717 | # only the matching one is a native compiler.\r | |
| 718 | #\r | |
| 719 | # Look for clang-cl.exe specifically, NOT for the directory. VC\Tools\Llvm\*\bin\r | |
| 720 | # holds clang-format.exe and clang-tidy.exe on every host whether or not the\r | |
| 721 | # Clang component was ever installed - those ship with the NativeDesktop\r | |
| 722 | # workload - so a present ARM64\bin proves nothing on its own. That is the\r | |
| 723 | # false positive to avoid when checking this by hand.\r | |
| 724 | $llvmRoot = Join-Path $InstallPath 'VC\Tools\Llvm'\r | |
| 725 | $clangArm = Test-Path (Join-Path $llvmRoot 'ARM64\bin\clang-cl.exe')\r | |
| 726 | $clangX64 = Test-Path (Join-Path $llvmRoot 'x64\bin\clang-cl.exe')\r | |
| 727 | $clangX86 = Test-Path (Join-Path $llvmRoot 'bin\clang-cl.exe')\r | |
| 7840e3c2 MV |
728 | $clangAny = $clangArm -or $clangX64 -or $clangX86\r |
| 729 | if ($IsArm64) {\r | |
| 730 | # Not installed here by design, so its absence is the expected result and\r | |
| 731 | # must not read as a fault. Its PRESENCE is the thing worth a line: a box\r | |
| 732 | # provisioned before this split still carries it, and the component stays\r | |
| 733 | # until it is explicitly removed - the installer never uninstalls what you\r | |
| 734 | # simply stopped asking for.\r | |
| 735 | if ($clangAny) {\r | |
| 736 | Write-Host ' clang-cl: present but no longer provisioned on ARM64 - left over from an earlier run.' -ForegroundColor Yellow\r | |
| 737 | Write-Host ' Remove it with: vs_installer.exe modify --installPath "<path>" --remove Microsoft.VisualStudio.Component.VC.Llvm.Clang --remove Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset --quiet' -ForegroundColor Yellow\r | |
| 738 | } else {\r | |
| 739 | Write-Host ' clang-cl: n/a on ARM64 (MSVC only by design; use the x64 box for ClangCL).' -ForegroundColor DarkGray\r | |
| 649b04df | 740 | }\r |
| 7840e3c2 MV |
741 | } elseif ($clangAny) {\r |
| 742 | Write-Host " clang-cl: $(@(if ($clangArm) {'ARM64'}; if ($clangX64) {'x64'}; if ($clangX86) {'x86'}) -join ', ')" -ForegroundColor Green\r | |
| 649b04df MV |
743 | } else {\r |
| 744 | Write-Warning 'clang-cl not found - the ClangCL presets will fail. Add the "C++ Clang tools for Windows" component.'\r | |
| 745 | }\r | |
| 746 | \r | |
| 747 | # v141 / XP. Only meaningful where the toolset can exist at all; on ARM64 the\r | |
| 748 | # group above was deliberately skipped, so warning here would be noise about\r | |
| 749 | # a decision this script made on purpose two steps ago.\r | |
| 750 | if ($IsArm64) {\r | |
| 751 | Write-Host ' v141 / Windows XP toolset: n/a on ARM64 (not offered for Arm hosts).' -ForegroundColor DarkGray\r | |
| 752 | } else {\r | |
| 753 | $V141 = Get-ChildItem $msvcRoot -Directory -ErrorAction SilentlyContinue |\r | |
| 754 | Where-Object { $_.Name -like '14.16.*' } | Select-Object -First 1\r | |
| 755 | if ($V141) {\r | |
| 756 | Write-Host " OK: v141 toolset present ($($V141.Name))" -ForegroundColor Green\r | |
| 757 | } else {\r | |
| 758 | Write-Warning 'v141 (14.16.x) toolset NOT found - the XP build presets will fail.'\r | |
| 759 | Write-Warning 'Add it via Visual Studio Installer > Modify > Individual components:'\r | |
| 760 | Write-Warning ' - MSVC v141 - VS 2017 C++ x64/x86 build tools (v14.16)'\r | |
| 761 | Write-Warning ' - C++ Windows XP Support for VS 2017 (v141) tools'\r | |
| 762 | }\r | |
| 763 | }\r | |
| 3c096107 MV |
764 | }\r |
| 765 | \r | |
| 766 | # ---------------------------------------------------------------------------\r | |
| 767 | # Windows Driver Kit (WDK 10.0.26100)\r | |
| 768 | # Build 26100 matches the Windows 11 SDK installed above.\r | |
| 769 | # Provides IddCx (iddcx.h / iddcx.lib) and UMDF 2.x for Indirect Display Drivers.\r | |
| 770 | # linkid=2335869 -> WDK 26100.6584 (per Microsoft "Other WDK Downloads").\r | |
| 7840e3c2 MV |
771 | #\r |
| 772 | # x64 ONLY. Two reasons, and the second is the one that decided it:\r | |
| 773 | #\r | |
| 774 | # 1. The ARM64 box builds user-mode software; no driver is developed on it.\r | |
| 775 | #\r | |
| 776 | # 2. This exact WDK cannot install next to the SDK that VS 2026 brings. The\r | |
| 777 | # WDK requires the MATCHING Windows SDK revision, and revisions are not\r | |
| 778 | # side-by-side - Include\10.0.26100.0 is one directory whichever revision\r | |
| 779 | # wrote it. VS 2026 installs SDK 26100.7705; linkid=2335869 is WDK\r | |
| 780 | # 26100.6584, which is the kit paired with VS 2022. So wdksetup.exe aborts:\r | |
| 781 | # exit 15605, WER signature "WDK / 10.1.26100.6584 / Install / 0x80070642"\r | |
| 782 | # (0x642 = 1602, ERROR_INSTALL_USEREXIT - a silent install cancelling\r | |
| 783 | # itself on a failed prerequisite check). It is not an ARM64 or emulation\r | |
| 784 | # problem; the same pairing fails on x64.\r | |
| 785 | #\r | |
| 786 | # If a driver ever does need building here, the fix is the WDK that matches\r | |
| 787 | # this generation - Microsoft's "Supported and other WDK downloads" table\r | |
| 788 | # pairs VS 2026 with the 28000.x kit - not this link.\r | |
| 789 | #\r | |
| 790 | # On x64 with VS 2022 the SDK and this WDK are the matched pair, so it installs.\r | |
| 3c096107 MV |
791 | # ---------------------------------------------------------------------------\r |
| 792 | $WdkVersion = '10.0.26100'\r | |
| 649b04df MV |
793 | # Both hives. The WDK installer is a 32-bit program, so on x64 it writes under\r |
| 794 | # WOW6432Node - but which hive a given kit lands in has varied across kit\r | |
| 795 | # versions and architectures, and reading only one of them makes an installed WDK\r | |
| 796 | # look absent, which costs a needless multi-GB reinstall on every run. Check the\r | |
| 797 | # native hive too and take whichever answers.\r | |
| 798 | $WdkInstalledRoot = @(\r | |
| 799 | 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots'\r | |
| 800 | 'HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots'\r | |
| 801 | ) | ForEach-Object { (Get-ItemProperty $_ -ErrorAction SilentlyContinue).WdkBinRootVersioned } |\r | |
| 802 | Where-Object { $_ } | Select-Object -First 1\r | |
| 3c096107 | 803 | \r |
| 7840e3c2 MV |
804 | if ($IsArm64) {\r |
| 805 | Write-Step 'Windows Driver Kit'\r | |
| 806 | Write-Host ' Skipped on ARM64: this box builds user-mode software only, and WDK 26100.6584' -ForegroundColor Yellow\r | |
| 807 | Write-Host ' cannot install beside the 26100.7705 SDK that Visual Studio 2026 brings - the' -ForegroundColor Yellow\r | |
| 808 | Write-Host ' kit needs the matching SDK revision and they are not side-by-side. See the' -ForegroundColor Yellow\r | |
| 809 | Write-Host ' comment above this step for the exit code and what to use instead.' -ForegroundColor Yellow\r | |
| 810 | } elseif ($WdkInstalledRoot -and $WdkInstalledRoot -match [regex]::Escape($WdkVersion)) {\r | |
| 3c096107 MV |
811 | # Re-running wdksetup.exe for an already-present version returns exit code\r |
| 812 | # 2008 (maintenance mode / nothing to do), which is not a real failure.\r | |
| 813 | Write-Step "WDK $WdkVersion already installed - skipping ($WdkInstalledRoot)"\r | |
| 814 | } else {\r | |
| 815 | Write-Step 'Downloading WDK installer'\r | |
| 816 | $WdkUrl = 'https://go.microsoft.com/fwlink/?linkid=2335869'\r | |
| 817 | $WdkInstaller = Join-Path $TempDir 'wdksetup.exe'\r | |
| 818 | Invoke-WebRequest -Uri $WdkUrl -OutFile $WdkInstaller -UseBasicParsing\r | |
| 819 | \r | |
| 820 | Write-Step 'Installing WDK'\r | |
| 649b04df MV |
821 | # wdksetup.exe is a 32-bit binary and runs under emulation on ARM64; the kit\r |
| 822 | # it lays down does include the ARM64 target headers, libs and tools (the\r | |
| 823 | # signing/deployment tools under bin\arm64), so an ARM64 driver builds from\r | |
| 824 | # an ARM64 host. Only the installer is emulated, not the toolchain.\r | |
| 3c096107 MV |
825 | $proc = Start-Process -FilePath $WdkInstaller -ArgumentList '/quiet /norestart' -Wait -PassThru -NoNewWindow\r |
| 826 | Write-Host " WDK installer exit code: $($proc.ExitCode)"\r | |
| 827 | if ($proc.ExitCode -eq 2008) {\r | |
| 828 | # 2008 = the WDK is already present; the installer has nothing to do.\r | |
| 829 | Write-Host ' [WDK already installed (exit 2008) - treating as success]' -ForegroundColor Yellow\r | |
| 830 | } else {\r | |
| 831 | Assert-ExitCode $proc.ExitCode 'WDK'\r | |
| 832 | }\r | |
| 833 | }\r | |
| 834 | \r | |
| 835 | # ---------------------------------------------------------------------------\r | |
| 99725a30 MV |
836 | # Windows Performance Toolkit: xperf, wpr, and Windows Performance Analyzer\r |
| 837 | # (wpa.exe) -- ETW CPU + loader profiling and the GUI that reads the traces.\r | |
| 838 | #\r | |
| 839 | # WPA is NOT a Visual Studio component and has no relationship to VS's own\r | |
| 840 | # Performance Profiler (a separate, .diagsession-based tool that cannot open an\r | |
| 841 | # .etl). It ships in exactly two places: as an optional FEATURE of the Windows\r | |
| 842 | # SDK ("Windows Performance Toolkit", OptionId.WindowsPerformanceToolkit), and\r | |
| 843 | # in the Windows ADK, which bundles the same toolkit. Whether the SDK install\r | |
| 844 | # that Visual Studio performs happens to select that feature varies with the VS\r | |
| 845 | # and SDK version - when it does, WPT lands in\r | |
| 846 | # %ProgramFiles(x86)%\Windows Kits\10\Windows Performance Toolkit and the SDK\r | |
| 847 | # puts that directory on the machine PATH itself - so this step DETECTS first\r | |
| 848 | # and only falls back to installing the ADK (winget owns the versioned download\r | |
| 849 | # URL, which makes it the reliable source) when nothing is there. That fallback\r | |
| 850 | # is a large download; to install just the toolkit instead, run the standalone\r | |
| 851 | # SDK setup with\r | |
| 852 | # winsdksetup.exe /features OptionId.WindowsPerformanceToolkit /q\r | |
| 853 | #\r | |
| 854 | # There is also a newer WPA in the Microsoft Store (`winget install --id\r | |
| 855 | # 9N0W1B2BXGNZ --source msstore`), which updates independently of the SDK. It is\r | |
| 856 | # not installed here: the Store package needs an interactive, signed-in session,\r | |
| 857 | # which is exactly what this elevated, unattended half does not have.\r | |
| 858 | #\r | |
| 859 | # Idempotent and non-fatal - it never aborts provisioning.\r | |
| 3c096107 | 860 | # ---------------------------------------------------------------------------\r |
| 99725a30 MV |
861 | Write-Step 'Windows Performance Toolkit (xperf / wpr / WPA)'\r |
| 862 | $WptDirs = @(\r | |
| 863 | (Join-Path ${env:ProgramFiles(x86)} 'Windows Kits\10\Windows Performance Toolkit'),\r | |
| 864 | (Join-Path $env:ProgramFiles 'Windows Kits\10\Windows Performance Toolkit'),\r | |
| 865 | (Join-Path ${env:ProgramFiles(x86)} 'Windows Kits\10\Assessment and Deployment Kit\Windows Performance Toolkit')\r | |
| 3c096107 | 866 | )\r |
| 99725a30 MV |
867 | function Find-WptDir { $script:WptDirs | Where-Object { Test-Path (Join-Path $_ 'xperf.exe') } | Select-Object -First 1 }\r |
| 868 | \r | |
| 869 | $WptDir = Find-WptDir\r | |
| 870 | if ($WptDir) {\r | |
| 871 | Write-Host " OK: WPT already present ($WptDir)" -ForegroundColor Green\r | |
| 3c096107 MV |
872 | } else {\r |
| 873 | try {\r | |
| 649b04df MV |
874 | # The ADK manifest offers no ARM64 installer, so on ARM64 winget fetches\r |
| 875 | # the x64 one; it runs under emulation and lays down a toolkit that does\r | |
| 876 | # include the ARM64 binaries. The SDK feature is the lighter route on any\r | |
| 877 | # architecture and is worth preferring if this fallback ever gives\r | |
| 878 | # trouble - see the winsdksetup.exe line in the comment above.\r | |
| 879 | if ($IsArm64) {\r | |
| 880 | Write-Host ' ARM64: the ADK installer is x64 (emulated); the toolkit it installs is ARM64.' -ForegroundColor Yellow\r | |
| 881 | }\r | |
| 3c096107 MV |
882 | winget install --id Microsoft.WindowsADK --exact --silent --disable-interactivity `\r |
| 883 | --accept-source-agreements --accept-package-agreements\r | |
| 884 | Write-Host ' Windows ADK (includes Windows Performance Toolkit) installed.'\r | |
| 99725a30 | 885 | $WptDir = Find-WptDir\r |
| 3c096107 MV |
886 | } catch {\r |
| 887 | Write-Warning "WPT install failed: $($_.Exception.Message)"\r | |
| 888 | Write-Warning 'Install manually: winget install Microsoft.WindowsADK, or add the'\r | |
| 889 | Write-Warning 'Windows SDK "Windows Performance Toolkit" optional feature.'\r | |
| 890 | }\r | |
| 891 | }\r | |
| 892 | \r | |
| 99725a30 MV |
893 | if ($WptDir) {\r |
| 894 | # Report what actually landed. wpa.exe is the piece people come looking for\r | |
| 895 | # and it is the one that is absent if a trimmed toolkit ever shows up.\r | |
| 896 | foreach ($tool in 'xperf.exe', 'wpr.exe', 'wpa.exe', 'wpaexporter.exe') {\r | |
| 897 | $p = Join-Path $WptDir $tool\r | |
| 898 | if (Test-Path $p) {\r | |
| 899 | Write-Host " $tool $((Get-Item $p).VersionInfo.ProductVersion)"\r | |
| 900 | } else {\r | |
| 901 | Write-Warning "$tool is missing from $WptDir"\r | |
| 902 | }\r | |
| 903 | }\r | |
| 904 | \r | |
| 905 | # The WPT installer normally adds this to the machine PATH itself (and the\r | |
| 906 | # Start Menu gets "Windows Kits > Windows Performance Toolkit" shortcuts for\r | |
| 907 | # WPA and WPR). Re-assert it anyway: on the machine PATH rather than a user\r | |
| 908 | # one so it also resolves for the non-interactive sshd sessions this box is\r | |
| 909 | # driven through, which build their environment from the registry PATH.\r | |
| 910 | # Compared trailing-backslash-insensitively - the installer's own entry has\r | |
| 911 | # one, and adding a second spelling of the same directory is just noise.\r | |
| 912 | $m = [Environment]::GetEnvironmentVariable('Path', 'Machine')\r | |
| 913 | if (-not $m) { $m = '' }\r | |
| 914 | $have = ($m -split ';') | Where-Object { $_.TrimEnd('\') -eq $WptDir.TrimEnd('\') }\r | |
| 915 | if ($have) {\r | |
| 916 | Write-Host " OK: $WptDir already in the machine PATH"\r | |
| 917 | } else {\r | |
| 918 | $new = if ($m.Trim()) { $m.TrimEnd(';') + ';' + $WptDir } else { $WptDir }\r | |
| 919 | [Environment]::SetEnvironmentVariable('Path', $new, 'Machine')\r | |
| 920 | Write-Host " Added $WptDir to the machine PATH (restart shells to pick it up)."\r | |
| 921 | }\r | |
| 922 | }\r | |
| 923 | \r | |
| 99725a30 | 924 | \r |
| 1e91b38f MV |
925 | # ---------------------------------------------------------------------------\r |
| 926 | # Intel VTune Profiler - reported, not installed\r | |
| 927 | #\r | |
| 928 | # Deliberately NOT automated, unlike everything above. The offline installer is\r | |
| 929 | # a ~750 MB download from a URL carrying a per-release GUID\r | |
| 930 | # (registrationcenter-download.intel.com/akdlm/IRC_NAS/<guid>/intel-vtune-<ver>_offline.exe)\r | |
| 931 | # with no "latest" redirect behind it, so every new build means editing a\r | |
| 932 | # hard-coded link in here - and it is only worth having on Intel silicon, since\r | |
| 933 | # hardware event-based sampling reads Intel PMU counters. Not a good trade for a\r | |
| 934 | # script that has to keep working unattended on any box.\r | |
| 935 | #\r | |
| 936 | # So this step only reports. To install it, take the Windows offline installer\r | |
| 937 | # from\r | |
| 938 | # https://www.intel.com/content/www/us/en/developer/tools/oneapi/vtune-profiler-download.html\r | |
| 939 | # and run it elevated; it installs unattended with\r | |
| 940 | # intel-vtune-<version>_offline.exe -a --silent --cli --eula accept\r | |
| 941 | # ---------------------------------------------------------------------------\r | |
| 942 | Write-Step 'Intel VTune Profiler (status only)'\r | |
| 649b04df MV |
943 | if ($IsArm64) {\r |
| 944 | # Not a "not installed yet" case - there is no Windows-on-Arm build of VTune,\r | |
| 945 | # and there is nothing for it to sample: its whole value is reading Intel PMU\r | |
| 946 | # counters. Say so plainly and point at what does work here, rather than\r | |
| 947 | # printing a download link for a product this box cannot run.\r | |
| 948 | Write-Host ' n/a on ARM64: Intel ships no Windows-on-Arm build, and hardware event-based' -ForegroundColor DarkGray\r | |
| 949 | Write-Host ' sampling reads Intel PMU counters. Use the Windows Performance Toolkit above' -ForegroundColor DarkGray\r | |
| 950 | Write-Host ' (wpr / xperf to collect, wpa to analyse) for profiling on this box.' -ForegroundColor DarkGray\r | |
| 951 | Write-Host ' Arm also publishes Arm Performance Studio / Streamline for Arm PMU sampling.' -ForegroundColor DarkGray\r | |
| 1e91b38f | 952 | } else {\r |
| 649b04df MV |
953 | $UninstallKeys = @(\r |
| 954 | 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*'\r | |
| 955 | 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'\r | |
| 956 | )\r | |
| 957 | $vtune = Get-ItemProperty $UninstallKeys -ErrorAction SilentlyContinue |\r | |
| 958 | Where-Object { $_.DisplayName -match 'VTune' } |\r | |
| 959 | Select-Object -First 1\r | |
| 960 | if ($vtune) {\r | |
| 961 | Write-Host " Installed: $($vtune.DisplayName.Trim()) $($vtune.DisplayVersion)" -ForegroundColor Green\r | |
| 962 | # The oneAPI layout keeps a `latest` junction beside the versioned directory,\r | |
| 963 | # so this path stays right across upgrades.\r | |
| 964 | $VTuneCli = Join-Path $vtune.InstallLocation 'vtune\latest\bin64\vtune.exe'\r | |
| 965 | if (Test-Path $VTuneCli) { Write-Host " CLI: $VTuneCli" }\r | |
| 966 | } else {\r | |
| 967 | Write-Host ' Not installed.' -ForegroundColor Yellow\r | |
| 968 | Write-Host ' https://www.intel.com/content/www/us/en/developer/tools/oneapi/vtune-profiler-download.html' -ForegroundColor Yellow\r | |
| 969 | $cpu = (Get-CimInstance Win32_Processor -ErrorAction SilentlyContinue | Select-Object -First 1).Manufacturer\r | |
| 970 | if ($cpu -and $cpu -notmatch 'Intel') {\r | |
| 971 | Write-Host " (This CPU reports itself as '$cpu' - VTune's hardware event-based sampling wants Intel silicon.)" -ForegroundColor Yellow\r | |
| 972 | }\r | |
| 1e91b38f MV |
973 | }\r |
| 974 | }\r | |
| 975 | \r | |
| 3c096107 MV |
976 | # ---------------------------------------------------------------------------\r |
| 977 | Write-Host "`nAll done." -ForegroundColor Green\r | |
| 649b04df | 978 | Write-Host "Host architecture was $HostArch."\r |
| 3c096107 MV |
979 | Write-Host 'If a reboot was flagged above, restart before opening VS or building drivers.'\r |
| 980 | \r | |
| 981 | }\r | |
| 982 | catch {\r | |
| 983 | $ExitCode = 1\r | |
| 984 | Write-Host "`n==> SETUP FAILED: $($_.Exception.Message)" -ForegroundColor Red\r | |
| 985 | if ($_.ScriptStackTrace) { Write-Host $_.ScriptStackTrace -ForegroundColor DarkGray }\r | |
| 986 | # Only fold in the VS Installer logs when a VS step actually failed; for other\r | |
| 987 | # steps (e.g. WDK) those logs are stale and misleading, so the message above\r | |
| 988 | # is what matters.\r | |
| 649b04df | 989 | if ($_.Exception.Message -match 'Visual Studio') {\r |
| 3c096107 MV |
990 | try { Show-VsSetupLogs } catch {}\r |
| 991 | }\r | |
| 992 | }\r | |
| 993 | finally {\r | |
| 994 | try { Stop-Transcript | Out-Null } catch {}\r | |
| 995 | \r | |
| 996 | # This log was created by the elevated (admin) process, so by default the\r | |
| 997 | # non-elevated caller can't delete it (their token has Administrators marked\r | |
| 998 | # deny-only). Grant BUILTIN\Users Modify rights so the user account that runs\r | |
| 999 | # setup-windows.bat can remove the log later. S-1-5-32-545 is the well-known\r | |
| 1000 | # Users SID, used here so this is locale-independent.\r | |
| 1001 | try {\r | |
| 1002 | if (Test-Path $LogFile) {\r | |
| 1003 | $usersSid = New-Object System.Security.Principal.SecurityIdentifier('S-1-5-32-545')\r | |
| 1004 | $acl = Get-Acl -Path $LogFile\r | |
| 1005 | $rule = New-Object System.Security.AccessControl.FileSystemAccessRule(\r | |
| 1006 | $usersSid, 'Modify', 'Allow')\r | |
| 1007 | $acl.AddAccessRule($rule)\r | |
| 1008 | Set-Acl -Path $LogFile -AclObject $acl\r | |
| 1009 | }\r | |
| 1010 | } catch {\r | |
| 1011 | Write-Host " [warning] could not relax ACL on $LogFile : $($_.Exception.Message)" -ForegroundColor Yellow\r | |
| 1012 | }\r | |
| 1013 | }\r | |
| 1014 | \r | |
| 1015 | exit $ExitCode\r |