Add bevy_dev_tools crate (#11341)

# Objective

- Resolves #11309

## Solution

- Add `bevy_dev_tools` crate as a default feature.
- Add `DevToolsPlugin` and add it to an app if the `bevy_dev_tools`
feature is enabled.

`bevy_dev_tools` is reserved by @alice-i-cecile, should we wait until it
gets transferred to cart before merging?

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com>
This commit is contained in:
Mateusz Wachowiak 2024-03-06 21:33:05 +01:00 committed by GitHub
parent 13d37c534f
commit 6533170e94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 99 additions and 16 deletions

View file

@ -155,6 +155,9 @@ bevy_winit = ["bevy_internal/bevy_winit"]
# Adds support for rendering gizmos # Adds support for rendering gizmos
bevy_gizmos = ["bevy_internal/bevy_gizmos", "bevy_color"] bevy_gizmos = ["bevy_internal/bevy_gizmos", "bevy_color"]
# Provides a collection of developer tools
bevy_dev_tools = ["bevy_internal/bevy_dev_tools"]
# Tracing support, saving a file in Chrome Tracing format # Tracing support, saving a file in Chrome Tracing format
trace_chrome = ["trace", "bevy_internal/trace_chrome"] trace_chrome = ["trace", "bevy_internal/trace_chrome"]

View file

@ -10,7 +10,6 @@ keywords = ["bevy"]
[features] [features]
trace = [] trace = []
bevy_ci_testing = ["serde", "ron"]
bevy_debug_stepping = [] bevy_debug_stepping = []
default = ["bevy_reflect", "bevy_debug_stepping"] default = ["bevy_reflect", "bevy_debug_stepping"]
bevy_reflect = ["dep:bevy_reflect", "bevy_ecs/bevy_reflect"] bevy_reflect = ["dep:bevy_reflect", "bevy_ecs/bevy_reflect"]

View file

@ -188,11 +188,6 @@ impl Default for App {
app.add_event::<AppExit>(); app.add_event::<AppExit>();
#[cfg(feature = "bevy_ci_testing")]
{
crate::ci_testing::setup_app(&mut app);
}
app app
} }
} }

View file

@ -6,9 +6,6 @@ mod plugin;
mod plugin_group; mod plugin_group;
mod schedule_runner; mod schedule_runner;
#[cfg(feature = "bevy_ci_testing")]
pub mod ci_testing;
pub use app::*; pub use app::*;
pub use bevy_derive::DynamicPlugin; pub use bevy_derive::DynamicPlugin;
pub use main_schedule::*; pub use main_schedule::*;

View file

@ -0,0 +1,25 @@
[package]
name = "bevy_dev_tools"
version = "0.14.0-dev"
edition = "2021"
description = "Collection of developer tools for the Bevy Engine"
homepage = "https://bevyengine.org"
repository = "https://github.com/bevyengine/bevy"
license = "MIT OR Apache-2.0"
keywords = ["bevy"]
[features]
bevy_ci_testing = ["serde", "ron"]
[dependencies]
# bevy
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
# other
serde = { version = "1.0", features = ["derive"], optional = true }
ron = { version = "0.8.0", optional = true }
[lints]
workspace = true

View file

@ -1,6 +1,6 @@
//! Utilities for testing in CI environments. //! Utilities for testing in CI environments.
use crate::{app::AppExit, App, Update}; use bevy_app::{App, AppExit, Update};
use serde::Deserialize; use serde::Deserialize;
use bevy_ecs::prelude::Resource; use bevy_ecs::prelude::Resource;

View file

@ -0,0 +1,44 @@
//! This crate provides additional utilities for the [Bevy game engine](https://bevyengine.org),
//! focused on improving developer experience.
use bevy_app::prelude::*;
#[cfg(feature = "bevy_ci_testing")]
pub mod ci_testing;
/// Enables developer tools in an [`App`]. This plugin is added automatically with `bevy_dev_tools`
/// feature.
///
/// Warning: It is not recommended to enable this in final shipped games or applications.
/// Dev tools provide a high level of access to the internals of your application,
/// and may interfere with ordinary use and gameplay.
///
/// To enable developer tools, you can either:
///
/// - Create a custom crate feature (e.g "`dev_mode`"), which enables the `bevy_dev_tools` feature
/// along with any other development tools you might be using:
///
/// ```toml
/// [feature]
/// dev_mode = ["bevy/bevy_dev_tools", "other_dev_tools"]
/// ```
///
/// - Use `--feature bevy/bevy_dev_tools` flag when using the `cargo run` command:
///
/// `cargo run --features bevy/bevy_dev_tools`
///
/// - Add the `bevy_dev_tools` feature to the bevy dependency in your `Cargo.toml` file:
///
/// `features = ["bevy_dev_tools"]`
///
/// Note: The third method is not recommended, as it requires you to remove the feature before
/// creating a build for release to the public.
pub struct DevToolsPlugin;
impl Plugin for DevToolsPlugin {
fn build(&self, _app: &mut App) {
#[cfg(feature = "bevy_ci_testing")]
{
ci_testing::setup_app(_app);
}
}
}

