Skip to content

Commit 62d7b6f

Browse files
committed
Fix a few bugs and output build tools version
* Incorrect value passed to `winsdk` in `gha-setup-vsdevenv` * Incorrect test for skipping setting up the VS Dev Environment * Regression tests added
1 parent 44c992c commit 62d7b6f

File tree

2 files changed

+133
-46
lines changed

2 files changed

+133
-46
lines changed

.github/actions/setup-build/action.yml

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@ inputs:
2020
required: false
2121
type: string
2222

23+
outputs:
24+
windows-build-tools-version:
25+
description: |
26+
The full version of the Windows build tools installed, eg. "14.42.34433". This is only set
27+
if the `msvc-version` input was provided, and only on Windows.
28+
value: ${{ steps.install-msvc.outputs.windows-build-tools-version }}
29+
2330
runs:
2431
using: composite
2532
steps:
26-
- name: Verify input
27-
id: verify-input
33+
- name: Sanitize input
34+
id: sanitize-input
2835
shell: pwsh
2936
run: |
3037
if ($IsWindows) {
@@ -71,15 +78,18 @@ runs:
7178
}
7279
}
7380
74-
switch ("${{ inputs.target-arch }}") {
75-
"x86" { $TargetArch = "x86" }
76-
"amd64" { $TargetArch = "amd64" }
77-
"arm64" { $TargetArch = "arm64" }
78-
"" { $TargetArch = $HostArch }
79-
default {
80-
Write-Output "::error::Unsupported target architecture: `"${{ inputs.target-arch }}`""
81-
exit 1
82-
}
81+
if ("${{ inputs.setup-vs-dev-env }}" -eq "true") {
82+
switch ("${{ inputs.target-arch }}") {
83+
"x86" { $TargetArch = "x86" }
84+
"amd64" { $TargetArch = "amd64" }
85+
"arm64" { $TargetArch = "arm64" }
86+
"" { $TargetArch = $HostArch }
87+
default {
88+
Write-Output "::error::Unsupported target architecture: `"${{ inputs.target-arch }}`""
89+
exit 1
90+
}
91+
} else {
92+
$TargetArch = $HostArch
8393
}
8494
8595
Write-Output "ℹ️ Host OS: $HostOS"
@@ -94,7 +104,7 @@ runs:
94104
"@ | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
95105
96106
- name: Install Windows SDK version ${{ inputs.windows-sdk-version }}
97-
if: steps.verify-input.outputs.host-os == 'windows' && inputs.windows-sdk-version != ''
107+
if: steps.sanitize-input.outputs.host-os == 'windows' && inputs.windows-sdk-version != ''
98108
shell: pwsh
99109
run: |
100110
$WinSdkVersionString = "${{ inputs.windows-sdk-version }}"
@@ -158,7 +168,8 @@ runs:
158168
}
159169
160170
- name: Install Windows MSVC version ${{ inputs.msvc-version }}
161-
if: steps.verify-input.outputs.host-os == 'windows' && inputs.msvc-version != ''
171+
if: steps.sanitize-input.outputs.host-os == 'windows' && inputs.msvc-version != ''
172+
id: setup-msvc
162173
shell: pwsh
163174
run: |
164175
# This is assuming a VS2022 toolchain. e.g.
@@ -172,15 +183,6 @@ runs:
172183
$InstallPath = (& "$VSWhere" -latest -products * -format json | ConvertFrom-Json).installationPath
173184
$MSVCDir = Join-Path $InstallPath "VC" "Tools" "MSVC"
174185
175-
# Check if this MSVC version is already installed.
176-
Get-ChildItem -Path $MSVCDir -Directory | ForEach-Object {
177-
$MSVCDirName = $_.Name
178-
if ($MSVCDirName.StartsWith($MSVCVersionString)) {
179-
Write-Output "ℹ️ MSVCPackageVersionMSVC ${MSVCVersionString} already installed."
180-
exit 0
181-
}
182-
}
183-
184186
# Compute the MSVC version package name from the MSVC version, assuming this is coming from
185187
# a VS2022 installation. The version package follows the following format:
186188
# * Major and minor version are the same as the MSVC version.
@@ -208,29 +210,32 @@ runs:
208210
$process.WaitForExit()
209211
210212
# Check if the MSVC version was installed successfully.
211-
$MSVCDirFound = $false
213+
$MSVCBuildToolsVersion = ""
212214
foreach ($dir in Get-ChildItem -Path $MSVCDir -Directory) {
213215
$MSVCDirName = $dir.Name
214216
if ($MSVCDirName.StartsWith($MSVCVersionString)) {
215217
Write-Output "ℹ️ MSVC ${MSVCVersionString} installed successfully."
216-
$MSVCDirFound = $true
218+
$MSVCBuildToolsVersion = $MsvcDirName
217219
break
218220
}
219221
}
220222
221-
if (-not $MSVCDirFound) {
223+
if ($MSVCBuildToolsVersion -eq "") {
222224
Write-Output "::error::Failed to install MSVC ${MSVCVersionString}."
223225
Write-Output "Installer log:"
224226
$log = Get-ChildItem "${env:TEMP}" -Filter "dd_installer_*.log" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
225227
Get-Content $log.FullName
226228
exit 1
229+
} else {
230+
Write-Output "ℹ️ MSVC ${MSVCBuildToolsVersion} installed successfully."
231+
"windows-build-tools-version=${MSVCBuildToolsVersion}" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
227232
}
228233
229234
- name: Setup Visual Studio Developer Environment
230-
if: steps.verify-input.outputs.host-os == 'windows' && inputs.setup-vs-dev-env
235+
if: steps.sanitize-input.outputs.host-os == 'windows' && inputs.setup-vs-dev-env == 'true'
231236
uses: compnerd/gha-setup-vsdevenv@5eb3eae1490d4f7875d574c4973539f69109700d # main
232237
with:
233-
host_arch: ${{ steps.verify-input.outputs.host-arch }}
234-
arch: ${{ steps.verify-input.outputs.target-arch }}
235-
winsdk: ${{ inputs.msvc-version }}
238+
host_arch: ${{ steps.sanitize-input.outputs.host-arch }}
239+
arch: ${{ steps.sanitize-input.outputs.target-arch }}
240+
winsdk: ${{ inputs.windows-sdk-version }}
236241
toolset_version: ${{ inputs.msvc-version }}

.github/workflows/test-setup-build.yml

Lines changed: 99 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@ on:
2020
type: string
2121

2222
env:
23-
TEST_WIN_SDK_VERSION: 10.0.22621.0
24-
TEST_MSVC_VERSION: 14.42
23+
TEST_WIN_SDK_VERSION: 10.0.22000.0
24+
TEST_MSVC_VERSION: 14.40
2525

2626
jobs:
27-
test-setup-build-windows:
28-
name: Test MSVC and Windows SDK environment setup
27+
test-setup-build-windows-vs-dev-env:
28+
name: MSVC + WinSDK With Dev Environment
2929
runs-on: ${{ inputs.windows-runner || 'windows-latest' }}
3030
steps:
3131
- name: Checkout
3232
uses: actions/checkout@v4.2.2
3333

3434
- name: Set up build
35+
id: setup-build
3536
uses: ./.github/actions/setup-build
3637
with:
3738
windows-sdk-version: ${{ env.TEST_WIN_SDK_VERSION }}
@@ -80,19 +81,11 @@ jobs:
8081
$InstallerLocation = Join-Path "${env:ProgramFiles(x86)}" "Microsoft Visual Studio" "Installer"
8182
$VSWhere = Join-Path "${InstallerLocation}" "vswhere.exe"
8283
$InstallPath = (& "$VSWhere" -latest -products * -format json | ConvertFrom-Json).installationPath
83-
$MSVCDir = Join-Path $InstallPath "VC" "Tools" "MSVC"
84-
$DirFound = $false
85-
foreach ($dir in Get-ChildItem -Path $MSVCDir -Directory) {
86-
$MSVCDirName = $dir.Name
87-
if ($MSVCDirName.StartsWith($env:TEST_MSVC_VERSION)) {
88-
$DirFound = $true
89-
break
90-
}
91-
}
92-
if ($DirFound) {
84+
$MSVCDir = Join-Path $InstallPath "VC" "Tools" "MSVC" "${{ steps.setup-build.outputs.windows-build-tools-version }}"
85+
if (Test-Path -Path $MSVCDir) {
9386
Write-Output "✅ MSVC version `${env:TEST_MSVC_VERSION}`" is installed."
9487
} else {
95-
Write-Output "::error::Expected MSVC version not found: `"${env:TEST_MSVC_VERSION}`"."
88+
Write-Output "::error::MSVC directory not found: `"${MSVCDir}`"."
9689
$HasError = $true
9790
}
9891
@@ -103,7 +96,7 @@ jobs:
10396
$lastLine = $clOutput | Select-Object -Last 1
10497
Remove-Item $tempFile -Force
10598
106-
# _MSC_VER expands to a number like 1942 for MSVC 14.42.
99+
# _MSC_VER expands to a number like 1940 for MSVC 14.40.
107100
$ParsedMSVCVersion = [System.Version]::Parse($env:TEST_MSVC_VERSION)
108101
$ExpectedVersion = ($ParsedMSVCVersion.Major + 5) * 100 + $ParsedMSVCVersion.Minor
109102
if ($lastLine -eq $ExpectedVersion) {
@@ -113,7 +106,7 @@ jobs:
113106
$HasError = $true
114107
}
115108
116-
# Check if the Windows SDK version is set in the environment.
109+
# Check that the Windows SDK version is set in the environment.
117110
if ($env:UCRTVersion -eq $env:TEST_WIN_SDK_VERSION) {
118111
Write-Output "✅ UCRTVersion environment variable is set to `"${env:TEST_WIN_SDK_VERSION}`"."
119112
} else {
@@ -127,3 +120,92 @@ jobs:
127120
} else {
128121
Write-Output "🎉 All environment checks passed successfully."
129122
}
123+
124+
test-setup-build-windows-no-dev-env:
125+
name: MSVC + WinSDK No Dev Environment
126+
runs-on: ${{ inputs.windows-runner || 'windows-latest' }}
127+
steps:
128+
- name: Checkout
129+
uses: actions/checkout@v4.2.2
130+
131+
- name: Set up build
132+
id: setup-build
133+
uses: ./.github/actions/setup-build
134+
with:
135+
windows-sdk-version: ${{ env.TEST_WIN_SDK_VERSION }}
136+
msvc-version: ${{ env.TEST_MSVC_VERSION }}
137+
setup-vs-dev-env: false
138+
139+
- name: Check environment
140+
run: |
141+
$HasError = $false
142+
143+
$ParsedWinSdkVersion = [System.Version]::Parse($env:TEST_WIN_SDK_VERSION)
144+
$Win10SdkRoot = Get-ItemPropertyValue `
145+
-Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots" `
146+
-Name "KitsRoot10"
147+
$Win10SdkInclude = Join-Path $Win10SdkRoot "Include"
148+
149+
# Check if the Windows SDK version is installed.
150+
$ExpectedWinSdkDir = Join-Path $Win10SdkInclude "$($env:TEST_WIN_SDK_VERSION)"
151+
if (Test-Path -Path $ExpectedWinSdkDir) {
152+
Write-Output "✅ Windows SDK version `"${env:TEST_WIN_SDK_VERSION}`" is installed."
153+
} else {
154+
Write-Output "::error::Expected Windows SDK version not found: `"${env:TEST_WIN_SDK_VERSION}`"."
155+
$HasError = $true
156+
}
157+
158+
# Check if Windows SDK versions greater than the expected version are installed.
159+
$UnexpectedSdkFound = $false
160+
Get-ChildItem -Path $Win10SdkInclude -Directory | ForEach-Object {
161+
$Version = $_.Name
162+
try {
163+
$ParsedVersion = [System.Version]::Parse($Version)
164+
if ($ParsedVersion -gt $ParsedWinSdkVersion) {
165+
Write-Output "::error::Unexpected Windows SDK version found: `"${Version}`" (greater than expected: `"${env:TEST_WIN_SDK_VERSION}`")."
166+
$HasError = $true
167+
$UnexpectedSdkFound = $true
168+
}
169+
} catch {
170+
# Skip if the directory cannot be parsed as a version.
171+
}
172+
}
173+
if (-not $UnexpectedSdkFound) {
174+
Write-Output "✅ No unexpected Windows SDK versions greater than `"${env:TEST_WIN_SDK_VERSION}`" found."
175+
}
176+
177+
# Check if the correct MSVC version is installed.
178+
$InstallerLocation = Join-Path "${env:ProgramFiles(x86)}" "Microsoft Visual Studio" "Installer"
179+
$VSWhere = Join-Path "${InstallerLocation}" "vswhere.exe"
180+
$InstallPath = (& "$VSWhere" -latest -products * -format json | ConvertFrom-Json).installationPath
181+
$MSVCDir = Join-Path $InstallPath "VC" "Tools" "MSVC" "${{ steps.setup-build.outputs.windows-build-tools-version }}"
182+
if (Test-Path -Path $MSVCDir) {
183+
Write-Output "✅ MSVC version `${env:TEST_MSVC_VERSION}`" is installed."
184+
} else {
185+
Write-Output "::error::MSVC directory not found: `"${MSVCDir}`"."
186+
$HasError = $true
187+
}
188+
189+
# Check that cl.exe was not set.
190+
$CLExe = Get-Command -Name cl.exe -ErrorAction Ignore
191+
if ($CLExe) {
192+
Write-Output "::error::cl.exe was unexpectedly found in the PATH: `"${CLExe.Path}`"."
193+
$HasError = $true
194+
} else {
195+
Write-Output "✅ cl.exe is not set in the PATH, as expected."
196+
}
197+
198+
# Check that the VS Dev Environment was not set.
199+
if ($env:UCRTVersion) {
200+
Write-Output "::error::UCRTVersion environment variable was set to `"${env:UCRTVersion}`"."
201+
$HasError = $true
202+
} else {
203+
Write-Output "✅ UCRTVersion environment variable is set to `"${env:TEST_WIN_SDK_VERSION}`"."
204+
}
205+
206+
if ($HasError) {
207+
Write-Output "::error::There were errors in the environment setup. Check the logs for details."
208+
exit 1
209+
} else {
210+
Write-Output "🎉 All environment checks passed successfully."
211+
}

0 commit comments

Comments
 (0)