Makefile 3.95 KB
Newer Older
1
# Model Gateway Makefile
2
3
# Provides convenient shortcuts for common development tasks

4
5
6
7
8
9
10
11
12
# Check if sccache is available and set RUSTC_WRAPPER accordingly
SCCACHE := $(shell which sccache 2>/dev/null)
ifdef SCCACHE
    export RUSTC_WRAPPER := $(SCCACHE)
    $(info Using sccache for compilation caching)
else
    $(info sccache not found. Install it for faster builds: cargo install sccache)
endif

13
14
15
.PHONY: help bench bench-quick bench-baseline bench-compare test build clean

help: ## Show this help message
16
	@echo "Model Gateway Development Commands"
17
18
19
20
21
22
	@echo "=================================="
	@echo ""
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-20s\033[0m %s\n", $$1, $$2}'
	@echo ""

build: ## Build the project in release mode
23
	@echo "Building SGLang Model Gateway..."
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
	@cargo build --release

test: ## Run all tests
	@echo "Running tests..."
	@cargo test

bench: ## Run full benchmark suite
	@echo "Running full benchmarks..."
	@python3 scripts/run_benchmarks.py

bench-quick: ## Run quick benchmarks only
	@echo "Running quick benchmarks..."
	@python3 scripts/run_benchmarks.py --quick

bench-baseline: ## Save current performance as baseline
	@echo "Saving performance baseline..."
	@python3 scripts/run_benchmarks.py --save-baseline main

bench-compare: ## Compare with saved baseline
	@echo "Comparing with baseline..."
	@python3 scripts/run_benchmarks.py --compare-baseline main

bench-ci: ## Run benchmarks suitable for CI (quick mode)
	@echo "Running CI benchmarks..."
	@python3 scripts/run_benchmarks.py --quick

clean: ## Clean build artifacts
	@echo "Cleaning build artifacts..."
	@cargo clean

docs: ## Generate and open documentation
	@echo "Generating documentation..."
	@cargo doc --open

check: ## Run cargo check and clippy
	@echo "Running cargo check..."
	@cargo check
	@echo "Running clippy..."
62
	@cargo clippy --all-targets --all-features -- -D warnings
63
64
65

fmt: ## Format code with rustfmt
	@echo "Formatting code..."
66
	@rustup run nightly cargo fmt
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

# Development workflow shortcuts
dev-setup: build test ## Set up development environment
	@echo "Development environment ready!"

pre-commit: fmt check test bench-quick ## Run pre-commit checks
	@echo "Pre-commit checks passed!"

# Benchmark analysis shortcuts
bench-report: ## Open benchmark HTML report
	@if [ -f "target/criterion/request_processing/report/index.html" ]; then \
		echo "Opening benchmark report..."; \
		if command -v xdg-open >/dev/null 2>&1; then \
			xdg-open target/criterion/request_processing/report/index.html; \
		elif command -v open >/dev/null 2>&1; then \
			open target/criterion/request_processing/report/index.html; \
		else \
			echo "Please open target/criterion/request_processing/report/index.html in your browser"; \
		fi \
	else \
		echo "No benchmark report found. Run 'make bench' first."; \
	fi

bench-clean: ## Clean benchmark results
	@echo "Cleaning benchmark results..."
	@rm -rf target/criterion

# Performance monitoring
perf-monitor: ## Run continuous performance monitoring
	@echo "Starting performance monitoring..."
	@if command -v watch >/dev/null 2>&1; then \
		watch -n 300 'make bench-quick'; \
	else \
		echo "Warning: 'watch' command not found. Install it or run 'make bench-quick' manually."; \
	fi
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

# sccache management targets
setup-sccache: ## Install and configure sccache
	@echo "Setting up sccache..."
	@./scripts/setup-sccache.sh

sccache-stats: ## Show sccache statistics
	@if [ -n "$(SCCACHE)" ]; then \
		echo "sccache statistics:"; \
		sccache -s; \
	else \
		echo "sccache not installed. Run 'make setup-sccache' to install it."; \
	fi

sccache-clean: ## Clear sccache cache
	@if [ -n "$(SCCACHE)" ]; then \
		echo "Clearing sccache cache..."; \
		sccache -C; \
		echo "sccache cache cleared"; \
	else \
		echo "sccache not installed"; \
	fi

sccache-stop: ## Stop the sccache server
	@if [ -n "$(SCCACHE)" ]; then \
		echo "Stopping sccache server..."; \
		sccache --stop-server || true; \
	else \
		echo "sccache not installed"; \
	fi