You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+46-79Lines changed: 46 additions & 79 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,100 +6,67 @@ license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
6
6
This file may not be copied, modified, or distributed except according to
7
7
those terms. -->
8
8
9
-
# Development Instructions
9
+
# Instructions for AI Agents
10
10
11
-
This repository uses a wrapper script around Cargo to ensure consistent toolchain usage and configuration.
11
+
## Agent Persona & Role
12
12
13
-
## Build and Test
13
+
You are an expert Rust systems programmer contributing to **zerocopy**, a
14
+
library for zero-cost memory manipulation which presents a safe API over what
15
+
would otherwise be dangerous operations. Your goal is to write high-quality,
16
+
sound, and performant Rust code that adheres to strict safety and soundness
17
+
guidelines and works across multiple Rust toolchains and compilation targets.
14
18
15
-
**IMPORTANT:** You must **NEVER** run `cargo` directly. Instead, you must **ALWAYS** use `yes | ./cargo.sh` for all `cargo` sub-commands (e.g., `check`, `test`, `build`). Using `yes |` is required to bypass interactive prompts for toolchain installation.
19
+
## Critical Rules
16
20
17
-
### Syntax
18
-
`yes | ./cargo.sh +<toolchain> <command> [args]`
21
+
-**README Generation:****DON'T** edit `README.md` directly. It is generated
22
+
from `src/lib.rs`. Edit the top-level doc comment in `src/lib.rs` instead.
23
+
-**To regenerate:**
24
+
`./cargo.sh +stable run --manifest-path tools/generate-readme/Cargo.toml > README.md`
19
25
20
-
### Toolchains
21
-
The `<toolchain>` argument is mandatory and can be one of the following:
26
+
<!-- TODO-check-disable -->
27
+
-**TODOs:****DON'T** use `TODO` comments unless you explicitly intend to block
28
+
the PR (CI fails on `TODO`). Use `FIXME` for non-blocking issues.
29
+
<!-- TODO-check-enable -->
22
30
23
-
-`msrv`: Runs with the Minimum Supported Rust Version.
24
-
-`stable`: Runs with the stable toolchain.
25
-
-`nightly`: Runs with the nightly toolchain.
26
-
-`all`: Runs the command on `msrv`, `stable`, and `nightly` sequentially.
27
-
- Version-gated toolchains: You can also pass specific version-gated toolchains defined in `Cargo.toml`, such as `zerocopy-core-error-1-81-0`.
31
+
-**Documentation:****DO** ensure that changes do not cause documentation to
32
+
become out of date (e.g., renaming files referenced here).
28
33
29
-
### Linting
34
+
##Project Context
30
35
31
-
Clippy should **always** be run on the `nightly` toolchain.
36
+
### Overview
32
37
33
-
```bash
34
-
yes | ./cargo.sh +nightly clippy
35
-
yes | ./cargo.sh +nightly clippy --tests
36
-
```
38
+
Zerocopy is a library designed to make zero-copy memory manipulation safe and
39
+
easy. It relies heavily on Rust's type system and specific traits to ensure
40
+
memory safety.
37
41
38
-
### Examples
42
+
### Project Structure
39
43
40
-
```bash
41
-
# Check the code using the nightly toolchain
42
-
# DO NOT RUN: cargo check
43
-
yes | ./cargo.sh +nightly check
44
+
-`src/`: Core library source code.
45
+
-`zerocopy-derive/`: Source code and tests for the procedural macros.
46
+
-`tests/`: UI and integration tests for the main crate.
47
+
-`tools/`: Internal tools and scripts.
48
+
-`ci/`: CI configuration and scripts.
49
+
-`githooks/`: Git hooks for pre-commit/pre-push checks.
Once you have made a change, you **MUST** read the relevant documents to ensure
61
+
that your change is valid and follows the style guidelines.
56
62
57
-
Before submitting code, run `./githooks/pre-push` to confirm that all pre-push hooks succeed.
63
+
-[agent_docs/validation.md](./agent_docs/validation.md) for validating code
64
+
changes
65
+
-[agent_docs/style.md](./agent_docs/style.md) for style and formatting
66
+
guidelines for files and commit messages
58
67
59
-
###UI Tests
68
+
#### Pre-submission Checks
60
69
61
-
When updating UI test files (in `tests/ui*` or `zerocopy-derive/tests/ui*`), run `./tools/update-ui-test-files.sh` to update the corresponding stderr files.
62
-
63
-
### Pull Requests and Commit Messages
64
-
65
-
When a PR resolves an issue, the PR description and commit message should include a line like `Closes #123`.
66
-
When a PR makes progress on, but does not close, an issue, the PR description and commit message should include a line like `Makes progress on #123`.
67
-
68
-
## Safety
69
-
70
-
### Pointer Casts
71
-
72
-
-**Avoid `&slice[0] as *const T` or `&slice[0] as *mut T`.**
73
-
Instead, use `slice.as_ptr()` or `slice.as_mut_ptr()`. Casting a reference to
74
-
a single element creates a raw pointer that is only valid for that element.
75
-
Accessing subsequent elements via pointer arithmetic is Undefined Behavior.
76
-
See [unsafe-code-guidelines#134](https://github.com/rust-lang/unsafe-code-guidelines/issues/134).
77
-
78
-
-**Avoid converting `&mut T` to `*const T` (or `*const U`)**.
79
-
This advice applies if you intend to later cast the pointer to `*mut T` and
80
-
mutate the data. This conversion reborrows `&mut T` as a shared reference
81
-
`&T`, which may restrict permissions under Stacked Borrows. Instead, cast
82
-
`&mut T` directly to `*mut T` first, then to `*const T` if necessary. See
Each file should contain a copyright header (excluding auto-generated files such as `.stderr` files). The header should follow the format found in existing files (e.g. `src/lib.rs`), using the appropriate comment syntax for the file type.
90
-
91
-
### Formatting
92
-
93
-
To determine how to format code, read the formatting checker script in `ci/check_fmt.sh`.
94
-
95
-
### Comments
96
-
97
-
All comments (including `//`, `///`, and `//!`) should be wrapped at 80 columns.
98
-
99
-
**Exceptions:**
100
-
- Markdown tables
101
-
- Inline ASCII diagrams
102
-
- Long URLs
103
-
- Comments inside of code blocks
104
-
- Comments which trail non-comment code
105
-
- Other cases where wrapping would significantly degrade readability (use your judgment).
70
+
Run `./githooks/pre-push` before submitting. This runs a comprehensive suite of
71
+
checks, including formatting, toolchain verification, and script validation. It
72
+
catches many issues that would otherwise fail in CI.
0 commit comments