Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/commands/build/mod.rs
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::debug;

#[cfg(feature = "web")]
use crate::web::build::build_web;
Expand Down Expand Up @@ -47,6 +49,39 @@ pub fn build(args: &mut BuildArgs) -> anyhow::Result<()> {
args.cargo_args.target_args.example.is_some(),
);

// 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;

debug!(
"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());

debug!("enabling `--all-features` to build all examples");
}

#[cfg(feature = "web")]
if args.is_web() {
build_web(args, &metadata, &bin_target)?;
Expand Down
35 changes: 34 additions & 1 deletion src/commands/lint/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub use args::*;
use tracing::error;
use tracing::{debug, error};

#[cfg(feature = "rustup")]
use crate::commands::lint::install::install_linter;
Expand Down Expand Up @@ -155,6 +155,39 @@ fn build_lint_cmd(args: &mut LintArgs) -> anyhow::Result<CommandExt> {
}
}

// 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(&cargo_metadata::TargetKind::Example))
{
let required_features = example_target.required_features;

debug!(
"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());

debug!("enabling `--all-features` to build all examples");
}

let cargo_args = args.cargo_args_builder();

cmd.args(cargo_args)
Expand Down
25 changes: 25 additions & 0 deletions src/commands/run/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Provides functionalities to run a Bevy app targeting either native or web platforms.

use tracing::debug;

pub use self::args::*;
#[cfg(feature = "web")]
use crate::web::run::run_web;
Expand Down Expand Up @@ -45,6 +47,29 @@ pub fn run(args: &mut RunArgs) -> anyhow::Result<()> {
args.cargo_args.target_args.example.is_some(),
);

// 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(&cargo_metadata::TargetKind::Example))
{
let required_features = example_target.required_features;

debug!(
"enabling required_features: {:?}, for example: {example}",
required_features
);

args.cargo_args
.feature_args
.features
.extend(required_features);
}

#[cfg(feature = "web")]
if args.is_web() {
return run_web(args, &metadata, &bin_target);
Expand Down