Skip to content

Commit a50a210

Browse files
authored
bevy_reflect gating / better compile error message (#20625)
# Objective - next batch of compile issues - I think that's the last for now... until we add more ## Solution - gate bevy_reflect properly in bevy_window - improve compile error when auto_register is enabled but not "*_inventory" or "*_static" is. Error is currently: ``` error[E0425]: cannot find function `register_types` in module `crate::__macro_exports::auto_register` --> crates/bevy_reflect/src/type_registry.rs:158:48 | 158 | crate::__macro_exports::auto_register::register_types(self); | ^^^^^^^^^^^^^^ not found in `crate::__macro_exports::auto_register` ```
1 parent 8ee3b09 commit a50a210

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

crates/bevy_reflect/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,14 @@ pub mod __macro_exports {
740740
pub mod auto_register {
741741
pub use super::*;
742742

743+
#[cfg(all(
744+
not(feature = "auto_register_inventory"),
745+
not(feature = "auto_register_static")
746+
))]
747+
compile_error!(
748+
"Choosing a backend is required for automatic reflect registration. Please enable either the \"auto_register_inventory\" or the \"auto_register_static\" feature."
749+
);
750+
743751
/// inventory impl
744752
#[cfg(all(
745753
not(feature = "auto_register_static"),

crates/bevy_window/src/cursor/custom_cursor.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ use alloc::string::String;
33
use bevy_asset::Handle;
44
use bevy_image::{Image, TextureAtlas};
55
use bevy_math::URect;
6+
7+
#[cfg(feature = "bevy_reflect")]
68
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
79

810
/// A custom cursor created from an image.
9-
#[derive(Debug, Clone, Default, Reflect, PartialEq, Eq, Hash)]
10-
#[reflect(Debug, Default, Hash, PartialEq, Clone)]
11+
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
12+
#[cfg_attr(
13+
feature = "bevy_reflect",
14+
derive(Reflect),
15+
reflect(Debug, Default, Hash, PartialEq, Clone)
16+
)]
1117
pub struct CustomCursorImage {
1218
/// Handle to the image to use as the cursor. The image must be in 8 bit int
1319
/// or 32 bit float rgba. PNG images work well for this.
@@ -41,8 +47,12 @@ pub struct CustomCursorImage {
4147
}
4248

4349
/// A custom cursor created from a URL. Note that this currently only works on the web.
44-
#[derive(Debug, Clone, Default, Reflect, PartialEq, Eq, Hash)]
45-
#[reflect(Debug, Default, Hash, PartialEq, Clone)]
50+
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
51+
#[cfg_attr(
52+
feature = "bevy_reflect",
53+
derive(Reflect),
54+
reflect(Debug, Default, Hash, PartialEq, Clone)
55+
)]
4656
pub struct CustomCursorUrl {
4757
/// Web URL to an image to use as the cursor. PNGs are preferred. Cursor
4858
/// creation can fail if the image is invalid or not reachable.
@@ -53,8 +63,12 @@ pub struct CustomCursorUrl {
5363
}
5464

5565
/// Custom cursor image data.
56-
#[derive(Debug, Clone, Reflect, PartialEq, Eq, Hash)]
57-
#[reflect(Clone, PartialEq, Hash)]
66+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
67+
#[cfg_attr(
68+
feature = "bevy_reflect",
69+
derive(Reflect),
70+
reflect(Clone, PartialEq, Hash)
71+
)]
5872
pub enum CustomCursor {
5973
/// Use an image as the cursor.
6074
Image(CustomCursorImage),

crates/bevy_window/src/cursor/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ pub use custom_cursor::*;
99
pub use system_cursor::*;
1010

1111
use bevy_ecs::{component::Component, reflect::ReflectComponent};
12+
#[cfg(feature = "bevy_reflect")]
1213
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
1314

1415
#[cfg(feature = "custom_cursor")]
1516
pub use crate::cursor::{CustomCursor, CustomCursorImage};
1617

1718
/// Insert into a window entity to set the cursor for that window.
18-
#[derive(Component, Debug, Clone, Reflect, PartialEq, Eq)]
19-
#[reflect(Component, Debug, Default, PartialEq, Clone)]
19+
#[derive(Component, Debug, Clone, PartialEq, Eq)]
20+
#[cfg_attr(
21+
feature = "bevy_reflect",
22+
derive(Reflect),
23+
reflect(Component, Debug, Default, PartialEq, Clone)
24+
)]
25+
2026
pub enum CursorIcon {
2127
#[cfg(feature = "custom_cursor")]
2228
/// Custom cursor image.

0 commit comments

Comments
 (0)