Set explicit Cargo linker in MSVC setup action

This commit is contained in:
starr-openai
2026-05-13 16:14:35 -07:00
parent 5440bbfaaa
commit d5ebb31383

View File

@@ -70,6 +70,7 @@ runs:
)
$envLines = & cmd.exe /c ('"{0}" -no_logo -arch={1} -host_arch={2} >nul && set' -f $vsDevCmd, $targetArch, $hostArch)
$vcToolsInstallDir = $null
foreach ($line in $envLines) {
if ($line -notmatch "^(.*?)=(.*)$") {
continue
@@ -81,6 +82,21 @@ runs:
if ($name -ieq "Path") {
$name = "PATH"
}
if ($name -eq "VCToolsInstallDir") {
$vcToolsInstallDir = $value
}
"$name=$value" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
}
}
if (-not $vcToolsInstallDir) {
throw "VCToolsInstallDir was not exported by VsDevCmd.bat"
}
$linker = Join-Path $vcToolsInstallDir "bin\Host${hostArch}\${targetArch}\link.exe"
if (-not (Test-Path $linker)) {
throw "MSVC linker not found at $linker"
}
$cargoTarget = "${{ inputs.target }}".ToUpperInvariant().Replace("-", "_")
"CARGO_TARGET_${cargoTarget}_LINKER=$linker" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append