build.ps1
965 B
| 1 | # Build Clancore Repo binaries for Windows and Debian/Linux. |
| 2 | # Usage: .\build.ps1 |
| 3 | $ErrorActionPreference = "Stop" |
| 4 | |
| 5 | $root = Split-Path -Parent $MyInvocation.MyCommand.Path |
| 6 | Set-Location $root |
| 7 | |
| 8 | $dist = Join-Path $root "dist" |
| 9 | New-Item -ItemType Directory -Force $dist | Out-Null |
| 10 | |
| 11 | $targets = @( |
| 12 | @{ GOOS = "windows"; GOARCH = "amd64"; Out = "clancore-repo-windows-amd64.exe" }, |
| 13 | @{ GOOS = "linux"; GOARCH = "amd64"; Out = "clancore-repo-linux-amd64" } |
| 14 | ) |
| 15 | |
| 16 | foreach ($t in $targets) { |
| 17 | Write-Host "==> $($t.GOOS)/$($t.GOARCH)" |
| 18 | $env:CGO_ENABLED = "0" |
| 19 | $env:GOOS = $t.GOOS |
| 20 | $env:GOARCH = $t.GOARCH |
| 21 | |
| 22 | go build -trimpath -ldflags "-s -w" -o (Join-Path $dist $t.Out) . |
| 23 | if ($LASTEXITCODE -ne 0) { |
| 24 | throw "Build failed for $($t.GOOS)/$($t.GOARCH)" |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | Remove-Item Env:CGO_ENABLED, Env:GOOS, Env:GOARCH -ErrorAction SilentlyContinue |
| 29 | |
| 30 | Write-Host "" |
| 31 | Write-Host "Done:" |
| 32 | Get-ChildItem $dist | Select-Object Name, Length | Format-Table -AutoSize |