<# .SYNOPSIS Cross-compiles deployr for every supported platform. .EXAMPLE .\scripts\build.ps1 # build everything into dist\ .\scripts\build.ps1 -Version 1.0.0 # stamp a release version .\scripts\build.ps1 -Only windows/amd64 #> [CmdletBinding()] param( [string]$Version = "dev", [string]$Only = "", [string]$OutDir = "dist" ) $ErrorActionPreference = "Stop" $root = Split-Path -Parent $PSScriptRoot Set-Location $root $targets = @( "windows/amd64", "windows/arm64", "darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm64" ) if ($Only) { $targets = @($Only) } $commit = "none" try { $commit = (git rev-parse --short HEAD 2>$null).Trim() } catch { } if (-not $commit) { $commit = "none" } $date = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ") $pkg = "git.starwarslab.us/ATOM_IT/Deployr/internal/version" $ldflags = "-s -w -X $pkg.Version=$Version -X $pkg.Commit=$commit -X $pkg.Date=$date" New-Item -ItemType Directory -Force -Path $OutDir | Out-Null foreach ($target in $targets) { $parts = $target.Split("/") $os = $parts[0] $arch = $parts[1] $name = "deployr_${Version}_${os}_${arch}" if ($os -eq "windows") { $name += ".exe" } Write-Host "building $target -> $OutDir\$name" $env:GOOS = $os $env:GOARCH = $arch $env:CGO_ENABLED = "0" go build -trimpath -ldflags $ldflags -o "$OutDir\$name" ./cmd/deployr if ($LASTEXITCODE -ne 0) { throw "build failed for $target" } } $env:GOOS = ""; $env:GOARCH = ""; $env:CGO_ENABLED = "" Get-ChildItem $OutDir -File | Where-Object { $_.Name -ne "SHA256SUMS" } | ForEach-Object { "{0} {1}" -f (Get-FileHash $_.FullName -Algorithm SHA256).Hash.ToLower(), $_.Name } | Set-Content -Path (Join-Path $OutDir "SHA256SUMS") -Encoding utf8 Write-Host "" Get-ChildItem $OutDir | Format-Table Name, @{N = "MB"; E = { [math]::Round($_.Length / 1MB, 1) } }