-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
427 lines (351 loc) · 13.3 KB
/
Makefile
File metadata and controls
427 lines (351 loc) · 13.3 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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# BitNet-rs Makefile - One-click everything
# Usage: make [target]
# Default goal & common vars
.DEFAULT_GOAL := quick
CARGO ?= cargo
# Pretty colors (safe fallbacks if not a TTY)
GREEN := $(shell tput setaf 2 2>/dev/null || echo "")
YELLOW := $(shell tput setaf 3 2>/dev/null || echo "")
BLUE := $(shell tput setaf 4 2>/dev/null || echo "")
RED := $(shell tput setaf 1 2>/dev/null || echo "")
NC := $(shell tput sgr0 2>/dev/null || echo "")
# Declare phony targets
.PHONY: help all quick install dev test bench clean gpu docker run serve repl release deploy update fmt lint check fix docs ci setup \
build test-quick test-gpu test-integration gpu-smoke download-model crossval tree loc size \
watch flame audit outdated bloat docker-run docker-gpu profile valgrind heaptrack wasm python list verbose \
guards preflight docs-check \
b t r c f l d g bt bf cf cb ct fr ft q a i
# Detect OS and features
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m)
# Check for GPU availability
GPU_AVAILABLE := $(shell command -v nvidia-smi 2> /dev/null)
ifeq ($(GPU_AVAILABLE),)
ifeq ($(OS),darwin)
ifeq ($(ARCH),arm64)
FEATURES ?= gpu
else
FEATURES ?= cpu
endif
else
FEATURES ?= cpu
endif
else
FEATURES ?= gpu
endif
# Number of parallel jobs
JOBS := $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
#############################################################################
# PRIMARY TARGETS - THE ONES YOU'LL USE MOST
#############################################################################
## help: Show annotated targets
help:
@echo "$(BLUE)BitNet-rs One-Click Commands$(NC)"
@echo ""
@echo "$(GREEN)Primary Commands:$(NC)"
@awk 'BEGIN {FS = ":.*?## "}; /^[a-zA-Z0-9_ -]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
@echo ""
@echo "$(YELLOW)Quick Examples:$(NC)"
@echo " make # Quick start (builds and tests)"
@echo " make run # Run the CLI"
@echo " make test # Run all tests"
@echo " make bench # Run benchmarks"
@echo ""
## quick: One-click quick start (default)
quick:
@echo "$(GREEN)🚀 Quick Start$(NC)"
@scripts/deploy.sh quick
## all: Build everything with all features
all:
@echo "$(GREEN)Building everything...$(NC)"
@$(CARGO) build --workspace --all-features --release
@echo "$(GREEN)✓ Build complete$(NC)"
## install: Full installation with all dependencies
install:
@echo "$(GREEN)Full installation...$(NC)"
@scripts/deploy.sh full
## dev: Setup development environment
dev:
@echo "$(GREEN)Setting up development environment...$(NC)"
@scripts/deploy.sh dev
#############################################################################
# BUILD TARGETS
#############################################################################
## build: Build with detected features
build:
@echo "$(GREEN)Building with $(FEATURES) features...$(NC)"
@$(CARGO) build --locked --release --no-default-features --features $(FEATURES)
## release: Build optimized release
release:
@echo "$(GREEN)Building optimized release...$(NC)"
@RUSTFLAGS="-C target-cpu=native -C lto=fat" \
$(CARGO) build --locked --release --no-default-features --features $(FEATURES)
## docker: Build Docker image
docker:
@echo "$(GREEN)Building Docker image...$(NC)"
@docker build -t bitnet-rs:latest .
#############################################################################
# TEST TARGETS
#############################################################################
## test: Run all tests
test:
@echo "$(GREEN)Running tests...$(NC)"
@$(CARGO) test --locked --workspace --no-default-features --features $(FEATURES)
## test-quick: Run quick tests only
test-quick:
@$(CARGO) test --locked --workspace --lib --no-default-features --features $(FEATURES)
## test-gpu: Run GPU tests (if available)
test-gpu:
@echo "$(GREEN)Running GPU tests...$(NC)"
@$(CARGO) xtask gpu-smoke
## test-integration: Run integration tests
test-integration:
@$(CARGO) test --locked --workspace --test '*' --no-default-features --features $(FEATURES)
## bench: Run benchmarks
bench:
@echo "$(GREEN)Running benchmarks...$(NC)"
@$(CARGO) bench --workspace --no-default-features --features $(FEATURES)
#############################################################################
# RUN TARGETS
#############################################################################
## run: Run the CLI
run:
@$(CARGO) run --release --no-default-features --features $(FEATURES) -- $(ARGS)
## serve: Start the server
serve:
@$(CARGO) run --release -p bitnet-server --no-default-features --features $(FEATURES)
## repl: Start interactive REPL
repl:
@$(CARGO) run --release --no-default-features --features $(FEATURES) -- repl
## demo: Run demos
demo:
@$(CARGO) xtask demo --which all
#############################################################################
# DEVELOPMENT TARGETS
#############################################################################
## fmt: Format all code
fmt:
@echo "$(GREEN)Formatting code...$(NC)"
@$(CARGO) fmt --all
@echo "$(GREEN)✓ Code formatted$(NC)"
## lint: Run clippy lints
lint:
@echo "$(GREEN)Running clippy...$(NC)"
@$(CARGO) clippy --workspace --all-targets --all-features -- -D warnings
## check: Run all checks (fmt, lint, test)
check: fmt lint test
@echo "$(GREEN)✓ All checks passed$(NC)"
## fix: Auto-fix issues
fix:
@echo "$(GREEN)Auto-fixing issues...$(NC)"
@$(CARGO) fix --workspace --allow-dirty --allow-staged
@$(CARGO) fmt --all
@$(CARGO) clippy --workspace --fix --allow-dirty --allow-staged -- -D warnings
## docs: Generate and open documentation
docs:
@echo "$(GREEN)Generating documentation...$(NC)"
@$(CARGO) doc --workspace --no-deps --open
## docs-check: Run automated documentation checks
docs-check:
@echo "$(GREEN)Running documentation automation checks...$(NC)"
@scripts/docs_automation.sh
#############################################################################
# GPU TARGETS
#############################################################################
## gpu: Check GPU availability
gpu:
@$(CARGO) xtask gpu-preflight
## gpu-smoke: Run GPU smoke tests
gpu-smoke:
@$(CARGO) xtask gpu-smoke
#############################################################################
# MAINTENANCE TARGETS
#############################################################################
## clean: Clean all build artifacts
clean:
@echo "$(YELLOW)Cleaning build artifacts...$(NC)"
@$(CARGO) clean
@rm -rf target/
@echo "$(GREEN)✓ Clean complete$(NC)"
## update: Update all dependencies
update:
@echo "$(GREEN)Updating dependencies...$(NC)"
@$(CARGO) update
@rustup update
@echo "$(GREEN)✓ Updates complete$(NC)"
## setup: Initial setup
setup:
@echo "$(GREEN)Running initial setup...$(NC)"
@scripts/deploy.sh full
#############################################################################
# CI/CD TARGETS
#############################################################################
## ci: Run CI checks
ci:
@echo "$(GREEN)Running CI checks...$(NC)"
@$(CARGO) fmt --all -- --check
@$(CARGO) clippy --workspace --all-targets --all-features -- -D warnings
@$(CARGO) test --locked --workspace --no-default-features --features cpu
@echo "$(GREEN)✓ CI checks passed$(NC)"
## guards: Run local preflight guards (floating refs, MSRV, --locked flags)
guards:
@echo "$(GREEN)Running local preflight guards...$(NC)"
@echo ""
@# Check for floating action refs
@echo "$(BLUE)Checking for floating action refs...$(NC)"
@if rg --color=never --glob '!guards.yml' \
-e '^\s*uses:\s*[^ @]+/[^ @]+@(?:v[0-9]+(?:\.[0-9]+)*)\b' \
-e '^\s*uses:\s*[^ @]+/[^ @]+@(?:stable|main|master|latest)\b' \
.github/workflows 2>/dev/null; then \
echo "$(RED)❌ Floating GitHub Action refs detected (must use SHA pins)$(NC)"; \
exit 1; \
fi
@echo "$(GREEN)✅ All actions pinned to SHA refs$(NC)"
@echo ""
@# Check for 40-hex SHA pins
@echo "$(BLUE)Checking for 40-hex SHA pins...$(NC)"
@if rg --pcre2 --color=never --glob '!guards.yml' \
-e '^\s*uses:\s*(?!\./)[^ @]+/[^ @]+@(?![0-9a-f]{40}\b)' \
.github/workflows 2>/dev/null; then \
echo "$(RED)❌ Non-immutable action pin detected (must be 40-hex SHA)$(NC)"; \
exit 1; \
fi
@echo "$(GREEN)✅ All actions pinned to 40-hex SHAs$(NC)"
@echo ""
@# Check for wrong MSRV (1.90.0 or other non-1.89.0 hardcoded versions)
@echo "$(BLUE)Checking for wrong MSRV versions (should be 1.89.0 or dynamic)...$(NC)"
@wrong_msrv=$$(rg --color=never --glob '!guards.yml' \
-e 'toolchain:\s*"?1\.90\.0"?' \
-e 'rust-version\s*=\s*"1\.90\.0"' \
-e '"RUST_VERSION"\s*:\s*"1\.90\.0"' \
.github/workflows 2>/dev/null || true); \
if [ -n "$$wrong_msrv" ]; then \
echo "$(RED)❌ Found wrong MSRV (1.90.0) in workflows:$(NC)"; \
echo "$$wrong_msrv"; \
exit 1; \
fi
@echo "$(GREEN)✅ No wrong MSRV versions found (1.89.0 or dynamic from rust-toolchain.toml)$(NC)"
@echo ""
@# Check cargo/cross --locked flags
@echo "$(BLUE)Checking cargo/cross --locked flags...$(NC)"
@violations=$$(rg --color=never --glob '*.yml' --glob '!guards.yml' \
-e '\b(cargo|cross)\s+(build|test|run|bench|clippy)\b' \
.github/workflows 2>/dev/null | grep -v -- '--locked' || true); \
if [ -n "$$violations" ]; then \
echo "$(RED)❌ Missing --locked in workflow cargo/cross command(s):$(NC)"; \
echo "$$violations"; \
exit 1; \
fi
@echo "$(GREEN)✅ All workflow cargo/cross commands use --locked$(NC)"
@echo ""
@echo "$(GREEN)✓ All preflight guards passed!$(NC)"
## preflight: Alias for guards
preflight: guards
## deploy: Deploy to production
deploy:
@echo "$(GREEN)Deploying to production...$(NC)"
@scripts/deploy.sh prod
#############################################################################
# UTILITY TARGETS
#############################################################################
## download-model: Download BitNet model
download-model:
@$(CARGO) xtask download-model
## crossval: Run cross-validation tests
crossval:
@$(CARGO) xtask full-crossval
## tree: Show project structure
tree:
@tree -I 'target|venv|__pycache__|.git|node_modules' -L 3
## loc: Count lines of code
loc:
@tokei --exclude target --exclude venv
## size: Show binary sizes
size:
@du -h target/release/bitnet* 2>/dev/null | sort -h || echo "No release binaries built yet"
#############################################################################
# SHORTCUTS
#############################################################################
# Single letter shortcuts for common commands
b: build
t: test
r: run
c: clean
f: fmt
l: lint
d: docs
g: gpu
# Quick compound commands
bt: build test
bf: build fmt
cf: clean fmt
cb: clean build
ct: clean test
fr: fmt run
ft: fmt test
# Even quicker
q: quick
a: all
i: install
#############################################################################
# SPECIAL TARGETS
#############################################################################
## watch: Watch for changes and rebuild
watch:
@$(CARGO) watch -x 'build --locked --release --no-default-features --features $(FEATURES)'
## flame: Generate flamegraph (requires cargo-flamegraph)
flame:
@$(CARGO) flamegraph --release --no-default-features --features $(FEATURES)
## audit: Security audit
audit:
@$(CARGO) audit
## outdated: Check for outdated dependencies
outdated:
@$(CARGO) outdated
## bloat: Analyze binary bloat
bloat:
@$(CARGO) bloat --release --no-default-features --features $(FEATURES)
#############################################################################
# DOCKER SHORTCUTS
#############################################################################
## docker-run: Run in Docker
docker-run: docker
@docker run -it --rm bitnet-rs:latest
## docker-gpu: Run with GPU support in Docker
docker-gpu: docker
@docker run -it --rm --gpus all bitnet-rs:latest
#############################################################################
# ADVANCED TARGETS
#############################################################################
## profile: Profile with perf (Linux only)
profile:
@$(CARGO) build --locked --release --no-default-features --features $(FEATURES)
@perf record -g target/release/bitnet
@perf report
## valgrind: Run with valgrind (Linux only)
valgrind:
@$(CARGO) build --locked --release --no-default-features --features $(FEATURES)
@valgrind --leak-check=full --show-leak-kinds=all target/release/bitnet
## heaptrack: Memory profiling (requires heaptrack)
heaptrack:
@$(CARGO) build --locked --release --no-default-features --features $(FEATURES)
@heaptrack target/release/bitnet
#############################################################################
# EXPERIMENTAL
#############################################################################
## wasm: Build WebAssembly target
wasm:
@$(CARGO) build --target wasm32-unknown-unknown -p bitnet-wasm
## python: Build Python bindings
python:
@cd crates/bitnet-py && maturin develop
#############################################################################
# HELP UTILITIES
#############################################################################
## list: List all targets
list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | grep -v Makefile
## verbose: Run with verbose output
verbose:
@RUST_LOG=debug $(CARGO) run --release --no-default-features --features $(FEATURES)
.SILENT: help list