-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
230 lines (196 loc) · 10.2 KB
/
Copy pathMakefile
File metadata and controls
230 lines (196 loc) · 10.2 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
223
224
225
226
227
228
229
230
# OpsIntelligence — Makefile
# Industry-standard build targets for the polyglot project.
.DEFAULT_GOAL := build
.PHONY: all build build-go build-ts build-sensing build-tui build-tui-host build-ui build-scrun clean test load-test lint vet fmt install uninstall help tui-ping tui
# ─────────────────────────────────────────────
# Variables
# ─────────────────────────────────────────────
BINARY := opsintelligence
GOCMD := go
# Default build includes in-process local Gemma; append optional extras (e.g. opsintelligence_embedlocalgemma)
EXTRA_TAGS ?=
comma := ,
BUILD_TAGS := fts5,opsintelligence_localgemma
ifneq ($(strip $(EXTRA_TAGS)),)
BUILD_TAGS := $(BUILD_TAGS)$(comma)$(EXTRA_TAGS)
endif
GOBUILD := CGO_ENABLED=1 $(GOCMD) build -tags $(BUILD_TAGS)
GOTEST := CGO_ENABLED=1 $(GOCMD) test -tags $(BUILD_TAGS)
GOVET := $(GOCMD) vet
GOLINT := golangci-lint
GOFMT := gofmt
PKG := ./...
BIN_DIR := ./bin
INSTALL_DIR?= /usr/local/bin
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS := -X main.version=$(VERSION) -s -w
SENSING_DIR:= sensing
NODE_CMD := node
PNPM := pnpm
# Colors
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[0;33m
BLUE := \033[0;34m
NC := \033[0m
# ─────────────────────────────────────────────
# Top-level targets
# ─────────────────────────────────────────────
## all: Build everything (Go binary + TypeScript layer)
all: build-go build-ts
## build: Build the Go binary
build: build-go
## build-go: Build the Go orchestrator binary. Depends on build-tui-host so the
## embedded Rust TUI binary for the current platform is staged before
## `go build` runs `//go:embed` against internal/tuibridge/assets/.
build-go: build-tui-host build-ui build-scrun
@echo "$(BLUE)Building Go binary...$(NC)"
@mkdir -p $(BIN_DIR)
$(GOBUILD) -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/$(BINARY) ./cmd/opsintelligence
@echo "$(GREEN)✓ Binary: $(BIN_DIR)/$(BINARY)$(NC)"
## build-ui: Build the React dashboard UI (Vite). Emits hashed bundles into
## internal/webui/dashboard/assets/ so `go:embed` picks them up.
build-ui:
@echo "$(BLUE)Building dashboard UI...$(NC)"
@command -v npm >/dev/null 2>&1 || { echo "$(RED)npm not found — install Node.js$(NC)"; exit 1; }
@cd internal/webui/dashboard/ui && \
([ -d node_modules ] || npm install --no-audit --no-fund --loglevel=error) && \
npm run build
@echo "$(GREEN)✓ Dashboard UI built$(NC)"
## build-scrun: Build the Scrun React app (Vite). Emits hashed bundles into
## internal/webui/dashboard/assets/scrun/ so `go:embed` picks them up.
build-scrun:
@echo "$(BLUE)Building Scrun React app...$(NC)"
@command -v npm >/dev/null 2>&1 || { echo "$(RED)npm not found — install Node.js$(NC)"; exit 1; }
@cd scrun && \
([ -d node_modules ] || npm install --no-audit --no-fund --loglevel=error) && \
npm run build
@echo "$(GREEN)✓ Scrun built$(NC)"
## build-ts: Build the TypeScript agent layer
build-ts:
@echo "$(BLUE)Building TypeScript layer...$(NC)"
$(PNPM) build
@echo "$(GREEN)✓ TypeScript build complete$(NC)"
## build-tui-host: Build the Rust TUI binary for the host platform only
## (writes to internal/tuibridge/assets/opsintel-tui-<os>-<arch>).
build-tui-host:
@echo "$(BLUE)Building Rust TUI for host platform...$(NC)"
@command -v cargo >/dev/null 2>&1 || { echo "$(RED)cargo not found — install Rust from https://rustup.rs$(NC)"; exit 1; }
cargo build --release -p opsintel-tui
@mkdir -p internal/tuibridge/assets
@HOST_OS=$$(go env GOOS); HOST_ARCH=$$(go env GOARCH); SUFFIX=""; \
if [ "$$HOST_OS" = "windows" ]; then SUFFIX=".exe"; fi; \
cp target/release/opsintel-tui$$SUFFIX internal/tuibridge/assets/opsintel-tui-$$HOST_OS-$$HOST_ARCH$$SUFFIX
@echo "$(GREEN)✓ Rust TUI built and staged for host platform$(NC)"
## build-tui: Build the Rust TUI for all supported release targets.
## Requires `rustup target add` for each triple and (typically) `cross`.
build-tui:
@echo "$(BLUE)Cross-building Rust TUI...$(NC)"
@command -v cargo >/dev/null 2>&1 || { echo "$(RED)cargo not found — install Rust from https://rustup.rs$(NC)"; exit 1; }
@mkdir -p internal/tuibridge/assets
cargo build --release -p opsintel-tui --target aarch64-apple-darwin
cp target/aarch64-apple-darwin/release/opsintel-tui internal/tuibridge/assets/opsintel-tui-darwin-arm64
cargo build --release -p opsintel-tui --target x86_64-apple-darwin
cp target/x86_64-apple-darwin/release/opsintel-tui internal/tuibridge/assets/opsintel-tui-darwin-amd64
cargo build --release -p opsintel-tui --target x86_64-unknown-linux-gnu
cp target/x86_64-unknown-linux-gnu/release/opsintel-tui internal/tuibridge/assets/opsintel-tui-linux-amd64
cargo build --release -p opsintel-tui --target aarch64-unknown-linux-gnu
cp target/aarch64-unknown-linux-gnu/release/opsintel-tui internal/tuibridge/assets/opsintel-tui-linux-arm64
cargo build --release -p opsintel-tui --target x86_64-pc-windows-msvc
cp target/x86_64-pc-windows-msvc/release/opsintel-tui.exe internal/tuibridge/assets/opsintel-tui-windows-amd64.exe
@echo "$(GREEN)✓ All Rust TUI targets staged into internal/tuibridge/assets/$(NC)"
## tui: Rebuild the Rust TUI for the host platform and the Go binary,
## ready to run as $(BIN_DIR)/$(BINARY). Use this during TUI dev.
tui: build-tui-host build-go
@echo "$(GREEN)✓ TUI dev build ready: $(BIN_DIR)/$(BINARY)$(NC)"
## tui-ping: Run the Phase 1 bridge smoke test (host build).
tui-ping: build-tui-host build-go
$(BIN_DIR)/$(BINARY) tui-ping
## build-sensing: Build the C++ sensing binaries
build-sensing:
@echo "$(BLUE)Building C++ sensing layer...$(NC)"
@command -v cmake >/dev/null 2>&1 || { echo "$(RED)cmake not found — skipping C++ build$(NC)"; exit 0; }
cmake -S $(SENSING_DIR) -B $(SENSING_DIR)/build -DCMAKE_BUILD_TYPE=Release
cmake --build $(SENSING_DIR)/build --parallel
@echo "$(GREEN)✓ Sensing binaries built$(NC)"
## cross: Build release binaries for multiple platforms
cross: build-tui
@echo "$(BLUE)Cross-compiling release binaries...$(NC)"
@mkdir -p dist
GOOS=darwin GOARCH=arm64 $(GOBUILD) -ldflags "$(LDFLAGS)" -o dist/$(BINARY)-darwin-arm64 ./cmd/opsintelligence
GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags "$(LDFLAGS)" -o dist/$(BINARY)-darwin-amd64 ./cmd/opsintelligence
GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags "$(LDFLAGS)" -o dist/$(BINARY)-linux-amd64 ./cmd/opsintelligence
GOOS=linux GOARCH=arm64 $(GOBUILD) -ldflags "$(LDFLAGS)" -o dist/$(BINARY)-linux-arm64 ./cmd/opsintelligence
GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags "$(LDFLAGS)" -o dist/$(BINARY)-windows-amd64.exe ./cmd/opsintelligence
@echo "$(GREEN)✓ Cross-compiled binaries in dist/$(NC)"
# ─────────────────────────────────────────────
# Testing
# ─────────────────────────────────────────────
## test: Run all Go tests with race detector
test:
@echo "$(BLUE)Running Go tests (race detector enabled)...$(NC)"
$(GOTEST) -race -coverprofile=coverage.out $(PKG)
@echo "$(GREEN)✓ Tests passed$(NC)"
## load-test: Run sprint-02 load and failure-injection harness
load-test:
@echo "$(BLUE)Running load test harness...$(NC)"
$(GOTEST) ./internal/channels/adapter -run TestLoadHarness_Report -count=1 -v
@echo "$(GREEN)✓ Load test harness completed$(NC)"
## test-ts: Run TypeScript/Node tests
test-ts:
$(PNPM) test
## coverage: Run tests and show coverage report
coverage: test
go tool cover -html=coverage.out
# ─────────────────────────────────────────────
# Code quality
# ─────────────────────────────────────────────
## lint: Run golangci-lint
lint:
@command -v $(GOLINT) >/dev/null 2>&1 || { echo "$(YELLOW)golangci-lint not found, run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest$(NC)"; exit 1; }
$(GOLINT) run $(PKG)
## vet: Run go vet
vet:
$(GOVET) $(PKG)
## fmt: Format Go source with gofmt
fmt:
$(GOFMT) -w -s .
## fmt-check: Check Go source formatting
fmt-check:
@out=$$($(GOFMT) -l .); if [ -n "$$out" ]; then echo "$(RED)Needs formatting:$(NC)\n$$out"; exit 1; fi
## check: Run all quality checks (vet + fmt-check + lint)
check: vet fmt-check lint
@echo "$(GREEN)✓ All checks passed$(NC)"
# ─────────────────────────────────────────────
# Installation
# ─────────────────────────────────────────────
## install: Build and install binary to INSTALL_DIR
install: build-go
@echo "$(BLUE)Installing to $(INSTALL_DIR)/$(BINARY)...$(NC)"
cp $(BIN_DIR)/$(BINARY) $(INSTALL_DIR)/$(BINARY)
chmod +x $(INSTALL_DIR)/$(BINARY)
@echo "$(GREEN)✓ Installed: $(INSTALL_DIR)/$(BINARY)$(NC)"
## uninstall: Remove installed binary
uninstall:
rm -f $(INSTALL_DIR)/$(BINARY)
@echo "$(GREEN)✓ Uninstalled$(NC)"
## deps: Download all Go dependencies
deps:
$(GOCMD) mod download
$(GOCMD) mod tidy
$(PNPM) install
# ─────────────────────────────────────────────
# Cleanup
# ─────────────────────────────────────────────
## clean: Remove build artifacts
clean:
rm -rf $(BIN_DIR) dist coverage.out
rm -rf $(SENSING_DIR)/build
$(PNPM) exec rimraf dist 2>/dev/null || true
## help: Show this help message
help:
@echo "$(BLUE)OpsIntelligence Build System$(NC)"
@echo ""
@echo "$(YELLOW)Optional:$(NC) EXTRA_TAGS=opsintelligence_embedlocalgemma to embed GGUF in binary."
@echo ""
@grep -E '^## ' Makefile | sed 's/## //' | column -t -s ':'