Skip to content

Commit 2f117dc

Browse files
committed
Add initial copilot instructions
1 parent b2f2f5d commit 2f117dc

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed

.github/copilot-instructions.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Copilot agent onboarding for `esp-hal`
2+
3+
Purpose
4+
- Give a coding agent the essential context, commands, and checks so PRs build cleanly and validate locally before proposing changes.
5+
- Trust these instructions first — search the repo only when an instruction is missing or fails.
6+
7+
High-level summary
8+
- `esp-hal` is a Rust, bare-metal (`no_std`) hardware abstraction layer for Espressif SoCs (ESP32 family, RISC-V/XTensa variants). The repository contains many crates (HALs, drivers, examples, tests) plus an `xtask` automation crate used to build, test, lint, format, and run CI-like workflows locally.
9+
- Languages / runtimes: Rust (embedded, no_std), some host tests run on x86_64. Primary tooling is `cargo` + `cargo xtask`. CI uses GitHub Actions.
10+
11+
Important facts (quick)
12+
- Primary automation hub: `xtask/` (see `xtask/README.md`). Use `cargo xtask <command>` for repository-level tasks.
13+
- GitHub workflows live in `.github/workflows/*.yml`. The canonical source-of-truth for the Minimum Supported Rust Version (MSRV) is the `MSRV` environment variable in `.github/workflows/ci.yml`. Always read it from that file before selecting which toolchain to use for MSRV validation.
14+
- Example: to inspect the workflow for the MSRV value, check `.github/workflows/ci.yml` (look for the `MSRV:` env). You can extract it with a quick grep locally:
15+
```esp-hal/.github/workflows/ci.yml#L1-200
16+
grep -E '^\s*MSRV:\s*' .github/workflows/ci.yml || true
17+
```
18+
- `xtask`'s `main()` will set `CARGO_TARGET_DIR` to `<workspace>/target` if that env var is not already set — do not rely on a different target dir unless intentional.
19+
20+
Top-level files and directories (priority)
21+
- `Cargo.toml` (workspace)
22+
- `README.md` (project overview)
23+
- `xtask/` (automation; primary place to run builds, lint, tests)
24+
- `.github/` (workflows and PR template)
25+
- `.cargo/config.toml` (useful aliases, e.g. `cargo xtask`)
26+
- `documentation/` (contrib guides like `CONTRIBUTING.md`, `DEVELOPER-GUIDELINES.md`)
27+
- Crate directories: `esp-hal`, `esp-alloc`, `esp-println`, `esp-lp-hal`, `esp-phy`, `esp-radio`, `esp-rtos`, `esp-storage`, `esp-metadata*`, `examples`, `extras`, `hil-test`, `qa-test`
28+
- Configs: `rustfmt.toml`
29+
- Licenses: `LICENSE-APACHE`, `LICENSE-MIT`
30+
31+
Developer / contributor expectations (must-dos before a PR)
32+
- Always run formatting across changed crates: `cargo xtask fmt-packages` (this is required by the PR template). Reviewer agent: do not comment on formatting issues in Rust source code.
33+
- Add/adjust changelog entries where relevant (changelog checks are automated).
34+
- Follow `documentation/CONTRIBUTING.md` and `documentation/DEVELOPER-GUIDELINES.md` for API changes, HIL updates, and release guidance.
35+
- Make sure examples affected by changes still build.
36+
37+
Recommended local environment bootstrap (what to install)
38+
- Install Rust toolchains (determine MSRV by reading `.github/workflows/ci.yml` first):
39+
- Read MSRV from the workflow and install it. Example (inspect file first):
40+
```esp-hal/.github/workflows/ci.yml#L1-200
41+
# Look for a line like: MSRV: "1.88.0" in the workflow and then install that toolchain
42+
grep -E '^\s*MSRV:\s*' .github/workflows/ci.yml || true
43+
```
44+
- Then install the MSRV toolchain (example shown uses the discovered version):
45+
```/dev/null/commands.md#L1-2
46+
rustup toolchain install <MSRV_VERSION>
47+
rustup component add rustfmt clippy --toolchain <MSRV_VERSION>
48+
```
49+
- Set up the Espressif `esp` toolchain using `espup`. Prefer the `esp` toolchain version documented in CI or project docs when available. Install it like this (replace <version> with the desired esp toolchain version):
50+
```/dev/null/commands.md#L3-3
51+
espup install -v <version>
52+
```
53+
- Note: the `esp` toolchain may be required to reproduce Xtensa builds locally. If the CI workflow uses an `esp` toolchain, mirror that version.
54+
- Nightly (optional) for some doc/tests/format checks if required: `rustup toolchain install nightly` and `rustup component add rustfmt miri --toolchain nightly`
55+
- Add common components:
56+
- For MSRV: `rustup component add rustfmt clippy --toolchain 1.88.0`
57+
- For nightly checks (if you use them): `rustup component add rustfmt miri --toolchain nightly`
58+
- Recommended: make sure `rust-src` is available for cross-target builds where CI uses it:
59+
- `rustup component add rust-src --toolchain 1.88.0`
60+
61+
Primary commands (bootstrap → build → test → lint → docs)
62+
- Bootstrap (one-time / ensure toolchain and components installed)
63+
- Set up rust toolchains and components as above.
64+
- Optional: create a consistent `CARGO_TARGET_DIR` if you have multi-repo workflows. By default `xtask` sets it to `<workspace>/target`.
65+
- Formatting (always before commit)
66+
- `cargo xtask fmt-packages`
67+
- Linting (recommended before PR)
68+
- `cargo xtask lint-packages`
69+
- For targeted linting: `cargo xtask lint-packages --packages <comma-separated>`
70+
- Build examples / tests / packages
71+
- See `cargo xtask build --help` or `cargo xtask build examples --help`. Typical patterns:
72+
- Build an example: `cargo xtask build examples <EXAMPLE> --chips <chip>` (use `--chips` to limit targets)
73+
- Build tests: `cargo xtask build tests <package-or-test> --chips <chip>`
74+
- To run host-side tests: `cargo xtask host-tests` (some host tests are executed inside `xtask` itself; in CI they `cd xtask && cargo test --features release`).
75+
- Running examples/tests
76+
- `cargo xtask run tests <chip> <testname>` or `cargo xtask run example <chip> <example-name>`
77+
- Documentation
78+
- Build docs (heavy): `cargo xtask build documentation --chips <chip-list>`
79+
- Run doctests: `cargo xtask run doc-tests <CHIP>`
80+
- Use `--packages` and `--chips` to reduce scope and build time during development.
81+
- Metadata & changelog checks (CI enforces)
82+
- `cargo xtask check-changelog`
83+
- `cargo xtask update-metadata` / `cargo xtask update-metadata --check` (CI runs metadata checks)
84+
- Quick clean
85+
- `cargo xtask clean`
86+
- There's also alias support in `.cargo/config.toml` (e.g. `cargo xclean` if installed).
87+
88+
CI / validation notes (what GH Actions runs)
89+
- CI workflows are in `.github/workflows/` and include `ci.yml`, `ci_nightly.yml`, `hil.yml`, and various helper workflows that:
90+
- Run builds for multiple chips and targets (XTENSA / RISCV combinations).
91+
- Use MSRV (read from `.github/workflows/ci.yml`) for many jobs; some jobs run on `nightly` (format/miri).
92+
- Run `cargo xtask` subcommands to format, lint, run host-tests, build documentation, generate reports, and run HIL tests.
93+
- To mirror CI locally, run the same `cargo xtask` commands the workflows run:
94+
- Format check: `cargo xtask fmt-packages --check`
95+
- Metadata check: `cargo xtask update-metadata --check`
96+
- Host tests: `cargo xtask host-tests`
97+
- Changelog check: `cargo xtask check-changelog`
98+
99+
Common pitfalls and tips
100+
- Long-running builds: documentation builds and building all examples for all chips is time-consuming. Use `--packages` and `--chips` to scope work.
101+
- `CARGO_TARGET_DIR`: `xtask` will set the target dir to `<workspace>/target` if unset. If you set `CARGO_TARGET_DIR` externally, `xtask` will not override it — prefer leaving it unset unless you know why.
102+
- Formatting & linting: maintainers expect `cargo xtask fmt-packages` and `cargo xtask lint-packages` to pass; include formatting changes in the PR.
103+
- Changelog & migration guide: if your change modifies public APIs, update changelogs and migration documentation. CI checks will reject PRs missing required changelog entries.
104+
- HIL and hardware-related changes: hardware behavior can differ from CI — prefer testing on actual hardware for critical changes and mark in PR if hardware testing is pending.
105+
106+
Where to make code changes (architecture overview)
107+
- Crates are organized under root directories named after crates (e.g. `esp-hal/`, `esp-alloc/`, `esp-println/`). Many crates implement chip-specific HALs and drivers.
108+
- Examples: `examples/` contains usage examples that CI builds for compatibility verification.
109+
- Tests & hardware-in-the-loop: `hil-test/` and `qa-test/` contain HIL tests and QA harnesses.
110+
- Automation: `xtask/` is the authoritative entrypoint for repository-wide tasks; prefer using or extending `xtask` for CI-like operations or new automation.
111+
112+
Agent workflow recommendations (how you should act)
113+
1. Read this file and trust it. Do not run a full repo search unless an instruction is missing or an executed command fails.
114+
2. Before producing a PR:
115+
- Run `cargo xtask fmt-packages`
116+
- Run `cargo xtask lint-packages` (or targeted linting)
117+
- Run `cargo xtask check-changelog`
118+
- Run any impacted example builds: `cargo xtask build examples <EXAMPLE> --chips <chip>` (use `--chips` to limit)
119+
- If you modify metadata, run `cargo xtask update-metadata --check`
120+
3. If any of the above commands fail, surface the exact error and only then search or open files to locate the cause.
121+
4. Keep changes small and focused (one logical change per PR), include changelog entries, and respect style changes produced by `fmt-packages` (do not hand-edit formatting diffs).
122+
123+
If something in these instructions is incorrect or incomplete
124+
- Only then perform targeted searches: prefer `xtask/` and `.github/workflows/ci.yml` first, then `documentation/` files.
125+
- When uncertain about toolchain constraints, prefer the MSRV value read from `.github/workflows/ci.yml`.
126+
127+
Short checklist for PRs (agent-friendly)
128+
- [ ] Ran `cargo xtask fmt-packages`
129+
- [ ] Ran `cargo xtask lint-packages` (or targeted equivalent) and fixed issues
130+
- [ ] Added/updated changelog entry if API behavior changed
131+
- [ ] Ran `cargo xtask update-metadata --check` if package metadata changed
132+
- [ ] Built relevant examples/tests with `cargo xtask build ... --chips ...`
133+
- [ ] Verified host-tests if you changed host-side code: `cargo xtask host-tests`
134+
135+
Key reference paths (where to look first)
136+
- `xtask/README.md` — xtask usage and metadata annotations (examples/tests)
137+
- `documentation/CONTRIBUTING.md` and `documentation/DEVELOPER-GUIDELINES.md` — contribution rules
138+
- `.github/workflows/ci.yml` — canonical CI steps and toolchain versions
139+
- `.cargo/config.toml` — helpful cargo aliases (`xtask`, `xfmt`, etc.)
140+
- `README.md` — project overview and links
141+
142+
Final note to the agent
143+
- Follow this file as your primary orientation. It condenses the commands and checks CI runs and reduces unnecessary repository exploration. Only search further when a commanded step fails or when the task requires additional context not documented here.

0 commit comments

Comments
 (0)