Skip to content

Commit a330ded

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 fa2a5b4 commit a330ded

File tree

8 files changed

+61
-9
lines changed

8 files changed

+61
-9
lines changed

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

Whitespace-only changes.

examples/lm3s6965/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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+
}

rtic-macros/CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fixed `#[cfg]` tags on hardware and software tasks.
13+
1014
## [v2.1.0] - 2024-02-27
1115

1216
### Added

rtic-macros/src/codegen/async_dispatchers.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ 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 exec_name = util::internal_task_ident(name, "EXEC");
21+
let cfgs = &task.cfgs;
2122

2223
items.push(quote!(
24+
#(#cfgs)*
2325
#[allow(non_upper_case_globals)]
2426
static #exec_name: rtic::export::executor::AsyncTaskExecutorPtr =
2527
rtic::export::executor::AsyncTaskExecutorPtr::new();
@@ -46,15 +48,15 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
4648

4749
for name in channel.tasks.iter() {
4850
let exec_name = util::internal_task_ident(name, "EXEC");
51+
let task = &app.software_tasks[name];
52+
let cfgs = &task.cfgs;
4953
let from_ptr_n_args =
5054
util::from_ptr_n_args_ident(app.software_tasks[name].inputs.len());
5155

52-
// TODO: Fix cfg
53-
// let task = &app.software_tasks[name];
54-
// let cfgs = &task.cfgs;
55-
5656
stmts.push(quote!(
57+
#(#cfgs)*
5758
let exec = rtic::export::executor::AsyncTaskExecutor::#from_ptr_n_args(#name, &#exec_name);
59+
#(#cfgs)*
5860
exec.poll(|| {
5961
let exec = rtic::export::executor::AsyncTaskExecutor::#from_ptr_n_args(#name, &#exec_name);
6062
exec.set_pending();

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-macros/src/codegen/main.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
3030

3131
let mut executor_allocations = Vec::new();
3232

33-
for (name, _) in app.software_tasks.iter() {
33+
for (name, task) in app.software_tasks.iter() {
3434
let exec_name = util::internal_task_ident(name, "EXEC");
3535
let new_n_args = util::new_n_args_ident(app.software_tasks[name].inputs.len());
36+
let cfgs = &task.cfgs;
3637

3738
executor_allocations.push(quote!(
39+
#(#cfgs)*
3840
let executor = ::core::mem::ManuallyDrop::new(rtic::export::executor::AsyncTaskExecutor::#new_n_args(#name));
39-
executors_size += ::core::mem::size_of_val(&executor);
40-
#exec_name.set_in_main(&executor);
41+
#(#cfgs)*
42+
{
43+
executors_size += ::core::mem::size_of_val(&executor);
44+
#exec_name.set_in_main(&executor);
45+
}
4146
));
4247
}
4348

rtic/CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fixed `#[cfg]` tags on hardware and software tasks.
13+
1014
## [v2.1.1] - 2024-03-13
1115

1216
### Fixed

0 commit comments

Comments
 (0)