|
| 1 | +# Copyright (c) 2026, the WebKit for Windows project authors. Please see the |
| 2 | +# AUTHORS file for details. All rights reserved. Use of this source code is |
| 3 | +# governed by a BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +<# |
| 6 | + .Synopsis |
| 7 | + Installs the Swift toolchain for Windows. |
| 8 | +
|
| 9 | + .Description |
| 10 | + Downloads the specified release of the Swift toolchain for Windows and |
| 11 | + installs it silently on the host. The installer places the toolchain under |
| 12 | + the user profile and updates the user PATH rather than the machine PATH, so |
| 13 | + the environment is refreshed from both targets before verifying. Compiling |
| 14 | + with Swift additionally requires the MSVC toolchain and Windows SDK. |
| 15 | +
|
| 16 | + .Parameter Version |
| 17 | + The version of the Swift toolchain to install. |
| 18 | +
|
| 19 | + .Example |
| 20 | + # Install 6.3.3 |
| 21 | + Install-Swift -Version 6.3.3 |
| 22 | +#> |
| 23 | +function Install-Swift { |
| 24 | + param( |
| 25 | + [Parameter(Mandatory)] |
| 26 | + [string]$version |
| 27 | + ) |
| 28 | + |
| 29 | + $url = ('https://download.swift.org/swift-{0}-release/windows10/swift-{0}-RELEASE/swift-{0}-RELEASE-windows10.exe' -f $version); |
| 30 | + |
| 31 | + $options = @( |
| 32 | + '-q' |
| 33 | + ); |
| 34 | + |
| 35 | + # Install-FromExe only refreshes the machine PATH before verifying, but the |
| 36 | + # Swift installer updates the user PATH, so skip the built-in verification. |
| 37 | + Install-FromExe -Name 'swift' -url $url -Options $options -NoVerify; |
| 38 | + |
| 39 | + # Refresh the PATH from both the machine and user targets so the newly |
| 40 | + # installed toolchain is resolvable, then verify. |
| 41 | + $env:PATH = @( |
| 42 | + [Environment]::GetEnvironmentVariable('PATH',[EnvironmentVariableTarget]::Machine), |
| 43 | + [Environment]::GetEnvironmentVariable('PATH',[EnvironmentVariableTarget]::User) |
| 44 | + ) -join ';'; |
| 45 | + |
| 46 | + Write-Information -MessageData 'Verifying swift install ...' -InformationAction Continue; |
| 47 | + swift --version; |
| 48 | +} |
0 commit comments