Skip to content

Commit 53afc0e

Browse files
committed
Add contributing guide
1 parent 02d92e1 commit 53afc0e

File tree

2 files changed

+262
-15
lines changed

2 files changed

+262
-15
lines changed

CONTRIBUTING.md

Lines changed: 261 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,261 @@
1-
TBA
1+
# Contributing to Puppyutils
2+
3+
We welcome contributions to Puppyutils. This guide will help you understand the project and contribute effectively.
4+
5+
## Code of Conduct
6+
7+
This project follows the organization code of conduct. An up-to-date version can be found in the [.github repository](https://github.com/puppyutils/.github).
8+
9+
## Project Overview
10+
11+
Puppyutils is a Rust implementation of core Unix utilities focused on four key principles:
12+
13+
- **Memory Safety**: Written in Rust with zero tolerance for memory-related bugs
14+
- **Minimal Size**: Aggressive optimization for the smallest possible binary footprint
15+
- **Correctness**: Faithful implementations that match standard Unix behavior
16+
- **Clean Organization**: Maintainable codebase with consistent patterns and clear structure
17+
18+
The project uses a multi-call binary architecture where a single executable acts as different utilities based on how it's invoked (similar to BusyBox). This approach significantly reduces disk space and memory usage compared to separate binaries.
19+
20+
### Current Status
21+
22+
The project is in active development with implementations ranging from simple utilities to more complex ones with partial feature sets and ongoing development.
23+
24+
## Getting Started
25+
26+
### Prerequisites
27+
28+
- Rust nightly toolchain (automatically managed via `rust-toolchain.toml`)
29+
- Git
30+
31+
### Building
32+
33+
```bash
34+
git clone https://github.com/puppyutils/puppyutils
35+
cd puppyutils
36+
cargo build
37+
```
38+
39+
For optimized release builds: `./build-release.sh`
40+
41+
This uses nightly features and build-std for maximum size optimization.
42+
43+
## Project Structure
44+
45+
```
46+
puppyutils/
47+
├── src/
48+
│ ├── main.rs # Multi-call binary dispatcher
49+
│ ├── lib.rs # Shared library with macros and utilities
50+
│ └── bin/ # Individual utility implementations
51+
│ ├── simple.rs # Single-file utilities
52+
│ └── complex/ # Multi-file utilities
53+
│ ├── main.rs
54+
│ ├── options.rs
55+
│ └── settings.rs
56+
├── docs/ # Help text for each utility
57+
│ ├── ls.txt
58+
│ ├── cat.txt
59+
│ └── ...
60+
├── build-release.sh # Optimized build script
61+
├── rust-toolchain.toml # Pinned nightly toolchain
62+
├── CLAUDE.md # Claude Code project instructions
63+
└── CONTRIBUTING.md # This file
64+
```
65+
66+
### Key Components
67+
68+
- **`src/main.rs`**: Entry point that dispatches to appropriate utility based on binary name
69+
- **`src/lib.rs`**: Shared code including the `cli!` macro, error types, and utility functions
70+
- **`src/bin/`**: Individual utility implementations following consistent patterns
71+
- **`docs/`**: Help text files included at compile time via the `help_text!` macro
72+
73+
## Adding New Utilities
74+
75+
### 1. Implementation Structure
76+
77+
**Simple utilities** (single file):
78+
79+
```
80+
src/bin/utilname.rs
81+
```
82+
83+
**Complex utilities** (multiple files):
84+
85+
```
86+
src/bin/utilname/
87+
├── main.rs
88+
├── options.rs
89+
└── settings.rs
90+
```
91+
92+
### 2. Implementation Pattern
93+
94+
Every utility follows this template:
95+
96+
```rust
97+
use std::io::{Write, stdout};
98+
use puppyutils::{Result, cli};
99+
100+
pub fn main() -> Result {
101+
let mut stdout = stdout();
102+
103+
cli! {
104+
"utilname", stdout, #error
105+
Short('a') | Long("all") => {
106+
// Handle --all flag
107+
}
108+
Value(path) => {
109+
// Handle positional arguments
110+
}
111+
};
112+
113+
// Implementation logic here
114+
// Use rustix for system calls when possible
115+
// Write directly to stdout/stderr
116+
// Flush buffers explicitly
117+
118+
Ok(())
119+
}
120+
```
121+
122+
### 3. Registration
123+
124+
Add your utility to `src/main.rs`:
125+
126+
```rust
127+
// In the mod bin block:
128+
pub mod utilname;
129+
130+
// In the match statement:
131+
b"utilname" => bin::utilname::main(),
132+
```
133+
134+
### 4. Documentation
135+
136+
Create `docs/utilname.txt` with help text that will be shown for `--help`:
137+
138+
```
139+
Usage: utilname [OPTION]... [FILE]...
140+
Brief description of what the utility does.
141+
142+
Options:
143+
-a, --all include entries starting with .
144+
--help display this help and exit
145+
--version output version information and exit
146+
```
147+
148+
## Coding Standards
149+
150+
### Core Principles
151+
152+
- **Minimal comments**: Code should be self-documenting (exception: complex system-level code like `get_umask()`)
153+
- **Use `rustix`**: Prefer `rustix` over `std` for system calls when possible
154+
- **Direct I/O**: Write directly to stdout/stderr using `Write` trait methods
155+
- **Explicit flushing**: Always flush output buffers before returning
156+
- **Consistent errors**: Return `puppyutils::Result<T, Exit>` for error handling
157+
158+
### Performance Requirements
159+
160+
- **Minimize allocations**: Use zero-copy approaches, stack allocation, and streaming where possible
161+
- **Binary size matters**: Avoid unnecessary dependencies, use `#[inline]` judiciously
162+
- **Memory efficiency**: Consider the memory footprint of data structures
163+
164+
### Code Patterns
165+
166+
- Use the `cli!` macro for argument parsing (handles `--help` and `--version` automatically)
167+
- Use `puppyutils::Exit` enum for error types with automatic conversions
168+
- Follow existing patterns in `src/bin/` for consistency
169+
- Use `bitflags!` for option flags when appropriate
170+
- Include help text via `help_text!` macro
171+
172+
## Development Workflow
173+
174+
### Local Development
175+
176+
1. **Format code**: `cargo fmt`
177+
2. **Lint code**: `cargo clippy --all-targets --all-features`
178+
3. **Check formatting**: `cargo fmt --check`
179+
4. **Build**: `cargo build`
180+
5. **Release build**: `./build-release.sh`
181+
182+
### Testing
183+
184+
Currently, the project has minimal testing infrastructure. When implementing utilities:
185+
186+
- Test manually with various inputs and edge cases
187+
- Verify compatibility with standard Unix utilities
188+
- Check error handling and exit codes
189+
- Test `--help` and `--version` flags
190+
191+
## Submission Process
192+
193+
### 1. Preparation
194+
195+
1. Fork the repository
196+
2. Create a feature branch: `git checkout -b feature/add-utilname`
197+
3. Implement your changes following the coding standards
198+
4. Test thoroughly with manual testing
199+
200+
### 2. Code Quality
201+
202+
Before submitting:
203+
204+
```bash
205+
# Format code
206+
cargo fmt
207+
208+
# Run linting
209+
cargo clippy --all-targets --all-features
210+
211+
# Ensure it builds
212+
cargo build
213+
214+
# Test release build
215+
./build-release.sh
216+
```
217+
218+
### 3. Pull Request
219+
220+
Submit a PR with:
221+
222+
- **Clear title**: "Add utilname utility" or "Fix bug in ls option parsing"
223+
- **Detailed description**: What the change does, why it's needed, how it was tested
224+
- **Reference issues**: Link to any related issues
225+
- **Breaking changes**: Note any compatibility concerns
226+
227+
### 4. Review Process
228+
229+
PRs will be reviewed for:
230+
231+
- **Correctness**: Does it implement the utility correctly?
232+
- **Performance**: Does it follow size and speed optimization principles?
233+
- **Code style**: Does it match existing patterns and standards?
234+
- **Completeness**: Are all standard options implemented or documented as missing?
235+
236+
### 5. CI Requirements
237+
238+
All PRs must pass:
239+
240+
- **Format check**: `cargo fmt --check`
241+
- **Lint check**: `cargo clippy --all-targets --all-features`
242+
- **Build check**: Both debug and release builds must succeed
243+
- **Binary size**: Release binary size should not increase unnecessarily
244+
245+
## Getting Help
246+
247+
- **Questions**: Open an issue for questions about contributing or implementation details
248+
- **Discussions**: Use GitHub Discussions for broader architectural questions
249+
- **Issues**: Report bugs or request features via GitHub Issues
250+
251+
## Priority Areas
252+
253+
Current focus areas for contributions:
254+
255+
1. **Complete existing utilities**: Add missing options to partially implemented utilities
256+
2. **New core utilities**: Implement essential utilities following established patterns
257+
3. **Performance optimization**: Reduce allocations, improve algorithms
258+
4. **Testing infrastructure**: Set up proper testing framework
259+
5. **Documentation**: Improve help text and edge case handling
260+
261+
The goal is building a solid foundation with the most essential utilities before expanding to the full coreutils suite.

README.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,7 @@ priorities.
5353
All utilities support standard `--help` and `--version` flags. Options after
5454
`--` will be ignored and passed as values.
5555

56-
### Project Structure
57-
58-
```
59-
src/
60-
├── bin/ # Individual utility implementations
61-
│ ├── ls/ # Complex utilities may have subdirectories
62-
│ ├── uname.rs
63-
│ ├── whoami.rs
64-
│ └── ...
65-
├── lib.rs # Shared library code and macros
66-
└── main.rs # Multi-call binary entry point
67-
```
68-
69-
### Contributing
56+
## Contributing
7057

7158
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for
7259
guidelines on contributing to the project.

0 commit comments

Comments
 (0)