Skip to content

Instantly share code, notes, and snippets.

@KaiserWerk
Last active February 8, 2023 17:12
Show Gist options
  • Save KaiserWerk/da92df587fda548716a2d5aec8745a5a to your computer and use it in GitHub Desktop.
Save KaiserWerk/da92df587fda548716a2d5aec8745a5a to your computer and use it in GitHub Desktop.
A small PowerShell script to automate cross-compilation (release) for a Go project
$sourcecode = ".\main.go"
$target = "build\binary-name"
# Windows, 64-bit
$env:GOOS = 'windows'; $env:GOARCH = 'amd64'; go build -o "$($target)-win64.exe" -ldflags "-s -w" $sourcecode
# Linux, 64-bit
$env:GOOS = 'linux'; $env:GOARCH = 'amd64'; go build -o "$($target)-linux64" -ldflags "-s -w" $sourcecode
# Raspberry Pi
$env:GOOS = 'linux'; $env:GOARCH = 'arm'; $env:GOARM=5; go build -o "$($target)-raspi32" -ldflags "-s -w" $sourcecode
# macOS
$env:GOOS = 'darwin'; $env:GOARCH = 'amd64'; go build -o "$($target)-macos64" -ldflags "-s -w" $sourcecode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment