-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
364 lines (294 loc) · 12.8 KB
/
Makefile
File metadata and controls
364 lines (294 loc) · 12.8 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# Mesh Network Project Makefile
# Comprehensive build, test, and development automation
.PHONY: help build test clean lint fmt doc install dev release
.PHONY: test-unit test-integration test-reliability test-tls test-all
.PHONY: check check-all clippy audit security
.PHONY: certs certs-localhost certs-test clean-certs
.PHONY: run-listener run-connector run-tls-listener run-tls-connector
.PHONY: bench profile flamegraph coverage
.PHONY: docker docker-build docker-run docker-clean
.PHONY: deps deps-update deps-tree deps-licenses
.PHONY: workspace-check workspace-update workspace-clean
# Default target
.DEFAULT_GOAL := help
# Project configuration
PROJECT_NAME := mesh
RUST_VERSION := $(shell rustc --version | cut -d' ' -f2)
CARGO_VERSION := $(shell cargo --version | cut -d' ' -f2)
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
# Build configuration
CARGO_FLAGS := --workspace
RELEASE_FLAGS := --release
TEST_FLAGS := --workspace --all-features
CLIPPY_FLAGS := --workspace --all-targets --all-features -- -D warnings
DOC_FLAGS := --workspace --all-features --no-deps
# Feature flags
DEFAULT_FEATURES := tls
ALL_FEATURES := --all-features
TLS_FEATURES := --features tls
# Directories
BUILD_DIR := target
DOCS_DIR := target/doc
COVERAGE_DIR := target/coverage
CERTS_DIR := certs
# Colors for output
RED := \033[31m
GREEN := \033[32m
YELLOW := \033[33m
BLUE := \033[34m
MAGENTA := \033[35m
CYAN := \033[36m
RESET := \033[0m
# Help target
help: ## Show this help message
@echo "$(CYAN)Mesh Network Project - Development Makefile$(RESET)"
@echo ""
@echo "$(YELLOW)Project Info:$(RESET)"
@echo " Name: $(PROJECT_NAME)"
@echo " Rust: $(RUST_VERSION)"
@echo " Cargo: $(CARGO_VERSION)"
@echo " Git Commit: $(GIT_COMMIT)"
@echo " Git Branch: $(GIT_BRANCH)"
@echo " Build Date: $(BUILD_DATE)"
@echo ""
@echo "$(YELLOW)Available targets:$(RESET)"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " $(GREEN)%-20s$(RESET) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# Build targets
build: ## Build the project in debug mode with default features (tls)
@echo "$(BLUE)Building project in debug mode with TLS...$(RESET)"
cargo build $(CARGO_FLAGS) $(TLS_FEATURES)
build-minimal: ## Build the project in debug mode without features
@echo "$(BLUE)Building project in debug mode (minimal)...$(RESET)"
cargo build $(CARGO_FLAGS)
build-all: ## Build the project in debug mode with all features
@echo "$(BLUE)Building project in debug mode with all features...$(RESET)"
cargo build $(CARGO_FLAGS) $(ALL_FEATURES)
release: ## Build the project in release mode with default features (tls)
@echo "$(BLUE)Building project in release mode with TLS...$(RESET)"
cargo build $(CARGO_FLAGS) $(RELEASE_FLAGS) $(TLS_FEATURES)
release-minimal: ## Build the project in release mode without features
@echo "$(BLUE)Building project in release mode (minimal)...$(RESET)"
cargo build $(CARGO_FLAGS) $(RELEASE_FLAGS)
release-all: ## Build the project in release mode with all features
@echo "$(BLUE)Building project in release mode with all features...$(RESET)"
cargo build $(CARGO_FLAGS) $(RELEASE_FLAGS) $(ALL_FEATURES)
install: ## Install the mesh binary with TLS support
@echo "$(BLUE)Installing mesh binary with TLS...$(RESET)"
cargo install --path mesh-bin --force $(TLS_FEATURES)
install-minimal: ## Install the mesh binary without features
@echo "$(BLUE)Installing mesh binary (minimal)...$(RESET)"
cargo install --path mesh-bin --force
dev: ## Build for development with all features
@echo "$(BLUE)Building for development...$(RESET)"
cargo build $(CARGO_FLAGS) --all-features
# Test targets
test: test-unit ## Run unit tests (default)
test-unit: ## Run unit tests
@echo "$(BLUE)Running unit tests...$(RESET)"
cargo test $(TEST_FLAGS)
test-integration: ## Run integration tests
@echo "$(BLUE)Running integration tests...$(RESET)"
cargo test $(TEST_FLAGS) --test '*'
test-reliability: build ## Test reliability features
@echo "$(BLUE)Testing reliability features...$(RESET)"
./tests/test_reliability.sh
test-tls: build certs-localhost ## Test TLS functionality
@echo "$(BLUE)Testing TLS functionality...$(RESET)"
./tests/test_tls_mvp.sh
test-all: test-unit test-integration test-reliability test-tls ## Run all tests
# Code quality targets
check: ## Run cargo check
@echo "$(BLUE)Running cargo check...$(RESET)"
cargo check $(CARGO_FLAGS)
check-all: ## Run cargo check with all features
@echo "$(BLUE)Running cargo check with all features...$(RESET)"
cargo check $(CARGO_FLAGS) --all-features
clippy: ## Run clippy linter
@echo "$(BLUE)Running clippy...$(RESET)"
cargo clippy $(CLIPPY_FLAGS)
fmt: ## Format code with rustfmt
@echo "$(BLUE)Formatting code...$(RESET)"
cargo fmt --all
lint: fmt clippy ## Run all linting tools
audit: ## Run security audit
@echo "$(BLUE)Running security audit...$(RESET)"
cargo audit
security: audit ## Alias for audit
# Documentation targets
doc: ## Generate documentation
@echo "$(BLUE)Generating documentation...$(RESET)"
cargo doc $(DOC_FLAGS)
doc-open: doc ## Generate and open documentation
@echo "$(BLUE)Opening documentation...$(RESET)"
cargo doc $(DOC_FLAGS) --open
# Certificate management
certs: certs-test ## Generate test certificates (default)
certs-test: ## Generate test certificates for nodes
@echo "$(BLUE)Generating test certificates...$(RESET)"
./generate_test_certs.sh
certs-localhost: ## Generate localhost certificates for local testing
@echo "$(BLUE)Generating localhost certificates...$(RESET)"
./generate_localhost_certs.sh
clean-certs: ## Clean up certificate files
@echo "$(YELLOW)Cleaning certificate files...$(RESET)"
rm -rf $(CERTS_DIR) $(CERTS_DIR)
# Development server targets
run-listener: build-minimal ## Run mesh node as listener (plain TCP)
@echo "$(BLUE)Starting mesh listener on 127.0.0.1:9000...$(RESET)"
./target/debug/mesh --node-id 1001 --listen 127.0.0.1:9000 --log-level info
run-connector: build-minimal ## Run mesh node as connector (plain TCP)
@echo "$(BLUE)Starting mesh connector to 127.0.0.1:9000...$(RESET)"
./target/debug/mesh --node-id 2002 --connect 127.0.0.1:9000 --log-level info
run-tls-listener: build certs-localhost ## Run mesh node as TLS listener
@echo "$(BLUE)Starting mesh TLS listener on 127.0.0.1:9000...$(RESET)"
./target/debug/mesh --node-id 1001 --listen 127.0.0.1:9000 --log-level info \
--tls --tls-cert $(CERTS_DIR)/node-1001.crt \
--tls-key $(CERTS_DIR)/node-1001.key \
--tls-ca $(CERTS_DIR)/ca.crt
run-tls-connector: build certs-localhost ## Run mesh node as TLS connector
@echo "$(BLUE)Starting mesh TLS connector to 127.0.0.1:9000...$(RESET)"
./target/debug/mesh --node-id 2002 --connect 127.0.0.1:9000 --log-level info \
--tls --tls-cert $(CERTS_DIR)/node-2002.crt \
--tls-key $(CERTS_DIR)/node-2002.key \
--tls-ca $(CERTS_DIR)/ca.crt --tls-sni localhost
# Performance and profiling
bench: ## Run benchmarks
@echo "$(BLUE)Running benchmarks...$(RESET)"
cargo bench $(CARGO_FLAGS)
profile: release ## Build with profiling symbols
@echo "$(BLUE)Building with profiling...$(RESET)"
RUSTFLAGS="-g" cargo build $(CARGO_FLAGS) $(RELEASE_FLAGS)
flamegraph: ## Generate flamegraph (requires flamegraph tool)
@echo "$(BLUE)Generating flamegraph...$(RESET)"
@if ! command -v flamegraph >/dev/null 2>&1; then \
echo "$(RED)Error: flamegraph not installed. Run: cargo install flamegraph$(RESET)"; \
exit 1; \
fi
flamegraph --output flamegraph.svg -- ./target/release/mesh --help
coverage: ## Generate code coverage report (requires tarpaulin)
@echo "$(BLUE)Generating coverage report...$(RESET)"
@if ! command -v cargo-tarpaulin >/dev/null 2>&1; then \
echo "$(RED)Error: tarpaulin not installed. Run: cargo install cargo-tarpaulin$(RESET)"; \
exit 1; \
fi
mkdir -p $(COVERAGE_DIR)
cargo tarpaulin --out Html --output-dir $(COVERAGE_DIR) $(TEST_FLAGS)
@echo "$(GREEN)Coverage report generated in $(COVERAGE_DIR)/tarpaulin-report.html$(RESET)"
# Docker targets
docker-build: ## Build Docker image
@echo "$(BLUE)Building Docker image...$(RESET)"
docker build -t $(PROJECT_NAME):latest .
docker-run: docker-build ## Run Docker container
@echo "$(BLUE)Running Docker container...$(RESET)"
docker run --rm -p 9000:9000 $(PROJECT_NAME):latest
docker-clean: ## Clean Docker images and containers
@echo "$(YELLOW)Cleaning Docker images...$(RESET)"
docker rmi $(PROJECT_NAME):latest 2>/dev/null || true
docker system prune -f
# Dependency management
deps: ## Show dependency tree
@echo "$(BLUE)Dependency tree:$(RESET)"
cargo tree
deps-update: ## Update dependencies
@echo "$(BLUE)Updating dependencies...$(RESET)"
cargo update
deps-tree: ## Show detailed dependency tree
@echo "$(BLUE)Detailed dependency tree:$(RESET)"
cargo tree --all-features -e all
deps-licenses: ## Show dependency licenses (requires cargo-license)
@echo "$(BLUE)Dependency licenses:$(RESET)"
@if ! command -v cargo-license >/dev/null 2>&1; then \
echo "$(RED)Error: cargo-license not installed. Run: cargo install cargo-license$(RESET)"; \
exit 1; \
fi
cargo license
# Workspace management
workspace-check: ## Check all workspace members
@echo "$(BLUE)Checking workspace members...$(RESET)"
@for crate in mesh-wire mesh-crypto mesh-storage mesh-session mesh-routing \
mesh-topology mesh-grpc mesh-config mesh-observe mesh-bin; do \
echo "$(CYAN)Checking $$crate...$(RESET)"; \
cargo check -p $$crate || exit 1; \
done
workspace-update: ## Update all workspace members
@echo "$(BLUE)Updating workspace...$(RESET)"
cargo update --workspace
workspace-clean: ## Clean all workspace build artifacts
@echo "$(YELLOW)Cleaning workspace...$(RESET)"
cargo clean
# Clean targets
clean: ## Clean build artifacts
@echo "$(YELLOW)Cleaning build artifacts...$(RESET)"
cargo clean
clean-all: clean clean-certs ## Clean everything (build artifacts and certificates)
@echo "$(YELLOW)Cleaning all generated files...$(RESET)"
rm -rf $(COVERAGE_DIR)
rm -f flamegraph.svg
rm -rf meshdata_test_*
# CI/CD targets
ci-check: fmt clippy check-all test-unit ## Run CI checks (formatting, linting, tests)
ci-test: test-all ## Run all tests for CI
ci-build: release ## Build release for CI
ci-full: ci-check ci-test ci-build ## Run full CI pipeline
# Development workflow
dev-setup: ## Set up development environment
@echo "$(BLUE)Setting up development environment...$(RESET)"
@echo "$(CYAN)Installing required tools...$(RESET)"
cargo install cargo-audit cargo-tarpaulin cargo-license flamegraph
@echo "$(GREEN)Development environment ready!$(RESET)"
dev-check: fmt clippy test-unit ## Quick development check (format, lint, test)
dev-full: clean build test-all lint doc ## Full development build and test
# Release preparation
pre-release: clean ci-full doc ## Prepare for release (full CI + docs)
@echo "$(GREEN)Pre-release checks completed successfully!$(RESET)"
# Information targets
info: ## Show project information
@echo "$(CYAN)Project Information:$(RESET)"
@echo " Name: $(PROJECT_NAME)"
@echo " Rust Version: $(RUST_VERSION)"
@echo " Cargo Version: $(CARGO_VERSION)"
@echo " Git Commit: $(GIT_COMMIT)"
@echo " Git Branch: $(GIT_BRANCH)"
@echo " Build Date: $(BUILD_DATE)"
@echo ""
@echo "$(CYAN)Workspace Crates:$(RESET)"
@cargo metadata --format-version 1 | jq -r '.workspace_members[]' | sed 's/.*#/ /'
status: ## Show git and build status
@echo "$(CYAN)Git Status:$(RESET)"
@git status --porcelain || echo " Not a git repository"
@echo ""
@echo "$(CYAN)Build Status:$(RESET)"
@if [ -f "$(BUILD_DIR)/debug/mesh" ]; then \
echo " Debug build: $(GREEN)✓$(RESET)"; \
else \
echo " Debug build: $(RED)✗$(RESET)"; \
fi
@if [ -f "$(BUILD_DIR)/release/mesh" ]; then \
echo " Release build: $(GREEN)✓$(RESET)"; \
else \
echo " Release build: $(RED)✗$(RESET)"; \
fi
# Feature-specific targets
build-tls: build ## Alias for build (with TLS)
run-release-tls-listener: release certs-localhost ## Run release TLS listener
@echo "$(BLUE)Starting release mesh TLS listener on 127.0.0.1:9000...$(RESET)"
./target/release/mesh --node-id 1001 --listen 127.0.0.1:9000 --log-level info \
--tls --tls-cert $(CERTS_DIR)/node-1001.crt \
--tls-key $(CERTS_DIR)/node-1001.key \
--tls-ca $(CERTS_DIR)/ca.crt
run-release-tls-connector: release certs-localhost ## Run release TLS connector
@echo "$(BLUE)Starting release mesh TLS connector to 127.0.0.1:9000...$(RESET)"
./target/release/mesh --node-id 2002 --connect 127.0.0.1:9000 --log-level info \
--tls --tls-cert $(CERTS_DIR)/node-2002.crt \
--tls-key $(CERTS_DIR)/node-2002.key \
--tls-ca $(CERTS_DIR)/ca.crt --tls-sni localhost
# Quick aliases
b: build ## Alias for build
t: test ## Alias for test
c: check ## Alias for check
r: release ## Alias for release
d: doc ## Alias for doc
f: fmt ## Alias for fmt
l: lint ## Alias for lint