66 description : The Windows SDK version to use, e.g. "10.0.22621.0"
77 required : false
88 type : string
9- windows- msvc-version :
9+ msvc-version :
1010 description : The Windows MSVC version to use, e.g. "14.42"
1111 required : false
1212 type : string
2828 shell : pwsh
2929 run : |
3030 if ($IsWindows) {
31- $HostOs = "windows"
31+ $HostOS = "windows"
3232 } elseif ($IsMacOS) {
33- $HostOs = "mac"
33+ $HostOS = "mac"
3434 } else {
3535 Write-Output "::error::Unsupported host OS."
3636 exit 1
@@ -46,23 +46,23 @@ runs:
4646 }
4747 }
4848
49- $WinMsvcVersion = "${{ inputs.windows- msvc-version }}"
50- if ($WinMsvcVersion -ne "") {
51- $ParsedWinMsvcVersion = [System.Version]::Parse($WinMsvcVersion )
52- if ($ParsedWinMsvcVersion -eq $null) {
53- Write-Output "::error::Invalid Windows MSVC version: `"${WinMsvcVersion }`"."
49+ $MSVCVersion = "${{ inputs.msvc-version }}"
50+ if ($MSVCVersion -ne "") {
51+ $ParsedMSVCVersion = [System.Version]::Parse($MSVCVersion )
52+ if ($ParsedMSVCVersion -eq $null) {
53+ Write-Output "::error::Invalid Windows MSVC version: `"${MSVCVersion }`"."
5454 exit 1
5555 }
56- if ($ParsedWinMsvcVersion .Major -ne 14) {
57- Write-Output "::error::Unsupported Windows MSVC version (major version not supported): `"${WinMsvcVersion }`"."
56+ if ($ParsedMSVCVersion .Major -ne 14) {
57+ Write-Output "::error::Unsupported Windows MSVC version (major version not supported): `"${MSVCVersion }`"."
5858 exit 1
5959 }
60- if ($ParsedWinMsvcVersion .Build -ne -1) {
61- Write-Output "::error::Unsupported Windows MSVC version (build version was specified): `"${WinMsvcVersion }`"."
60+ if ($ParsedMSVCVersion .Build -ne -1) {
61+ Write-Output "::error::Unsupported Windows MSVC version (build version was specified): `"${MSVCVersion }`"."
6262 exit 1
6363 }
64- if ($ParsedWinMsvcVersion .Revision -ne -1) {
65- Write-Output "::error::Unsupported Windows MSVC version (revision version was specified): `"${WinMsvcVersion }`"."
64+ if ($ParsedMSVCVersion .Revision -ne -1) {
65+ Write-Output "::error::Unsupported Windows MSVC version (revision version was specified): `"${MSVCVersion }`"."
6666 exit 1
6767 }
6868 }
@@ -78,16 +78,16 @@ runs:
7878 }
7979 }
8080
81- Write-Output "Host OS: $HostOs"
82- Write-Output "Host architecture: $HostArch"
83- Write-Output "Target architecture: $TargetArch"
81+ Write-Output "::info::Build OS: $HostOS"
82+ Write-Output "::info::Build architecture: $HostArch"
83+ Write-Output "::info::Host OS: $HostOS"
84+ Write-Output "::info::Host architecture: $TargetArch"
8485
85- $VerifiedInput = @"
86- host-os=$HostOs
86+ @"
87+ host-os=$HostOS
8788 host-arch=$HostArch
8889 target-arch=$TargetArch
89- "@
90- Write-Output $VerifiedInput | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
90+ "@ | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
9191
9292 - name : Install Windows SDK version ${{ inputs.windows-sdk-version }}
9393 if : steps.verify-input.outputs.host-os == 'windows' && inputs.windows-sdk-version != ''
@@ -105,16 +105,16 @@ runs:
105105 $Win10SdkIncludeVersion = Join-Path $Win10SdkInclude $WinSdkVersionString
106106
107107 if (Test-Path -Path $Win10SdkIncludeVersion -PathType Container) {
108- Write-Output "Windows SDK ${WinSdkVersionString} already installed."
108+ Write-Output "::info:: Windows SDK ${WinSdkVersionString} already installed."
109109 } else {
110110 # Install the missing SDK.
111111 Write-Output "Installing Windows SDK ${WinSdkVersionString}..."
112112
113113 $InstallerLocation = Join-Path "${env:ProgramFiles(x86)}" "Microsoft Visual Studio" "Installer"
114- $VsWhere = Join-Path "${InstallerLocation}" "vswhere .exe"
115- $VsInstaller = Join-Path "${InstallerLocation}" "vs_installer.exe"
116- $InstallPath = (& "$VsWhere " -latest -products * -format json | ConvertFrom-Json).installationPath
117- $process = Start-Process "$VsInstaller " `
114+ $VSWhere = Join-Path "${InstallerLocation}" "VSWhere .exe"
115+ $VSInstaller = Join-Path "${InstallerLocation}" "vs_installer.exe"
116+ $InstallPath = (& "$VSWhere " -latest -products * -format json | ConvertFrom-Json).installationPath
117+ $process = Start-Process "$VSInstaller " `
118118 -PassThru `
119119 -ArgumentList "modify", `
120120 "--installPath", "`"$InstallPath`"", `
@@ -136,6 +136,8 @@ runs:
136136
137137 # Remove more recent Windows SDKs, if present. This is used to work
138138 # around issues where LLVM uses the most recent Windows SDK.
139+ # This should be removed once a more permanent solution is found.
140+ # See https://github.com/compnerd/swift-build/issues/958 for details.
139141 Get-ChildItem -Path $Win10SdkInclude -Directory | ForEach-Object {
140142 $IncludeDirName = $_.Name
141143 try {
@@ -151,65 +153,69 @@ runs:
151153 }
152154 }
153155
154- - name : Install Windows MSVC version ${{ inputs.windows- msvc-version }}
155- if : steps.verify-input.outputs.host-os == 'windows' && inputs.windows- msvc-version != ''
156+ - name : Install Windows MSVC version ${{ inputs.msvc-version }}
157+ if : steps.verify-input.outputs.host-os == 'windows' && inputs.msvc-version != ''
156158 shell : pwsh
157159 run : |
158160 # This is assuming a VS2022 toolchain. e.g.
159161 # MSVC 14.42 corresponds to the 14.42.17.12 package.
160162 # MSVC 14.43 corresponds to the 14.43.17.13 package.
161- $WinMsvcVersionString = "${{ inputs.windows- msvc-version }}"
163+ $MSVCVersionString = "${{ inputs.msvc-version }}"
162164
163165 $InstallerLocation = Join-Path "${env:ProgramFiles(x86)}" "Microsoft Visual Studio" "Installer"
164- $VsWhere = Join-Path "${InstallerLocation}" "vswhere .exe"
165- $VsInstaller = Join-Path "${InstallerLocation}" "vs_installer.exe"
166- $InstallPath = (& "$VsWhere " -latest -products * -format json | ConvertFrom-Json).installationPath
166+ $VSWhere = Join-Path "${InstallerLocation}" "VSWhere .exe"
167+ $VSInstaller = Join-Path "${InstallerLocation}" "vs_installer.exe"
168+ $InstallPath = (& "$VSWhere " -latest -products * -format json | ConvertFrom-Json).installationPath
167169 $MSVCDir = Join-Path $InstallPath "VC" "Tools" "MSVC"
168170
169171 # Check if this MSVC version is already installed.
170172 Get-ChildItem -Path $MSVCDir -Directory | ForEach-Object {
171- $MsvcDirName = $_.Name
172- if ($MsvcDirName .StartsWith($WinMsvcVersionString )) {
173- Write-Output "MSVC ${WinMsvcVersionString } already installed."
173+ $MSVCDirName = $_.Name
174+ if ($MSVCDirName .StartsWith($MSVCVersionString )) {
175+ Write-Output "::info:: MSVC ${MSVCVersionString } already installed."
174176 exit 0
175177 }
176178 }
177179
178- # Compute the MSVC version package name.
179- $WinMsvcVersion = [System.Version]::Parse($WinMsvcVersionString)
180- $MajorVersion = $WinMsvcVersion.Major
181- $MinorVersion = $WinMsvcVersion.Minor
180+ # Compute the MSVC version package name from the MSVC version, assuming this is coming from
181+ # a VS2022 installation. The version package follows the following format:
182+ # * Major and minor version are the same as the MSVC version.
183+ # * Build version is always 17 (VS2002 is VS17).
184+ # * The revision is set to the number of minor versions since VS17 release.
185+ $MSVCVersion = [System.Version]::Parse($MSVCVersionString)
186+ $MajorVersion = $MSVCVersion.Major
187+ $MinorVersion = $MSVCVersion.Minor
182188 $BuildVersion = 17
183189 $RevisionVersion = $MinorVersion - 30
184- $WinMsvcVersionBuild = "${MajorVersion}.${MinorVersion}.${BuildVersion}.${RevisionVersion}"
190+ $MSVCPackageVersion = "${MajorVersion}.${MinorVersion}.${BuildVersion}.${RevisionVersion}"
185191
186192 # Install the missing MSVC version.
187- Write-Output "Installing MSVC packages for ${WinMsvcVersionBuild }..."
188- $process = Start-Process "$VsInstaller " `
193+ Write-Output "Installing MSVC packages for ${MSVCPackageVersion }..."
194+ $process = Start-Process "$VSInstaller " `
189195 -PassThru `
190196 -ArgumentList "modify", `
191197 "--installPath", "`"$InstallPath`"", `
192198 "--channelId", "https://aka.ms/vs/17/release/channel", `
193199 "--quiet", "--norestart", "--nocache", `
194- "--add", "Microsoft.VisualStudio.Component.VC.${WinMsvcVersionBuild }.x86.x64", `
195- "--add", "Microsoft.VisualStudio.Component.VC.${WinMsvcVersionBuild }.ATL", `
196- "--add", "Microsoft.VisualStudio.Component.VC.${WinMsvcVersionBuild }.ARM64", `
197- "--add", "Microsoft.VisualStudio.Component.VC.${WinMsvcVersionBuild }.ATL.ARM64"
200+ "--add", "Microsoft.VisualStudio.Component.VC.${MSVCPackageVersion }.x86.x64", `
201+ "--add", "Microsoft.VisualStudio.Component.VC.${MSVCPackageVersion }.ATL", `
202+ "--add", "Microsoft.VisualStudio.Component.VC.${MSVCPackageVersion }.ARM64", `
203+ "--add", "Microsoft.VisualStudio.Component.VC.${MSVCPackageVersion }.ATL.ARM64"
198204 $process.WaitForExit()
199205
200206 # Check if the MSVC version was installed successfully.
201207 $MSVCDirFound = $false
202- Get-ChildItem -Path $MSVCDir -Directory | ForEach-Object {
203- $MsvcDirName = $_ .Name
204- if ($MsvcDirName .StartsWith($WinMsvcVersionString )) {
205- Write-Output "MSVC ${WinMsvcVersionString } installed successfully."
208+ foreach ($dir in Get-ChildItem -Path $MSVCDir -Directory) {
209+ $MSVCDirName = $dir .Name
210+ if ($MSVCDirName .StartsWith($MSVCVersionString )) {
211+ Write-Output "MSVC ${MSVCVersionString } installed successfully."
206212 $MSVCDirFound = $true
207213 break
208214 }
209215 }
210216
211217 if (-not $MSVCDirFound) {
212- Write-Output "::error::Failed to install MSVC ${WinMsvcVersionString }."
218+ Write-Output "::error::Failed to install MSVC ${MSVCVersionString }."
213219 Write-Output "Installer log:"
214220 $log = Get-ChildItem "${env:TEMP}" -Filter "dd_installer_*.log" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
215221 Get-Content $log.FullName
@@ -222,5 +228,5 @@ runs:
222228 with :
223229 host_arch : ${{ steps.verify-input.outputs.host-arch }}
224230 arch : ${{ steps.verify-input.outputs.target-arch }}
225- winsdk : ${{ inputs.windows- msvc-version }}
226- toolset_version : ${{ inputs.windows- msvc-version }}
231+ winsdk : ${{ inputs.msvc-version }}
232+ toolset_version : ${{ inputs.msvc-version }}
0 commit comments