summaryrefslogtreecommitdiff
path: root/ecs-macros/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs-macros/src/lib.rs')
-rw-r--r--ecs-macros/src/lib.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/ecs-macros/src/lib.rs b/ecs-macros/src/lib.rs
index 3d0de6d..bc2d5ed 100644
--- a/ecs-macros/src/lib.rs
+++ b/ecs-macros/src/lib.rs
@@ -1,3 +1,4 @@
+use std::env;
use std::path::PathBuf as FsPathBuf;
use proc_macro::TokenStream;
@@ -263,11 +264,33 @@ fn find_engine_ecs_crate_path() -> Option<Path>
{
let cargo_manifest_dir = FsPathBuf::from(std::env::var("CARGO_MANIFEST_DIR").ok()?);
+ let cargo_crate_name = std::env::var("CARGO_CRATE_NAME").ok()?;
+ let cargo_pkg_name = std::env::var("CARGO_PKG_NAME").ok()?;
+
+ if cargo_pkg_name == "ecs" && cargo_crate_name != "ecs" {
+ // Macro is used by a ecs crate example/test/benchmark
+ return Some(syn_path!(ecs));
+ }
+
let crate_manifest = std::fs::read_to_string(cargo_manifest_dir.join("Cargo.toml"))
.ok()?
.parse::<TomlTable>()
.expect("Failed to parse crate manifest file");
+ let package = match crate_manifest.get("package")? {
+ TomlValue::Table(package) => Some(package),
+ _ => None,
+ }?;
+
+ let package_name = match package.get("name")? {
+ TomlValue::String(package_name) => Some(package_name),
+ _ => None,
+ }?;
+
+ if package_name == "ecs" {
+ return Some(syn_path!(crate));
+ }
+
let crate_dependencies = match crate_manifest.get("dependencies")? {
TomlValue::Table(dependencies) => Some(dependencies),
_ => None,