View file

@ -114,7 +114,7 @@ webgpu = [
# enable systems that allow for automated testing on CI # enable systems that allow for automated testing on CI
bevy_ci_testing = [ bevy_ci_testing = [
"bevy_app/bevy_ci_testing", "bevy_dev_tools/bevy_ci_testing",
"bevy_time/bevy_ci_testing", "bevy_time/bevy_ci_testing",
"bevy_render?/bevy_ci_testing", "bevy_render?/bevy_ci_testing",
"bevy_render?/ci_limits", "bevy_render?/ci_limits",
@ -163,6 +163,9 @@ bevy_debug_stepping = [
"bevy_app/bevy_debug_stepping", "bevy_app/bevy_debug_stepping",
] ]
# Provides a collection of developer tools
bevy_dev_tools = ["dep:bevy_dev_tools"]
# Enable support for the ios_simulator by downgrading some rendering capabilities # Enable support for the ios_simulator by downgrading some rendering capabilities
ios_simulator = ["bevy_pbr?/ios_simulator", "bevy_render?/ios_simulator"] ios_simulator = ["bevy_pbr?/ios_simulator", "bevy_render?/ios_simulator"]
@ -204,6 +207,7 @@ bevy_ui = { path = "../bevy_ui", optional = true, version = "0.14.0-dev" }
bevy_winit = { path = "../bevy_winit", optional = true, version = "0.14.0-dev" } bevy_winit = { path = "../bevy_winit", optional = true, version = "0.14.0-dev" }
bevy_gilrs = { path = "../bevy_gilrs", optional = true, version = "0.14.0-dev" } bevy_gilrs = { path = "../bevy_gilrs", optional = true, version = "0.14.0-dev" }
bevy_gizmos = { path = "../bevy_gizmos", optional = true, version = "0.14.0-dev", default-features = false } bevy_gizmos = { path = "../bevy_gizmos", optional = true, version = "0.14.0-dev", default-features = false }
bevy_dev_tools = { path = "../bevy_dev_tools/", optional = true, version = "0.14.0-dev" }
[lints] [lints]
workspace = true workspace = true

View file

@ -27,6 +27,7 @@ use bevy_app::{Plugin, PluginGroup, PluginGroupBuilder};
/// * [`AudioPlugin`](crate::audio::AudioPlugin) - with feature `bevy_audio` /// * [`AudioPlugin`](crate::audio::AudioPlugin) - with feature `bevy_audio`
/// * [`GilrsPlugin`](crate::gilrs::GilrsPlugin) - with feature `bevy_gilrs` /// * [`GilrsPlugin`](crate::gilrs::GilrsPlugin) - with feature `bevy_gilrs`
/// * [`AnimationPlugin`](crate::animation::AnimationPlugin) - with feature `bevy_animation` /// * [`AnimationPlugin`](crate::animation::AnimationPlugin) - with feature `bevy_animation`
/// * [`DevToolsPlugin`](crate::dev_tools::DevToolsPlugin) - with feature `bevy_dev_tools`
/// ///
/// [`DefaultPlugins`] obeys *Cargo* *feature* flags. Users may exert control over this plugin group /// [`DefaultPlugins`] obeys *Cargo* *feature* flags. Users may exert control over this plugin group
/// by disabling `default-features` in their `Cargo.toml` and enabling only those features /// by disabling `default-features` in their `Cargo.toml` and enabling only those features
@ -134,6 +135,11 @@ impl PluginGroup for DefaultPlugins {
group = group.add(bevy_gizmos::GizmoPlugin); group = group.add(bevy_gizmos::GizmoPlugin);
} }
#[cfg(feature = "bevy_dev_tools")]
{
group = group.add(bevy_dev_tools::DevToolsPlugin);
}
group = group.add(IgnoreAmbiguitiesPlugin); group = group.add(IgnoreAmbiguitiesPlugin);
group group

View file

@ -199,3 +199,9 @@ pub mod dynamic_plugin {
//! Dynamic linking of plugins //! Dynamic linking of plugins
pub use bevy_dynamic_plugin::*; pub use bevy_dynamic_plugin::*;
} }
#[cfg(feature = "bevy_dev_tools")]
pub mod dev_tools {
//! Collection of developer tools
pub use bevy_dev_tools::*;
}

View file

