-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
222 lines (183 loc) · 8.79 KB
/
Makefile
File metadata and controls
222 lines (183 loc) · 8.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
.PHONY: help build install clean test test-unit test-e2e test-coverage test-verbose test-race fmt vet lint deps tidy
# Variables
BINARY_NAME=ggo
MAIN_PACKAGE=./cmd/ggo
MOCK_BINARY_NAME=mock-worker
MOCK_MAIN_PACKAGE=./cmd/mock-worker
BUILD_DIR=./bin
COVERAGE_DIR=./coverage
GO_VERSION=1.25.0
# Version info (can be overridden via environment variables)
# Use := for immediate evaluation to ensure values are computed at Makefile parse time
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Build flags - ensure version info is always included
LDFLAGS=-s -w \
-X 'github.com/NexusGPU/gpu-go/cmd/ggo/version.Version=$(VERSION)' \
-X 'github.com/NexusGPU/gpu-go/cmd/ggo/version.Commit=$(COMMIT)' \
-X 'github.com/NexusGPU/gpu-go/cmd/ggo/version.BuildDate=$(BUILD_DATE)'
BUILD_FLAGS=-trimpath
# Default target
.DEFAULT_GOAL := help
help: ## Display this help message
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
# Build targets
build: ## Build the binary (default: release build)
@echo "Building $(BINARY_NAME)..."
@echo " Version: $(VERSION)"
@echo " Commit: $(COMMIT)"
@echo " Build Date: $(BUILD_DATE)"
@mkdir -p $(BUILD_DIR)
@go build $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PACKAGE)
@echo "Binary built: $(BUILD_DIR)/$(BINARY_NAME)"
build-debug: ## Build the binary with debug symbols
@echo "Building $(BINARY_NAME) (debug)..."
@echo " Version: $(VERSION)"
@echo " Commit: $(COMMIT)"
@echo " Build Date: $(BUILD_DATE)"
@mkdir -p $(BUILD_DIR)
@go build $(BUILD_FLAGS) -ldflags "-X 'github.com/NexusGPU/gpu-go/cmd/ggo/version.Version=$(VERSION)' -X 'github.com/NexusGPU/gpu-go/cmd/ggo/version.Commit=$(COMMIT)' -X 'github.com/NexusGPU/gpu-go/cmd/ggo/version.BuildDate=$(BUILD_DATE)'" -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PACKAGE)
@echo "Debug binary built: $(BUILD_DIR)/$(BINARY_NAME)"
build-race: ## Build the binary with race detector
@echo "Building $(BINARY_NAME) (race detector)..."
@echo " Version: $(VERSION)"
@echo " Commit: $(COMMIT)"
@echo " Build Date: $(BUILD_DATE)"
@mkdir -p $(BUILD_DIR)
@go build $(BUILD_FLAGS) -race -ldflags "-X 'github.com/NexusGPU/gpu-go/cmd/ggo/version.Version=$(VERSION)' -X 'github.com/NexusGPU/gpu-go/cmd/ggo/version.Commit=$(COMMIT)' -X 'github.com/NexusGPU/gpu-go/cmd/ggo/version.BuildDate=$(BUILD_DATE)'" -o $(BUILD_DIR)/$(BINARY_NAME)-race $(MAIN_PACKAGE)
@echo "Race detector binary built: $(BUILD_DIR)/$(BINARY_NAME)-race"
install: ## Install the binary to GOPATH/bin
@echo "Installing $(BINARY_NAME)..."
@go install $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" $(MAIN_PACKAGE)
@echo "Installed to $$(go env GOPATH)/bin/$(BINARY_NAME)"
# Test targets
test: ## Run all tests
@echo "Running all tests..."
@go test -v ./...
test-unit: ## Run unit tests only (excludes E2E tests)
@echo "Running unit tests..."
@go test -v -short ./...
test-e2e: ## Run E2E tests only
@echo "Running E2E tests..."
@go test -v -run "E2E" ./...
test-verbose: ## Run all tests with verbose output
@echo "Running all tests (verbose)..."
@go test -v -count=1 ./...
test-race: ## Run tests with race detector
@echo "Running tests with race detector..."
@go test -race -v ./...
test-coverage: ## Run tests and generate coverage report
@echo "Running tests with coverage..."
@mkdir -p $(COVERAGE_DIR)
@go test -v -coverprofile=$(COVERAGE_DIR)/coverage.out ./...
@go tool cover -html=$(COVERAGE_DIR)/coverage.out -o $(COVERAGE_DIR)/coverage.html
@go tool cover -func=$(COVERAGE_DIR)/coverage.out
@echo "Coverage report generated: $(COVERAGE_DIR)/coverage.html"
test-coverage-unit: ## Run unit tests with coverage
@echo "Running unit tests with coverage..."
@mkdir -p $(COVERAGE_DIR)
@go test -v -short -coverprofile=$(COVERAGE_DIR)/coverage-unit.out ./...
@go tool cover -html=$(COVERAGE_DIR)/coverage-unit.out -o $(COVERAGE_DIR)/coverage-unit.html
@go tool cover -func=$(COVERAGE_DIR)/coverage-unit.out
@echo "Unit test coverage report: $(COVERAGE_DIR)/coverage-unit.html"
test-coverage-e2e: ## Run E2E tests with coverage
@echo "Running E2E tests with coverage..."
@mkdir -p $(COVERAGE_DIR)
@go test -v -run "E2E" -coverprofile=$(COVERAGE_DIR)/coverage-e2e.out ./...
@go tool cover -html=$(COVERAGE_DIR)/coverage-e2e.out -o $(COVERAGE_DIR)/coverage-e2e.html
@go tool cover -func=$(COVERAGE_DIR)/coverage-e2e.out
@echo "E2E test coverage report: $(COVERAGE_DIR)/coverage-e2e.html"
test-bench: ## Run benchmark tests
@echo "Running benchmark tests..."
@go test -bench=. -benchmem ./...
test-bench-cpu: ## Run benchmark tests with CPU profile
@echo "Running benchmark tests with CPU profile..."
@go test -bench=. -benchmem -cpuprofile=$(COVERAGE_DIR)/cpu.prof ./...
@echo "CPU profile generated: $(COVERAGE_DIR)/cpu.prof"
test-bench-mem: ## Run benchmark tests with memory profile
@echo "Running benchmark tests with memory profile..."
@go test -bench=. -benchmem -memprofile=$(COVERAGE_DIR)/mem.prof ./...
@echo "Memory profile generated: $(COVERAGE_DIR)/mem.prof"
# Code quality targets
fmt: ## Format Go code
@echo "Formatting Go code..."
@go fmt ./...
@echo "Code formatted"
vet: ## Run go vet
@echo "Running go vet..."
@go vet ./...
@echo "Vet checks passed"
lint: ## Run golangci-lint (if installed)
@echo "Running golangci-lint..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
check: fmt vet ## Format code and run vet checks
# Dependency management
deps: ## Download dependencies
@echo "Downloading dependencies..."
@go mod download
@echo "Dependencies downloaded"
tidy: ## Tidy go.mod and go.sum
@echo "Tidying go.mod..."
@go mod tidy
@echo "go.mod tidied"
# Clean targets
clean: ## Remove build artifacts
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
@rm -rf $(COVERAGE_DIR)
@go clean -cache
@echo "Clean complete"
clean-coverage: ## Remove coverage reports only
@echo "Cleaning coverage reports..."
@rm -rf $(COVERAGE_DIR)
@echo "Coverage reports cleaned"
clean-build: ## Remove build binaries only
@echo "Cleaning build binaries..."
@rm -rf $(BUILD_DIR)
@echo "Build binaries cleaned"
# Development workflow
dev: clean deps build test ## Full development workflow: clean, deps, build, test
ci: tidy check test-coverage ## CI workflow: tidy, check, test with coverage
# Cross-platform builds (examples)
build-linux: ## Build for Linux
@echo "Building for Linux..."
@mkdir -p $(BUILD_DIR)
@GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(MAIN_PACKAGE)
@echo "Linux binary: $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64"
build-darwin: ## Build for macOS
@echo "Building for macOS..."
@mkdir -p $(BUILD_DIR)
@GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(MAIN_PACKAGE)
@GOOS=darwin GOARCH=arm64 go build $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(MAIN_PACKAGE)
@echo "macOS binaries built"
build-windows: ## Build for Windows
@echo "Building for Windows..."
@mkdir -p $(BUILD_DIR)
@GOOS=windows GOARCH=amd64 go build $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe $(MAIN_PACKAGE)
@echo "Windows binary: $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe"
build-all: build-linux build-darwin build-windows ## Build for all platforms
# Mock Worker targets
build-mock: ## Build the mock worker binary
@echo "Building $(MOCK_BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
@go build $(BUILD_FLAGS) -o $(BUILD_DIR)/$(MOCK_BINARY_NAME) $(MOCK_MAIN_PACKAGE)
@echo "Binary built: $(BUILD_DIR)/$(MOCK_BINARY_NAME)"
build-mock-linux: ## Build mock worker for Linux (amd64 and arm64)
@echo "Building $(MOCK_BINARY_NAME) for Linux..."
@mkdir -p $(BUILD_DIR)
@GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o $(BUILD_DIR)/$(MOCK_BINARY_NAME)-linux-amd64 $(MOCK_MAIN_PACKAGE)
@GOOS=linux GOARCH=arm64 go build $(BUILD_FLAGS) -o $(BUILD_DIR)/$(MOCK_BINARY_NAME)-linux-arm64 $(MOCK_MAIN_PACKAGE)
@echo "Linux binaries built"
build-mock-darwin: ## Build mock worker for macOS (amd64 and arm64)
@echo "Building $(MOCK_BINARY_NAME) for macOS..."
@mkdir -p $(BUILD_DIR)
@GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAGS) -o $(BUILD_DIR)/$(MOCK_BINARY_NAME)-darwin-amd64 $(MOCK_MAIN_PACKAGE)
@GOOS=darwin GOARCH=arm64 go build $(BUILD_FLAGS) -o $(BUILD_DIR)/$(MOCK_BINARY_NAME)-darwin-arm64 $(MOCK_MAIN_PACKAGE)
@echo "macOS binaries built"
build-mock-all: build-mock-linux build-mock-darwin ## Build mock worker for all target platforms