From f957f05b665909f35da0054a5d87d7fa53196487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Sun, 15 Nov 2020 17:27:08 +0000 Subject: [PATCH 1/2] Move entry-point main into a separate module Prevents conflict with user provided tasks named main --- examples/task_named_main.rs | 26 ++++++++++++++++++++++++++ macros/src/codegen.rs | 19 +++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 examples/task_named_main.rs diff --git a/examples/task_named_main.rs b/examples/task_named_main.rs new file mode 100644 index 0000000000..c3d21b5806 --- /dev/null +++ b/examples/task_named_main.rs @@ -0,0 +1,26 @@ +//! examples/task_named_main.rs + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] +mod app { + use cortex_m_semihosting::{debug, hprintln}; + + #[init] + fn init(_: init::Context) -> init::LateResources { + main::spawn().unwrap(); + + init::LateResources {} + } + + #[task] + fn main(_: main::Context) { + hprintln!("This task is named main, useful for rust-analyzer").unwrap(); + debug::exit(debug::EXIT_SUCCESS); + } +} diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 8309473acb..acd03d77c9 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -57,19 +57,22 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let main = util::suffixed("main"); mains.push(quote!( - #[no_mangle] - unsafe extern "C" fn #main() -> ! { - let _TODO: () = (); + pub mod rtic_ext { + use super::*; + #[no_mangle] + unsafe extern "C" fn #main() -> ! { + let _TODO: () = (); - #(#assertion_stmts)* + #(#assertion_stmts)* - #(#pre_init_stmts)* + #(#pre_init_stmts)* - #call_init + #call_init - #(#post_init_stmts)* + #(#post_init_stmts)* - #call_idle + #call_idle + } } )); From ad7b5a90c49da6078025d5ac46d1f48656836bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Sun, 15 Nov 2020 17:40:14 +0000 Subject: [PATCH 2/2] The module should not be pub --- macros/src/codegen.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index acd03d77c9..3cddf57018 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -57,7 +57,7 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let main = util::suffixed("main"); mains.push(quote!( - pub mod rtic_ext { + mod rtic_ext { use super::*; #[no_mangle] unsafe extern "C" fn #main() -> ! {