Skip to content

Commit ef123a4

Browse files
Harden Windows build setup (#840)
* Harden Windows build setup - Prefer VS 2017/2019/2022 over newer installs (e.g. VS 2026) when vswhere reports both, so a host with a newer VS installed alongside VS 2022 still builds with v143. Without this the downstream Select-String version checks miss and the VS 2015 fallback dereferences a null VS140COMNTOOLS. - Pin vcpkg's CMake with VCPKG_VISUAL_STUDIO_PATH and VCPKG_PLATFORM_TOOLSET=v143 so it uses the same toolset as the .vcxproj files, avoiding MSB8040 (Spectre-libs missing for v145) when vcpkg would otherwise pick up a newer VS. - Fall back to the repo root for OpenSSH-build.ps1 -destination when \$env:WORKSPACE is unset. CI still has its WORKSPACE value, and no longer invokes this script directly anyway. - Document Windows build prerequisites in README.txt: VS 2022 Desktop C++ workload, v143 Spectre-mitigated libs, Git, the one-time vcpkg bootstrap/integrate step, and the need to run from an elevated PowerShell. * Prefer VS 2022 specifically, not 2017/2019/2022 as a group The .vcxproj files pin PlatformToolset v143, which ships with VS 2022. VS 2017 (v141) and VS 2019 (v142) would need v143 build tools sideloaded to build this, which is a non-default setup — so they shouldn't be treated as equals to VS 2022 in the preference order.
1 parent fbfe284 commit ef123a4

3 files changed

Lines changed: 56 additions & 4 deletions

File tree

contrib/win32/openssh/OpenSSH-build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# PowerShell Script to clone, build and package PowerShell from specified fork and branch
33
param (
44
[string] $repolocation = "$PSScriptRoot\..\..\..",
5-
[string] $destination = "$env:WORKSPACE",
5+
[string] $destination = $(if ($env:WORKSPACE) { $env:WORKSPACE } else { "$PSScriptRoot\..\..\.." }),
66
[ValidateSet('x86', 'x64', 'arm64', 'arm')]
77
[String]$NativeHostArch = 'x64',
88
[ValidateSet('Debug', 'Release')]

contrib/win32/openssh/OpenSSHBuildHelper.psm1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,11 @@ function Start-OpenSSHBuild
559559
$VisualStudioPath = Get-VisualStudioPath -NativeHostArch $NativeHostArch
560560
if ($null -ne $VisualStudioPath) {
561561
$msbuildCmd = Get-MSBuildPath -VSInstallPath $VisualStudioPath
562+
# Pin vcpkg's CMake to the same VS install / toolset (v143) as the
563+
# OpenSSH vcxproj files, so manifest-mode auto-install doesn't pick a
564+
# newer VS (e.g. VS 2026) whose v14x toolset is unsupported here.
565+
$env:VCPKG_VISUAL_STUDIO_PATH = $VisualStudioPath
566+
$env:VCPKG_PLATFORM_TOOLSET = "v143"
562567
}
563568
else {
564569
$msbuildCmd = Get-VS2015BuildToolPath
@@ -614,7 +619,12 @@ function Get-VisualStudioPath {
614619
$VSPaths = (& $vsWherePath -products * -requires $requiredVCtools -property installationPath)
615620
# for some reason, VSWhere does not seem to find MSBuild so check manually
616621
if ($null -ne $VSPaths) {
617-
foreach ($VSPath in $VSPaths) {
622+
# Prefer VS 2022 — the .vcxproj files pin <PlatformToolset>v143</PlatformToolset>,
623+
# which ships with VS 2022. Older VS (2017=v141, 2019=v142) would need v143 build tools
624+
# sideloaded; newer VS (e.g. 2026) defaults to v145 which isn't supported here.
625+
$preferred = @($VSPaths | Where-Object { $_ -match '\\2022\\' })
626+
$ordered = $preferred + @($VSPaths | Where-Object { $_ -notmatch '\\2022\\' })
627+
foreach ($VSPath in $ordered) {
618628
if (Get-MSBuildPath -VSInstallPath $VSPath) {
619629
return $VSPath
620630
}

contrib/win32/openssh/README.txt

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Custom paths for the visual studio projects are defined in paths.targets.
1+
Custom paths for the visual studio projects are defined in paths.targets.
22

33
All projects import this targets file, and it should be in the same directory as the project.
44

@@ -10,12 +10,54 @@ OpenSSH-Lib-Path = The directory path of the location to which libra
1010
LibreSSL-x86-Path = The directory path of LibreSSL statically compiled for x86 platform.
1111
LibreSSL-x64-Path = The directory path of LibreSSL statically compiled for x64 platform.
1212

13+
Prerequisites
14+
-------------
15+
16+
Before building OpenSSH for Windows, install the following:
17+
18+
1. Visual Studio 2022 (Community, Professional, or Build Tools).
19+
Required components (Visual Studio Installer -> Modify):
20+
- Workload: "Desktop development with C++"
21+
This installs MSBuild, the v143 toolset, and the Windows 10/11 SDK.
22+
- Individual component: "MSVC v143 - VS 2022 C++ x64/x86 Spectre-mitigated libs (Latest)"
23+
Required because the vcpkg x64-custom triplet compiles
24+
dependencies (LibreSSL, libfido2, zlib) with /Qspectre, which
25+
demands matching Spectre-mitigated runtime libraries.
26+
- For ARM64 builds, also install "MSVC v143 - VS 2022 C++ ARM64 Spectre-mitigated libs".
27+
28+
Note: If a newer Visual Studio (e.g. VS 2026) is also installed,
29+
OpenSSH-build.ps1 prefers VS 2022 and pins vcpkg's CMake to the
30+
same install / v143 toolset automatically.
31+
32+
2. Git for Windows.
33+
The build script expects git.exe to be on PATH (it will add
34+
"%ProgramFiles%\Git\cmd" to the machine PATH if missing).
35+
36+
3. vcpkg (one-time bootstrap).
37+
Dependencies (LibreSSL, libfido2, zlib, libcbor) are managed via a
38+
vcpkg manifest (vcpkg.json). MSBuild auto-installs them at build
39+
time, but vcpkg must be cloned, bootstrapped, and integrated first:
40+
41+
git clone https://github.com/microsoft/vcpkg
42+
cd vcpkg
43+
.\bootstrap-vcpkg.bat
44+
.\vcpkg.exe integrate install
45+
46+
"vcpkg integrate install" registers vcpkg's MSBuild props user-wide;
47+
after that, every OpenSSH-build.ps1 run picks up the manifest
48+
automatically. No need to run "vcpkg install" manually.
49+
50+
4. Administrator PowerShell.
51+
The build script updates the machine PATH (to add Git / Chocolatey)
52+
and may install the Windows SDK via Chocolatey if missing. Run the
53+
build from an elevated PowerShell session.
54+
1355
Notes on FIDO2 support
1456
----------------------
1557

1658
* How to build:
1759

18-
- Open Windows PowerShell.
60+
- Open Windows PowerShell as Administrator.
1961

2062
- Build OpenSSH for Windows:
2163

0 commit comments

Comments
 (0)