1use proc_macro::TokenStream;
2use rtic_syntax::Settings;
3use std::{fs, path::Path};
4
5mod codegen;
6
7#[proc_macro_attribute]
11pub fn app(args: TokenStream, input: TokenStream) -> TokenStream {
12 let mut settings = Settings::default();
13 settings.optimize_priorities = false;
14 settings.parse_binds = true;
15 settings.parse_extern_interrupt = true;
16
17 let (app, analysis) = match rtic_syntax::parse(args, input, settings) {
18 Err(e) => return e.to_compile_error().into(),
19 Ok(x) => x,
20 };
21
22 let ts = codegen::app(&app, &analysis);
23
24 if Path::new("target").exists() {
26 fs::write("target/rtic-expansion.rs", ts.to_string()).ok();
27 std::process::Command::new("rustfmt")
28 .arg("target/rtic-expansion.rs")
29 .status()
30 .ok();
31 }
32
33 ts.into()
34}