From 858c74408115addebfb422b8b3960b8bf652c7b0 Mon Sep 17 00:00:00 2001 From: starr-openai Date: Wed, 13 May 2026 15:59:13 -0700 Subject: [PATCH] Add MSVC env helper for ARM64 archive build --- .github/actions/setup-msvc-env/action.yml | 83 +++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/actions/setup-msvc-env/action.yml diff --git a/.github/actions/setup-msvc-env/action.yml b/.github/actions/setup-msvc-env/action.yml new file mode 100644 index 0000000000..6db00f3c92 --- /dev/null +++ b/.github/actions/setup-msvc-env/action.yml @@ -0,0 +1,83 @@ +name: setup-msvc-env +description: Expose an MSVC developer environment for the requested Windows target. +inputs: + target: + description: Rust target triple that will be built on this Windows runner. + required: true + host-arch: + description: Optional Visual Studio host architecture override. + required: false + default: "" + +runs: + using: composite + steps: + - name: Expose MSVC SDK environment + shell: pwsh + run: | + switch ("${{ inputs.target }}") { + "x86_64-pc-windows-msvc" { + $targetArch = "x64" + $requiredComponent = "Microsoft.VisualStudio.Component.VC.Tools.x86.x64" + } + "aarch64-pc-windows-msvc" { + $targetArch = "arm64" + $requiredComponent = "Microsoft.VisualStudio.Component.VC.Tools.ARM64" + } + default { + throw "Unsupported Windows MSVC target: ${{ inputs.target }}" + } + } + + $hostArch = "${{ inputs.host-arch }}" + if (-not $hostArch) { + $hostArch = if ($env:PROCESSOR_ARCHITEW6432 -eq "ARM64" -or $env:PROCESSOR_ARCHITECTURE -eq "ARM64") { + "arm64" + } else { + "x64" + } + } + + $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" + if (-not (Test-Path $vswhere)) { + throw "vswhere.exe not found" + } + + $installPath = & $vswhere -latest -products * -requires $requiredComponent -property installationPath 2>$null + if (-not $installPath) { + throw "Could not locate a Visual Studio installation with component $requiredComponent" + } + + $vsDevCmd = Join-Path $installPath "Common7\Tools\VsDevCmd.bat" + if (-not (Test-Path $vsDevCmd)) { + throw "VsDevCmd.bat not found at $vsDevCmd" + } + + $varsToExport = @( + "INCLUDE", + "LIB", + "LIBPATH", + "PATH", + "UCRTVersion", + "UniversalCRTSdkDir", + "VCINSTALLDIR", + "VCToolsInstallDir", + "WindowsLibPath", + "WindowsSdkBinPath", + "WindowsSdkDir", + "WindowsSDKLibVersion", + "WindowsSDKVersion" + ) + + $envLines = & cmd.exe /c ('"{0}" -no_logo -arch={1} -host_arch={2} >nul && set' -f $vsDevCmd, $targetArch, $hostArch) + foreach ($line in $envLines) { + if ($line -notmatch "^(.*?)=(.*)$") { + continue + } + + $name = $matches[1] + $value = $matches[2] + if ($varsToExport -contains $name) { + "$name=$value" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } + }