Skip to content

Commit 9387fcf

Browse files
Add no_std Support to bevy_a11y (#17505)
# Objective - Contributes to #15460 ## Solution - Add `std` feature gate - Fixed partially used serialisation and reflection features. ## Testing - CI
1 parent 434bbe6 commit 9387fcf

File tree

3 files changed

+105
-8
lines changed

3 files changed

+105
-8
lines changed

crates/bevy_a11y/Cargo.toml

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,73 @@ repository = "https://github.com/bevyengine/bevy"
88
license = "MIT OR Apache-2.0"
99
keywords = ["bevy", "accessibility", "a11y"]
1010

11+
[features]
12+
default = ["std", "bevy_reflect", "bevy_ecs/async_executor"]
13+
14+
# Functionality
15+
16+
## Adds runtime reflection support using `bevy_reflect`.
17+
bevy_reflect = [
18+
"dep:bevy_reflect",
19+
"bevy_app/bevy_reflect",
20+
"bevy_ecs/bevy_reflect",
21+
"bevy_input_focus/bevy_reflect",
22+
]
23+
24+
## Adds serialization support through `serde`.
25+
serialize = [
26+
"dep:serde",
27+
"bevy_ecs/serialize",
28+
"bevy_input_focus/serialize",
29+
"accesskit/serde",
30+
]
31+
32+
# Platform Compatibility
33+
34+
## Allows access to the `std` crate. Enabling this feature will prevent compilation
35+
## on `no_std` targets, but provides access to certain additional features on
36+
## supported platforms.
37+
std = [
38+
"bevy_app/std",
39+
"bevy_ecs/std",
40+
"bevy_reflect/std",
41+
"bevy_input_focus/std",
42+
]
43+
44+
## `critical-section` provides the building blocks for synchronization primitives
45+
## on all platforms, including `no_std`.
46+
critical-section = [
47+
"bevy_app/critical-section",
48+
"bevy_ecs/critical-section",
49+
"bevy_reflect?/critical-section",
50+
"bevy_input_focus/critical-section",
51+
]
52+
53+
## `portable-atomic` provides additional platform support for atomic types and
54+
## operations, even on targets without native support.
55+
portable-atomic = [
56+
"bevy_app/portable-atomic",
57+
"bevy_ecs/portable-atomic",
58+
"bevy_reflect?/portable-atomic",
59+
"bevy_input_focus/portable-atomic",
60+
]
61+
62+
## Uses the `libm` maths library instead of the one provided in `std` and `core`.
63+
libm = ["bevy_input_focus/libm"]
64+
1165
[dependencies]
1266
# bevy
13-
bevy_app = { path = "../bevy_app", version = "0.16.0-dev" }
67+
bevy_app = { path = "../bevy_app", version = "0.16.0-dev", default-features = false }
1468
bevy_derive = { path = "../bevy_derive", version = "0.16.0-dev" }
15-
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev" }
16-
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev" }
17-
bevy_input_focus = { path = "../bevy_input_focus", version = "0.16.0-dev" }
69+
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev", default-features = false }
70+
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", default-features = false, optional = true }
71+
bevy_input_focus = { path = "../bevy_input_focus", version = "0.16.0-dev", default-features = false }
1872

19-
accesskit = "0.17"
73+
# other
74+
accesskit = { version = "0.17", default-features = false }
75+
serde = { version = "1", default-features = false, features = [
76+
"alloc",
77+
], optional = true }
2078

2179
[lints]
2280
workspace = true

crates/bevy_a11y/src/lib.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
html_logo_url = "https://bevyengine.org/assets/icon.png",
55
html_favicon_url = "https://bevyengine.org/assets/icon.png"
66
)]
7+
#![no_std]
78

89
//! Accessibility for Bevy
910
//!
@@ -13,6 +14,9 @@
1314
//!
1415
//! Make sure to use the same version of `accesskit` as Bevy.
1516
17+
#[cfg(feature = "std")]
18+
extern crate std;
19+
1620
extern crate alloc;
1721

1822
use alloc::sync::Arc;
@@ -27,8 +31,21 @@ use bevy_ecs::{
2731
schedule::SystemSet,
2832
};
2933

