-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
225 lines (170 loc) · 7.86 KB
/
Makefile
File metadata and controls
225 lines (170 loc) · 7.86 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
# Security Test Sample - Mixed Rust/Solidity Project Makefile
# Supports both Cargo (Rust) and Forge (Solidity) workflows
.PHONY: help install build test clean security lint fmt check all
.DEFAULT_GOAL := help
# Colors for output
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m # No Color
# Project info
PROJECT_NAME := security-test-sample
RUST_TARGET_DIR := target
SOLIDITY_OUT_DIR := out
help: ## Show this help message
@echo "$(GREEN)$(PROJECT_NAME) - Mixed Rust/Solidity Project$(NC)"
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z_-]+:.*##/ { printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
# =============================================================================
# INSTALLATION TARGETS
# =============================================================================
install: install-rust install-solidity ## Install all dependencies
install-rust: ## Install Rust dependencies
@echo "$(YELLOW)Installing Rust dependencies...$(NC)"
cargo fetch
install-solidity: ## Install Solidity dependencies and forge-std
@echo "$(YELLOW)Installing Solidity dependencies...$(NC)"
@if [ ! -d "lib/forge-std" ]; then \
forge install foundry-rs/forge-std --no-commit; \
fi
npm install
# =============================================================================
# BUILD TARGETS
# =============================================================================
build: build-rust build-solidity ## Build both Rust and Solidity projects
build-rust: ## Build Rust project
@echo "$(YELLOW)Building Rust project...$(NC)"
cargo build
build-rust-release: ## Build Rust project in release mode
@echo "$(YELLOW)Building Rust project (release)...$(NC)"
cargo build --release
build-solidity: ## Build Solidity contracts with Forge
@echo "$(YELLOW)Building Solidity contracts...$(NC)"
forge build
# =============================================================================
# TEST TARGETS
# =============================================================================
test: test-rust test-solidity ## Run all tests
test-rust: ## Run Rust tests
@echo "$(YELLOW)Running Rust tests...$(NC)"
cargo test
test-rust-verbose: ## Run Rust tests with verbose output
@echo "$(YELLOW)Running Rust tests (verbose)...$(NC)"
cargo test -- --nocapture
test-solidity: ## Run Solidity tests with Forge
@echo "$(YELLOW)Running Solidity tests...$(NC)"
forge test
test-solidity-verbose: ## Run Solidity tests with verbose output
@echo "$(YELLOW)Running Solidity tests (verbose)...$(NC)"
forge test -vvv
test-solidity-gas: ## Run Solidity tests with gas reporting
@echo "$(YELLOW)Running Solidity tests with gas report...$(NC)"
forge test --gas-report
# =============================================================================
# SECURITY ANALYSIS TARGETS
# =============================================================================
security: security-rust security-solidity ## Run security analysis on both projects
security-rust: ## Run security analysis on Rust code
@echo "$(YELLOW)Running Rust security analysis...$(NC)"
@if command -v cargo-audit >/dev/null 2>&1; then \
cargo audit; \
else \
echo "$(RED)cargo-audit not installed. Run: cargo install cargo-audit$(NC)"; \
fi
security-solidity: ## Run Slither analysis on Solidity contracts
@echo "$(YELLOW)Running Slither analysis...$(NC)"
@if command -v slither >/dev/null 2>&1; then \
slither src/; \
else \
echo "$(RED)Slither not installed. Visit: https://github.com/crytic/slither$(NC)"; \
fi
security-mythril: ## Run Mythril analysis on Solidity contracts (optional)
@echo "$(YELLOW)Running Mythril analysis...$(NC)"
@if command -v myth >/dev/null 2>&1; then \
myth analyze src/VulnerableToken.sol; \
else \
echo "$(RED)Mythril not installed. Run: pip3 install mythril$(NC)"; \
fi
# =============================================================================
# CODE QUALITY TARGETS
# =============================================================================
lint: lint-rust lint-solidity ## Run linting on both projects
lint-rust: ## Run Rust linting
@echo "$(YELLOW)Linting Rust code...$(NC)"
cargo clippy -- -D warnings
lint-solidity: ## Run Solidity linting
@echo "$(YELLOW)Linting Solidity code...$(NC)"
forge fmt --check
fmt: fmt-rust fmt-solidity ## Format code for both projects
fmt-rust: ## Format Rust code
@echo "$(YELLOW)Formatting Rust code...$(NC)"
cargo fmt
fmt-solidity: ## Format Solidity code
@echo "$(YELLOW)Formatting Solidity code...$(NC)"
forge fmt
check: check-rust check-solidity ## Check code quality for both projects
check-rust: ## Check Rust code without building
@echo "$(YELLOW)Checking Rust code...$(NC)"
cargo check
check-solidity: ## Check Solidity compilation
@echo "$(YELLOW)Checking Solidity compilation...$(NC)"
forge build --sizes
# =============================================================================
# UTILITY TARGETS
# =============================================================================
clean: clean-rust clean-solidity ## Clean build artifacts for both projects
clean-rust: ## Clean Rust build artifacts
@echo "$(YELLOW)Cleaning Rust artifacts...$(NC)"
cargo clean
clean-solidity: ## Clean Solidity build artifacts
@echo "$(YELLOW)Cleaning Solidity artifacts...$(NC)"
forge clean
rm -rf out/ cache/ artifacts/
clean-all: clean ## Alias for clean
@echo "$(GREEN)All build artifacts cleaned$(NC)"
run-rust: ## Run the Rust application
@echo "$(YELLOW)Running Rust application...$(NC)"
cargo run
deploy-local: ## Deploy contracts to local network (requires anvil)
@echo "$(YELLOW)Deploying to local network...$(NC)"
forge script script/Deploy.s.sol --fork-url http://localhost:8545 --broadcast
coverage-solidity: ## Generate test coverage for Solidity
@echo "$(YELLOW)Generating Solidity test coverage...$(NC)"
forge coverage
# =============================================================================
# DEVELOPMENT TARGETS
# =============================================================================
dev: ## Start development environment
@echo "$(YELLOW)Starting development environment...$(NC)"
@echo "Run 'make watch-rust' in one terminal and 'make watch-solidity' in another"
watch-rust: ## Watch Rust files for changes and rebuild
@echo "$(YELLOW)Watching Rust files...$(NC)"
@if command -v cargo-watch >/dev/null 2>&1; then \
cargo watch -x check -x test; \
else \
echo "$(RED)cargo-watch not installed. Run: cargo install cargo-watch$(NC)"; \
fi
watch-solidity: ## Watch Solidity files for changes and rebuild
@echo "$(YELLOW)Watching Solidity files...$(NC)"
forge build --watch
# =============================================================================
# CI/RELEASE TARGETS
# =============================================================================
ci: install build test lint security ## Run full CI pipeline
ci-rust: install-rust build-rust test-rust lint-rust security-rust ## Run Rust CI pipeline
ci-solidity: install-solidity build-solidity test-solidity lint-solidity security-solidity ## Run Solidity CI pipeline
release-rust: ## Build release version of Rust project
@echo "$(YELLOW)Building Rust release...$(NC)"
cargo build --release
# =============================================================================
# INFO TARGETS
# =============================================================================
info: ## Show project information
@echo "$(GREEN)Project Information:$(NC)"
@echo "Name: $(PROJECT_NAME)"
@echo "Rust version: $(shell rustc --version 2>/dev/null || echo 'Not installed')"
@echo "Cargo version: $(shell cargo --version 2>/dev/null || echo 'Not installed')"
@echo "Forge version: $(shell forge --version 2>/dev/null || echo 'Not installed')"
@echo "Node version: $(shell node --version 2>/dev/null || echo 'Not installed')"
@echo "NPM version: $(shell npm --version 2>/dev/null || echo 'Not installed')"
all: clean install build test lint security ## Run complete build pipeline