@@ -29,7 +29,7 @@ $x86Directory = Join-Path $projectDirectory "nuget.package\runtimes\win-x86\nati
2929$x64Directory = Join-Path $projectDirectory " nuget.package\runtimes\win-x64\native"
3030$arm64Directory = Join-Path $projectDirectory " nuget.package\runtimes\win-arm64\native"
3131$hashFile = Join-Path $projectDirectory " nuget.package\libgit2\libgit2_hash.txt"
32- $sha = Get-Content $hashFile
32+ $sha = Get-Content $hashFile
3333$binaryFilename = " git2-" + $sha.Substring (0 , 7 )
3434
3535$build_tests = ' OFF'
@@ -101,6 +101,56 @@ function Assert-Consistent-Naming($expected, $path) {
101101 Ensure- Property $expected $dll.VersionInfo.OriginalFilename " VersionInfo.OriginalFilename" $dll.Fullname
102102}
103103
104+ function Install-Libssh2 ($arch ) {
105+ $triplet = " $arch -windows"
106+
107+ $vcpkg = Join-Path $Env: VCPKG_INSTALLATION_ROOT " vcpkg.exe"
108+ if (-not (Test-Path $vcpkg )) {
109+ throw " Error: vcpkg not found at $Env: VCPKG_INSTALLATION_ROOT "
110+ }
111+
112+ # Install libssh2 with the WinCNG crypto backend (no OpenSSL dependency).
113+ # 'openssl' is a default vcpkg feature for libssh2, so manifest mode is required
114+ # to override it — classic mode has no --no-default-features flag.
115+ # The overlay triplet injects -DENABLE_ECDSA_WINCNG=ON into every package's
116+ # cmake configure step (zlib ignores it; libssh2 uses it).
117+ $manifestDir = Join-Path $projectDirectory " libssh2-wincng-manifest"
118+ New-Item - ItemType Directory - Force - Path $manifestDir | Out-Null
119+ @"
120+ {
121+ "name": "libssh2-wincng",
122+ "version": "1.0.0",
123+ "dependencies": [
124+ {
125+ "name": "libssh2",
126+ "default-features": false,
127+ "features": ["zlib"]
128+ }
129+ ]
130+ }
131+ "@ | Set-Content (Join-Path $manifestDir " vcpkg.json" )
132+
133+ $installRoot = Join-Path $projectDirectory " libssh2-wincng-installed"
134+ $overlayTriplets = Join-Path $projectDirectory " libssh2-wincng-triplets"
135+
136+ Write-Host " Installing libssh2 (WinCNG + ECDSA) for $triplet via vcpkg..."
137+ Push-Location $manifestDir
138+ try {
139+ Run- Command - Fatal - Quiet { & $vcpkg install -- vcpkg- root $Env: VCPKG_INSTALLATION_ROOT -- triplet $triplet " --x-install-root=$installRoot " " --overlay-triplets=$overlayTriplets " }
140+ } finally {
141+ Pop-Location
142+ }
143+
144+ $installedDir = Join-Path $installRoot $triplet
145+
146+ return @ {
147+ IncludeDir = Join-Path $installedDir " include"
148+ LibDir = Join-Path $installedDir " lib"
149+ BinDir = Join-Path $installedDir " bin"
150+ Prefix = $installedDir
151+ }
152+ }
153+
104154try {
105155 if ((! $x86.isPresent -and ! $x64.IsPresent ) -and ! $arm64.IsPresent ) {
106156 Write-Output - Stderr " Error: usage $MyInvocation .MyCommand [-x86] [-x64] [-arm64]"
@@ -118,7 +168,8 @@ try {
118168
119169 if ($x86.IsPresent ) {
120170 Write-Output " Building x86..."
121- Run- Command - Fatal { & $cmake - A Win32 - D USE_SSH= exec - D USE_HTTPS= Schannel - D " BUILD_TESTS=$build_tests " - D " BUILD_CLI=OFF" - D " LIBGIT2_FILENAME=$binaryFilename " .. }
171+ $ssh2 = Install-Libssh2 " x86"
172+ Run- Command - Fatal { & $cmake - A Win32 - D USE_SSH= ON - D USE_HTTPS= Schannel - D " BUILD_TESTS=$build_tests " - D " BUILD_CLI=OFF" - D " LIBGIT2_FILENAME=$binaryFilename " - D " CMAKE_PREFIX_PATH=$ ( $ssh2.Prefix ) " .. }
122173 Run- Command - Fatal { & $cmake -- build . -- config $configuration }
123174 if ($test.IsPresent ) { Run- Command - Quiet - Fatal { & $ctest - V . } }
124175 cd $configuration
@@ -127,14 +178,17 @@ try {
127178 Run- Command - Quiet { & rm $x86Directory \* - ErrorAction Ignore }
128179 Run- Command - Quiet { & mkdir - fo $x86Directory }
129180 Run- Command - Quiet - Fatal { & copy - fo * $x86Directory - Exclude * .lib }
181+ Run- Command - Quiet - Fatal { & copy - fo (Join-Path $ssh2.BinDir " *.dll" ) $x86Directory }
182+ if (-not (Test-Path (Join-Path $x86Directory " libssh2.dll" ))) { throw " Error: libssh2.dll was not copied to $x86Directory " }
130183 cd ..
131184 }
132185
133186 if ($x64.IsPresent ) {
134187 Write-Output " Building x64..."
188+ $ssh2 = Install-Libssh2 " x64"
135189 Run- Command - Quiet { & mkdir build64 }
136190 cd build64
137- Run- Command - Fatal { & $cmake - A x64 - D USE_SSH= exec - D USE_HTTPS= Schannel - D " BUILD_TESTS=$build_tests " - D " BUILD_CLI=OFF" - D " LIBGIT2_FILENAME=$binaryFilename " ../ .. }
191+ Run- Command - Fatal { & $cmake - A x64 - D USE_SSH= ON - D USE_HTTPS= Schannel - D " BUILD_TESTS=$build_tests " - D " BUILD_CLI=OFF" - D " LIBGIT2_FILENAME=$binaryFilename " - D " CMAKE_PREFIX_PATH= $ ( $ssh2 .Prefix ) " ../ .. }
138192 Run- Command - Fatal { & $cmake -- build . -- config $configuration }
139193 if ($test.IsPresent ) { Run- Command - Quiet - Fatal { & $ctest - V . } }
140194 cd $configuration
@@ -143,13 +197,16 @@ try {
143197 Run- Command - Quiet { & rm $x64Directory \* - ErrorAction Ignore }
144198 Run- Command - Quiet { & mkdir - fo $x64Directory }
145199 Run- Command - Quiet - Fatal { & copy - fo * $x64Directory - Exclude * .lib }
200+ Run- Command - Quiet - Fatal { & copy - fo (Join-Path $ssh2.BinDir " *.dll" ) $x64Directory }
201+ if (-not (Test-Path (Join-Path $x64Directory " libssh2.dll" ))) { throw " Error: libssh2.dll was not copied to $x64Directory " }
146202 }
147203
148204 if ($arm64.IsPresent ) {
149205 Write-Output " Building arm64..."
206+ $ssh2 = Install-Libssh2 " arm64"
150207 Run- Command - Quiet { & mkdir buildarm64 }
151208 cd buildarm64
152- Run- Command - Fatal { & $cmake - A ARM64 - D USE_SSH= exec - D USE_HTTPS= Schannel - D " BUILD_TESTS=$build_tests " - D " BUILD_CLI=OFF" - D " LIBGIT2_FILENAME=$binaryFilename " ../ .. }
209+ Run- Command - Fatal { & $cmake - A ARM64 - D USE_SSH= ON - D USE_HTTPS= Schannel - D " BUILD_TESTS=$build_tests " - D " BUILD_CLI=OFF" - D " LIBGIT2_FILENAME=$binaryFilename " - D " CMAKE_PREFIX_PATH= $ ( $ssh2 .Prefix ) " ../ .. }
153210 Run- Command - Fatal { & $cmake -- build . -- config $configuration }
154211 if ($test.IsPresent ) { Run- Command - Quiet - Fatal { & $ctest - V . } }
155212 cd $configuration
@@ -158,6 +215,8 @@ try {
158215 Run- Command - Quiet { & rm $arm64Directory \* - ErrorAction Ignore }
159216 Run- Command - Quiet { & mkdir - fo $arm64Directory }
160217 Run- Command - Quiet - Fatal { & copy - fo * $arm64Directory - Exclude * .lib }
218+ Run- Command - Quiet - Fatal { & copy - fo (Join-Path $ssh2.BinDir " *.dll" ) $arm64Directory }
219+ if (-not (Test-Path (Join-Path $arm64Directory " libssh2.dll" ))) { throw " Error: libssh2.dll was not copied to $arm64Directory " }
161220 }
162221
163222 Write-Output " Done!"
0 commit comments