34+
#[cfg(feature = "bevy_reflect")]
35+
use {
36+
bevy_ecs::reflect::ReflectResource, bevy_reflect::std_traits::ReflectDefault,
37+
bevy_reflect::Reflect,
38+
};
39+
40+
#[cfg(feature = "serialize")]
41+
use serde::{Deserialize, Serialize};
42+
43+
#[cfg(all(feature = "bevy_reflect", feature = "serialize"))]
44+
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
45+
3046
/// Wrapper struct for [`accesskit::ActionRequest`]. Required to allow it to be used as an `Event`.
3147
#[derive(Event, Deref, DerefMut)]
48+
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
3249
pub struct ActionRequest(pub accesskit::ActionRequest);
3350

3451
/// Resource that tracks whether an assistive technology has requested
@@ -37,6 +54,7 @@ pub struct ActionRequest(pub accesskit::ActionRequest);
3754
/// Useful if a third-party plugin needs to conditionally integrate with
3855
/// `AccessKit`
3956
#[derive(Resource, Default, Clone, Debug, Deref, DerefMut)]
57+
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Default, Resource))]
4058
pub struct AccessibilityRequested(Arc<AtomicBool>);
4159

4260
impl AccessibilityRequested {
@@ -59,6 +77,12 @@ impl AccessibilityRequested {
5977
/// accessibility updates instead. Without this, the external library and ECS
6078
/// will generate conflicting updates.
6179
#[derive(Resource, Clone, Debug, Deref, DerefMut)]
80+
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
81+
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Resource))]
82+
#[cfg_attr(
83+
all(feature = "bevy_reflect", feature = "serialize"),
84+
reflect(Serialize, Deserialize)
85+
)]
6286
pub struct ManageAccessibilityUpdates(bool);
6387

6488
impl Default for ManageAccessibilityUpdates {
@@ -88,6 +112,7 @@ impl ManageAccessibilityUpdates {
88112
/// If the entity doesn't have a parent, or if the immediate parent doesn't have
89113
/// an `AccessibilityNode`, its node will be an immediate child of the primary window.
90114
#[derive(Component, Clone, Deref, DerefMut)]
115+
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
91116
pub struct AccessibilityNode(pub Node);
92117

93118
impl From<Node> for AccessibilityNode {
@@ -98,6 +123,12 @@ impl From<Node> for AccessibilityNode {
98123

99124
/// Set enum for the systems relating to accessibility
100125
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
126+
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
127+
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
128+
#[cfg_attr(
129+
all(feature = "bevy_reflect", feature = "serialize"),
130+
reflect(Serialize, Deserialize)
131+
)]
101132
pub enum AccessibilitySystem {
102133
/// Update the accessibility tree
103134
Update,

tools/ci/src/commands/compile_check_no_std.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl Prepare for CompileCheckNoStdCommand {
131131
sh,
132132
"cargo check -p bevy_window --no-default-features --features libm,bevy_reflect,serialize --target {target}"
133133
),
134-
"Please fix compiler errors in output above for bevy_state no_std compatibility.",
134+
"Please fix compiler errors in output above for bevy_window no_std compatibility.",
135135
));
136136

137137
commands.push(PreparedCommand::new::<Self>(
@@ -147,15 +147,23 @@ impl Prepare for CompileCheckNoStdCommand {
147147
sh,
148148
"cargo check -p bevy_time --no-default-features --features bevy_reflect,serialize --target {target}"
149149
),
150-
"Please fix compiler errors in output above for bevy_transform no_std compatibility.",
150+
"Please fix compiler errors in output above for bevy_time no_std compatibility.",
151151
));
152152

153153
commands.push(PreparedCommand::new::<Self>(
154154
cmd!(
155155
sh,
156156
"cargo check -p bevy_input_focus --no-default-features --features libm,serialize,bevy_reflect --target {target}"
157157
),
158-
"Please fix compiler errors in output above for bevy_input no_std compatibility.",
158+
"Please fix compiler errors in output above for bevy_input_focus no_std compatibility.",
159+
));
160+
161+
commands.push(PreparedCommand::new::<Self>(
162+
cmd!(
163+
sh,
164+
"cargo check -p bevy_a11y --no-default-features --features libm,serialize,bevy_reflect --target {target}"
165+
),
166+
"Please fix compiler errors in output above for bevy_a11y no_std compatibility.",
159167
));
160168

161169
commands

0 commit comments

Comments
 (0)