Skip to content

Commit 2a3e92c

Browse files
AfoHTkorken89
authored andcommitted
book: view_code update for xtask
1 parent 3f48ad7 commit 2a3e92c

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

book/en/src/by-example/tips/view_code.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
# Inspecting generated code
22

3-
`#[rtic::app]` is a procedural macro that produces support code. If for some reason you need to inspect the code generated by this macro you have two options:
3+
`#[rtic::app]` is a procedural macro that produces support code.
4+
If for some reason you need to inspect the code generated by this macro you have two options:
45

5-
You can inspect the file `rtic-expansion.rs` inside the `target` directory. This file contains the expansion of the `#[rtic::app]` item (not your whole program!) of the *last built* (via `cargo build` or `cargo check`) RTIC application. The expanded code is not pretty printed by default, so you'll want to run `rustfmt` on it before you read it.
6+
* You can inspect the file `rtic-expansion.rs` inside the `target` directory.
7+
* Use the [`cargo-expand`] sub-command
8+
9+
## Using generated `rtic-expansion.rs`
10+
11+
Locating this file depends on how building is performed.
12+
13+
Using e.g. `cargo xtask build-example` within the main RTIC repo will place the file based on "platform" used:
14+
```
15+
$ cargo xtask example-build --example smallest
16+
$ cargo xtask example-build --example monotonic --platform esp32-c3
17+
18+
$ fd -u rtic-expansion.rs
19+
examples/esp32c3/target/rtic-expansion.rs
20+
examples/lm3s6965/target/rtic-expansion.rs
21+
```
22+
23+
In the regular cargo project case it goes directly in the `target` folder.
24+
25+
This file contains the expansion of the `#[rtic::app]` item (not your whole program!) of the *last built* (via `cargo build` or `cargo check`) RTIC application.
26+
The expanded code is not pretty printed by default, so you'll want to run `rustfmt` on it before you read it.
627

728
``` console
829
$ cargo build --example smallest --target thumbv7m-none-eabi
@@ -34,7 +55,16 @@ mod app {
3455
}
3556
```
3657

37-
Or, you can use the [`cargo-expand`] sub-command. This sub-command will expand *all* the macros, including the `#[rtic::app]` attribute, and modules in your crate and print the output to the console.
58+
## Using `cargo-expand` tool
59+
60+
If not available, install:
61+
62+
```
63+
$ cargo install cargo-expand
64+
```
65+
66+
This sub-command will expand *all* the macros, including the `#[rtic::app]` attribute, and modules in your crate and print the output to the console.
67+
3868

3969
[`cargo-expand`]: https://crates.io/crates/cargo-expand
4070

0 commit comments

Comments
 (0)