Skip to content

Commit 4868961

Browse files
CAICAIIsPlucky923
authored andcommitted
docs: add contribution guidelines and pre-commit hooks
- Add CONTRIBUTING.md (English) and CONTRIBUTING_CN.md (Chinese) - Configure pre-commit hooks with Rust and Python tooling - On commit: rustfmt, clippy, cargo check, black, pylint - On push: cargo test - File validation: trailing whitespace, EOF, YAML/TOML/JSON - Add pre-commit to requirements.txt - Update README files with Contributing section links
1 parent 9a1668e commit 4868961

17 files changed

+494
-25
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ coverage/
4747

4848
# Temporary files
4949
*.tmp
50-
*.temp
50+
*.temp

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ max_line_length = 120
3838

3939
# Shell scripts
4040
[*.sh]
41-
indent_size = 2
41+
indent_size = 2

.pre-commit-config.yaml

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
repos:
2-
- repo: https://github.com/doublify/pre-commit-rust
3-
rev: v1.0
4-
hooks:
5-
- id: fmt
6-
- id: clippy
7-
args: ['--all-features', '--', '-D', 'warnings']
8-
92
- repo: https://github.com/pre-commit/pre-commit-hooks
10-
rev: v4.4.0
3+
rev: v5.0.0
114
hooks:
125
- id: trailing-whitespace
136
- id: end-of-file-fixer
@@ -17,19 +10,52 @@ repos:
1710
- id: check-merge-conflict
1811
- id: check-case-conflict
1912
- id: check-added-large-files
13+
args: ['--maxkb=500']
14+
15+
- repo: https://github.com/psf/black
16+
rev: 24.4.2
17+
hooks:
18+
- id: black
19+
name: black
20+
language_version: python3
21+
files: ^test/
22+
exclude: ^test/scripts/generate_test_cases\.py$
23+
24+
- repo: https://github.com/PyCQA/pylint
25+
rev: v3.2.0
26+
hooks:
27+
- id: pylint
28+
name: pylint
29+
files: ^test/
30+
args: ['--rcfile=pyproject.toml']
2031

2132
- repo: local
2233
hooks:
23-
- id: cargo-test
24-
name: cargo test
25-
entry: cargo test
34+
- id: rustfmt
35+
name: rustfmt
36+
entry: cargo fmt --all --
2637
language: system
38+
types: [rust]
39+
pass_filenames: false
40+
41+
- id: clippy
42+
name: clippy
43+
entry: cargo clippy --workspace --all-features -- -D warnings
44+
language: system
45+
types: [rust]
2746
pass_filenames: false
28-
always_run: true
2947

3048
- id: cargo-check
3149
name: cargo check
32-
entry: cargo check
50+
entry: cargo check --workspace
51+
language: system
52+
types: [rust]
53+
pass_filenames: false
54+
55+
- id: cargo-test
56+
name: cargo test
57+
entry: cargo test --workspace
3358
language: system
59+
types: [rust]
3460
pass_filenames: false
35-
always_run: true
61+
stages: [pre-push]

