diff --git a/tools/windows/load-msvc-env.ps1 b/tools/windows/load-msvc-env.ps1 new file mode 100644 index 0000000000..b13441a51b --- /dev/null +++ b/tools/windows/load-msvc-env.ps1 @@ -0,0 +1,42 @@ +# SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +# SPDX-License-Identifier: GPL-3.0-or-later + +$osArch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture + +switch ($osArch) { + "X64" { $arch = "x64" } + "Arm64" { $arch = "arm64" } + default { + Write-Error "❌ Unsupported architecture: $osArch" + exit 1 + } +} + +$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" + +if (!(Test-Path $vswhere)) { + Write-Error "load-msvc-env.ps1: vswhere not found" + exit 1 +} + +$vs = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath + +if (-not $vs) { + Write-Error "load-msvc-env.ps1: Visual Studio (with Desktop development with C++) not found" + exit 1 +} + +$bat = "$vs\VC\Auxiliary\Build\vcvarsall.bat" + +if (!(Test-Path $bat)) { + Write-Error "load-msvc-env.ps1: (vcvarsall.bat) not found" + exit 1 +} + +cmd /c "`"$bat`" $arch && set" | ForEach-Object { + if ($_ -match "^(.*?)=(.*)$") { + [Environment]::SetEnvironmentVariable($matches[1], $matches[2], 'Process') + } +} + +Write-Host "load-msvc-env.ps1: MSVC environment loaded for $arch ($vs)"