From b1e8b11948aa24c8415e947a793f6526122a1114 Mon Sep 17 00:00:00 2001 From: mayor Date: Sat, 24 Jan 2026 22:23:07 -0800 Subject: [PATCH] fix(build): error on raw go build, require make build Raw `go build` produces unsigned binaries that macOS kills. Add a BuiltProperly ldflag that make build sets, and check it at startup. If missing, print an error directing users to use make build. Co-Authored-By: Claude Opus 4.5 --- Makefile | 3 ++- internal/cmd/root.go | 9 +++++++++ internal/cmd/version.go | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9f3b5907..c43d9de7 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,8 @@ BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") LDFLAGS := -X github.com/steveyegge/gastown/internal/cmd.Version=$(VERSION) \ -X github.com/steveyegge/gastown/internal/cmd.Commit=$(COMMIT) \ - -X github.com/steveyegge/gastown/internal/cmd.BuildTime=$(BUILD_TIME) + -X github.com/steveyegge/gastown/internal/cmd.BuildTime=$(BUILD_TIME) \ + -X github.com/steveyegge/gastown/internal/cmd.BuiltProperly=1 generate: go generate ./... diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 3b5f6b92..b3de8c6f 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -68,6 +68,15 @@ var branchCheckExemptCommands = map[string]bool{ // persistentPreRun runs before every command. func persistentPreRun(cmd *cobra.Command, args []string) error { + // Check if binary was built properly (via make build, not raw go build). + // Raw go build produces unsigned binaries that macOS will kill. + if BuiltProperly == "" { + fmt.Fprintln(os.Stderr, "ERROR: This binary was built with 'go build' directly.") + fmt.Fprintln(os.Stderr, " Use 'make build' to create a properly signed binary.") + fmt.Fprintln(os.Stderr, " Run from: ~/gt/gastown/mayor/rig (or your rig's worktree)") + os.Exit(1) + } + // Initialize CLI theme (dark/light mode support) initCLITheme() diff --git a/internal/cmd/version.go b/internal/cmd/version.go index f4eb63b0..ee8e8823 100644 --- a/internal/cmd/version.go +++ b/internal/cmd/version.go @@ -18,6 +18,9 @@ var ( // Commit and Branch - the git revision the binary was built from (optional ldflag) Commit = "" Branch = "" + // BuiltProperly is set to "1" by `make build`. If empty, the binary was built + // with raw `go build` and is likely unsigned (will be killed on macOS). + BuiltProperly = "" ) var versionCmd = &cobra.Command{