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

plugin_group! macro #11460

Closed
wants to merge 20 commits into from
Closed

plugin_group! macro #11460

wants to merge 20 commits into from

Conversation

doonv
Copy link
Contributor

@doonv doonv commented Jan 21, 2024

Objective

Solution

I created a plugin_group! macro that takes in a list of Plugins and then generates a PluginGroup along with it's documentation.


Changelog

  • Bevy App: Added the plugin_group! macro, which allows easy creation of PluginGroups.

@doonv doonv force-pushed the plugin-group-macro branch from 84b6282 to a67ac80 Compare January 21, 2024 19:03
@doonv doonv force-pushed the plugin-group-macro branch from d1ae952 to 4c8b853 Compare January 21, 2024 19:15
crates/bevy_internal/src/default_plugins.rs Show resolved Hide resolved
crates/bevy_app/src/plugin_group.rs Outdated Show resolved Hide resolved
crates/bevy_app/src/plugin_group.rs Outdated Show resolved Hide resolved
Comment on lines 31 to 32
#[custom(cfg(all(not(target_arch = "wasm32"), feature = "multi-threaded")))]
bevy_render::pipelined_rendering:::PipelinedRenderingPlugin,
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

@doonv doonv Jan 26, 2024

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.

Copy link
Member

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`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah mb

@matiqo15 matiqo15 added C-Docs An addition or correction to our documentation A-Core labels Jan 21, 2024
Co-authored-by: Mateusz Wachowiak <[email protected]>
@alice-i-cecile alice-i-cecile added the A-App Bevy apps and plugins label Jan 22, 2024
crates/bevy_app/src/plugin_group.rs Outdated Show resolved Hide resolved
crates/bevy_app/src/plugin_group.rs Show resolved Hide resolved
github-merge-queue bot pushed a commit that referenced this pull request Jan 28, 2024
# Objective

- Fixes #11453

This is a temporary fix. There is PR fixing it (#11460), but I'm not
sure if it's going to be merged before the 0.13 release.
Copy link
Member

@BD103 BD103 left a 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 Show resolved Hide resolved
Comment on lines 97 to 99
impl PluginGroup for $group {
fn build(self) -> PluginGroupBuilder {
let mut group = PluginGroupBuilder::start::<Self>();
Copy link
Member

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.

Suggested change
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>();

Copy link
Contributor Author

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?

Copy link
Member

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 :)

crates/bevy_app/src/plugin_group.rs Outdated Show resolved Hide resolved
crates/bevy_app/src/plugin_group.rs Outdated Show resolved Hide resolved
crates/bevy_app/src/plugin_group.rs Outdated Show resolved Hide resolved
tjamaan pushed a commit to tjamaan/bevy that referenced this pull request Feb 6, 2024
# 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.
@doonv doonv requested a review from BD103 February 6, 2024 10:27
Copy link
Member

@BD103 BD103 left a 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 :)

@BD103
Copy link
Member

BD103 commented Apr 21, 2024

@doonv would you mind rebasing this onto main?

@doonv doonv requested a review from BD103 April 25, 2024 21:34
Copy link
Member

@BD103 BD103 left a 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.

@doonv doonv requested a review from BD103 May 8, 2024 11:34
Copy link
Member

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?

@BD103 BD103 added C-Feature A new feature, making something new possible C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels May 8, 2024
Copy link
Member

@BD103 BD103 left a comment

Choose a reason for hiding this comment

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

Thank you!

@BD103 BD103 added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels May 8, 2024
Copy link
Member

@alice-i-cecile alice-i-cecile left a 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 :)

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 14, 2024
@alice-i-cecile alice-i-cecile enabled auto-merge July 15, 2024 13:50
@alice-i-cecile
Copy link
Member

@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 :)

@BD103
Copy link
Member

BD103 commented Jul 15, 2024

I'm going to adopt this and fix merge conflicts. (I may also change a few things, since I have fresh eyes again.)

@alice-i-cecile
Copy link
Member

Closing as adopted :)

auto-merge was automatically disabled July 15, 2024 16:36

Pull request was closed

github-merge-queue bot pushed a commit that referenced this pull request Jul 16, 2024
# 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-App Bevy apps and plugins C-Docs An addition or correction to our documentation C-Feature A new feature, making something new possible C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DefaultPlugins documentation is out of date Documented list of DefaultPlugins is out-of-date.
4 participants