-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
plugin_group! macro #11460
plugin_group! macro #11460
Conversation
84b6282
to
a67ac80
Compare
d1ae952
to
4c8b853
Compare
#[custom(cfg(all(not(target_arch = "wasm32"), feature = "multi-threaded")))] | ||
bevy_render::pipelined_rendering:::PipelinedRenderingPlugin, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if it would document not targeting wasm32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice, but it would be quite difficult to implement this with the macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original DefaultPlugins
documentation didn't mention this requirement. So I don't think that's necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It did.
/// * [`PipelinedRenderingPlugin`](crate::render::pipelined_rendering::PipelinedRenderingPlugin) - with feature `bevy_render` when not targeting `wasm32` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah mb
Co-authored-by: Mateusz Wachowiak <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few more changes requested, mostly to make it harder to use the macro incorrectly and to catch some edge cases.
crates/bevy_app/src/plugin_group.rs
Outdated
impl PluginGroup for $group { | ||
fn build(self) -> PluginGroupBuilder { | ||
let mut group = PluginGroupBuilder::start::<Self>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail to compile if PluginGroup
and PluginGroupBuilder
are not imported. Using $crate
will fix this.
Additionally, #[allow(unused_mut)]
will allow an empty plugin_group!(MyPlugins {})
to build without warnings.
impl PluginGroup for $group { | |
fn build(self) -> PluginGroupBuilder { | |
let mut group = PluginGroupBuilder::start::<Self>(); | |
impl $crate::PluginGroup for $group { | |
fn build(self) -> $crate::PluginGroupBuilder { | |
#[allow(unused_mut)] | |
let mut group = $crate::PluginGroupBuilder::start::<Self>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you want to create a plugin group with no plugins?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is any long-term use of having an empty plugin group, but I could see someone testing the macro empty and being confused why rustc
is raising an warning on code they can't see. Additionally the macro doesn't prevent you from creating an empty group, so it's bound to happen at some point.
I don't think the extra #[allow(...)]
annotation will be confusing for future reviewers, but feel free to add a comment explaining why it's there. It can't hurt :)
# Objective - Fixes bevyengine#11453 This is a temporary fix. There is PR fixing it (bevyengine#11460), but I'm not sure if it's going to be merged before the 0.13 release.
Co-authored-by: BD103 <[email protected]>
…art 2)) Co-authored-by: BD103 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for your patience with my requests :)
@doonv would you mind rebasing this onto main? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please derive Default
on the DevToolsPlugin
? That seems to be causing the CI error.
.cargo/aconfig.toml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this was committed by mistake, would you mind deleting it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the docs generation, and the macro is nice and simple :)
@doonv it's warning me about merge conflicts but not showing me them. If the merge fails, please resolve the merge conflicts and then ping me :) |
I'm going to adopt this and fix merge conflicts. (I may also change a few things, since I have fresh eyes again.) |
Closing as adopted :) |
Pull request was closed
# Objective - Adopted from #11460. - Closes #7332. - The documentation for `DefaultPlugins` and `MinimalPlugins` frequently goes out of date because it is not . ## Solution - Create a macro, `plugin_group!`, to automatically create `PluginGroup`s and document them. ## Testing - Run `cargo-expand` on the generated code for `DefaultPlugins` and `MinimalPlugins`. - Try creating a custom plugin group with the macro. --- ## Showcase - You can now define custom `PluginGroup`s using the `plugin_group!` macro. ```rust plugin_group! { /// My really cool plugic group! pub struct MyPluginGroup { physics:::PhysicsPlugin, rendering:::RenderingPlugin, ui:::UiPlugin, } } ``` <details> <summary>Expanded output</summary> ```rust /// My really cool plugic group! /// /// - [`PhysicsPlugin`](physics::PhysicsPlugin) /// - [`RenderingPlugin`](rendering::RenderingPlugin) /// - [`UiPlugin`](ui::UiPlugin) pub struct MyPluginGroup; impl ::bevy_app::PluginGroup for MyPluginGroup { fn build(self) -> ::bevy_app::PluginGroupBuilder { let mut group = ::bevy_app::PluginGroupBuilder::start::<Self>(); { const _: () = { const fn check_default<T: Default>() {} check_default::<physics::PhysicsPlugin>(); }; group = group.add(<physics::PhysicsPlugin>::default()); } { const _: () = { const fn check_default<T: Default>() {} check_default::<rendering::RenderingPlugin>(); }; group = group.add(<rendering::RenderingPlugin>::default()); } { const _: () = { const fn check_default<T: Default>() {} check_default::<ui::UiPlugin>(); }; group = group.add(<ui::UiPlugin>::default()); } group } } ``` </details> --------- Co-authored-by: Doonv <[email protected]> Co-authored-by: Mateusz Wachowiak <[email protected]>
Objective
DefaultPlugins
documentation is out of date #11453.DefaultPlugins
is out-of-date. #7332.Solution
I created a
plugin_group!
macro that takes in a list ofPlugin
s and then generates aPluginGroup
along with it's documentation.Changelog
plugin_group!
macro, which allows easy creation ofPluginGroup
s.