diff --git a/rtic-macros/CHANGELOG.md b/rtic-macros/CHANGELOG.md index daee6c38645a..6bfea62cc063 100644 --- a/rtic-macros/CHANGELOG.md +++ b/rtic-macros/CHANGELOG.md @@ -15,6 +15,10 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top! - Upgraded from syn 1.x to syn 2.x +### Fixed + +- Fixed `#[cfg]` tags on hardware and software tasks. + ## [v2.0.1] - 2023-07-25 ### Added diff --git a/rtic-macros/src/codegen/async_dispatchers.rs b/rtic-macros/src/codegen/async_dispatchers.rs index 54db2b345337..3d9ff1602341 100644 --- a/rtic-macros/src/codegen/async_dispatchers.rs +++ b/rtic-macros/src/codegen/async_dispatchers.rs @@ -16,13 +16,16 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { let interrupts = &analysis.interrupts; // Generate executor definition and priority in global scope - for (name, _) in app.software_tasks.iter() { + for (name, task) in app.software_tasks.iter() { let type_name = util::internal_task_ident(name, "F"); let exec_name = util::internal_task_ident(name, "EXEC"); + let cfgs = &task.cfgs; items.push(quote!( + #(#cfgs)* #[allow(non_camel_case_types)] type #type_name = impl core::future::Future; + #(#cfgs)* #[allow(non_upper_case_globals)] static #exec_name: rtic::export::executor::AsyncTaskExecutor<#type_name> = rtic::export::executor::AsyncTaskExecutor::new(); @@ -50,11 +53,11 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { for name in channel.tasks.iter() { let exec_name = util::internal_task_ident(name, "EXEC"); - // TODO: Fix cfg - // let task = &app.software_tasks[name]; - // let cfgs = &task.cfgs; + let task = &app.software_tasks[name]; + let cfgs = &task.cfgs; stmts.push(quote!( + #(#cfgs)* #exec_name.poll(|| { #exec_name.set_pending(); #pend_interrupt diff --git a/rtic-macros/src/codegen/hardware_tasks.rs b/rtic-macros/src/codegen/hardware_tasks.rs index ee85f59f3351..e1bc4720adf5 100644 --- a/rtic-macros/src/codegen/hardware_tasks.rs +++ b/rtic-macros/src/codegen/hardware_tasks.rs @@ -73,10 +73,12 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { if !task.is_extern { let attrs = &task.attrs; + let cfgs = &task.cfgs; let context = &task.context; let stmts = &task.stmts; user_tasks.push(quote!( #(#attrs)* + #(#cfgs)* #[allow(non_snake_case)] fn #name(#context: #name::Context) { use rtic::Mutex as _; diff --git a/rtic/CHANGELOG.md b/rtic/CHANGELOG.md index 815b1bb0df97..df8050fc5ff9 100644 --- a/rtic/CHANGELOG.md +++ b/rtic/CHANGELOG.md @@ -15,6 +15,7 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top! - **Soundness fix:** Monotonics did not wait long enough in `Duration` based delays. This is not directly a change for `rtic`, but required bumping the minimal version of `rtic-monotonics`. +- Fixed `#[cfg]` tags on hardware and software tasks. ### Changed diff --git a/rtic/ci/expected/t-cfg-tasks.run b/rtic/ci/expected/t-cfg-tasks.run new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/rtic/examples/t-cfg-tasks.rs b/rtic/examples/t-cfg-tasks.rs new file mode 100644 index 000000000000..bea5f76e1f52 --- /dev/null +++ b/rtic/examples/t-cfg-tasks.rs @@ -0,0 +1,35 @@ +//! [compile-pass] check that `#[cfg]` attributes applied on tasks work + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] + +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] +mod app { + use cortex_m_semihosting::debug; + + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) { + debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator + + (Shared {}, Local {}) + } + + #[cfg(feature = "feature_x")] + #[task] + async fn opt_sw_task(cx: opt_sw_task::Context) {} + + #[cfg(feature = "feature_x")] + #[task(binds = UART0)] + fn opt_hw_task(cx: opt_hw_task::Context) {} +}