@ -19,7 +19,7 @@ webp = ["image/webp"]
dds = ["ddsfile"] dds = ["ddsfile"]
pnm = ["image/pnm"] pnm = ["image/pnm"]
multi-threaded = ["bevy_tasks/multi-threaded"] multi-threaded = ["bevy_tasks/multi-threaded"]
bevy_ci_testing = ["bevy_app/bevy_ci_testing"] bevy_ci_testing = ["bevy_dev_tools/bevy_ci_testing"]
shader_format_glsl = ["naga/glsl-in", "naga/wgsl-out", "naga_oil/glsl"] shader_format_glsl = ["naga/glsl-in", "naga/wgsl-out", "naga_oil/glsl"]
shader_format_spirv = ["wgpu/spirv", "naga/spv-in", "naga/spv-out"] shader_format_spirv = ["wgpu/spirv", "naga/spv-in", "naga/spv-out"]
@ -57,6 +57,7 @@ bevy_transform = { path = "../bevy_transform", version = "0.14.0-dev" }
bevy_window = { path = "../bevy_window", version = "0.14.0-dev" } bevy_window = { path = "../bevy_window", version = "0.14.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" } bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" }
bevy_dev_tools = { path = "../bevy_dev_tools", version = "0.14.0-dev", optional = true }
# rendering # rendering
image = { version = "0.24", default-features = false } image = { version = "0.24", default-features = false }

View file

@ -144,7 +144,7 @@ impl Plugin for ScreenshotPlugin {
#[cfg(feature = "bevy_ci_testing")] #[cfg(feature = "bevy_ci_testing")]
if app if app
.world .world
.contains_resource::<bevy_app::ci_testing::CiTestingConfig>() .contains_resource::<bevy_dev_tools::ci_testing::CiTestingConfig>()
{ {
app.add_systems(bevy_app::Update, ci_testing_screenshot_at); app.add_systems(bevy_app::Update, ci_testing_screenshot_at);
} }
@ -154,7 +154,7 @@ impl Plugin for ScreenshotPlugin {
#[cfg(feature = "bevy_ci_testing")] #[cfg(feature = "bevy_ci_testing")]
fn ci_testing_screenshot_at( fn ci_testing_screenshot_at(
mut current_frame: Local<u32>, mut current_frame: Local<u32>,
ci_testing_config: Res<bevy_app::ci_testing::CiTestingConfig>, ci_testing_config: Res<bevy_dev_tools::ci_testing::CiTestingConfig>,
mut screenshot_manager: ResMut<ScreenshotManager>, mut screenshot_manager: ResMut<ScreenshotManager>,
main_window: Query<Entity, With<bevy_window::PrimaryWindow>>, main_window: Query<Entity, With<bevy_window::PrimaryWindow>>,
) { ) {

View file

@ -11,7 +11,7 @@ keywords = ["bevy"]
[features] [features]
default = [] default = []
serialize = ["serde"] serialize = ["serde"]
bevy_ci_testing = ["bevy_app/bevy_ci_testing"] bevy_ci_testing = ["bevy_dev_tools/bevy_ci_testing"]
[dependencies] [dependencies]
# bevy # bevy
@ -23,6 +23,7 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [
"bevy", "bevy",
] } ] }
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
bevy_dev_tools = { path = "../bevy_dev_tools", version = "0.14.0-dev", optional = true }
# other # other
crossbeam-channel = "0.5.0" crossbeam-channel = "0.5.0"

View file

@ -68,7 +68,7 @@ impl Plugin for TimePlugin {
#[cfg(feature = "bevy_ci_testing")] #[cfg(feature = "bevy_ci_testing")]
if let Some(ci_testing_config) = app if let Some(ci_testing_config) = app
.world .world
.get_resource::<bevy_app::ci_testing::CiTestingConfig>() .get_resource::<bevy_dev_tools::ci_testing::CiTestingConfig>()
{ {
if let Some(frame_time) = ci_testing_config.frame_time { if let Some(frame_time) = ci_testing_config.frame_time {
app.world app.world

View file

@ -50,6 +50,7 @@ The default feature set enables most of the expected features of a game engine,
|async-io|Use async-io's implementation of block_on instead of futures-lite's implementation. This is preferred if your application uses async-io.| |async-io|Use async-io's implementation of block_on instead of futures-lite's implementation. This is preferred if your application uses async-io.|
|basis-universal|Basis Universal compressed texture support| |basis-universal|Basis Universal compressed texture support|
|bevy_ci_testing|Enable systems that allow for automated testing on CI| |bevy_ci_testing|Enable systems that allow for automated testing on CI|
|bevy_dev_tools|Provides a collection of developer tools|
|bevy_dynamic_plugin|Plugin for dynamic loading (using [libloading](https://crates.io/crates/libloading))| |bevy_dynamic_plugin|Plugin for dynamic loading (using [libloading](https://crates.io/crates/libloading))|
|bmp|BMP image format support| |bmp|BMP image format support|
|dds|DDS compressed texture support| |dds|DDS compressed texture support|

View file

@ -41,6 +41,7 @@ crates=(
bevy_a11y bevy_a11y
bevy_ui bevy_ui
bevy_winit bevy_winit
bevy_dev_tools
bevy_internal bevy_internal
bevy_dylib bevy_dylib
bevy_color bevy_color