@@ -7,6 +7,13 @@ GOPRIVATE := github.com/globalcyberalliance
77LDFLAGS := -s -w
88GOBUILD = GOPRIVATE=$(GOPRIVATE ) CGO_ENABLED=0 $(GO ) build -trimpath -ldflags "$(LDFLAGS ) "
99
10+ # betteralign is PINNED. v0.14.0 regressed -fix (GoReleaser v2 migration + "honor -fix in
11+ # shipped binary") and intermittently corrupts multi-struct files with per-field doc comments,
12+ # which broke the release build. v0.13.0 is the last release carrying all the correctness fixes
13+ # (v0.9.0 multi-struct rewrite loss + data race, v0.12.0 comment-handling hardening) before that
14+ # regression. Do NOT bump to @latest without re-validating against pkg/scanner.
15+ BETTERALIGN_VERSION := v0.13.0
16+
1017# VERSION is optional. The binary carries a default version baked into the source
1118# (cmd/dss/main.go). Passing VERSION= (e.g. a release tag from CI) overrides it via
1219# -ldflags -X. A passed-but-empty VERSION= is stripped and ignored so we never embed
@@ -20,28 +27,28 @@ endif
2027need = command -v $(1 ) >/dev/null 2>&1 || { echo "$(1 ) not found — run 'make setup'"; exit 1; }
2128
2229.DEFAULT_GOAL := dev
23- .PHONY : dev prod optimize clean clean-all format lint lint-fix nil test benchmark tidy setup help
30+ .PHONY : dev prod clean clean-all format lint lint-fix nil test benchmark tidy setup-prod setup help
2431
25- dev : # # Default: fast local build, compiles in-place
32+ dev : # # Default: fast local build, no struct alignment, compiles in-place
2633 @$(call need,$(GO ) )
2734 @echo " Building $( BIN) ..."
2835 @mkdir -p bin
2936 @$(GOBUILD ) -o $(BIN ) $(CMD )
3037
31- prod : # # Production release build (stripped, trimmed, reproducible )
38+ prod : # # Production binary: struct-aligned, optimized (working tree untouched )
3239 @$(call need,$(GO ) )
33- @echo " Building $( BIN) ..."
34- @mkdir -p bin
35- @$(GOBUILD ) -o $(BIN ) $(CMD )
36-
37- optimize : # # Rewrite structs for optimal field alignment — run manually, review the diff, commit
38- # Struct alignment is deliberately kept OFF the build path. betteralign -fix mutates source
39- # and can intermittently corrupt files, so it must never gate a build; run it by hand and let
40- # `go build`/review catch any bad rewrite. `|| true` because betteralign exits non-zero simply
41- # when it has findings, even after a successful fix.
4240 @$(call need,betteralign)
41+ @echo " Preparing build directory..."
42+ @rm -rf bin build && mkdir -p bin build
43+ @cp -r cmd go.mod go.sum pkg build/
4344 @echo " Optimizing struct field alignment..."
44- @betteralign -fix ./... || true
45+ # betteralign exits non-zero whenever it has findings (even after -fix succeeds, and when
46+ # already aligned), so `|| true` is required — alignment is best-effort here, not a gate.
47+ # The version is pinned (see BETTERALIGN_VERSION) because @latest corrupts source.
48+ @cd build && betteralign -fix ./... >/dev/null 2>&1 || true
49+ @echo "Building $(BIN)..."
50+ @cd build && $(GOBUILD) -o ../$(BIN) $(CMD)
51+ @rm -rf build
4552
4653clean : # # Remove build artifacts
4754 @echo " Cleaning..."
@@ -80,12 +87,15 @@ benchmark: ## Run benchmarks
8087tidy : # # Tidy go.mod / go.sum
8188 @$(GO ) mod tidy
8289
83- setup : # # Install dev tools (gofumpt, nilaway, golangci-lint, betteralign)
90+ setup-prod : # # Install build-time tools only (pinned betteralign — needed by `make prod`)
91+ @echo " Installing build tools..."
92+ @$(GO ) install github.com/dkorunic/betteralign/cmd/betteralign@$(BETTERALIGN_VERSION )
93+
94+ setup : setup-prod # # Install all dev tools (build + gofumpt, nilaway, golangci-lint)
8495 @echo " Installing dev tools..."
8596 @$(GO ) install mvdan.cc/gofumpt@latest
8697 @$(GO ) install go.uber.org/nilaway/cmd/nilaway@latest
8798 @$(GO ) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
88- @$(GO ) install github.com/dkorunic/betteralign/cmd/betteralign@latest
8999
90100help : # # Show this help
91101 @grep -hE ' ^[a-zA-Z_-]+:.*## ' $(MAKEFILE_LIST ) | awk -F' :.*## ' ' {printf " \033[36m%-12s\033[0m %s\n", $$1, $$2}'
0 commit comments