Replies: 5 comments 7 replies
-
As patient zero of this viral outbreak, I completely agree with your assessment of the situation. Here are some solutions I can think of in no particular order: Remove the features as much as possibleThe fewer crates that care about a feature, the easier it is to manage. This would require a bottom-up approach where we stabilize the public API across platforms through a combination of runtime feature detection and polyfills (like Put the features everywhere!We might not be able to remove the boilerplate, but standardizing on a set of features for every crate would make it consistent, removing the guess work from the equation. That is, add a Environment variables and/or featuresCargo environment variables can be set once and read at compile time just like feature flags, but with the added benefit of being visible across all dependencies. Perhaps we could control these features using the Bevy CLI tool, or some build.rs wizardry.
|
Beta Was this translation helpful? Give feedback.
-
How much is no_alloc factoring into all this? To my understanding, no_std means no sync primitives and no OS-specific features (std::sys and std::os), but that leaves both core and alloc. Some crates are no_alloc as well, which involves things like using heapless to allocate e.g. Vecs onto the stack, but that also comes with significant limitations, and I'd hate to slow down development speed with those hurdles. |
Beta Was this translation helpful? Give feedback.
-
I put together a |
Beta Was this translation helpful? Give feedback.
-
Have an initial PR for better feature management and a bottom-up feature communication paradigm here. |
Beta Was this translation helpful? Give feedback.
-
One thing that would be nice to address is imports. It's annoying to have to manually make sure I use core imports and not std. |
Beta Was this translation helpful? Give feedback.
-
Bevy increasingly has "no std" (supports platforms that don't have an
std
impl) and "no web" (supports wasm builds that don't have access to the full web). This is really cool!However I think the "virality" of both
std
andweb
features (and the proliferation of them in our codebase) is a maintenance liability and an "ecosystem UX" liability. Writing a new crate that supports these platforms requires intimate knowledge of the patterns we use to support them, what Bevy crates currently support them, and how to wire everything up to ensure you enable these features in the relevant crates.Things like this are now everywhere in our codebase:
Every time you add some
bevy_x
dependency (either official or 3rd party), you need to ask yourself:bevy_x/std
feature when that is enabled.bevy_x/web
when building for thewasm32
target.Likewise having
#[cfg(feature = "std")]
and#[cfg(feature = "web")]
everywhere significantly affects legibility and maintainability.I think the way these things are framed (optional, but "viral" cargo features) is correct, but I think we should investigate scoping down which crates needs to care about this (and in an ideal world, no crates need to care about this). If we had a single place that handled these platform specific concerns and provided platform agnostic interfaces consumers can code to (as in, the code compiles regardless of no_std / web-ness), then that crate wouldn't need to explicitly worry about platform configuration at all. Instead, the end user (or the
bevy
crate) could define the "web" / "std" features directly on that crate.That way the interface could be this for crates that depend on "core" bevy crates :
Likewise consumers of "my_bevy_plugin" could just do
And then the top level app could do:
Or alternatively:
Or
The downside here is that all std and web functionality would need to live in
bevy_platform_support
(risking compile time bottlenecking), and we'd need to ensure that we expose platform agnostic interfaces. This is a technical challenge, but not necessarily insurmountable.It also wouldn't necessarily need to be exhaustive. We could focus on the low hanging fruit and piecemeal port things over to that paradigm, which could reduce how "deep" the roots currently go.
To keep
bevy_platform_support
slim, we could feature gate what it provides (ex: a "log" feature, a "collections" feature, etc).I'll note that pretty much every platform-agnostic app framework builds interfaces like this (and we already use this approach in plenty of places, we're just overly leaky atm) .
In practice, this would result in writing some APIs that do nothing on some platforms, adding runtime
if bevy_platform_support::IS_WEB { }
checks (which would be const), etc.Beta Was this translation helpful? Give feedback.
All reactions