Skip to content

Commit 6543215

Browse files
authored
- Add Cargo.toml with embedded/no_std configuration and proper metadata (OpenPRoT#11)
- Create src/lib.rs with no_std, unsafe code denial, and Apache License header - Add .gitignore for Rust development artifacts - Include AI coding instructions in .github/copilot-instructions.md
1 parent e8f67fa commit 6543215

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed

.github/copilot-instructions.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copilot Instructions for mctp-lib
2+
3+
## Project Overview
4+
5+
This is a **platform-agnostic MCTP (Management Component Transport Protocol) stack** implemented in Rust for the OpenPRoT project. The crate provides a bare-metal routing layer designed for embedded systems without std support.
6+
7+
8+
## Project State & Development Strategy
9+
**Current Status:** Early-stage project with minimal codebase (README + LICENSE only)
10+
11+
When adding code, expect to create:
12+
- `Cargo.toml` with appropriate dependencies for embedded/no_std environments
13+
- `src/lib.rs` as the main library entry point
14+
- MCTP protocol implementation modules (packet parsing, routing, message handling)
15+
- Platform-specific transport bindings (I2C, PCIe, USB, etc.)
16+
- Error handling that works in both std and no_std environments
17+
18+
## Architecture Principles
19+
20+
### Protocol Implementation
21+
- **Standards Compliance**: Follow DMTF MCTP specifications precisely
22+
- **Transport Agnostic**: Core protocol separate from transport implementations
23+
- **Embedded-First**: Design for resource-constrained environments (no_std support)
24+
- **Security Focus**: Implement proper validation, bounds checking, and secure defaults
25+
26+
27+
## Development Guidelines
28+
29+
### Rust-Specific Conventions
30+
- **Use `#![no_std]` by default** with optional std feature flag
31+
32+
### Testing Strategy
33+
- **Unit tests** for packet parsing and protocol logic
34+
- **Integration tests** with mock transports
35+
- **Embedded testing** on actual hardware when available
36+
37+
### Dependencies Management
38+
- **Minimal dependencies** - justify each addition
39+
- **Embedded-friendly crates only** (check no_std compatibility)
40+
- **Avoid async** unless specifically needed (prefer blocking APIs)
41+
42+
43+
Focus on creating clean, well-tested abstractions that can be easily integrated into larger firmware systems while maintaining security and reliability standards.
44+
45+
## Pull Request Review Checklist
46+
47+
- [ ] Code is completely panic-free (no unwrap/expect/panic/indexing)
48+
- [ ] All fallible operations return Result or Option
49+
- [ ] Integer operations use checked/saturating/wrapping methods where needed
50+
- [ ] Array/slice access uses get() or pattern matching, not direct indexing
51+
- [ ] Interior mutability uses try_borrow/try_borrow_mut, not borrow/borrow_mut
52+
- [ ] Interior mutability requires justification (RefCell/Cell can cause runtime panics)
53+
- [ ] Error cases are well documented and handled appropriately
54+
- [ ] Tests verify error handling paths, not just happy paths
55+
- [ ] No unsafe code added (crate enforces `#![deny(unsafe_code)]`)
56+
57+
## Quick Reference: Forbidden Patterns
58+
59+
| Forbidden Pattern | Required Alternative |
60+
|-------------------|----------------------|
61+
| `value.unwrap()` | `match value { Some(v) => v, None => return Err(...) }` |
62+
| `result.expect("msg")` | `match result { Ok(v) => v, Err(e) => return Err(e.into()) }` |
63+
| `collection[index]` | `collection.get(index).ok_or(Error::OutOfBounds)?` |
64+
| `a + b` (integers) | `a.checked_add(b).ok_or(Error::Overflow)?` |
65+
| `refcell.borrow()` | `refcell.try_borrow().map_err(\|_\| Error::BorrowConflict)?` |
66+
| `refcell.borrow_mut()` | `refcell.try_borrow_mut().map_err(\|_\| Error::BorrowConflict)?` |
67+
68+
## File Organization
69+
70+
- `src/lib.rs`: Single-file crate with Router implementation and tests
71+
- `Cargo.toml`: Minimal dependencies, Edition 2024
72+
- No examples or additional modules currently
73+
74+
When extending this crate, follow the existing patterns of const generic parameterization and handle-based resource management.

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
# Generated by Cargo
3+
# will have compiled files and executables
4+
target/
5+
6+
# These are backup files generated by rustfmt
7+
**/*.rs.bk

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "mctp-lib"
3+
version = "0.1.0"
4+
edition = "2024"
5+
authors = ["OpenPRoT Contributors"]
6+
license = "Apache-2.0"
7+
description = "Platform-agnostic MCTP (Management Component Transport Protocol) library for embedded systems"
8+
repository = "https://github.com/rusty1968/mctp-lib"
9+
keywords = ["mctp", "embedded", "no-std", "protocol", "openprot"]
10+
categories = ["embedded", "no-std"]
11+
12+
[features]
13+
14+
[dependencies]
15+
16+
[dev-dependencies]
17+
18+
[package.metadata.docs.rs]
19+
all-features = true

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Licensed under the Apache-2.0 license
2+
//! OpenPRoT MCTP Library
3+
4+
#![no_std]
5+
#![deny(unsafe_code)]
6+
#![deny(missing_docs)]

0 commit comments

Comments
 (0)