Skip to content

Allow plugin functions in plugin_group!#24345

Open
Jengamon wants to merge 1 commit into
bevyengine:mainfrom
Jengamon:allow-plugin-func-in-group
Open

Allow plugin functions in plugin_group!#24345
Jengamon wants to merge 1 commit into
bevyengine:mainfrom
Jengamon:allow-plugin-func-in-group

Conversation

@Jengamon
Copy link
Copy Markdown

Objective

Allow plugin functions to be used inside plugin_group! declarations.

Right now, functions of signature fn(&mut App) implement Plugin, but cannot be added to plugin groups, due
to how the macro is implemented.

This fixes that.

Solution

This PR fixes the problem by introducing a block after the top-level members, labeled with fn, where the names are considered to be referencing values directly, rather than types. It looks like:

plugin_group! {
  pub struct MyFnGroup {
     // ... stuff that `impl Plugin` ...
     fn {
       :local_fn,
       outer:::outer_fn,
       #[doc(hidden)]
       internal:::hidden_fn,
    }
  }
}

Testing

I edited the doctest above the macro implementation, and made sure that passes, and the syntax is non-invasive otherwise, so overall, not much should change.


@github-actions
Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨

@Jengamon Jengamon force-pushed the allow-plugin-func-in-group branch from 4cb37a0 to 9d8b233 Compare May 18, 2026 23:47
introduces a little idiosyncratic `fn {}` block for containing the
function members, mostly as a workaround for the fact that macro parsing
cannot backtrack
@Jengamon Jengamon force-pushed the allow-plugin-func-in-group branch from 9d8b233 to 30f8623 Compare May 19, 2026 01:34
@kfc35 kfc35 added A-App Bevy apps and plugins S-Needs-Review Needs reviewer attention (from anyone!) to move forward D-Macros Code that generates Rust code labels May 20, 2026
Copy link
Copy Markdown
Member

@NiklasEi NiklasEi left a comment

Choose a reason for hiding this comment

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

Please also extend the existing tests with fn plugins (hidden and unhidden). Make sure to check the build order after fixing it.

group = group.add(<$($plugin_path::)*$plugin_name>::default());
}
)*
$($(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With these changes, the order of the plugins in the expanded macro is no longer the same order they have in the macro block. Since plugin order matters for dependencies (e.g. on Resource), the order should stay consistent.

" - [`", stringify!($plugin_group_name), "`](" $(, stringify!($plugin_group_path), "::")*, stringify!($plugin_group_name), ")"
$(, " - with feature `", $plugin_group_feature, "`")?
)])+)?
$(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should also add the documentation of the fn plugins here.

/// #[doc(hidden)]
/// internal:::InternalPlugin
/// internal:::InternalPlugin,
/// // The last thing within the block can be a "fn block", which allows using plugin functions
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The last part of this sentence reads strange.

@alice-i-cecile alice-i-cecile added X-Uncontroversial This work is generally agreed upon 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 and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 21, 2026
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 D-Macros Code that generates Rust code 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 X-Uncontroversial This work is generally agreed upon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants