Skip to content

Commit

Permalink
feature gate picking backends (#15369)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
BenjaminBrienen authored Sep 22, 2024
1 parent 58f6fa9 commit 9386bd0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"]

Expand Down Expand Up @@ -141,6 +149,7 @@ bevy_sprite = [
"bevy_render",
"bevy_core_pipeline",
"bevy_color",
"bevy_sprite_picking_backend",
]

# Provides text functionality
Expand All @@ -153,6 +162,7 @@ bevy_ui = [
"bevy_text",
"bevy_sprite",
"bevy_color",
"bevy_ui_picking_backend",
]

# winit window and input backend
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_sprite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_sprite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions docs/cargo_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down

0 comments on commit 9386bd0

Please sign in to comment.