diff --git a/crates/bevy_xr/Cargo.toml b/crates/bevy_xr/Cargo.toml index 54f9c00..71977bf 100644 --- a/crates/bevy_xr/Cargo.toml +++ b/crates/bevy_xr/Cargo.toml @@ -7,4 +7,3 @@ edition = "2021" [dependencies] bevy.workspace = true -bevy_xr_macros.path = "macros" diff --git a/crates/bevy_xr/macros/Cargo.toml b/crates/bevy_xr/macros/Cargo.toml deleted file mode 100644 index 38074e9..0000000 --- a/crates/bevy_xr/macros/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "bevy_xr_macros" -version = "0.1.0" -edition = "2021" - -[lib] -proc-macro = true - -[dependencies] -proc-macro2 = "1.0" -quote = "1.0" -syn = "2.0" diff --git a/crates/bevy_xr/macros/src/lib.rs b/crates/bevy_xr/macros/src/lib.rs deleted file mode 100644 index 927b6da..0000000 --- a/crates/bevy_xr/macros/src/lib.rs +++ /dev/null @@ -1,136 +0,0 @@ -use proc_macro::TokenStream; -use proc_macro2::Span; -use quote::quote; -use syn::parse::{Parse, ParseStream}; -use syn::punctuated::Punctuated; -use syn::spanned::Spanned; -use syn::token::{Comma, Eq}; -use syn::{parse_macro_input, parse_quote, AttrStyle, DeriveInput, Expr, Type}; - -mod kw { - syn::custom_keyword!(action_type); - syn::custom_keyword!(name); - syn::custom_keyword!(pretty_name); -} - -enum AttributeInput { - Kind(Type, Span), - Name(Expr, Span), - PrettyName(Expr, Span), -} - -impl Parse for AttributeInput { - fn parse(input: ParseStream) -> syn::Result { - if let Ok(field) = input.parse::() { - input.parse::()?; - Ok(Self::Kind(input.parse()?, field.span())) - } else if let Ok(field) = input.parse::() { - input.parse::()?; - Ok(Self::Name(input.parse()?, field.span())) - } else if let Ok(field) = input.parse::() { - input.parse::()?; - Ok(Self::PrettyName(input.parse()?, field.span())) - } else { - Err(input.error("expected 'action_type', 'name' or 'pretty_name'")) - } - } -} - -#[proc_macro_derive(Action, attributes(action))] -pub fn derive_action(input: TokenStream) -> TokenStream { - let input = parse_macro_input!(input as DeriveInput); - let item = input.ident; - let mut attributes = vec![]; - for attribute in input.attrs { - if let AttrStyle::Inner(token) = attribute.style { - return TokenStream::from( - syn::Error::new( - token.span, - "This derive macro does not accept inner attributes", - ) - .to_compile_error(), - ); - }; - let parsed_attributes = match attribute - .parse_args_with(Punctuated::::parse_terminated) - { - Ok(inner) => inner, - Err(e) => return TokenStream::from(e.to_compile_error()), - }; - for attr in parsed_attributes { - attributes.push(attr); - } - } - let mut kind: Option = None; - let mut name: Option = None; - let mut pretty_name: Option = None; - for attribute in attributes { - match attribute { - AttributeInput::Kind(ty, span) => { - if kind.is_some() { - return syn::Error::new( - span, - "attribute 'action_type' is defined more than once", - ) - .to_compile_error() - .into(); - } - - kind = Some(ty); - } - AttributeInput::Name(expr, span) => { - if name.is_some() { - return syn::Error::new(span, "attribute 'name' is defined more than once") - .to_compile_error() - .into(); - } - - name = Some(expr); - } - AttributeInput::PrettyName(expr, span) => { - if pretty_name.is_some() { - return syn::Error::new( - span, - "attribute 'pretty_name' is defined more than once", - ) - .to_compile_error() - .into(); - } - - pretty_name = Some(expr); - } - } - } - - if kind.is_none() { - panic!("action_type isn't specified") - } - if name.is_none() { - name = Some(parse_quote! { - std::stringify!(#item) - }); - } - if pretty_name.is_none() { - pretty_name = name.clone(); - } - let kind = kind.unwrap(); - let name = name.unwrap(); - let pretty_name = pretty_name.unwrap(); - - let expanded = quote! { - impl bevy_xr::actions::Action for #item { - type ActionType = #kind; - - fn info() -> bevy_xr::actions::ActionInfo { - bevy_xr::actions::ActionInfo { - pretty_name: #pretty_name, - name: #name, - action_type: ::TYPE, - type_id: std::any::TypeId::of::(), - } - } - } - }; - - TokenStream::from(expanded) -} diff --git a/crates/bevy_xr/src/actions.rs b/crates/bevy_xr/src/actions.rs index 7234392..b7034f3 100644 --- a/crates/bevy_xr/src/actions.rs +++ b/crates/bevy_xr/src/actions.rs @@ -3,7 +3,6 @@ use std::{any::TypeId, marker::PhantomData}; use bevy::app::{App, Plugin}; use bevy::ecs::system::Resource; use bevy::math::Vec2; -pub use bevy_xr_macros::Action; pub struct ActionPlugin(PhantomData); diff --git a/crates/bevy_xr_utils/Cargo.toml b/crates/bevy_xr_utils/Cargo.toml index 4146f0c..3e200ec 100644 --- a/crates/bevy_xr_utils/Cargo.toml +++ b/crates/bevy_xr_utils/Cargo.toml @@ -8,5 +8,7 @@ edition = "2021" [dependencies] bevy.workspace = true bevy_mod_xr.path = "../bevy_xr" -openxr = "0.18.0" bevy_mod_openxr.path = "../bevy_openxr" + +[target.'cfg(not(target_family = "wasm"))'.dependencies] +openxr = "0.18.0" diff --git a/crates/bevy_xr_utils/src/lib.rs b/crates/bevy_xr_utils/src/lib.rs index 6db8e46..df9edfd 100644 --- a/crates/bevy_xr_utils/src/lib.rs +++ b/crates/bevy_xr_utils/src/lib.rs @@ -1,4 +1,6 @@ // use bevy::prelude::*; pub mod hand_gizmos; +#[cfg(not(target_family = "wasm"))] pub mod xr_utils_actions; +#[cfg(not(target_family = "wasm"))] pub mod transform_utils;