From 9386bd0114c44c9f00a2e9c41db1225aaa78d159 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Sun, 22 Sep 2024 21:35:15 +0200 Subject: [PATCH] feature gate picking backends (#15369) # Objective Fixes #15306 ## Solution - Add feature gate on the module and the place where each one is used - Declare the features and make them default ## Testing - CI --- Cargo.toml | 12 ++++++++++++ crates/bevy_sprite/Cargo.toml | 3 ++- crates/bevy_sprite/src/lib.rs | 4 ++-- crates/bevy_ui/Cargo.toml | 4 ++-- crates/bevy_ui/src/lib.rs | 4 ++-- docs/cargo_features.md | 2 ++ 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e913e3ef58..87325a4993 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,6 +68,8 @@ default = [ "bevy_core_pipeline", "bevy_pbr", "bevy_picking", + "bevy_sprite_picking_backend", + "bevy_ui_picking_backend", "bevy_gltf", "bevy_render", "bevy_sprite", @@ -87,6 +89,12 @@ default = [ "sysinfo_plugin", ] +# Provides an implementation for picking sprites +bevy_sprite_picking_backend = ["bevy_picking"] + +# Provides an implementation for picking ui +bevy_ui_picking_backend = ["bevy_picking"] + # Force dynamic linking, which improves iterative compile times dynamic_linking = ["dep:bevy_dylib", "bevy_internal/dynamic_linking"] @@ -141,6 +149,7 @@ bevy_sprite = [ "bevy_render", "bevy_core_pipeline", "bevy_color", + "bevy_sprite_picking_backend", ] # Provides text functionality @@ -153,6 +162,7 @@ bevy_ui = [ "bevy_text", "bevy_sprite", "bevy_color", + "bevy_ui_picking_backend", ] # winit window and input backend @@ -3459,12 +3469,14 @@ wasm = true name = "sprite_picking" path = "examples/picking/sprite_picking.rs" doc-scrape-examples = true +required-features = ["bevy_sprite_picking_backend"] [package.metadata.example.sprite_picking] name = "Sprite Picking" description = "Demonstrates picking sprites and sprite atlases" category = "Picking" wasm = true +required-features = ["bevy_sprite_picking_backend"] [[example]] name = "animation_masks" diff --git a/crates/bevy_sprite/Cargo.toml b/crates/bevy_sprite/Cargo.toml index 59d33d76e0..7e0a834514 100644 --- a/crates/bevy_sprite/Cargo.toml +++ b/crates/bevy_sprite/Cargo.toml @@ -9,7 +9,8 @@ license = "MIT OR Apache-2.0" keywords = ["bevy"] [features] -bevy_picking = ["dep:bevy_picking", "dep:bevy_window"] +default = ["bevy_sprite_picking_backend"] +bevy_sprite_picking_backend = ["bevy_picking", "bevy_window"] webgl = [] webgpu = [] diff --git a/crates/bevy_sprite/src/lib.rs b/crates/bevy_sprite/src/lib.rs index 7dd930b22d..163d3878bc 100644 --- a/crates/bevy_sprite/src/lib.rs +++ b/crates/bevy_sprite/src/lib.rs @@ -11,7 +11,7 @@ mod bundle; mod dynamic_texture_atlas_builder; mod mesh2d; -#[cfg(feature = "bevy_picking")] +#[cfg(feature = "bevy_sprite_picking_backend")] mod picking_backend; mod render; mod sprite; @@ -134,7 +134,7 @@ impl Plugin for SpritePlugin { ), ); - #[cfg(feature = "bevy_picking")] + #[cfg(feature = "bevy_sprite_picking_backend")] app.add_plugins(picking_backend::SpritePickingBackend); if let Some(render_app) = app.get_sub_app_mut(RenderApp) { diff --git a/crates/bevy_ui/Cargo.toml b/crates/bevy_ui/Cargo.toml index de8909337e..c0d95b85d6 100644 --- a/crates/bevy_ui/Cargo.toml +++ b/crates/bevy_ui/Cargo.toml @@ -40,9 +40,9 @@ nonmax = "0.5" smallvec = "1.11" [features] +default = ["bevy_ui_picking_backend"] serialize = ["serde", "smallvec/serde", "bevy_math/serialize"] -bevy_picking = ["dep:bevy_picking"] - +bevy_ui_picking_backend = ["bevy_picking"] [lints] workspace = true diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 5a366b782e..e1f46c405b 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -17,7 +17,7 @@ pub mod ui_material; pub mod update; pub mod widget; -#[cfg(feature = "bevy_picking")] +#[cfg(feature = "bevy_ui_picking_backend")] pub mod picking_backend; use bevy_derive::{Deref, DerefMut}; @@ -194,7 +194,7 @@ impl Plugin for UiPlugin { build_ui_render(app); - #[cfg(feature = "bevy_picking")] + #[cfg(feature = "bevy_ui_picking_backend")] app.add_plugins(picking_backend::UiPickingBackend); } diff --git a/docs/cargo_features.md b/docs/cargo_features.md index ca6b982b71..0fc97d48c4 100644 --- a/docs/cargo_features.md +++ b/docs/cargo_features.md @@ -26,9 +26,11 @@ The default feature set enables most of the expected features of a game engine, |bevy_render|Provides rendering functionality| |bevy_scene|Provides scene functionality| |bevy_sprite|Provides sprite functionality| +|bevy_sprite_picking_backend|Provides an implementation for picking sprites| |bevy_state|Enable built in global state machines| |bevy_text|Provides text functionality| |bevy_ui|A custom ECS-driven UI framework| +|bevy_ui_picking_backend|Provides an implementation for picking ui| |bevy_winit|winit window and input backend| |default_font|Include a default font, containing only ASCII characters, at the cost of a 20kB binary size increase| |hdr|HDR image format support|