From 6533170e9447df61f84010fa233aa0f30e5bf298 Mon Sep 17 00:00:00 2001 From: Mateusz Wachowiak Date: Wed, 6 Mar 2024 21:33:05 +0100 Subject: [PATCH] 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 Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com> --- Cargo.toml | 3 ++ crates/bevy_app/Cargo.toml | 1 - crates/bevy_app/src/app.rs | 5 --- crates/bevy_app/src/lib.rs | 3 -- crates/bevy_dev_tools/Cargo.toml | 25 +++++++++++ .../src/ci_testing.rs | 2 +- crates/bevy_dev_tools/src/lib.rs | 44 +++++++++++++++++++ crates/bevy_internal/Cargo.toml | 6 ++- crates/bevy_internal/src/default_plugins.rs | 6 +++ crates/bevy_internal/src/lib.rs | 6 +++ crates/bevy_render/Cargo.toml | 3 +- .../bevy_render/src/view/window/screenshot.rs | 4 +- crates/bevy_time/Cargo.toml | 3 +- crates/bevy_time/src/lib.rs | 2 +- docs/cargo_features.md | 1 + tools/publish.sh | 1 + 16 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 crates/bevy_dev_tools/Cargo.toml rename crates/{bevy_app => bevy_dev_tools}/src/ci_testing.rs (98%) create mode 100644 crates/bevy_dev_tools/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index d95f1b6d7f..dd9a56d466 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/crates/bevy_app/Cargo.toml b/crates/bevy_app/Cargo.toml index 020245b644..e42d986f1a 100644 --- a/crates/bevy_app/Cargo.toml +++ b/crates/bevy_app/Cargo.toml @@ -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"] diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index f08a3e73bd..f339b5d800 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -188,11 +188,6 @@ impl Default for App { app.add_event::(); - #[cfg(feature = "bevy_ci_testing")] - { - crate::ci_testing::setup_app(&mut app); - } - app } } diff --git a/crates/bevy_app/src/lib.rs b/crates/bevy_app/src/lib.rs index 8f6ba7972f..721cf1618a 100644 --- a/crates/bevy_app/src/lib.rs +++ b/crates/bevy_app/src/lib.rs @@ -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::*; diff --git a/crates/bevy_dev_tools/Cargo.toml b/crates/bevy_dev_tools/Cargo.toml new file mode 100644 index 0000000000..eb6597d8bd --- /dev/null +++ b/crates/bevy_dev_tools/Cargo.toml @@ -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 diff --git a/crates/bevy_app/src/ci_testing.rs b/crates/bevy_dev_tools/src/ci_testing.rs similarity index 98% rename from crates/bevy_app/src/ci_testing.rs rename to crates/bevy_dev_tools/src/ci_testing.rs index 3ba0dde78e..db2d4a14fc 100644 --- a/crates/bevy_app/src/ci_testing.rs +++ b/crates/bevy_dev_tools/src/ci_testing.rs @@ -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; diff --git a/crates/bevy_dev_tools/src/lib.rs b/crates/bevy_dev_tools/src/lib.rs new file mode 100644 index 0000000000..b025539ebb --- /dev/null +++ b/crates/bevy_dev_tools/src/lib.rs @@ -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); + } + } +} diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index da98324894..0ea6362ee3 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -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", @@ -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"] @@ -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 diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index c0869a2490..08d68b0fdc 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -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 @@ -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 diff --git a/crates/bevy_internal/src/lib.rs b/crates/bevy_internal/src/lib.rs index 25a2584c7d..896091c404 100644 --- a/crates/bevy_internal/src/lib.rs +++ b/crates/bevy_internal/src/lib.rs @@ -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::*; +} diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index 84b58b0003..7e9012d99d 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -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"] @@ -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 } diff --git a/crates/bevy_render/src/view/window/screenshot.rs b/crates/bevy_render/src/view/window/screenshot.rs index ca93f73afd..b51c4f4797 100644 --- a/crates/bevy_render/src/view/window/screenshot.rs +++ b/crates/bevy_render/src/view/window/screenshot.rs @@ -144,7 +144,7 @@ impl Plugin for ScreenshotPlugin { #[cfg(feature = "bevy_ci_testing")] if app .world - .contains_resource::() + .contains_resource::() { app.add_systems(bevy_app::Update, ci_testing_screenshot_at); } @@ -154,7 +154,7 @@ impl Plugin for ScreenshotPlugin { #[cfg(feature = "bevy_ci_testing")] fn ci_testing_screenshot_at( mut current_frame: Local, - ci_testing_config: Res, + ci_testing_config: Res, mut screenshot_manager: ResMut, main_window: Query>, ) { diff --git a/crates/bevy_time/Cargo.toml b/crates/bevy_time/Cargo.toml index beb9d0db56..5b586ebab3 100644 --- a/crates/bevy_time/Cargo.toml +++ b/crates/bevy_time/Cargo.toml @@ -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 @@ -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" diff --git a/crates/bevy_time/src/lib.rs b/crates/bevy_time/src/lib.rs index e5c0a40797..c94e6f46db 100644 --- a/crates/bevy_time/src/lib.rs +++ b/crates/bevy_time/src/lib.rs @@ -68,7 +68,7 @@ impl Plugin for TimePlugin { #[cfg(feature = "bevy_ci_testing")] if let Some(ci_testing_config) = app .world - .get_resource::() + .get_resource::() { if let Some(frame_time) = ci_testing_config.frame_time { app.world diff --git a/docs/cargo_features.md b/docs/cargo_features.md index e82d98adf8..c5bf29bd20 100644 --- a/docs/cargo_features.md +++ b/docs/cargo_features.md @@ -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| diff --git a/tools/publish.sh b/tools/publish.sh index 3bb2f9b09c..d9b63ddde8 100644 --- a/tools/publish.sh +++ b/tools/publish.sh @@ -41,6 +41,7 @@ crates=( bevy_a11y bevy_ui bevy_winit + bevy_dev_tools bevy_internal bevy_dylib bevy_color