From d8383fb5358bd0097d2482115f4eddace6d8f137 Mon Sep 17 00:00:00 2001 From: Gabriel Kwong Date: Thu, 28 Mar 2024 19:04:56 -0700 Subject: [PATCH] Move PanicHandlerPlugin into bevy_app (#12640) # Objective - Move `PanicHandlerPlugin` into `bevy_app` - Fixes #12603 . ## Solution - I moved the `bevy_panic_handler` into `bevy_app` - Copy pasted `bevy_panic_handler`'s lib.rs into a separate module in `bevy_app` as a `panic_handler.rs` module file and added the `PanicHandlerPlugin` in lib.rs of `bevy_app` - added the dependency into `cargo.toml` ## Review notes - I probably want some feedback if I imported App and Plugin correctly in `panic_handler.rs` line 10 and 11. - As of yet I have not deleted `bevy_panic_handler` crate, wanted to get a check if I added it correctly. - Once validated that my move was correct, I'll probably have to remove the panic handler find default plugins which I probably need some help to find. - And then remove bevy panic_handler and making sure ci passes. - This is my first issue for contributing to bevy so let me know if I am doing anything wrong. ## tools context - rust is 1.76 version - Windows 11 --------- Co-authored-by: Alice Cecile --- crates/bevy_app/Cargo.toml | 1 + crates/bevy_app/src/lib.rs | 2 ++ .../lib.rs => bevy_app/src/panic_handler.rs} | 17 ++++--------- crates/bevy_internal/Cargo.toml | 1 - crates/bevy_internal/src/default_plugins.rs | 4 ++-- crates/bevy_internal/src/lib.rs | 5 ---- crates/bevy_panic_handler/Cargo.toml | 24 ------------------- 7 files changed, 10 insertions(+), 44 deletions(-) rename crates/{bevy_panic_handler/src/lib.rs => bevy_app/src/panic_handler.rs} (80%) delete mode 100644 crates/bevy_panic_handler/Cargo.toml diff --git a/crates/bevy_app/Cargo.toml b/crates/bevy_app/Cargo.toml index 984518d1ccdc6..15f511ceb30a2 100644 --- a/crates/bevy_app/Cargo.toml +++ b/crates/bevy_app/Cargo.toml @@ -31,6 +31,7 @@ thiserror = "1.0" [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen = { version = "0.2" } web-sys = { version = "0.3", features = ["Window"] } +console_error_panic_hook = "0.1.6" [lints] workspace = true diff --git a/crates/bevy_app/src/lib.rs b/crates/bevy_app/src/lib.rs index d231780c4ae7f..232c3e801e73a 100644 --- a/crates/bevy_app/src/lib.rs +++ b/crates/bevy_app/src/lib.rs @@ -9,6 +9,7 @@ mod app; mod main_schedule; +mod panic_handler; mod plugin; mod plugin_group; mod schedule_runner; @@ -16,6 +17,7 @@ mod schedule_runner; pub use app::*; pub use bevy_derive::DynamicPlugin; pub use main_schedule::*; +pub use panic_handler::*; pub use plugin::*; pub use plugin_group::*; pub use schedule_runner::*; diff --git a/crates/bevy_panic_handler/src/lib.rs b/crates/bevy_app/src/panic_handler.rs similarity index 80% rename from crates/bevy_panic_handler/src/lib.rs rename to crates/bevy_app/src/panic_handler.rs index 398877f595b66..d66062e104f41 100644 --- a/crates/bevy_panic_handler/src/lib.rs +++ b/crates/bevy_app/src/panic_handler.rs @@ -1,10 +1,4 @@ -#![cfg_attr(docsrs, feature(doc_auto_cfg))] -#![doc( - html_logo_url = "https://bevyengine.org/assets/icon.png", - html_favicon_url = "https://bevyengine.org/assets/icon.png" -)] - -//! This crate provides panic handlers for [Bevy](https://bevyengine.org) +//! This module provides panic handlers for [Bevy](https://bevyengine.org) //! apps, and automatically configures platform specifics (i.e. WASM or Android). //! //! By default, the [`PanicHandlerPlugin`] from this crate is included in Bevy's `DefaultPlugins`. @@ -12,7 +6,8 @@ //! For more fine-tuned control over panic behavior, disable the [`PanicHandlerPlugin`] or //! `DefaultPlugins` during app initialization. -use bevy_app::{App, Plugin}; +use crate::App; +use crate::Plugin; /// Adds sensible panic handlers to Apps. This plugin is part of the `DefaultPlugins`. Adding /// this plugin will setup a panic hook appropriate to your target platform: @@ -21,8 +16,7 @@ use bevy_app::{App, Plugin}; /// * Other platforms are currently not setup. /// /// ```no_run -/// # use bevy_app::{App, NoopPluginGroup as MinimalPlugins, PluginGroup}; -/// # use bevy_panic_handler::PanicHandlerPlugin; +/// # use bevy_app::{App, NoopPluginGroup as MinimalPlugins, PluginGroup, PanicHandlerPlugin}; /// fn main() { /// App::new() /// .add_plugins(MinimalPlugins) @@ -34,8 +28,7 @@ use bevy_app::{App, Plugin}; /// If you want to setup your own panic handler, you should disable this /// plugin from `DefaultPlugins`: /// ```no_run -/// # use bevy_app::{App, NoopPluginGroup as DefaultPlugins, PluginGroup}; -/// # use bevy_panic_handler::PanicHandlerPlugin; +/// # use bevy_app::{App, NoopPluginGroup as DefaultPlugins, PluginGroup, PanicHandlerPlugin}; /// fn main() { /// App::new() /// .add_plugins(DefaultPlugins.build().disable::()) diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 4520256258c2d..25476de016e50 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -182,7 +182,6 @@ bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" } bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.14.0-dev" } bevy_input = { path = "../bevy_input", version = "0.14.0-dev" } bevy_log = { path = "../bevy_log", version = "0.14.0-dev" } -bevy_panic_handler = { path = "../bevy_panic_handler", version = "0.14.0-dev" } bevy_math = { path = "../bevy_math", version = "0.14.0-dev" } bevy_ptr = { path = "../bevy_ptr", version = "0.14.0-dev" } bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [ diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index fdc33428e58eb..14e04238c9ec5 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -1,7 +1,7 @@ use bevy_app::{Plugin, PluginGroup, PluginGroupBuilder}; /// This plugin group will add all the default plugins for a *Bevy* application: -/// * [`PanicHandlerPlugin`](crate::panic_handler::PanicHandlerPlugin) +/// * [`PanicHandlerPlugin`](crate::app::PanicHandlerPlugin) /// * [`LogPlugin`](crate::log::LogPlugin) /// * [`TaskPoolPlugin`](crate::core::TaskPoolPlugin) /// * [`TypeRegistrationPlugin`](crate::core::TypeRegistrationPlugin) @@ -43,7 +43,7 @@ impl PluginGroup for DefaultPlugins { fn build(self) -> PluginGroupBuilder { let mut group = PluginGroupBuilder::start::(); group = group - .add(bevy_panic_handler::PanicHandlerPlugin) + .add(bevy_app::PanicHandlerPlugin) .add(bevy_log::LogPlugin::default()) .add(bevy_core::TaskPoolPlugin::default()) .add(bevy_core::TypeRegistrationPlugin) diff --git a/crates/bevy_internal/src/lib.rs b/crates/bevy_internal/src/lib.rs index 5bb91b57aee60..944502e484163 100644 --- a/crates/bevy_internal/src/lib.rs +++ b/crates/bevy_internal/src/lib.rs @@ -60,11 +60,6 @@ pub mod log { pub use bevy_log::*; } -pub mod panic_handler { - //! Platform-specific panic handlers - pub use bevy_panic_handler::*; -} - pub mod math { //! Math types (Vec3, Mat4, Quat, etc) and helpers. pub use bevy_math::*; diff --git a/crates/bevy_panic_handler/Cargo.toml b/crates/bevy_panic_handler/Cargo.toml deleted file mode 100644 index 5a99d2bd338be..0000000000000 --- a/crates/bevy_panic_handler/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "bevy_panic_handler" -version = "0.14.0-dev" -edition = "2021" -description = "Provides panic handlers for Bevy Engine" -homepage = "https://bevyengine.org" -repository = "https://github.com/bevyengine/bevy" -license = "MIT OR Apache-2.0" -keywords = ["bevy"] - -[features] - -[dependencies] -bevy_app = { path = "../bevy_app", version = "0.14.0-dev" } - -[target.'cfg(target_arch = "wasm32")'.dependencies] -console_error_panic_hook = "0.1.6" - -[lints] -workspace = true - -[package.metadata.docs.rs] -rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] -all-features = true