|
1 | 1 | # Inspecting generated code
|
2 | 2 |
|
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: |
4 | 5 |
|
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. |
6 | 27 |
|
7 | 28 | ``` console
|
8 | 29 | $ cargo build --example smallest --target thumbv7m-none-eabi
|
@@ -34,7 +55,16 @@ mod app {
|
34 | 55 | }
|
35 | 56 | ```
|
36 | 57 |
|
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 | + |
38 | 68 |
|
39 | 69 | [`cargo-expand`]: https://crates.io/crates/cargo-expand
|
40 | 70 |
|
|
0 commit comments