Makefile RawHistoryFolder
1# Makefile for dumber (Clean Architecture - puregotk)
2
3.PHONY: build build-systemviews generate-systemviews build-quick install-local test lint clean install-tools dev generate help init man flatpak-deps flatpak-build flatpak-install flatpak-run flatpak-clean stress-omnibox-callbacks verify-purego check
4
5# Load local overrides from .env.local if present (Makefile syntax)
6ifneq (,$(wildcard .env.local))
7include .env.local
8export
9endif
10
11# Variables
12BINARY_NAME=dumber
13MAIN_PATH=./cmd/dumber
14DIST_DIR=dist
15LOCAL_BIN_DIR?=$(HOME)/.local/bin
16
17# Detect number of CPU cores for parallel compilation
18NPROCS?=$(shell nproc 2>/dev/null || echo 1)
19
20# Version information from git
21VERSION=$(shell git describe --tags --always --dirty 2>/dev/null || echo "v0.0.0-dev")
22COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
23BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
24
25# Go flags. NATIVE_GOFLAGS can add native-only hardening such as
26# -buildmode=pie without breaking js/wasm systemviews builds.
27GOFLAGS?=-mod=mod
28NATIVE_GOFLAGS?=$(GOFLAGS)
29WASM_GOFLAGS?=$(GOFLAGS)
30
31# Linker flags
32LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildDate=$(BUILD_DATE)"
33
34# Disable optimizations and inlining for ALL packages. purego callbacks
35# create mixed Go/C stack frames; the Go runtime (stack growth, GC,
36# scheduler) cannot reliably traverse optimised frames across these
37# boundaries. -N prevents register-only variables and stack slot reuse
38# that corrupt the runtime's stack walker. -l prevents inlining across
39# package boundaries. Both are required — -l alone is insufficient.
40GCFLAGS=-gcflags 'all=-N -l'
41
42# Default target
43help: ## Show this help message
44 @echo "Available targets:"
45 @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
46
47# Build targets
48build: build-systemviews ## Build the application (pure Go, no CGO)
49 @echo "Building $(BINARY_NAME) $(VERSION) using $(NPROCS) cores..."
50 @mkdir -p $(DIST_DIR)
51 GOFLAGS="$(NATIVE_GOFLAGS)" CGO_ENABLED=0 go build -buildvcs=false -p $(NPROCS) $(GCFLAGS) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME) $(MAIN_PATH)
52 @rm -f $(DIST_DIR)/cef-helper
53 @echo "Build successful! Binary: $(DIST_DIR)/$(BINARY_NAME)"
54
55generate-systemviews: ## Generate Go code from systemviews templ components
56 @echo "Generating systemviews templ components..."
57 go tool templ generate -path internal/ui/systemviews -include-version=false
58 @echo "Systemviews templ generation complete"
59
60build-systemviews: generate-systemviews ## Build the WASM systemviews runtime
61 @echo "Building systemviews wasm assets..."
62 @command -v brotli >/dev/null 2>&1 || { echo "Error: brotli is required to build compressed systemviews assets. Install brotli and retry."; exit 1; }
63 @mkdir -p assets/systemviews
64 @cp "$$(go env GOROOT)/lib/wasm/wasm_exec.js" assets/systemviews/wasm_exec.js
65 GOFLAGS="$(WASM_GOFLAGS)" GOOS=js GOARCH=wasm go build -buildvcs=false -ldflags="-s -w" -o assets/systemviews/systemviews.wasm ./cmd/systemviews
66 brotli -f -o assets/systemviews/systemviews.wasm.br assets/systemviews/systemviews.wasm
67 @echo "Systemviews build complete"
68
69build-quick: ## Build quickly for backend development
70 @echo "Building $(BINARY_NAME) $(VERSION) (quick)..."
71 @mkdir -p $(DIST_DIR)
72 GOFLAGS="$(NATIVE_GOFLAGS)" CGO_ENABLED=0 go build -buildvcs=false -p $(NPROCS) $(GCFLAGS) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME) $(MAIN_PATH)
73 @rm -f $(DIST_DIR)/cef-helper
74 @echo "Build successful! Binary: $(DIST_DIR)/$(BINARY_NAME)"
75
76install-local: build-quick ## Install dumber to ~/.local/bin atomically
77 @echo "Installing $(BINARY_NAME) to $(LOCAL_BIN_DIR)..."
78 @mkdir -p $(LOCAL_BIN_DIR)
79 @tmp_dumber="$$(mktemp '$(LOCAL_BIN_DIR)/.dumber.tmp.XXXXXX')"; \
80 trap 'rm -f "$$tmp_dumber"' EXIT INT TERM; \
81 install -m 0755 $(DIST_DIR)/$(BINARY_NAME) "$$tmp_dumber"; \
82 mv -f "$$tmp_dumber" $(LOCAL_BIN_DIR)/$(BINARY_NAME); \
83 removed_stale=0; \
84 if [ -e $(LOCAL_BIN_DIR)/cef-helper ]; then rm -f $(LOCAL_BIN_DIR)/cef-helper && removed_stale=1; fi; \
85 trap - EXIT INT TERM; \
86 echo "Installed: $(LOCAL_BIN_DIR)/$(BINARY_NAME)"; \
87 if [ "$$removed_stale" -eq 1 ]; then echo "Removed stale: $(LOCAL_BIN_DIR)/cef-helper"; fi
88
89# Development targets
90dev: ## Run in development mode
91 @echo "Running in development mode..."
92 go run $(MAIN_PATH)
93
94run: build-quick ## Build and run
95 @echo "Running $(BINARY_NAME)..."
96 $(DIST_DIR)/$(BINARY_NAME)
97
98generate: ## Generate code (SQLC)
99 @echo "Generating code with SQLC..."
100 sqlc generate
101 @echo "Code generation complete"
102
103mocks: ## Generate mock implementations with mockery
104 @echo "Generating mocks with mockery..."
105 mockery
106 @echo "Mock generation complete"
107
108# Testing
109test: ## Run tests
110 @echo "Running tests..."
111 GOFLAGS=-mod=mod go test -v ./...
112
113test-race: ## Run tests with race detection
114 @echo "Running tests with race detection..."
115 GOFLAGS=-mod=mod go test -race -v ./...
116
117test-cover: ## Run tests with coverage
118 @echo "Running tests with coverage..."
119 GOFLAGS=-mod=mod go test -coverprofile=coverage.out ./...
120 go tool cover -html=coverage.out -o coverage.html
121 @echo "Coverage report: coverage.html"
122
123stress-omnibox-callbacks: ## Run placeholder omnibox callback stress harness
124 GOFLAGS=-mod=mod CGO_ENABLED=0 go run ./scripts/stress_omnibox_callbacks.go
125
126verify-purego: ## Ensure callback path stays cgo/export free
127 bash ./scripts/verify_purego_only.sh
128
129# Linting
130lint: ## Run golangci-lint
131 @echo "Running golangci-lint..."
132 golangci-lint run
133
134lint-fix: ## Run golangci-lint with --fix
135 @echo "Running golangci-lint with --fix..."
136 golangci-lint run --fix
137
138# Format code
139fmt: ## Format Go code with gofmt
140 @echo "Formatting Go code..."
141 go fmt ./...
142
143# Tools installation
144install-tools: ## Install development tools
145 @echo "Installing development tools..."
146 go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
147 go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
148 @echo "Tools installed successfully"
149
150# Cleanup
151clean: ## Clean build artifacts
152 @echo "Cleaning build artifacts..."
153 rm -rf $(DIST_DIR)
154 rm -f $(BINARY_NAME)
155 rm -f assets/systemviews/wasm_exec.js assets/systemviews/systemviews.wasm assets/systemviews/systemviews.wasm.br
156 rm -f coverage.out coverage.html
157 go clean -cache
158 go clean -testcache
159
160# Project initialization
161init: install-tools ## Initialize project dependencies and tools
162 @echo "Initializing project..."
163 go mod tidy
164 @echo "Project initialized! Run 'make help' for available commands."
165
166# Check setup
167check: ## Check that all tools and dependencies are working
168 @echo "Checking project setup..."
169 @echo "Go version:"
170 @go version
171 @echo "\nSQLC version:"
172 @sqlc version
173 @echo "\nGolangci-lint version:"
174 @golangci-lint version
175 @echo "\nBuilding project..."
176 @$(MAKE) build-quick
177 @echo "\nRunning tests..."
178 @$(MAKE) test
179 @echo "\nVerifying purego-only constraints..."
180 @$(MAKE) verify-purego
181 @echo "\nAll checks passed!"
182
183# Documentation
184man: build-quick ## Install man pages to ~/.local/share/man/man1/
185 @echo "Installing man pages..."
186 $(DIST_DIR)/$(BINARY_NAME) gen-docs
187
188# Native release targets
189.PHONY: release-snapshot release
190
191release-snapshot: build-systemviews ## Build snapshot using goreleaser
192 @echo "Building snapshot with goreleaser..."
193 goreleaser release --snapshot --clean
194
195release: ## Create full release using goreleaser
196 @echo "Building release with goreleaser..."
197 GITHUB_TOKEN=$$(gh auth token) goreleaser release --clean
198
199# Flatpak targets
200flatpak-deps: ## Install Flatpak build dependencies (Arch)
201 @echo "Installing Flatpak build dependencies..."
202 sudo pacman -S --needed flatpak flatpak-builder
203 flatpak remote-add --if-not-exists --user flathub https://dl.flathub.org/repo/flathub.flatpakrepo
204 flatpak install --user -y flathub org.gnome.Platform//48 org.gnome.Sdk//48
205 flatpak install --user -y flathub org.freedesktop.Sdk.Extension.golang//24.08
206 flatpak install --user -y flathub org.freedesktop.Sdk.Extension.node20//24.08
207 @echo "Flatpak dependencies installed!"
208
209flatpak-build: ## Build Flatpak bundle locally
210 @echo "Building Flatpak bundle..."
211 flatpak-builder --force-clean --user --repo=flatpak-repo flatpak-build dev.bnema.Dumber.yml
212 flatpak build-bundle flatpak-repo dumber.flatpak dev.bnema.Dumber
213 @echo "Flatpak bundle created: dumber.flatpak"
214
215flatpak-install: ## Install Flatpak locally for testing
216 @echo "Installing Flatpak locally..."
217 flatpak-builder --force-clean --user --install flatpak-build dev.bnema.Dumber.yml
218 @echo "Flatpak installed! Run with: make flatpak-run"
219
220flatpak-run: ## Run the installed Flatpak
221 flatpak run dev.bnema.Dumber
222
223flatpak-clean: ## Clean Flatpak build artifacts
224 @echo "Cleaning Flatpak build artifacts..."
225 rm -rf flatpak-build flatpak-repo .flatpak-builder dumber.flatpak
226 @echo "Flatpak artifacts cleaned!"