diff options
| author | Jorge Aparicio <jorge@japaric.io> | 2018-12-16 20:56:57 +0100 |
|---|---|---|
| committer | Jorge Aparicio <jorge@japaric.io> | 2018-12-16 20:57:04 +0100 |
| commit | 34e74f4bb36b0866be94c9bfdb41c11270b448a7 (patch) | |
| tree | aef6e61ab3e88fc222b50bb3d373679739a066df /book | |
| parent | 06c1e2f9b47b5bc9de049e1e1edfed27d8dd2c58 (diff) | |
book: add an example of conditional compilation of resources and tasks
Diffstat (limited to 'book')
| -rw-r--r-- | book/src/by-example/tips.md | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/book/src/by-example/tips.md b/book/src/by-example/tips.md index c163328..5057c80 100644 --- a/book/src/by-example/tips.md +++ b/book/src/by-example/tips.md @@ -20,6 +20,20 @@ rewrite code. If you consistently use `lock`s to access the data behind shared resources then your code will continue to compile when you change the priority of tasks. +## Conditional compilation + +You can use conditional compilation (`#[cfg]`) on resources (`static [mut]` +items) and tasks (`fn` items). The effect of using `#[cfg]` attributes is that +the resource / task will *not* be injected into the prelude of tasks that use +them (see `resources`, `spawn` and `schedule`) if the condition doesn't hold. + +The example below logs a message whenever the `foo` task is spawned, but only if +the program has been compiled using the `dev` profile. + +``` rust +{{#include ../../../examples/cfg.rs}} +``` + ## Running tasks from RAM The main goal of moving the specification of RTFM applications to attributes in |
