mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
rtic-macros: wrap everything in macro_rules! to improve the error experience and
royally **** up the DX experience (for lib.rs in rtic-macros, at least :P)
This commit is contained in:
parent
68ccf0423d
commit
2ba09dd68d
2 changed files with 86 additions and 70 deletions
|
@ -1,10 +1,3 @@
|
|||
#[cfg(not(any(
|
||||
feature = "cortex-m-source-masking",
|
||||
feature = "cortex-m-basepri",
|
||||
feature = "test-template"
|
||||
)))]
|
||||
compile_error!("No backend selected");
|
||||
|
||||
#[cfg(any(feature = "cortex-m-source-masking", feature = "cortex-m-basepri"))]
|
||||
pub use cortex::*;
|
||||
|
||||
|
|
|
@ -4,14 +4,27 @@
|
|||
)]
|
||||
//deny_warnings_placeholder_for_ci
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use std::{env, fs, path::Path};
|
||||
macro_rules! with_backend {
|
||||
(mod: [$($mod:tt),*]) => {
|
||||
$(
|
||||
with_backend!{ mod $mod; }
|
||||
)*
|
||||
};
|
||||
($($tokens:tt)*) => {
|
||||
#[cfg(any(
|
||||
feature = "cortex-m-source-masking",
|
||||
feature = "cortex-m-basepri",
|
||||
feature = "test-template"
|
||||
))]
|
||||
$($tokens)*
|
||||
};
|
||||
}
|
||||
|
||||
mod analyze;
|
||||
mod check;
|
||||
mod codegen;
|
||||
mod syntax;
|
||||
with_backend! { mod: [analyze, check, codegen, syntax] }
|
||||
with_backend! { use std::{fs, env, path::Path}; }
|
||||
with_backend! { use proc_macro::TokenStream; }
|
||||
|
||||
with_backend! {
|
||||
// Used for mocking the API in testing
|
||||
#[doc(hidden)]
|
||||
#[proc_macro_attribute]
|
||||
|
@ -22,7 +35,9 @@ pub fn mock_app(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
"fn main() {}".parse().unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
with_backend! {
|
||||
/// Attribute used to declare a RTIC application
|
||||
///
|
||||
/// For user documentation see the [RTIC book](https://rtic.rs)
|
||||
|
@ -31,8 +46,8 @@ pub fn mock_app(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
///
|
||||
/// Should never panic, cargo feeds a path which is later converted to a string
|
||||
#[proc_macro_attribute]
|
||||
pub fn app(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let (app, analysis) = match syntax::parse(args, input) {
|
||||
pub fn app(_args: TokenStream, _input: TokenStream) -> TokenStream {
|
||||
let (app, analysis) = match syntax::parse(_args, _input) {
|
||||
Err(e) => return e.to_compile_error().into(),
|
||||
Ok(x) => x,
|
||||
};
|
||||
|
@ -88,3 +103,11 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
|
||||
ts.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(
|
||||
feature = "cortex-m-source-masking",
|
||||
feature = "cortex-m-basepri",
|
||||
feature = "test-template"
|
||||
)))]
|
||||
compile_error!("Cannot compile. No backend feature selected.");
|
||||
|
|
Loading…
Reference in a new issue