|
| 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