Skip to content

Commit

Permalink
Merge pull request #30 from MrGVSV/fix-derive-backend-dependency
Browse files Browse the repository at this point in the history
Fix: Derive macro requiring backend crate as dependency
  • Loading branch information
MrGVSV authored Apr 23, 2023
2 parents 97e4dfc + d19e7e8 commit 5701889
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_proto"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
authors = ["Gino Valente <gino.valente.code@gmail.com>"]
description = "Create config files for entities in Bevy"
Expand Down Expand Up @@ -57,7 +57,7 @@ bevy_sprite = ["bevy/bevy_sprite", "bevy_proto_backend/bevy_sprite"]
bevy_text = ["bevy/bevy_text", "bevy_proto_backend/bevy_text"]

[dependencies]
bevy_proto_backend = { version = "0.1", path = "./bevy_proto_backend" }
bevy_proto_backend = { version = "0.1.1", path = "./bevy_proto_backend" }
bevy = { version = ">=0.10.1", default-features = false, features = ["bevy_asset"] }
anyhow = "1.0"
serde = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions bevy_proto_backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_proto_backend"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
authors = ["Gino Valente <gino.valente.code@gmail.com>"]
description = "Backend crate for bevy_proto"
Expand Down Expand Up @@ -44,7 +44,7 @@ bevy_sprite = ["bevy/bevy_sprite"]
bevy_text = ["bevy/bevy_text"]

[dependencies]
bevy_proto_derive = { version = "0.3", path = "../bevy_proto_derive" }
bevy_proto_derive = { version = "0.3.1", path = "../bevy_proto_derive" }
bevy = { version = ">=0.10.1", default-features = false, features = ["bevy_asset"] }
anyhow = "1.0"
serde = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion bevy_proto_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_proto_derive"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = ["Gino Valente <gino.valente.code@gmail.com>"]
description = "Derive macro for use with bevy_proto"
Expand Down
20 changes: 14 additions & 6 deletions bevy_proto_derive/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
use proc_macro2::{Ident, Span, TokenStream};
use proc_macro_crate::{crate_name, FoundCrate};
use proc_macro_crate::{crate_name, Error, FoundCrate};
use quote::quote;

/// Returns a path to the `bevy_proto_backend` crate.
/// Returns a path to either the `bevy_proto_backend` crate or `bevy_proto::backend` module.
pub(crate) fn get_proto_crate() -> TokenStream {
get_crate_path(
crate_name("bevy_proto_backend").expect("bevy_proto_backend is present in `Cargo.toml`"),
)
match crate_name("bevy_proto_backend") {
Ok(found_crate) => get_crate_path(found_crate),
Err(Error::CrateNotFound { .. }) => {
let path = get_crate_path(
crate_name("bevy_proto")
.expect("bevy_proto or bevy_proto_backend should be present in `Cargo.toml`"),
);
quote!(#path::backend)
}
Err(error) => panic!("{}", error),
}
}

/// Returns a path to the `bevy` crate.
Expand All @@ -19,7 +27,7 @@ fn get_crate_path(found_crate: FoundCrate) -> TokenStream {
FoundCrate::Itself => quote!(crate),
FoundCrate::Name(name) => {
let ident = Ident::new(&name, Span::call_site());
quote!( #ident )
quote!( ::#ident )
}
}
}

0 comments on commit 5701889

Please sign in to comment.