diff options
author | 2020-04-22 14:18:32 +0000 | |
---|---|---|
committer | 2020-04-22 14:18:32 +0000 | |
commit | 7406f77a4ec163165fa2f89e8e9351b792e305e3 (patch) | |
tree | 4d2563b527be8f59b8c013e84df47da46ec27b22 /examples/t-cfg-resources.rs | |
parent | bb59606b7cf14105492c034c9875edc4c1725da0 (diff) | |
parent | f58f37b2b9a292a0e0d0be7d8afbe4df651c3432 (diff) | |
download | rtic-7406f77a4ec163165fa2f89e8e9351b792e305e3.tar.gz rtic-7406f77a4ec163165fa2f89e8e9351b792e305e3.tar.zst rtic-7406f77a4ec163165fa2f89e8e9351b792e305e3.zip |
Merge #306
306: Retain cfg-attributes on resources r=korken89 a=AfoHT
When rust 1.43 lands as stable this will resolve #301 and allow for the kind of conditional compilation exemplified in the issue.
Tested on beta and nightly.
Co-authored-by: Henrik Tjäder <henrik@tjaders.com>
Diffstat (limited to 'examples/t-cfg-resources.rs')
-rw-r--r-- | examples/t-cfg-resources.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/t-cfg-resources.rs b/examples/t-cfg-resources.rs new file mode 100644 index 00000000..86b5ea20 --- /dev/null +++ b/examples/t-cfg-resources.rs @@ -0,0 +1,40 @@ +//! [compile-pass] check that `#[cfg]` attributes applied on resources work +//! +#![no_main] +#![no_std] + +use panic_halt as _; + +#[cfg(rustc_is_nightly)] +mod example { + + #[rtfm::app(device = lm3s6965)] + const APP: () = { + struct Resources { + // A resource + #[init(0)] + shared: u32, + + // A conditionally compiled resource behind feature_x + #[cfg(feature = "feature_x")] + x: u32, + + dummy: (), + } + + #[init] + fn init(_: init::Context) -> init::LateResources { + init::LateResources { + // The feature needs to be applied everywhere x is defined or used + #[cfg(feature = "feature_x")] + x: 0, + dummy: () // dummy such that we have at least one late resource + } + } + + #[idle] + fn idle(_cx: idle::Context) -> ! { + loop {} + } + }; +} |