1mod item_fn;
2
3mod main_fn;
4
5mod test_fn;
6
7use proc_macro::TokenStream;
8use proc_macro2::{Ident, Span};
9use proc_macro_crate::{crate_name, FoundCrate};
10use quote::{quote, ToTokens};
11use syn::parse_macro_input;
12
13#[proc_macro_attribute]
14pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
15 parse_macro_input!(item as main_fn::CompioMain)
16 .with_args(parse_macro_input!(args as item_fn::RawAttr))
17 .into_token_stream()
18 .into()
19}
20
21#[proc_macro_attribute]
22pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
23 parse_macro_input!(item as test_fn::CompioTest)
24 .with_args(parse_macro_input!(args as item_fn::RawAttr))
25 .into_token_stream()
26 .into()
27}
28
29fn retrieve_runtime_mod() -> proc_macro2::TokenStream {
30 match crate_name("compio-runtime") {
31 Ok(FoundCrate::Itself) => quote!(crate),
32 Ok(FoundCrate::Name(name)) => {
33 let ident = Ident::new(&name, Span::call_site());
34 quote!(::#ident)
35 }
36 Err(_) => match crate_name("compio") {
37 Ok(FoundCrate::Itself) => quote!(crate::runtime),
38 Ok(FoundCrate::Name(name)) => {
39 let ident = Ident::new(&name, Span::call_site());
40 quote!(::#ident::runtime)
41 }
42 Err(_) => panic!("Cannot find compio or compio_runtime."),
43 },
44 }
45}