$ErrorActionPreference = 'Stop' $ridTools = 'D:/Rust_Contact/util/tools/rid-map-downloader/0.1.0' $env:GOCACHE = 'D:/Rust_Contact/util/tools/go-cache' $env:GOMODCACHE = 'D:/Rust_Contact/util/tools/go-modules' $ridGo = (Get-Command go -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1).Source if (-not $ridGo) { $ridGo = 'D:/Rust_Contact/util/tools/go/1.27.4/go/bin/go.exe' } if (-not (Test-Path -LiteralPath $ridGo -PathType Leaf)) { throw '找不到 Go。请将 go.exe 加入 PATH 或安装到项目统一工具目录。' } New-Item -ItemType Directory -Force $ridTools | Out-Null Push-Location (Join-Path $PSScriptRoot 'map-downloader') try { & $ridGo test ./... if ($LASTEXITCODE -ne 0) { throw 'Go map downloader tests failed' } & $ridGo build -trimpath -ldflags '-s -w' -o (Join-Path $ridTools 'rid-map-downloader.exe') . if ($LASTEXITCODE -ne 0) { throw 'Go map downloader build failed' } Copy-Item -LiteralPath 'LICENSE-upstream.txt' -Destination $ridTools $env:RID_MAP_DOWNLOADER = Join-Path $ridTools 'rid-map-downloader.exe' Write-Output $env:RID_MAP_DOWNLOADER } finally { Pop-Location }