Skip to content

Commit

Permalink
Add bevy_dev_tools crate (bevyengine#11341)
Browse files Browse the repository at this point in the history
# Objective

- Resolves bevyengine#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 <[email protected]>
Co-authored-by: BD103 <[email protected]>
  • Loading branch information
3 people authored and spectria-limina committed Mar 9, 2024
1 parent 72fc7da commit 306e686
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ bevy_winit = ["bevy_internal/bevy_winit"]
# Adds support for rendering gizmos
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
trace_chrome = ["trace", "bevy_internal/trace_chrome"]

Expand Down
1 change: 0 additions & 1 deletion crates/bevy_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ keywords = ["bevy"]

[features]
trace = []
bevy_ci_testing = ["serde", "ron"]
bevy_debug_stepping = []
default = ["bevy_reflect", "bevy_debug_stepping"]
bevy_reflect = ["dep:bevy_reflect", "bevy_ecs/bevy_reflect"]
Expand Down
5 changes: 0 additions & 5 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@ impl Default for App {

app.add_event::<AppExit>();

#[cfg(feature = "bevy_ci_testing")]
{
crate::ci_testing::setup_app(&mut app);
}

app
}
}
Expand Down
3 changes: 0 additions & 3 deletions crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ mod plugin;
mod plugin_group;
mod schedule_runner;

#[cfg(feature = "bevy_ci_testing")]
pub mod ci_testing;

pub use app::*;
pub use bevy_derive::DynamicPlugin;
pub use main_schedule::*;
Expand Down
25 changes: 25 additions & 0 deletions crates/bevy_dev_tools/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Utilities for testing in CI environments.
use crate::{app::AppExit, App, Update};
use bevy_app::{App, AppExit, Update};
use serde::Deserialize;

use bevy_ecs::prelude::Resource;
Expand Down
44 changes: 44 additions & 0 deletions crates/bevy_dev_tools/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
6 changes: 5 additions & 1 deletion crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ webgpu = [

# enable systems that allow for automated testing on CI
bevy_ci_testing = [
"bevy_app/bevy_ci_testing",
"bevy_dev_tools/bevy_ci_testing",
"bevy_time/bevy_ci_testing",
"bevy_render?/bevy_ci_testing",
"bevy_render?/ci_limits",
Expand Down Expand Up @@ -163,6 +163,9 @@ 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
ios_simulator = ["bevy_pbr?/ios_simulator", "bevy_render?/ios_simulator"]

Expand Down Expand Up @@ -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_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_dev_tools = { path = "../bevy_dev_tools/", optional = true, version = "0.14.0-dev" }

[lints]
workspace = true
6 changes: 6 additions & 0 deletions crates/bevy_internal/src/default_plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use bevy_app::{Plugin, PluginGroup, PluginGroupBuilder};
/// * [`AudioPlugin`](crate::audio::AudioPlugin) - with feature `bevy_audio`
/// * [`GilrsPlugin`](crate::gilrs::GilrsPlugin) - with feature `bevy_gilrs`
/// * [`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
/// by disabling `default-features` in their `Cargo.toml` and enabling only those features
Expand Down Expand Up @@ -134,6 +135,11 @@ impl PluginGroup for DefaultPlugins {
group = group.add(bevy_gizmos::GizmoPlugin);
}

#[cfg(feature = "bevy_dev_tools")]
{
group = group.add(bevy_dev_tools::DevToolsPlugin);
}

group = group.add(IgnoreAmbiguitiesPlugin);

group
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,9 @@ pub mod dynamic_plugin {
//! Dynamic linking of plugins
pub use bevy_dynamic_plugin::*;
}

#[cfg(feature = "bevy_dev_tools")]
pub mod dev_tools {
//! Collection of developer tools
pub use bevy_dev_tools::*;
}
3 changes: 2 additions & 1 deletion crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ webp = ["image/webp"]
dds = ["ddsfile"]
pnm = ["image/pnm"]
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_spirv = ["wgpu/spirv", "naga/spv-in", "naga/spv-out"]
Expand Down Expand Up @@ -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_utils = { path = "../bevy_utils", 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
image = { version = "0.24", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/view/window/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Plugin for ScreenshotPlugin {
#[cfg(feature = "bevy_ci_testing")]
if app
.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);
}
Expand All @@ -154,7 +154,7 @@ impl Plugin for ScreenshotPlugin {
#[cfg(feature = "bevy_ci_testing")]
fn ci_testing_screenshot_at(
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>,
main_window: Query<Entity, With<bevy_window::PrimaryWindow>>,
) {
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = ["bevy"]
[features]
default = []
serialize = ["serde"]
bevy_ci_testing = ["bevy_app/bevy_ci_testing"]
bevy_ci_testing = ["bevy_dev_tools/bevy_ci_testing"]

[dependencies]
# bevy
Expand All @@ -23,6 +23,7 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [
"bevy",
] }
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
crossbeam-channel = "0.5.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_time/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Plugin for TimePlugin {
#[cfg(feature = "bevy_ci_testing")]
if let Some(ci_testing_config) = app
.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 {
app.world
Expand Down
1 change: 1 addition & 0 deletions docs/cargo_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.|
|basis-universal|Basis Universal compressed texture support|
|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))|
|bmp|BMP image format support|
|dds|DDS compressed texture support|
Expand Down
1 change: 1 addition & 0 deletions tools/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ crates=(
bevy_a11y
bevy_ui
bevy_winit
bevy_dev_tools
bevy_internal
bevy_dylib
bevy_color
Expand Down

0 comments on commit 306e686

Please sign in to comment.