@@ -13,6 +13,7 @@ if (-not $RID) {
1313 Write-Output " No RID specified, building all known RIDs"
1414 ./ build.win.ps1 " win-x86"
1515 ./ build.win.ps1 " win-x64"
16+ ./ build.win.ps1 " win-arm64"
1617 exit
1718}
1819
@@ -21,13 +22,16 @@ $Generator = 'Visual Studio 17 2022'
2122# See also: https://learn.microsoft.com/en-us/dotnet/core/rid-catalog#known-rids
2223switch ($RID ) {
2324 ' win-x86' {
24- $Architecture = ' Win32'
25+ $ArchitectureCMake = ' Win32'
26+ $Architecture = ' x86'
2527 }
2628 ' win-x64' {
29+ $ArchitectureCMake = ' x64'
2730 $Architecture = ' x64'
2831 }
2932 ' win-arm64' {
30- $Architecture = ' ARM64'
33+ $ArchitectureCMake = ' ARM64'
34+ $Architecture = ' arm64'
3135 }
3236 Default {
3337 Write-Error " Unknown RID '$RID '"
@@ -37,7 +41,7 @@ switch ($RID) {
3741
3842Write-Output " Building $RID "
3943Write-Output " Using $Generator as the cmake generator"
40- Write-Output " Using architecture $Architecture "
44+ Write-Output " Using architecture $ArchitectureCMake "
4145
4246$SFMLBranch = " 3.0.1" # The branch or tag of the SFML repository to be cloned
4347$CSFMLDir = (Get-Item (git rev- parse -- show-toplevel )).FullName # The directory of the source code of CSFML
@@ -115,8 +119,9 @@ cmake `
115119 ' -DSFML_USE_STATIC_STD_LIBS=OFF' `
116120 ' -DSFML_BUILD_NETWORK=OFF' `
117121 " -DCMAKE_INSTALL_PREFIX=$SFMLInstallDir " `
122+ " -DCMAKE_POLICY_VERSION_MINIMUM=3.5" `
118123 " -G$Generator " `
119- " -A$Architecture " `
124+ " -A$ArchitectureCMake " `
120125 $SFMLDir
121126Ensure- Success
122127
@@ -156,7 +161,7 @@ cmake `
156161 ' -DCSFML_BUILD_NETWORK=OFF' `
157162 `
158163 " -G$generator " `
159- " -A$Architecture " `
164+ " -A$ArchitectureCMake " `
160165 `
161166 $CSFMLDir
162167Ensure- Success
@@ -198,6 +203,74 @@ Copy-Module 'graphics'
198203Copy-Module ' system'
199204Copy-Module ' window'
200205
206+ # ====================================================== #
207+ # STEP 6: Copy the required runtime to the NuGet folders #
208+ # ====================================================== #
209+
210+ <#
211+ . SYNOPSIS
212+ Copies the required and allowed redistributable runtime DLLs to the NuGet folders.
213+
214+ . DESCRIPTION
215+ Since we're no longer linking statically against the runtime, we need to ensure
216+ that the required redistributable DLLs are included in the NuGet package.
217+ Microsoft only allows the distribution of the DLLs listed in the redist.txt, as
218+ such we make sure to only include those.
219+ Additionally, we're checking what the DLLs actually depend on with dumpbin.exe
220+ and make sure to find those dependencies.
221+ #>
222+
223+ # Locate VS installation
224+ $vswhere = " ${env: ProgramFiles(x86)} \Microsoft Visual Studio\Installer\vswhere.exe"
225+ if (-not (Test-Path $vswhere )) {
226+ throw " vswhere.exe not found. Install Visual Studio Installer."
227+ }
228+
229+ $vsPath = & $vswhere - latest - products * - requires Microsoft.VisualStudio.Component.VC.Redist.* - property installationPath
230+ if (-not $vsPath ) {
231+ throw " Could not locate Visual Studio installation with VC++ Redist components."
232+ }
233+
234+ # Find latest VC redist folder
235+ $redistRoot = Join-Path $vsPath " VC\Redist\MSVC"
236+ $latestRedist = Get-ChildItem $redistRoot - Directory - Exclude " v*" | Sort-Object Name - Descending | Select-Object - First 1
237+ $redistCRT = Join-Path $latestRedist.FullName " $Architecture \Microsoft.VC*"
238+
239+ Write-Host " Using CRT redistributables from $redistCRT "
240+
241+ # Get list of DLLs in redistributable CRT folder
242+ $redistributableDlls = Get-ChildItem - Path $redistCRT - Recurse - Filter * .dll | Select-Object - ExpandProperty Name
243+
244+ # Helper: check binary dependencies
245+ function Get-BinaryDependencies {
246+ param ([string ]$Path )
247+
248+ $dumpbin = Get-Command dumpbin.exe - ErrorAction SilentlyContinue
249+ if (-not $dumpbin ) {
250+ $dumpbin = Get-ChildItem - Path $vsPath - Recurse - Filter dumpbin.exe - ErrorAction SilentlyContinue | Where-Object { $_.FullName -match " \\$Architecture \\" } - ErrorAction SilentlyContinue | Select-Object - First 1
251+ }
252+ if (-not $dumpbin ) { throw " dumpbin.exe not found. Run from a Developer Command Prompt." }
253+
254+ & $dumpbin / DEPENDENTS $Path | Where-Object { $_ -match " \.DLL" } | ForEach-Object { $_.Trim () }
255+ }
256+
257+ # Process binaries
258+ Get-ChildItem $OutDir - Filter * .dll | ForEach-Object {
259+ $dll = $_.FullName
260+ Write-Host " Checking dependencies for $dll "
261+
262+ $deps = Get-BinaryDependencies - Path $dll
263+ foreach ($dep in $deps ) {
264+ if ($redistributableDlls -contains $dep ) {
265+ $source = Get-ChildItem - Path $redistCRT - Recurse - Filter $dep | Select-Object - First 1
266+ if ($source ) {
267+ Copy-Item $source.FullName - Destination $OutDir - Force
268+ Write-Host " -> Copied $dep from $ ( $source.DirectoryName ) "
269+ }
270+ }
271+ }
272+ }
273+
201274Pop-Location # Pop CSFML
202275Pop-Location # Pop $RID
203276Pop-Location # Pop Build
0 commit comments