Stage 1 · Code
Capstone — Ship a Real Tool
Cross-Compile Releases
Build release binaries for every major platform, embed version metadata, generate checksums, and produce a clean dist/ folder.
7 min readProgramming Foundations (Go)Code
Platform Matrix
| GOOS | GOARCH | Typical users |
|---|---|---|
| linux | amd64 | Most servers, Docker containers, CI runners |
| linux | arm64 | AWS Graviton, Raspberry Pi, ARM servers |
| darwin | amd64 | Intel Macs |
| darwin | arm64 | Apple Silicon Macs (M1/M2/M3) |
| windows | amd64 | Windows developers and servers |
Release Makefile Target
Complete release Makefile
APP := tasker
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS := -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildDate=$(DATE) -s -w"
TARGETS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64
.PHONY: release clean
release: clean
mkdir -p dist
$(foreach target,$(TARGETS), $(eval OS := $(word 1,$(subst /, ,$(target)))) $(eval ARCH := $(word 2,$(subst /, ,$(target)))) $(eval EXT := $(if $(filter windows,$(OS)),.exe,)) GOOS=$(OS) GOARCH=$(ARCH) go build $(LDFLAGS) -o dist/$(APP)_$(OS)_$(ARCH)$(EXT) ./cmd/$(APP);)
clean:
rm -rf dist/Version Embedding
Goversion-variables-in-main.go.go
28 linesLn 1, Col 1Go
Checksums and Archives
Generate archives and checksums
#!/usr/bin/env bash
# scripts/package.sh
set -euo pipefail
APP=tasker
VERSION=${1:-dev}
DIST=dist
mkdir -p "$DIST"
for binary in "$DIST"/${APP}_*; do
base=$(basename "$binary")
if [[ "$base" == *windows* ]]; then
zip -j "$DIST/${base%.exe}.zip" "$binary"
else
tar -czf "$DIST/${base}.tar.gz" -C "$DIST" "$(basename "$binary")"
fi
done
# Generate checksums file
cd "$DIST"
sha256sum *.tar.gz *.zip 2>/dev/null > checksums.txt || sha256sum *.tar.gz > checksums.txt
cat checksums.txtStripping debug symbols for smaller binaries
The -s -w flags in ldflags strip the symbol table (-s) and DWARF debug info (-w). This reduces binary size by 20-30% with no impact on functionality. Only omit them if you need to attach Delve to a production binary.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.