Skip to content

Commit f7c17f3

Browse files
bugadaniCopilot
andauthored
Explain (my) rust-analyzer setup (#4583)
* Explain (my) rust-analyzer setup * Update documentation/DEVELOPER-GUIDELINES.md Co-authored-by: Copilot <[email protected]> * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 29a3e39 commit f7c17f3

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

documentation/DEVELOPER-GUIDELINES.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,75 @@ This is a living document - make sure to check the latest version of this docume
1010
In general, the [Rust API Guidelines](https://rust-lang.github.io/api-guidelines) apply to all projects in the ESP-RS GitHub organization where possible.
1111
- Especially for public API but if possible also for internal APIs.
1212

13+
## Working with the repository
14+
15+
### rust-analyzer
16+
17+
The repository contains multiple crates, with support for multiple different devices. `rust-analyzer` is not able to handle the complete repository at once, so you will need to change configuration depending on what you work on.
18+
You will need to point `rust-analyzer` to one of the crates you want to work on, using `linkedProjects`. While this option can be used to add multiple crates to the workspace, we often need to enable features
19+
on them which may only exist in one of the crates (e.g. `esp-radio`'s `wifi` feature). The recommendation is, therefore, to only enable a single crate at a time - ideally one that pulls in other crates as a dependency.
20+
21+
Additionally, you will need to specify the target triple of your particular chip, enable the chip's Cargo feature, and select the `esp` toolchain if you are working with an Xtensa MCU.
22+
23+
It is also recommended to directly configure `rustfmt` to use the config file in the repository root. This will
24+
prevent your editor from reformatting code in a way that CI would reject.
25+
26+
An example configuration for the Zed editor may look like this:
27+
28+
```json
29+
{
30+
"lsp": {
31+
"rust-analyzer": {
32+
"initialization_options": {
33+
"rustfmt": {
34+
// note this needs to be an absolute path
35+
"extraArgs": ["--config-path=<path to the repository>/rustfmt.toml"]
36+
},
37+
// Select esp-rtos, which also pulls in esp-hal
38+
"linkedProjects": ["./esp-rtos/Cargo.toml"],
39+
"cargo": {
40+
// This must match the target MCU's target
41+
"target": "xtensa-esp32s3-none-elf",
42+
// Prevents rust-analyzer from blocking cargo
43+
"targetDir": "target/rust-analyzer",
44+
"extraEnv": {
45+
// ESP32-S3 is an Xtensa MCU, we need to work with the esp toolchain
46+
"RUSTUP_TOOLCHAIN": "esp"
47+
},
48+
// Enable device support and a wide set of features on the esp-rtos crate.
49+
"features": ["esp32s3", "embassy", "esp-radio", "rtos-trace"]
50+
}
51+
}
52+
}
53+
}
54+
}
55+
```
56+
57+
The same configuration in VSCode is:
58+
```json
59+
{
60+
"rust-analyzer.rustfmt.extraArgs": [
61+
"--config-path=<path to the repository>/rustfmt.toml"
62+
],
63+
"rust-analyzer.cargo.target": "xtensa-esp32s3-none-elf",
64+
"rust-analyzer.cargo.targetDir": "target/rust-analyzer",
65+
"rust-analyzer.cargo.extraEnv": {
66+
"RUSTUP_TOOLCHAIN": "esp"
67+
},
68+
"rust-analyzer.linkedProjects": [
69+
"./esp-rtos/Cargo.toml"
70+
],
71+
"rust-analyzer.cargo.features": [
72+
"esp32s3",
73+
"embassy",
74+
"esp-radio",
75+
"rtos-trace"
76+
]
77+
}
78+
```
79+
80+
If you switch between crates and/or devices often, you may want to keep multiple sets of configurations commented in your config file, or as separate files as templates.
81+
1382
## Amendments to the Rust API Guidelines
1483

1584
- `C-RW-VALUE` and `C-SERDE` do not apply.

0 commit comments

Comments
 (0)