Skip to content

Enabled required features from examples automatically#636

Merged
BD103 merged 12 commits intomainfrom
set-features-for-examples-622
Feb 16, 2026
Merged

Enabled required features from examples automatically#636
BD103 merged 12 commits intomainfrom
set-features-for-examples-622

Conversation

@DaAlbrecht
Copy link
Copy Markdown
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
Copy Markdown
Member

Yay! That's very nice.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 thread src/commands/build/mod.rs Outdated
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
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown
Collaborator Author

@DaAlbrecht DaAlbrecht Feb 11, 2026

Choose a reason for hiding this comment

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

Eh i think this is just because im dumb ^^ Imo you should try to avoid having mutually incompatible features (on a compiler level), that would kinda break what features are used for.

Comment thread docs/src/cli/index.md Outdated
Comment thread docs/src/cli/examples.md
@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
DaAlbrecht and others added 3 commits February 11, 2026 11:29
Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com>
Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com>
@DaAlbrecht DaAlbrecht added S-Needs-Review The PR needs to be reviewed before it can be merged and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Feb 12, 2026
Copy link
Copy Markdown
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! Looking forward to using this in the next release :)

@BD103 BD103 enabled auto-merge (squash) February 16, 2026 17:55
@BD103 BD103 merged commit 9f48eed into main Feb 16, 2026
10 checks passed
@BD103 BD103 deleted the set-features-for-examples-622 branch February 16, 2026 18:03
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-Needs-Review The PR needs to be reviewed before it 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