aboutsummaryrefslogtreecommitdiff
path: root/embassy-macros/src/lib.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-11-23 13:21:59 +0000
committerGitHub <[email protected]>2022-11-23 13:21:59 +0000
commita4f9e7cbcc8cb3ff679b4677a85a06d514b0c465 (patch)
treeacb48252c134b900eca51299995e84a95fbd0cd3 /embassy-macros/src/lib.rs
parentde95ab264d8ee2bf5ba9c3615ecb1b44e3940694 (diff)
parent04a7d976733e021395ff26e26dfa983e67b773a0 (diff)
Merge #1071
1071: refactor: autodetect macro variant r=Dirbaio a=lulf Apply heuristics using target_arch, target_os and target_family to determine which variant of the entry point to use. Co-authored-by: Ulf Lilleengen <[email protected]>
Diffstat (limited to 'embassy-macros/src/lib.rs')
-rw-r--r--embassy-macros/src/lib.rs81
1 files changed, 78 insertions, 3 deletions
diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs
index f5df2a269..d2c696c72 100644
--- a/embassy-macros/src/lib.rs
+++ b/embassy-macros/src/lib.rs
@@ -45,7 +45,7 @@ pub fn task(args: TokenStream, item: TokenStream) -> TokenStream {
45 task::run(args, f).unwrap_or_else(|x| x).into() 45 task::run(args, f).unwrap_or_else(|x| x).into()
46} 46}
47 47
48/// Creates a new `executor` instance and declares an application entry point spawning the corresponding function body as an async task. 48/// Creates a new `executor` instance and declares an application entry point for Cortex-M spawning the corresponding function body as an async task.
49/// 49///
50/// The following restrictions apply: 50/// The following restrictions apply:
51/// 51///
@@ -64,10 +64,85 @@ pub fn task(args: TokenStream, item: TokenStream) -> TokenStream {
64/// } 64/// }
65/// ``` 65/// ```
66#[proc_macro_attribute] 66#[proc_macro_attribute]
67pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { 67pub fn main_cortex_m(args: TokenStream, item: TokenStream) -> TokenStream {
68 let args = syn::parse_macro_input!(args as syn::AttributeArgs); 68 let args = syn::parse_macro_input!(args as syn::AttributeArgs);
69 let f = syn::parse_macro_input!(item as syn::ItemFn); 69 let f = syn::parse_macro_input!(item as syn::ItemFn);
70 main::run(args, f).unwrap_or_else(|x| x).into() 70 main::run(args, f, main::cortex_m()).unwrap_or_else(|x| x).into()
71}
72
73/// Creates a new `executor` instance and declares an application entry point for RISC-V spawning the corresponding function body as an async task.
74///
75/// The following restrictions apply:
76///
77/// * The function must accept exactly 1 parameter, an `embassy_executor::Spawner` handle that it can use to spawn additional tasks.
78/// * The function must be declared `async`.
79/// * The function must not use generics.
80/// * Only a single `main` task may be declared.
81///
82/// ## Examples
83/// Spawning a task:
84///
85/// ``` rust
86/// #[embassy_executor::main]
87/// async fn main(_s: embassy_executor::Spawner) {
88/// // Function body
89/// }
90/// ```
91#[proc_macro_attribute]
92pub fn main_riscv(args: TokenStream, item: TokenStream) -> TokenStream {
93 let args = syn::parse_macro_input!(args as syn::AttributeArgs);
94 let f = syn::parse_macro_input!(item as syn::ItemFn);
95 main::run(args, f, main::riscv()).unwrap_or_else(|x| x).into()
96}
97
98/// Creates a new `executor` instance and declares an application entry point for STD spawning the corresponding function body as an async task.
99///
100/// The following restrictions apply:
101///
102/// * The function must accept exactly 1 parameter, an `embassy_executor::Spawner` handle that it can use to spawn additional tasks.
103/// * The function must be declared `async`.
104/// * The function must not use generics.
105/// * Only a single `main` task may be declared.
106///
107/// ## Examples
108/// Spawning a task:
109///
110/// ``` rust
111/// #[embassy_executor::main]
112/// async fn main(_s: embassy_executor::Spawner) {
113/// // Function body
114/// }
115/// ```
116#[proc_macro_attribute]
117pub fn main_std(args: TokenStream, item: TokenStream) -> TokenStream {
118 let args = syn::parse_macro_input!(args as syn::AttributeArgs);
119 let f = syn::parse_macro_input!(item as syn::ItemFn);
120 main::run(args, f, main::std()).unwrap_or_else(|x| x).into()
121}
122
123/// Creates a new `executor` instance and declares an application entry point for WASM spawning the corresponding function body as an async task.
124///
125/// The following restrictions apply:
126///
127/// * The function must accept exactly 1 parameter, an `embassy_executor::Spawner` handle that it can use to spawn additional tasks.
128/// * The function must be declared `async`.
129/// * The function must not use generics.
130/// * Only a single `main` task may be declared.
131///
132/// ## Examples
133/// Spawning a task:
134///
135/// ``` rust
136/// #[embassy_executor::main]
137/// async fn main(_s: embassy_executor::Spawner) {
138/// // Function body
139/// }
140/// ```
141#[proc_macro_attribute]
142pub fn main_wasm(args: TokenStream, item: TokenStream) -> TokenStream {
143 let args = syn::parse_macro_input!(args as syn::AttributeArgs);
144 let f = syn::parse_macro_input!(item as syn::ItemFn);
145 main::run(args, f, main::wasm()).unwrap_or_else(|x| x).into()
71} 146}
72 147
73#[proc_macro_attribute] 148#[proc_macro_attribute]