-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
340 lines (289 loc) · 10.9 KB
/
Makefile
File metadata and controls
340 lines (289 loc) · 10.9 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
# Luhn Ultra - Comprehensive Makefile
# High-performance SIMD-optimized Luhn validator library
# Variables
RUST_VERSION := stable
NIGHTLY_VERSION := nightly
CARGO := cargo
CARGO_NIGHTLY := cargo +nightly
# Build configurations
DEBUG_FLAGS := --profile dev
RELEASE_FLAGS := --profile release
BENCH_FLAGS := --profile bench
# Test configurations
TEST_FLAGS := --all-features
FUZZ_FLAGS := --release
MIRI_FLAGS := -Zmiri-symbolic-alignment-check -Zmiri-disable-isolation
# Colors for output
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[1;33m
BLUE := \033[0;34m
PURPLE := \033[0;35m
CYAN := \033[0;36m
NC := \033[0m # No Color
.PHONY: help all build test clean install setup check format lint doc bench fuzz examples
.PHONY: test-unit test-integration test-property test-fuzz test-miri test-all
.PHONY: clean-all clean-target clean-fuzz clean-docs clean-artifacts
.PHONY: release debug profile security audit
# Default target
all: check test build
# Help target
help:
@echo "$(CYAN)Luhn Ultra - High-Performance SIMD Luhn Validator$(NC)"
@echo ""
@echo "$(YELLOW)Build Targets:$(NC)"
@echo " build - Build the library (debug)"
@echo " release - Build optimized release version"
@echo " debug - Build with debug symbols"
@echo " examples - Build all examples"
@echo ""
@echo "$(YELLOW)Test Targets:$(NC)"
@echo " test - Run standard tests"
@echo " test-all - Run all test types"
@echo " test-unit - Run unit tests"
@echo " test-integration - Run integration tests"
@echo " test-property - Run property-based tests"
@echo " test-fuzz - Run fuzz tests (requires nightly)"
@echo " test-miri - Run Miri undefined behavior detection"
@echo ""
@echo "$(YELLOW)Quality Targets:$(NC)"
@echo " check - Check code without building"
@echo " format - Format code with rustfmt"
@echo " lint - Run clippy linter"
@echo " audit - Security audit with cargo-audit"
@echo " security - Comprehensive security checks"
@echo ""
@echo "$(YELLOW)Performance Targets:$(NC)"
@echo " bench - Run benchmarks"
@echo " profile - Profile performance"
@echo ""
@echo "$(YELLOW)Documentation Targets:$(NC)"
@echo " doc - Generate documentation"
@echo " doc-open - Generate and open documentation"
@echo ""
@echo "$(YELLOW)Maintenance Targets:$(NC)"
@echo " clean - Clean build artifacts"
@echo " clean-all - Deep clean everything"
@echo " setup - Setup development environment"
@echo " install - Install required tools"
# Setup and installation
setup: install
@echo "$(GREEN)Setting up development environment...$(NC)"
rustup component add rustfmt clippy
rustup toolchain install $(NIGHTLY_VERSION)
rustup component add --toolchain $(NIGHTLY_VERSION) miri
@echo "$(GREEN)Development environment ready!$(NC)"
install:
@echo "$(BLUE)Installing required tools...$(NC)"
@command -v cargo-audit >/dev/null 2>&1 || cargo install cargo-audit
@command -v cargo-fuzz >/dev/null 2>&1 || cargo install cargo-fuzz
@command -v cargo-criterion >/dev/null 2>&1 || cargo install cargo-criterion
@command -v cargo-expand >/dev/null 2>&1 || cargo install cargo-expand
@command -v cargo-bloat >/dev/null 2>&1 || cargo install cargo-bloat
@echo "$(GREEN)Tools installed successfully!$(NC)"
# Build targets
build:
@echo "$(BLUE)Building Luhn Ultra (debug)...$(NC)"
$(CARGO) build $(DEBUG_FLAGS)
release:
@echo "$(BLUE)Building Luhn Ultra (release)...$(NC)"
$(CARGO) build $(RELEASE_FLAGS)
@echo "$(GREEN)Release build complete!$(NC)"
debug:
@echo "$(BLUE)Building with debug symbols...$(NC)"
$(CARGO) build --profile dev --features debug
examples:
@echo "$(BLUE)Building all examples...$(NC)"
$(CARGO) build --examples $(RELEASE_FLAGS)
@echo "$(GREEN)Examples built successfully!$(NC)"
# Test targets
test:
@echo "$(BLUE)Running standard tests...$(NC)"
$(CARGO) test $(TEST_FLAGS)
test-all: test-unit test-integration test-property test-fuzz test-miri
@echo "$(GREEN)All tests completed!$(NC)"
test-unit:
@echo "$(BLUE)Running unit tests...$(NC)"
$(CARGO) test --lib $(TEST_FLAGS)
test-integration:
@echo "$(BLUE)Running integration tests...$(NC)"
$(CARGO) test --test integration_tests $(TEST_FLAGS)
test-property:
@echo "$(BLUE)Running property-based tests...$(NC)"
$(CARGO) test --test property_tests $(TEST_FLAGS)
test-fuzz:
@echo "$(BLUE)Running fuzz tests (requires nightly)...$(NC)"
@if command -v cargo-fuzz >/dev/null 2>&1; then \
cd fuzz && $(CARGO_NIGHTLY) fuzz run validate_pan16_ascii -- -max_total_time=30; \
cd fuzz && $(CARGO_NIGHTLY) fuzz run validate_pan_relaxed -- -max_total_time=30; \
cd fuzz && $(CARGO_NIGHTLY) fuzz run check_digit_ascii -- -max_total_time=30; \
cd fuzz && $(CARGO_NIGHTLY) fuzz run complete_ascii -- -max_total_time=30; \
else \
echo "$(YELLOW)cargo-fuzz not installed. Run 'make install' first.$(NC)"; \
fi
test-miri:
@echo "$(BLUE)Running Miri undefined behavior detection...$(NC)"
@if rustup toolchain list | grep -q $(NIGHTLY_VERSION); then \
$(CARGO_NIGHTLY) miri test $(MIRI_FLAGS); \
else \
echo "$(YELLOW)Nightly toolchain not installed. Run 'make setup' first.$(NC)"; \
fi
# Quality assurance targets
check:
@echo "$(BLUE)Checking code...$(NC)"
$(CARGO) check --all-targets $(TEST_FLAGS)
$(CARGO) check --examples
$(CARGO) check --benches
format:
@echo "$(BLUE)Formatting code...$(NC)"
$(CARGO) fmt --all
@echo "$(GREEN)Code formatted!$(NC)"
format-check:
@echo "$(BLUE)Checking code formatting...$(NC)"
$(CARGO) fmt --all -- --check
lint:
@echo "$(BLUE)Running clippy linter...$(NC)"
$(CARGO) clippy --all-targets $(TEST_FLAGS)
$(CARGO) clippy --examples
audit:
@echo "$(BLUE)Running security audit...$(NC)"
@if command -v cargo-audit >/dev/null 2>&1; then \
cargo audit; \
else \
echo "$(YELLOW)cargo-audit not installed. Run 'make install' first.$(NC)"; \
fi
security: audit
@echo "$(BLUE)Running comprehensive security checks...$(NC)"
$(CARGO) check --profile release
@echo "$(BLUE)Checking for unsafe code usage...$(NC)"
@grep -r "unsafe" src/ || echo "$(GREEN)No unsafe code found in src/$(NC)"
@echo "$(GREEN)Security checks complete!$(NC)"
# Performance targets
bench:
@echo "$(BLUE)Running benchmarks...$(NC)"
$(CARGO) bench --bench luhn_bench
@echo "$(GREEN)Benchmarks complete!$(NC)"
bench-criterion:
@echo "$(BLUE)Running Criterion benchmarks...$(NC)"
@if command -v cargo-criterion >/dev/null 2>&1; then \
cargo criterion; \
else \
echo "$(YELLOW)cargo-criterion not installed. Using built-in benchmarks...$(NC)"; \
$(CARGO) bench; \
fi
profile:
@echo "$(BLUE)Profiling performance...$(NC)"
$(CARGO) build $(RELEASE_FLAGS)
@echo "$(YELLOW)Run examples with profiling tools like perf, valgrind, or flamegraph$(NC)"
# Documentation targets
doc:
@echo "$(BLUE)Generating documentation...$(NC)"
$(CARGO) doc --all-features --no-deps
doc-open:
@echo "$(BLUE)Generating and opening documentation...$(NC)"
$(CARGO) doc --all-features --no-deps --open
doc-private:
@echo "$(BLUE)Generating documentation with private items...$(NC)"
$(CARGO) doc --all-features --no-deps --document-private-items
# Example targets
run-examples:
@echo "$(BLUE)Running all examples...$(NC)"
@echo "$(CYAN)=== Basic Validation ===$(NC)"
$(CARGO) run --example basic_validation --quiet
@echo "$(CYAN)=== Batch Processing ===$(NC)"
$(CARGO) run --example batch_processing --quiet
@echo "$(CYAN)=== Error Handling ===$(NC)"
$(CARGO) run --example error_handling --quiet
@echo "$(CYAN)=== Utility Functions ===$(NC)"
$(CARGO) run --example utility_functions --quiet
@echo "$(CYAN)=== Performance Comparison ===$(NC)"
$(CARGO) run --example performance_comparison --quiet
@echo "$(CYAN)=== Real-world Integration ===$(NC)"
$(CARGO) run --example real_world_integration --quiet
@echo "$(GREEN)All examples completed!$(NC)"
# Analysis targets
bloat:
@echo "$(BLUE)Analyzing binary size...$(NC)"
@if command -v cargo-bloat >/dev/null 2>&1; then \
cargo bloat --release; \
else \
echo "$(YELLOW)cargo-bloat not installed. Run 'make install' first.$(NC)"; \
fi
expand:
@echo "$(BLUE)Expanding macros...$(NC)"
@if command -v cargo-expand >/dev/null 2>&1; then \
cargo expand --lib; \
else \
echo "$(YELLOW)cargo-expand not installed. Run 'make install' first.$(NC)"; \
fi
# Cleaning targets
clean:
@echo "$(BLUE)Cleaning build artifacts...$(NC)"
$(CARGO) clean
clean-target:
@echo "$(BLUE)Cleaning target directory...$(NC)"
rm -rf target/
clean-fuzz:
@echo "$(BLUE)Cleaning fuzz artifacts...$(NC)"
rm -rf fuzz/target/
rm -rf fuzz/corpus/*/
rm -rf fuzz/artifacts/*/
clean-docs:
@echo "$(BLUE)Cleaning documentation...$(NC)"
rm -rf target/doc/
clean-artifacts:
@echo "$(BLUE)Cleaning test artifacts...$(NC)"
find . -name "*.profraw" -delete
find . -name "*.gcda" -delete
find . -name "*.gcno" -delete
clean-all: clean clean-fuzz clean-docs clean-artifacts
@echo "$(BLUE)Deep cleaning everything...$(NC)"
$(CARGO) clean
rm -rf Cargo.lock
@echo "$(GREEN)Deep clean complete!$(NC)"
# CI/CD targets
ci: format-check lint check test-all audit
@echo "$(GREEN)CI pipeline completed successfully!$(NC)"
ci-fast: format-check lint check test
@echo "$(GREEN)Fast CI pipeline completed!$(NC)"
# Release preparation
pre-release: clean-all format lint test-all bench doc audit
@echo "$(GREEN)Pre-release checks completed!$(NC)"
# Development workflow
dev: format lint-quiet check test
@echo "$(GREEN)Development workflow completed!$(NC)"
# Quiet lint for development (allows warnings)
lint-quiet:
@echo "$(BLUE)Running clippy linter (quiet mode)...$(NC)"
$(CARGO) clippy --all-targets $(TEST_FLAGS) -- -A dead_code -A unused_variables -A unused_imports
$(CARGO) clippy --examples -- -A dead_code -A unused_variables -A unused_imports
# Performance testing
perf-test: release
@echo "$(BLUE)Running performance tests...$(NC)"
$(CARGO) run --example performance_comparison --release
$(CARGO) bench --bench luhn_bench
# Memory testing
memory-test: test-miri
@echo "$(BLUE)Running memory safety tests...$(NC)"
@echo "$(GREEN)Memory tests completed!$(NC)"
# Full validation suite
validate: clean format lint check test-all bench audit doc
@echo "$(GREEN)Full validation suite completed!$(NC)"
# Quick development check
quick: format-check check test-unit
@echo "$(GREEN)Quick development check completed!$(NC)"
# Show project status
status:
@echo "$(CYAN)Luhn Ultra Project Status$(NC)"
@echo "=========================="
@echo "Rust version: $(shell rustc --version)"
@echo "Cargo version: $(shell cargo --version)"
@echo "Project features: SIMD optimization, batch processing, fuzzing"
@echo "Test coverage: Unit, Integration, Property-based, Fuzz, Miri"
@echo "Performance targets: SSE2 ≥1.5 GB/s, p50 ≤200ns"
@echo ""
@echo "$(YELLOW)Available examples:$(NC)"
@ls examples/*.rs | sed 's/examples\///g' | sed 's/\.rs//g' | sed 's/^/ - /'
@echo ""
@echo "$(YELLOW)Available benchmarks:$(NC)"
@ls benches/*.rs | sed 's/benches\///g' | sed 's/\.rs//g' | sed 's/^/ - /'