Last active
February 8, 2023 17:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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