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 <alice.i.cecile@gmail.com>
This commit is contained in:
Gabriel Kwong 2024-03-28 19:04:56 -07:00 committed by GitHub
parent ac4b9beb00
commit d8383fb535
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 10 additions and 44 deletions

View File

@ -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

View File

@ -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::*;

View File

@ -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::<PanicHandlerPlugin>())

View File

@ -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 = [

View File

@ -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::<Self>();
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)

View File

@ -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::*;

View File

@ -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