diff options
author | HampusM <hampus@hampusmat.com> | 2024-11-11 21:02:05 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-11-12 19:31:43 +0100 |
commit | bd6ca069999352012ca8664db199213e9b3b3269 (patch) | |
tree | db62245e1800c01fe28acea6d4fe455e1c719256 /ecs-macros | |
parent | 8ba11038a22e78d6c2aeedbc47f5ce3198b5624a (diff) |
feat(ecs-macros): add support for ecs crate path
Diffstat (limited to 'ecs-macros')
-rw-r--r-- | ecs-macros/src/lib.rs | 23 |
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, |