Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhysicsLayer import crate based on which crate (2d or 3d) is being used #601

Merged
merged 4 commits into from
Dec 31, 2024

Conversation

ironpeak
Copy link
Contributor

Objective

I've been getting warnings in my project when using the PhysicsLayer derive enum, because it's generating code that is using the feature flags 2d and 3d. Since the code is procedurally generated within my game project it is checking for these features in my project rather then picking based on which library is being used (avian2d or avian3d).

Solution

Add 2 feature flags for avian_derive (2d and 3d). Use the feature flag when importing avian_derive in avian2d and avian3d. Move the feature flag check out of the qoute! macro so that it is checked within avian_derive rather then the consuming project.


Changelog

Adds 2 feature flags to avian_derive which should be setup correctly for both avian2d and avian3d.

Migration Guide

N/A

@Jondolf
Copy link
Owner

Jondolf commented Dec 25, 2024

I switched to nighly to get the warning (it's not on stable Rust yet, which is why I haven't noticed it before). I'm still getting it in crates/avian2d/examples/collision_layers.rs with this PR though, even after running cargo clean, restarting RA, etc. 🤔

warning

I assume the changes here fixed the warnings for you though? The fix itself makes sense to me, so I'd be fine merging this if it works for other people. It's just strange that I'm still getting it with this PR

@ironpeak
Copy link
Contributor Author

I simplified the approach and created a demo project here:

https://github.com/ironpeak/avian-pr-601-demo

There is a caveat with this change, it assumes that the correct PhysicsLayer is in scope so a fully qualified derive would fail e.g.

#[derive(avian3d::prelude::PhysicsLayer, Default)]
pub enum GameLayer {
    #[default]
    Wall,
    Player,
    Enemy,
}

If that is a problem I can rework it so that it supports both, but I liked this simplified implementation.

Copy link
Owner

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this approach should be fine. Thanks!

I have published a 0.2.1 patch for avian_derive with these changes now, so running cargo update for apps using Avian 0.2 should hopefully update it and fix the warning.

@Jondolf Jondolf enabled auto-merge (squash) December 31, 2024 15:35
@Jondolf Jondolf merged commit 7e945ae into Jondolf:main Dec 31, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PhysicsLayer derive macro appears to expect undocumented cargo features to be present
2 participants