Skip to content

Commit 1f7e46e

Browse files
committed
rtic-macros: fix #[cfg] for hardware and software tasks
Disabling hardware and software tasks via `#[cfg]` flags was broken. Added test case to verify, and fixed codegen to output missing cfgs.
1 parent 4a23c8d commit 1f7e46e

File tree

6 files changed

+49
-4
lines changed

6 files changed

+49
-4
lines changed

rtic-macros/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
1515

1616
- Upgraded from syn 1.x to syn 2.x
1717

18+
### Fixed
19+
20+
- Fixed `#[cfg]` tags on hardware and software tasks.
21+
1822
## [v2.0.1] - 2023-07-25
1923

2024
### Added

rtic-macros/src/codegen/async_dispatchers.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
1616
let interrupts = &analysis.interrupts;
1717

1818
// Generate executor definition and priority in global scope
19-
for (name, _) in app.software_tasks.iter() {
19+
for (name, task) in app.software_tasks.iter() {
2020
let type_name = util::internal_task_ident(name, "F");
2121
let exec_name = util::internal_task_ident(name, "EXEC");
22+
let cfgs = &task.cfgs;
2223

2324
items.push(quote!(
25+
#(#cfgs)*
2426
#[allow(non_camel_case_types)]
2527
type #type_name = impl core::future::Future;
28+
#(#cfgs)*
2629
#[allow(non_upper_case_globals)]
2730
static #exec_name: rtic::export::executor::AsyncTaskExecutor<#type_name> =
2831
rtic::export::executor::AsyncTaskExecutor::new();
@@ -50,11 +53,11 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
5053

5154
for name in channel.tasks.iter() {
5255
let exec_name = util::internal_task_ident(name, "EXEC");
53-
// TODO: Fix cfg
54-
// let task = &app.software_tasks[name];
55-
// let cfgs = &task.cfgs;
56+
let task = &app.software_tasks[name];
57+
let cfgs = &task.cfgs;
5658

5759
stmts.push(quote!(
60+
#(#cfgs)*
5861
#exec_name.poll(|| {
5962
#exec_name.set_pending();
6063
#pend_interrupt

rtic-macros/src/codegen/hardware_tasks.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
7373

7474
if !task.is_extern {
7575
let attrs = &task.attrs;
76+
let cfgs = &task.cfgs;
7677
let context = &task.context;
7778
let stmts = &task.stmts;
7879
user_tasks.push(quote!(
7980
#(#attrs)*
81+
#(#cfgs)*
8082
#[allow(non_snake_case)]
8183
fn #name(#context: #name::Context) {
8284
use rtic::Mutex as _;

rtic/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
1515

1616
- **Soundness fix:** Monotonics did not wait long enough in `Duration` based delays.
1717
This is not directly a change for `rtic`, but required bumping the minimal version of `rtic-monotonics`.
18+
- Fixed `#[cfg]` tags on hardware and software tasks.
1819

1920
### Changed
2021

rtic/ci/expected/t-cfg-tasks.run

Whitespace-only changes.

rtic/examples/t-cfg-tasks.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//! [compile-pass] check that `#[cfg]` attributes applied on tasks work
2+
3+
#![no_main]
4+
#![no_std]
5+
#![deny(warnings)]
6+
#![deny(unsafe_code)]
7+
#![deny(missing_docs)]
8+
9+
use panic_semihosting as _;
10+
11+
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
12+
mod app {
13+
use cortex_m_semihosting::debug;
14+
15+
#[shared]
16+
struct Shared {}
17+
18+
#[local]
19+
struct Local {}
20+
21+
#[init]
22+
fn init(_: init::Context) -> (Shared, Local) {
23+
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
24+
25+
(Shared {}, Local {})
26+
}
27+
28+
#[cfg(feature = "feature_x")]
29+
#[task]
30+
async fn opt_sw_task(cx: opt_sw_task::Context) {}
31+
32+
#[cfg(feature = "feature_x")]
33+
#[task(binds = UART0)]
34+
fn opt_hw_task(cx: opt_hw_task::Context) {}
35+
}

0 commit comments

Comments
 (0)