Skip to content

Commit e64efd3

Browse files
committed
Remove the dependency cycles (#5171)
# Objective - I think our codebase is hit badly by rust-lang/rust-analyzer#11410 - None of our uses of cyclic dependencies are remotely necessary - Note that these are false positives in rust-analyzer, however it's probably easier for us to work around this - Note also that I haven't confirmed that this is causing rust-analyzer to not work very well, but it's not a bad guess. ## Solution - Remove our cyclic dependencies - Import the trick from #2851 for no-op plugin groups.
1 parent 3a102e7 commit e64efd3

File tree

7 files changed

+41
-29
lines changed

7 files changed

+41
-29
lines changed

crates/bevy_app/Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,3 @@ ron = { version = "0.7.0", optional = true }
3131
wasm-bindgen = { version = "0.2" }
3232
web-sys = { version = "0.3", features = [ "Window" ] }
3333

34-
[dev-dependencies]
35-
# bevy
36-
bevy_log = { path = "../bevy_log", version = "0.8.0-dev" }

crates/bevy_app/src/app.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,16 @@ impl App {
761761
/// ```
762762
/// # use bevy_app::prelude::*;
763763
/// #
764+
/// # // Dummies created to avoid using `bevy_log`,
765+
/// # // which pulls in too many dependencies and breaks rust-analyzer
766+
/// # pub mod bevy_log {
767+
/// # use bevy_app::prelude::*;
768+
/// # #[derive(Default)]
769+
/// # pub struct LogPlugin;
770+
/// # impl Plugin for LogPlugin{
771+
/// # fn build(&self, app: &mut App) {}
772+
/// # }
773+
/// # }
764774
/// App::new().add_plugin(bevy_log::LogPlugin::default());
765775
/// ```
766776
pub fn add_plugin<T>(&mut self, plugin: T) -> &mut Self
@@ -784,13 +794,7 @@ impl App {
784794
///
785795
/// ## Examples
786796
/// ```
787-
/// # use bevy_app::{prelude::*, PluginGroupBuilder};
788-
/// #
789-
/// # // Dummy created to avoid using bevy_internal, which pulls in to many dependencies.
790-
/// # struct MinimalPlugins;
791-
/// # impl PluginGroup for MinimalPlugins {
792-
/// # fn build(&mut self, group: &mut PluginGroupBuilder){;}
793-
/// # }
797+
/// # use bevy_app::{prelude::*, PluginGroupBuilder, NoopPluginGroup as MinimalPlugins};
794798
/// #
795799
/// App::new()
796800
/// .add_plugins(MinimalPlugins);
@@ -814,7 +818,16 @@ impl App {
814818
/// ```
815819
/// # use bevy_app::{prelude::*, PluginGroupBuilder};
816820
/// #
817-
/// # // Dummies created to avoid using bevy_internal which pulls in too many dependencies.
821+
/// # // Dummies created to avoid using `bevy_internal` and `bevy_log`,
822+
/// # // which pulls in too many dependencies and breaks rust-analyzer
823+
/// # pub mod bevy_log {
824+
/// # use bevy_app::prelude::*;
825+
/// # #[derive(Default)]
826+
/// # pub struct LogPlugin;
827+
/// # impl Plugin for LogPlugin{
828+
/// # fn build(&self, app: &mut App) {}
829+
/// # }
830+
/// # }
818831
/// # struct DefaultPlugins;
819832
/// # impl PluginGroup for DefaultPlugins {
820833
/// # fn build(&mut self, group: &mut PluginGroupBuilder){

crates/bevy_app/src/plugin_group.rs

+16
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ impl PluginGroupBuilder {
139139
}
140140
}
141141

142+
/// A plugin group which doesn't do anything. Useful for examples:
143+
/// ```rust
144+
/// # use bevy_app::prelude::*;
145+
/// use bevy_app::NoopPluginGroup as MinimalPlugins;
146+
///
147+
/// fn main(){
148+
/// App::new().add_plugins(MinimalPlugins).run();
149+
/// }
150+
/// ```
151+
#[doc(hidden)]
152+
pub struct NoopPluginGroup;
153+
154+
impl PluginGroup for NoopPluginGroup {
155+
fn build(&mut self, _: &mut PluginGroupBuilder) {}
156+
}
157+
142158
#[cfg(test)]
143159
mod tests {
144160
use super::PluginGroupBuilder;

crates/bevy_audio/Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ parking_lot = "0.11.0"
2424
[target.'cfg(target_arch = "wasm32")'.dependencies]
2525
rodio = { version = "0.15", default-features = false, features = ["wasm-bindgen"] }
2626

27-
[dev-dependencies]
28-
# bevy
29-
bevy_internal = { path = "../bevy_internal", version = "0.8.0-dev" }
3027

3128
[features]
3229
mp3 = ["rodio/mp3"]

crates/bevy_audio/src/lib.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
//! Audio support for the game engine Bevy
22
//!
3-
//! ```
3+
//! ```no_run
44
//! # use bevy_ecs::{system::Res, event::EventWriter};
55
//! # use bevy_audio::{Audio, AudioPlugin};
66
//! # use bevy_asset::{AssetPlugin, AssetServer};
7-
//! # use bevy_app::{App, AppExit};
8-
//! # use bevy_internal::MinimalPlugins;
7+
//! # use bevy_app::{App, AppExit, NoopPluginGroup as MinimalPlugins};
98
//! fn main() {
109
//! App::new()
1110
//! .add_plugins(MinimalPlugins)
1211
//! .add_plugin(AssetPlugin)
1312
//! .add_plugin(AudioPlugin)
14-
//! # .add_system(stop)
1513
//! .add_startup_system(play_background_audio)
1614
//! .run();
1715
//! }
1816
//!
1917
//! fn play_background_audio(asset_server: Res<AssetServer>, audio: Res<Audio>) {
2018
//! audio.play(asset_server.load("background_audio.ogg"));
2119
//! }
22-
//!
23-
//! # fn stop(mut events: EventWriter<AppExit>) {
24-
//! # events.send(AppExit)
25-
//! # }
2620
//! ```
2721
2822
#![forbid(unsafe_code)]

crates/bevy_log/Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,3 @@ android_log-sys = "0.2.0"
2727
[target.'cfg(target_arch = "wasm32")'.dependencies]
2828
console_error_panic_hook = "0.1.6"
2929
tracing-wasm = "0.2.1"
30-
31-
[dev-dependencies]
32-
bevy_internal = { path = "../bevy_internal", version = "0.8.0-dev" }

crates/bevy_log/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ use tracing_subscriber::{prelude::*, registry::Registry, EnvFilter};
4747
///
4848
/// You can configure this plugin using the resource [`LogSettings`].
4949
/// ```no_run
50-
/// # use bevy_internal::DefaultPlugins;
51-
/// # use bevy_app::App;
50+
/// # use bevy_app::{App, NoopPluginGroup as DefaultPlugins};
5251
/// # use bevy_log::LogSettings;
5352
/// # use bevy_utils::tracing::Level;
5453
/// fn main() {
@@ -72,8 +71,7 @@ use tracing_subscriber::{prelude::*, registry::Registry, EnvFilter};
7271
/// If you want to setup your own tracing collector, you should disable this
7372
/// plugin from `DefaultPlugins` with [`App::add_plugins_with`]:
7473
/// ```no_run
75-
/// # use bevy_internal::DefaultPlugins;
76-
/// # use bevy_app::App;
74+
/// # use bevy_app::{App, NoopPluginGroup as DefaultPlugins};
7775
/// # use bevy_log::LogPlugin;
7876
/// fn main() {
7977
/// App::new()

0 commit comments

Comments
 (0)