-
Notifications
You must be signed in to change notification settings - Fork 33
Enabled required features from examples automatically #636
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?
Changes from all commits
b884403
f21dc30
0a1a9bf
5d06df4
f31d3f4
91e3205
f86a10e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Examples | ||
|
|
||
| The CLI makes it easy to build, run and lint examples by automatically enabling required features of the example. | ||
|
|
||
| ## Build and run a specific example | ||
|
|
||
| ```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 | ||
| ``` | ||
|
|
||
| ## Build all examples | ||
|
|
||
| The CLI supports building all examples only for the native target, for the web this is not supported yet. | ||
| When building all examples, the CLI will build with `--all-features`. | ||
|
|
||
| ```sh | ||
| bevy build --examples | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ The CLI is a prototype tool intended to streamline common tasks when working on | |||||||||||||
| - [**Project Scaffolding**](scaffolding.md) | ||||||||||||||
| - [**Build and running Bevy Web Apps**](web.md) | ||||||||||||||
| - [**Linter Integration**](linter.md) | ||||||||||||||
| - [**Enabling required features for examples**](examples.md) | ||||||||||||||
|
Comment on lines
6
to
+8
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(Nit) Let's make all of these title case |
||||||||||||||
|
|
||||||||||||||
| [initial scope document]: https://hackmd.io/cCHAfbtaSviU_MDnbNHKxg | ||||||||||||||
| [original issue]: https://github.com/bevyengine/bevy/issues/436 | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| //! Provides functionalities to build a Bevy app targeting either native or web platforms. | ||
|
|
||
| pub use args::*; | ||
| use cargo_metadata::TargetKind; | ||
| use tracing::info; | ||
|
|
||
| #[cfg(feature = "web")] | ||
| use crate::web::build::build_web; | ||
|
|
@@ -39,6 +41,39 @@ pub fn build(args: &mut BuildArgs) -> anyhow::Result<()> { | |
|
|
||
| args.apply_config(&config); | ||
|
|
||
| // If a specific example was passed, extend the already present features with the | ||
| // required_features from this example. | ||
| if let Some(example) = &args.cargo_args.target_args.example | ||
| // Search in the current workspace packages for an `example` target that matches the given | ||
| // example name. | ||
| && let Some(example_target) = metadata | ||
| .workspace_packages() | ||
| .iter() | ||
| .flat_map(|p| p.targets.clone()) | ||
| .find(|t| t.name.as_str() == example && t.kind.contains(&TargetKind::Example)) | ||
| { | ||
| let required_features = example_target.required_features; | ||
|
|
||
| info!( | ||
| "enabling required_features: {:?}, for example: {example}", | ||
| required_features | ||
| ); | ||
|
|
||
| args.cargo_args | ||
| .feature_args | ||
| .features | ||
| .extend(required_features); | ||
| } | ||
| // build `--examples` with all features enabled. | ||
| else if args.cargo_args.target_args.is_examples { | ||
| args.cargo_args | ||
| .feature_args | ||
| .features | ||
| .push("--all-features".to_owned()); | ||
|
|
||
| info!("automatically added `--all-features` to build examples with all features enabled"); | ||
|
Comment on lines
+69
to
+74
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we should always enable In @alice-i-cecile's original comment when I asked how to deal with
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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we update this, make sure to also update the section in |
||
| } | ||
|
|
||
| #[cfg(feature = "web")] | ||
| if args.is_web() { | ||
| build_web(args, &metadata)?; | ||
|
|
||
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 think it would be good to show how required features are specified in
Cargo.toml:)