Skip to content

Conversation

@DaAlbrecht
Copy link
Collaborator

@DaAlbrecht DaAlbrecht commented Oct 6, 2025

Objective

Enable the required features from examples automatically. If all examples should be built/checked, enable --all-features.

Testing

❯ bevy run --example web_asset -v
debug: running: `cargo metadata --format-version 1`
debug: enabling required_features: ["https"], for example: web_asset
debug: running: `cargo run --example web_asset --features https --profile dev`
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
❯ bevy build --example web_asset -v
debug: running: `cargo metadata --format-version 1`
debug: enabling required_features: ["https"], for example: web_asset
debug: running: `cargo build --example web_asset --features https --profile dev`
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s

Note

Building and lining all examples does not work until #629

Closes #622

@DaAlbrecht DaAlbrecht added A-Run Related to the bevy run command A-Build Related to the bevy build command D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review The PR needs to be reviewed before it can be merged labels Oct 6, 2025
@alice-i-cecile
Copy link
Member

Yay! That's very nice.

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 haven't had a chance to look over the code yet, but could you please add some basic docs on this feature? I don't want to diverge from Cargo without documenting it :)

@DaAlbrecht
Copy link
Collaborator Author

DaAlbrecht commented Oct 6, 2025

I haven't had a chance to look over the code yet, but could you please add some basic docs on this feature? I don't want to diverge from Cargo without documenting it :)

yea good point! Alice mentioned she would like a yes/no prompt i think that would be self documenting and no longer silently diverge from cargo what do you think?

@BD103
Copy link
Member

BD103 commented Oct 7, 2025

yea good point! Alice mentioned she would like a yes/no prompt i think that would be self documenting and no longer silently diverge from cargo what do you think?

While I think a prompt would be good with users who are unaware of the feature, I think it would also be really annoying for users who are aware and actively want the example's required features to be enabled. Maybe a good alternative would be switching the enabling required_features log message from debug!() to info!()?

But I also don't think that replaces having documentation on our website. A user shouldn't have to install the CLI or read the changelog to see all the features supported by a program. I can draft up something if you want me to!

@DaAlbrecht
Copy link
Collaborator Author

I can draft up something if you want me to!

I added a section but I always appreciate your docs/writing style, so feel free to delete it ^^

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.

Very good, the implementation is especially clean after #622 was merged!

Comment on lines +69 to +74
args.cargo_args
.feature_args
.features
.push("--all-features".to_owned());

info!("automatically added `--all-features` to build examples with all features enabled");
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure we should always enable --all-features when --examples is passed. When I run cargo build --examples --all-features in Bevy's repo, it fails with a compile error. That's not a great user experience, especially when the primary use of this feature will be by Bevy devs.

In @alice-i-cecile's original comment when I asked how to deal with --examples and --all-targets, she said:

Based on the design proposed in the linked issue, I would build these with --all-features (uh, except where mutually incompatible features exist) and diverge from cargo. Or at least warn users that they probably want to enable all the features and try again.

I think we either need to be more intelligent with how we handle mutually incompatible features, or just cut this for now. The alternative is Bevy devs being unable to compile the Bevy workspace with bevy build --examples, having to switch to cargo build --examples, which I don't think is acceptable.

Copy link
Member

Choose a reason for hiding this comment

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

If we update this, make sure to also update the section in examples.md and lint/mod.rs.

Comment on lines 6 to +8
- [**Build and running Bevy Web Apps**](web.md)
- [**Linter Integration**](linter.md)
- [**Enabling required features for examples**](examples.md)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- [**Build and running Bevy Web Apps**](web.md)
- [**Linter Integration**](linter.md)
- [**Enabling required features for examples**](examples.md)
- [**Build and Running Bevy Web Apps**](web.md)
- [**Linter Integration**](linter.md)
- [**Enabling Required Features for Examples**](examples.md)

(Nit) Let's make all of these title case

Comment on lines +7 to +15
```sh
# Run the `web_asset` example from https://github.com/bevyengine/bevy that requires the feature `https`.
bevy run --example web_asset
info: enabling required_features: ["https"], for example: web_asset

# Build the `web_asset` example in the web.
bevy build --example web_asset web
info: enabling required_features: ["https"], for example: web_asset
```
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
```sh
# Run the `web_asset` example from https://github.com/bevyengine/bevy that requires the feature `https`.
bevy run --example web_asset
info: enabling required_features: ["https"], for example: web_asset
# Build the `web_asset` example in the web.
bevy build --example web_asset web
info: enabling required_features: ["https"], for example: web_asset
```
Take Bevy's `web_asset` example, for instance. It requires the `https` feature in `Cargo.toml`:
```toml
[[example]]
name = "web_asset"
path = "examples/asset/web_asset.rs"
required-features = ["https"]
```
Running `cargo build --example web_asset` will fail with Cargo complaining that the `https` feature was not enabled. The Bevy CLI differs by automatically enabling the feature for you:
```sh
# The CLI will automatically add `--feature https`, as that feature is required to run the example.
bevy run --example web_asset
# It also works when building for the web.
bevy build --example web_asset web
```

I think it would be good to show how required features are specified in Cargo.toml :)

@BD103 BD103 added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review The PR needs to be reviewed before it can be merged labels Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Build Related to the bevy build command A-Run Related to the bevy run command D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bevy run --example should enable required features of examples

3 participants