-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Put input sources for bevy_input
under features
#21447
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
base: main
Are you sure you want to change the base?
Conversation
`bevy_input` provides primitives for all kinds of input. But on consoles you usually don't have things like touch. On more obscure platforms, like GBA, only gamepad input is needed. To avoid including extra stuff, I put each source under a feature. I didn't enable them by default to avoid typing ```toml default-features = false, features = [ "std", "bevy_reflect", "bevy_ecs/async_executor", "smol_str" ] in all places that include `bevy_input`. Instead, I just enabled the used input sources in `bevy_window` and `bevy_gilrs`. This way, when a crate that provides hardware support for a specific input source is not used, the corresponding feature in `bevy_input` also won't be enabled. For GBA this reduced the binary size for the game example from 1.6M to 1.4M.
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 this change. That space savings is nothing to sneeze at on embedded, and this feels like the cleanest way to do this. Some platforms / projects genuinely don't need various input modes.
The features aren't set up quite right: you need descriptions over each individual feature and then you'll need to regenerate a file. See #21434 for details.
in all places that include bevy_input. Instead, I just enabled the used input sources in bevy_window and bevy_gilrs. This way, when a crate that provides hardware support for a specific input source is not used, the corresponding feature in bevy_input also won't be enabled.
I was expecting default features to be enabled for these, but your explanation here makes sense and seems fine to me.
Oh and this also needs a solid migration guide: changes to features are really hard to debug!
Yep, I'm already working on all of these! |
Objective
bevy_input
provides primitives for all kinds of input. But on consoles you usually don't have things like touch. On more obscure platforms, like GBA, only gamepad input is needed.Solution
To avoid including extra stuff, I put each source under a feature. I didn't enable them by default to avoid typing
in all places that include
bevy_input
. Instead, I just enabled the used input sources inbevy_window
andbevy_gilrs
. This way, when a crate that provides hardware support for a specific input source is not used, the corresponding feature inbevy_input
also won't be enabled.For GBA this reduced the binary size for the
game
example from 1.6M to 1.4M.Considered alternatives
I also considered doing something like this:
But this doesn't eliminate extra code even with LTO enabled and might be confusing for users, since toggling these values could cause a crash due to a missing resource when a crate like
bevy_window
expects it.