|
| 1 | +# Contributing to ros-z |
| 2 | + |
| 3 | +Thank you for your interest in contributing to ros-z! This document provides guidelines and workflows for contributors. |
| 4 | + |
| 5 | +## Getting Started |
| 6 | + |
| 7 | +### Prerequisites |
| 8 | + |
| 9 | +1. **Rust toolchain**: Install via [rustup](https://rustup.rs/) |
| 10 | +2. **Nix** (optional but recommended): For reproducible development environment |
| 11 | +3. **mdbook**: For documentation (included in nix environment) |
| 12 | + |
| 13 | +### Setting Up Your Development Environment |
| 14 | + |
| 15 | +#### Using Nix (Recommended) |
| 16 | + |
| 17 | +```bash |
| 18 | +# Clone the repository |
| 19 | +git clone https://github.com/ZettaScaleLabs/ros-z.git |
| 20 | +cd ros-z |
| 21 | + |
| 22 | +# Enter the development shell (includes all dependencies) |
| 23 | +nix develop |
| 24 | +# or if direnv is installed |
| 25 | +direnv allow |
| 26 | +``` |
| 27 | + |
| 28 | +#### Without Nix |
| 29 | + |
| 30 | +```bash |
| 31 | +# Install Rust |
| 32 | +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh |
| 33 | + |
| 34 | +# Install mdbook |
| 35 | +cargo install mdbook |
| 36 | + |
| 37 | +# Install other dependencies as needed |
| 38 | +``` |
| 39 | + |
| 40 | +## Development Workflow |
| 41 | + |
| 42 | +### 1. Build the Project |
| 43 | + |
| 44 | +```bash |
| 45 | +# Build the entire workspace |
| 46 | +cargo build |
| 47 | + |
| 48 | +# Build specific packages |
| 49 | +cargo build -p ros-z |
| 50 | +cargo build -p ros-z-msgs |
| 51 | +``` |
| 52 | + |
| 53 | +### 2. Run Tests |
| 54 | + |
| 55 | +```bash |
| 56 | +# Run all tests |
| 57 | +cargo test |
| 58 | + |
| 59 | +# Run tests for specific package |
| 60 | +cargo test -p ros-z |
| 61 | + |
| 62 | +# Run integration tests |
| 63 | +cargo test -p ros-z-tests --features ros-msgs |
| 64 | +``` |
| 65 | + |
| 66 | +### 3. Test Documentation |
| 67 | + |
| 68 | +When making changes to examples or documentation: |
| 69 | + |
| 70 | +```bash |
| 71 | +# Build the library first (required for mdbook test) |
| 72 | +cargo build |
| 73 | + |
| 74 | +# Test all code examples in the book |
| 75 | +mdbook test book -L ./target/debug/deps |
| 76 | + |
| 77 | +# Preview the book locally |
| 78 | +mdbook serve book |
| 79 | +``` |
| 80 | + |
| 81 | +Open <http://localhost:3000> to see the rendered documentation. |
| 82 | + |
| 83 | +## Pre-Commit Checklist |
| 84 | + |
| 85 | +Before submitting changes, ensure all of these pass: |
| 86 | + |
| 87 | +```bash |
| 88 | +# 1. Build succeeds |
| 89 | +cargo build |
| 90 | + |
| 91 | +# 2. All tests pass |
| 92 | +cargo test |
| 93 | + |
| 94 | +# 3. Documentation examples work (if examples changed) |
| 95 | +mdbook test book -L ./target/debug/deps |
| 96 | + |
| 97 | +# 4. Code is formatted |
| 98 | +cargo fmt |
| 99 | + |
| 100 | +# 5. No clippy warnings |
| 101 | +cargo clippy --all-targets --all-features |
| 102 | +``` |
| 103 | + |
| 104 | +If you're using the Nix environment, pre-commit hooks will automatically run these checks. |
| 105 | + |
| 106 | +## Making Changes |
| 107 | + |
| 108 | +### Adding New Features |
| 109 | + |
| 110 | +When adding a new ros-z feature: |
| 111 | + |
| 112 | +1. **Implement** the feature in `ros-z/src/` |
| 113 | +2. **Add an example** to `ros-z/examples/` demonstrating the feature |
| 114 | +3. **Update documentation**: |
| 115 | + - Add or update book chapter in `book/src/chapters/` |
| 116 | + - Use `{{#include ../../ros-z/examples/your_example.rs}}` to reference the example |
| 117 | + - Update `book/src/SUMMARY.md` if adding a new chapter |
| 118 | +4. **Test everything**: |
| 119 | + ```bash |
| 120 | + cargo build |
| 121 | + cargo test |
| 122 | + mdbook test book -L ./target/debug/deps |
| 123 | + ``` |
| 124 | + |
| 125 | +### Updating Existing Features |
| 126 | + |
| 127 | +When changing existing APIs: |
| 128 | + |
| 129 | +1. **Update** the implementation in `ros-z/src/` |
| 130 | +2. **Update** affected examples in `ros-z/examples/` |
| 131 | +3. **Update** book chapters with new explanations (if needed) |
| 132 | +4. **Run tests** to ensure everything still works |
| 133 | +5. Make all changes in a **single commit**: "feat: new API + examples + docs" |
| 134 | + |
| 135 | +### Documentation Guidelines |
| 136 | + |
| 137 | +Documentation in ros-z follows a specific pattern: |
| 138 | + |
| 139 | +#### Examples are the Single Source of Truth |
| 140 | + |
| 141 | +- All code examples live in `ros-z/examples/` as complete, runnable programs |
| 142 | +- Book chapters reference these examples using `{{#include}}` directives |
| 143 | +- **Never** write inline code blocks >5 lines in markdown files |
| 144 | +- Examples must compile and pass `mdbook test` |
| 145 | + |
| 146 | +#### Example Template |
| 147 | + |
| 148 | +Every example should follow this pattern: |
| 149 | + |
| 150 | +```rust |
| 151 | +use ros_z::prelude::*; |
| 152 | + |
| 153 | +fn main() -> Result<()> { |
| 154 | + // Your example code here |
| 155 | + let ctx = ZContextBuilder::default().build()?; |
| 156 | + let node = ctx.create_node("example").build()?; |
| 157 | + // ... rest of example |
| 158 | + Ok(()) |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | +For examples that should also work as library functions (testable), use: |
| 163 | + |
| 164 | +```rust |
| 165 | +pub fn run_example(ctx: ZContext, /* other params */) -> Result<()> { |
| 166 | + // Implementation here |
| 167 | +} |
| 168 | + |
| 169 | +#[cfg(not(any(test, doctest)))] |
| 170 | +fn main() -> Result<()> { |
| 171 | + // CLI argument parsing |
| 172 | + let ctx = ZContextBuilder::default().build()?; |
| 173 | + run_example(ctx /* pass params */) |
| 174 | +} |
| 175 | +``` |
| 176 | + |
| 177 | +#### Book Chapter Template |
| 178 | + |
| 179 | +```markdown |
| 180 | +# Feature Name |
| 181 | + |
| 182 | +Brief introduction to the feature. |
| 183 | + |
| 184 | +## Complete Example |
| 185 | + |
| 186 | +\`\`\`rust,no_run |
| 187 | +{{#include ../../../ros-z/examples/your_example.rs}} |
| 188 | +\`\`\` |
| 189 | + |
| 190 | +## Key Points |
| 191 | + |
| 192 | +- **Line X**: Explanation of important line |
| 193 | +- **Line Y**: Another important detail |
| 194 | + |
| 195 | +## Usage |
| 196 | + |
| 197 | +\`\`\`bash |
| 198 | +cargo run --example your_example |
| 199 | +\`\`\` |
| 200 | +``` |
| 201 | + |
| 202 | +### Code Style |
| 203 | + |
| 204 | +- Follow Rust standard formatting: `cargo fmt` |
| 205 | +- Run clippy and fix warnings: `cargo clippy` |
| 206 | +- Write clear, self-documenting code |
| 207 | +- Add comments for complex logic |
| 208 | +- Use descriptive variable names |
| 209 | + |
| 210 | +### Commit Messages |
| 211 | + |
| 212 | +Follow conventional commit format: |
| 213 | + |
| 214 | +- `feat: add new feature` |
| 215 | +- `fix: resolve bug in X` |
| 216 | +- `docs: update documentation for Y` |
| 217 | +- `refactor: restructure Z` |
| 218 | +- `test: add tests for W` |
| 219 | +- `chore: update dependencies` |
| 220 | + |
| 221 | +## Submitting Changes |
| 222 | + |
| 223 | +1. **Fork** the repository |
| 224 | +2. **Create a branch** from `main` with a descriptive name |
| 225 | +3. **Make your changes** following the guidelines above |
| 226 | +4. **Test thoroughly** using the pre-commit checklist |
| 227 | +5. **Commit** with clear, conventional commit messages |
| 228 | +6. **Push** to your fork |
| 229 | +7. **Open a Pull Request** with: |
| 230 | + - Clear description of changes |
| 231 | + - Reference to related issues (if any) |
| 232 | + - Screenshots/examples (if applicable) |
| 233 | + |
| 234 | +## Pull Request Process |
| 235 | + |
| 236 | +1. Ensure all CI checks pass |
| 237 | +2. Request review from maintainers |
| 238 | +3. Address review feedback |
| 239 | +4. Once approved, maintainers will merge |
| 240 | + |
| 241 | +## Project Structure |
| 242 | + |
| 243 | +``` |
| 244 | +ros-z/ |
| 245 | +├── ros-z/ # Core library |
| 246 | +│ ├── src/ # Production code |
| 247 | +│ └── examples/ # Runnable examples (used by book) |
| 248 | +├── ros-z-msgs/ # Generated message types |
| 249 | +├── ros-z-codegen/ # Code generation utilities |
| 250 | +├── rcl-z/ # RCL C bindings |
| 251 | +├── ros-z-tests/ # Integration tests |
| 252 | +├── book/ # mdBook documentation |
| 253 | +│ ├── book.toml # mdBook configuration |
| 254 | +│ └── src/ # Book chapters |
| 255 | +└── .github/workflows/ # CI/CD |
| 256 | +``` |
| 257 | + |
| 258 | +## Maintenance Rules |
| 259 | + |
| 260 | +### If-Then Flows |
| 261 | + |
| 262 | +**IF adding new ros-z feature:** |
| 263 | +- ADD `examples/new_feature.rs` |
| 264 | +- ADD/UPDATE book chapter with `{{#include}}` |
| 265 | +- RUN `cargo build && mdbook test book -L ./target/debug/deps` |
| 266 | + |
| 267 | +**IF making API breaking change:** |
| 268 | +- UPDATE `examples/*.rs` files |
| 269 | +- UPDATE book text references |
| 270 | +- Single commit: "feat: new API + examples + docs" |
| 271 | + |
| 272 | +**IF mdbook test fails:** |
| 273 | +- RUN `cargo clean && cargo build` |
| 274 | +- CHECK `target/debug/deps` contains `libros_z-*.rlib` |
| 275 | +- RE-RUN `mdbook test book -L ./target/debug/deps` |
| 276 | + |
| 277 | +## Getting Help |
| 278 | + |
| 279 | +- **Questions**: Open a [GitHub Discussion](https://github.com/ZettaScaleLabs/ros-z/discussions) |
| 280 | +- **Bugs**: Open a [GitHub Issue](https://github.com/ZettaScaleLabs/ros-z/issues) |
| 281 | +- **Chat**: Join the [Zenoh Discord](https://discord.gg/vSDSpqnbkm) |
| 282 | + |
| 283 | +## License |
| 284 | + |
| 285 | +By contributing to ros-z, you agree that your contributions will be licensed under the same license as the project (see LICENSE file). |
| 286 | + |
| 287 | +## Code of Conduct |
| 288 | + |
| 289 | +Be respectful, inclusive, and professional in all interactions. We're all here to make ROS 2 better! |
| 290 | + |
| 291 | +Thank you for contributing to ros-z! 🦀 |
0 commit comments