1+ # Security Test Sample - Mixed Rust/Solidity Project Makefile
2+ # Supports both Cargo (Rust) and Forge (Solidity) workflows
3+
4+ .PHONY : help install build test clean security lint fmt check all
5+ .DEFAULT_GOAL := help
6+
7+ # Colors for output
8+ GREEN := \033[0;32m
9+ YELLOW := \033[0;33m
10+ RED := \033[0;31m
11+ NC := \033[0m # No Color
12+
13+ # Project info
14+ PROJECT_NAME := security-test-sample
15+ RUST_TARGET_DIR := target
16+ SOLIDITY_OUT_DIR := out
17+
18+ help : # # Show this help message
19+ @echo " $( GREEN) $( PROJECT_NAME) - Mixed Rust/Solidity Project$( NC) "
20+ @echo " Available targets:"
21+ @awk ' BEGIN {FS = ":.*##"} /^[a-zA-Z_-]+:.*##/ { printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2 }' $(MAKEFILE_LIST )
22+
23+ # =============================================================================
24+ # INSTALLATION TARGETS
25+ # =============================================================================
26+
27+ install : install-rust install-solidity # # Install all dependencies
28+
29+ install-rust : # # Install Rust dependencies
30+ @echo " $( YELLOW) Installing Rust dependencies...$( NC) "
31+ cargo fetch
32+
33+ install-solidity : # # Install Solidity dependencies and forge-std
34+ @echo " $( YELLOW) Installing Solidity dependencies...$( NC) "
35+ @if [ ! -d " lib/forge-std" ]; then \
36+ forge install foundry-rs/forge-std --no-commit; \
37+ fi
38+ npm install
39+
40+ # =============================================================================
41+ # BUILD TARGETS
42+ # =============================================================================
43+
44+ build : build-rust build-solidity # # Build both Rust and Solidity projects
45+
46+ build-rust : # # Build Rust project
47+ @echo " $( YELLOW) Building Rust project...$( NC) "
48+ cargo build
49+
50+ build-rust-release : # # Build Rust project in release mode
51+ @echo " $( YELLOW) Building Rust project (release)...$( NC) "
52+ cargo build --release
53+
54+ build-solidity : # # Build Solidity contracts with Forge
55+ @echo " $( YELLOW) Building Solidity contracts...$( NC) "
56+ forge build
57+
58+ # =============================================================================
59+ # TEST TARGETS
60+ # =============================================================================
61+
62+ test : test-rust test-solidity # # Run all tests
63+
64+ test-rust : # # Run Rust tests
65+ @echo " $( YELLOW) Running Rust tests...$( NC) "
66+ cargo test
67+
68+ test-rust-verbose : # # Run Rust tests with verbose output
69+ @echo " $( YELLOW) Running Rust tests (verbose)...$( NC) "
70+ cargo test -- --nocapture
71+
72+ test-solidity : # # Run Solidity tests with Forge
73+ @echo " $( YELLOW) Running Solidity tests...$( NC) "
74+ forge test
75+
76+ test-solidity-verbose : # # Run Solidity tests with verbose output
77+ @echo " $( YELLOW) Running Solidity tests (verbose)...$( NC) "
78+ forge test -vvv
79+
80+ test-solidity-gas : # # Run Solidity tests with gas reporting
81+ @echo " $( YELLOW) Running Solidity tests with gas report...$( NC) "
82+ forge test --gas-report
83+
84+ # =============================================================================
85+ # SECURITY ANALYSIS TARGETS
86+ # =============================================================================
87+
88+ security : security-rust security-solidity # # Run security analysis on both projects
89+
90+ security-rust : # # Run security analysis on Rust code
91+ @echo " $( YELLOW) Running Rust security analysis...$( NC) "
92+ @if command -v cargo-audit > /dev/null 2>&1 ; then \
93+ cargo audit; \
94+ else \
95+ echo " $( RED) cargo-audit not installed. Run: cargo install cargo-audit$( NC) " ; \
96+ fi
97+
98+ security-solidity : # # Run Slither analysis on Solidity contracts
99+ @echo " $( YELLOW) Running Slither analysis...$( NC) "
100+ @if command -v slither > /dev/null 2>&1 ; then \
101+ slither src/; \
102+ else \
103+ echo " $( RED) Slither not installed. Visit: https://github.com/crytic/slither$( NC) " ; \
104+ fi
105+
106+ security-mythril : # # Run Mythril analysis on Solidity contracts (optional)
107+ @echo " $( YELLOW) Running Mythril analysis...$( NC) "
108+ @if command -v myth > /dev/null 2>&1 ; then \
109+ myth analyze src/VulnerableToken.sol; \
110+ else \
111+ echo " $( RED) Mythril not installed. Run: pip3 install mythril$( NC) " ; \
112+ fi
113+
114+ # =============================================================================
115+ # CODE QUALITY TARGETS
116+ # =============================================================================
117+
118+ lint : lint-rust lint-solidity # # Run linting on both projects
119+
120+ lint-rust : # # Run Rust linting
121+ @echo " $( YELLOW) Linting Rust code...$( NC) "
122+ cargo clippy -- -D warnings
123+
124+ lint-solidity : # # Run Solidity linting
125+ @echo " $( YELLOW) Linting Solidity code...$( NC) "
126+ forge fmt --check
127+
128+ fmt : fmt-rust fmt-solidity # # Format code for both projects
129+
130+ fmt-rust : # # Format Rust code
131+ @echo " $( YELLOW) Formatting Rust code...$( NC) "
132+ cargo fmt
133+
134+ fmt-solidity : # # Format Solidity code
135+ @echo " $( YELLOW) Formatting Solidity code...$( NC) "
136+ forge fmt
137+
138+ check : check-rust check-solidity # # Check code quality for both projects
139+
140+ check-rust : # # Check Rust code without building
141+ @echo " $( YELLOW) Checking Rust code...$( NC) "
142+ cargo check
143+
144+ check-solidity : # # Check Solidity compilation
145+ @echo " $( YELLOW) Checking Solidity compilation...$( NC) "
146+ forge build --sizes
147+
148+ # =============================================================================
149+ # UTILITY TARGETS
150+ # =============================================================================
151+
152+ clean : clean-rust clean-solidity # # Clean build artifacts for both projects
153+
154+ clean-rust : # # Clean Rust build artifacts
155+ @echo " $( YELLOW) Cleaning Rust artifacts...$( NC) "
156+ cargo clean
157+
158+ clean-solidity : # # Clean Solidity build artifacts
159+ @echo " $( YELLOW) Cleaning Solidity artifacts...$( NC) "
160+ forge clean
161+ rm -rf out/ cache/ artifacts/
162+
163+ clean-all : clean # # Alias for clean
164+ @echo " $( GREEN) All build artifacts cleaned$( NC) "
165+
166+ run-rust : # # Run the Rust application
167+ @echo " $( YELLOW) Running Rust application...$( NC) "
168+ cargo run
169+
170+ deploy-local : # # Deploy contracts to local network (requires anvil)
171+ @echo " $( YELLOW) Deploying to local network...$( NC) "
172+ forge script script/Deploy.s.sol --fork-url http://localhost:8545 --broadcast
173+
174+ coverage-solidity : # # Generate test coverage for Solidity
175+ @echo " $( YELLOW) Generating Solidity test coverage...$( NC) "
176+ forge coverage
177+
178+ # =============================================================================
179+ # DEVELOPMENT TARGETS
180+ # =============================================================================
181+
182+ dev : # # Start development environment
183+ @echo " $( YELLOW) Starting development environment...$( NC) "
184+ @echo " Run 'make watch-rust' in one terminal and 'make watch-solidity' in another"
185+
186+ watch-rust : # # Watch Rust files for changes and rebuild
187+ @echo " $( YELLOW) Watching Rust files...$( NC) "
188+ @if command -v cargo-watch > /dev/null 2>&1 ; then \
189+ cargo watch -x check -x test ; \
190+ else \
191+ echo " $( RED) cargo-watch not installed. Run: cargo install cargo-watch$( NC) " ; \
192+ fi
193+
194+ watch-solidity : # # Watch Solidity files for changes and rebuild
195+ @echo " $( YELLOW) Watching Solidity files...$( NC) "
196+ forge build --watch
197+
198+ # =============================================================================
199+ # CI/RELEASE TARGETS
200+ # =============================================================================
201+
202+ ci : install build test lint security # # Run full CI pipeline
203+
204+ ci-rust : install-rust build-rust test-rust lint-rust security-rust # # Run Rust CI pipeline
205+
206+ ci-solidity : install-solidity build-solidity test-solidity lint-solidity security-solidity # # Run Solidity CI pipeline
207+
208+ release-rust : # # Build release version of Rust project
209+ @echo " $( YELLOW) Building Rust release...$( NC) "
210+ cargo build --release
211+
212+ # =============================================================================
213+ # INFO TARGETS
214+ # =============================================================================
215+
216+ info : # # Show project information
217+ @echo " $( GREEN) Project Information:$( NC) "
218+ @echo " Name: $( PROJECT_NAME) "
219+ @echo " Rust version: $( shell rustc --version 2> /dev/null || echo ' Not installed' ) "
220+ @echo " Cargo version: $( shell cargo --version 2> /dev/null || echo ' Not installed' ) "
221+ @echo " Forge version: $( shell forge --version 2> /dev/null || echo ' Not installed' ) "
222+ @echo " Node version: $( shell node --version 2> /dev/null || echo ' Not installed' ) "
223+ @echo " NPM version: $( shell npm --version 2> /dev/null || echo ' Not installed' ) "
224+
225+ all : clean install build test lint security # # Run complete build pipeline
0 commit comments