Move entry-point main into a separate module

Prevents conflict with user provided tasks named main
This commit is contained in:
Henrik Tjäder 2020-11-15 17:27:08 +00:00
parent 9527c92192
commit f957f05b66
2 changed files with 37 additions and 8 deletions

View file

@ -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);
}
}

View file

@ -57,6 +57,8 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
let main = util::suffixed("main"); let main = util::suffixed("main");
mains.push(quote!( mains.push(quote!(
pub mod rtic_ext {
use super::*;
#[no_mangle] #[no_mangle]
unsafe extern "C" fn #main() -> ! { unsafe extern "C" fn #main() -> ! {
let _TODO: () = (); let _TODO: () = ();
@ -71,6 +73,7 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
#call_idle #call_idle
} }
}
)); ));
let (mod_app_resources, mod_resources) = resources::codegen(app, analysis, extra); let (mod_app_resources, mod_resources) = resources::codegen(app, analysis, extra);