CONTRIBUTING.md

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
# Contributing to Robustone
2+
3+
Thank you for your interest in contributing to Robustone. This document provides guidelines and instructions for contributing to the project.
4+
5+
## Table of Contents
6+
7+
- [Prerequisites](#prerequisites)
8+
- [Development Setup](#development-setup)
9+
- [Pre-commit Hooks](#pre-commit-hooks)
10+
- [Code Style](#code-style)
11+
- [Testing](#testing)
12+
- [Submitting Changes](#submitting-changes)
13+
- [Pull Request Checklist](#pull-request-checklist)
14+
15+
## Prerequisites
16+
17+
Before contributing, ensure you have the following installed:
18+
19+
- [Rust](https://www.rust-lang.org/tools/install) 1.75 or newer (edition 2021)
20+
- [Python](https://www.python.org/) 3.8 or newer
21+
- `git` and basic build tools
22+
- `make` (for running Makefile commands)
23+
24+
## Development Setup
25+
26+
1. Clone the repository:
27+
28+
```bash
29+
git clone https://github.com/hust-open-atom-club/robustone.git
30+
cd robustone
31+
```
32+
33+
2. Set up the Python virtual environment:
34+
35+
```bash
36+
make virt-env
37+
```
38+
39+
3. Install pre-commit hooks:
40+
41+
```bash
42+
source virt-py/bin/activate
43+
pre-commit install
44+
pre-commit install --hook-type pre-push
45+
```
46+
47+
4. Verify the setup:
48+
49+
```bash
50+
make build
51+
make check
52+
```
53+
54+
## Pre-commit Hooks
55+
56+
This project uses pre-commit hooks to ensure code quality before each commit. The hooks include:
57+
58+
**On commit:**
59+
- `rustfmt` - Rust code formatting
60+
- `clippy` - Rust linting with `-D warnings`
61+
- `cargo check` - Rust compilation check
62+
- `black` - Python code formatting
63+
- `pylint` - Python linting
64+
- Trailing whitespace removal
65+
- End-of-file fixer
66+
- YAML/TOML/JSON validation
67+
- Merge conflict detection
68+
69+
**On push:**
70+
- `cargo test` - Full test suite
71+
72+
To run all hooks manually:
73+
74+
```bash
75+
pre-commit run --all-files
76+
```
77+
78+
To skip hooks temporarily (not recommended):
79+
80+
```bash
81+
git commit --no-verify
82+
```
83+
84+
## Code Style
85+
86+
### Rust
87+
88+
- Follow the existing code style enforced by `rustfmt`
89+
- All public items require documentation comments (`///`)
90+
- Use `Result<T, DisasmError>` for fallible operations
91+
- Never use `unwrap()` in library code; use the `?` operator
92+
- Prefer `&str` over `String` for function parameters
93+
- Group imports: std, external crates, crate-local
94+
95+
Example:
96+
97+
```rust
98+
use std::collections::HashMap;
99+
100+
use clap::Parser;
101+
102+
use crate::error::DisasmError;
103+
use super::types::*;
104+
```
105+
106+
### Python
107+
108+
- Follow PEP 8, enforced by `black` and `pylint`
109+
- Maximum line length: 120 characters
110+
- Use type hints where practical
111+
- Configuration is in `pyproject.toml`
112+
113+
## Testing
114+
115+
### Running Tests
116+
117+
Run the full test suite:
118+
119+
```bash
120+
make test
121+
```
122+
123+
This command:
124+
1. Clones Capstone if not present
125+
2. Builds the Capstone comparison tool
126+
3. Runs parity tests against Capstone
127+
4. Runs Rust unit tests
128+
129+
### Quick Testing
130+
131+
For faster iteration during development:
132+
133+
```bash
134+
# Quick parity test (20 cases)
135+
make test-quick
136+
137+
# Rust unit tests only
138+
cargo test --manifest-path robustone/Cargo.toml
139+
140+
# Parity tests only
141+
make test-parity
142+
```
143+
144+
### Adding Tests
145+
146+
When adding new instructions or features:
147+
148+
1. Add unit tests in the relevant Rust module
149+
2. Add parity test cases in `test/` directory
150+
3. Validate configurations: `make test-validate`
151+
152+
## Submitting Changes
153+
154+
1. Create a new branch from `main`:
155+
156+
```bash
157+
git checkout -b feature/your-feature-name
158+
```
159+
160+
2. Make your changes, ensuring:
161+
- All pre-commit hooks pass
162+
- All tests pass
163+
- Documentation is updated if needed
164+
165+
3. Commit your changes with a clear message:
166+
167+
```bash
168+
git add .
169+
git commit -m "feat: add support for XYZ instruction"
170+
```
171+
172+
Commit message format:
173+
- `feat:` for new features
174+
- `fix:` for bug fixes
175+
- `docs:` for documentation changes
176+
- `refactor:` for code refactoring
177+
- `test:` for test additions or changes
178+
- `chore:` for maintenance tasks
179+
180+
4. Push and create a pull request:
181+
182+
```bash
183+
git push origin feature/your-feature-name
184+
```
185+
186+
## Pull Request Checklist
187+
188+
Before submitting your pull request, verify:
189+
190+
- [ ] Code compiles without warnings (`make build`)
191+
- [ ] All lints pass (`make check`)
192+
- [ ] All tests pass (`make test`)
193+
- [ ] Pre-commit hooks pass (`pre-commit run --all-files`)
194+
- [ ] New code includes appropriate tests
195+
- [ ] Public APIs include documentation
196+
- [ ] Commit messages follow the format above
197+
198+
## Adding a New Architecture
199+
200+
When implementing support for a new architecture:
201+
202+
1. Create a new module under `robustone-core/src/<arch>/`
203+
2. Implement the `ArchitectureHandler` trait
204+
3. Add a feature flag in `robustone-core/Cargo.toml`
205+
4. Register the handler in `ArchitectureDispatcher::new()`
206+
5. Add parity tests in `test/<arch>/`
207+
6. Update documentation
208+
209+
## Questions
210+
211+
If you have questions about contributing, please open an issue on GitHub.

0 commit comments

Comments
 (0)