From 03a3b12f13ce7783291fc8f8f4eb4b2d6e474c54 Mon Sep 17 00:00:00 2001 From: Zac Harrold Date: Thu, 23 Jan 2025 13:05:24 +1100 Subject: [PATCH] Initial Commit --- crates/bevy_a11y/Cargo.toml | 68 +++++++++++++++++-- crates/bevy_a11y/src/lib.rs | 31 +++++++++ tools/ci/src/commands/compile_check_no_std.rs | 14 +++- 3 files changed, 105 insertions(+), 8 deletions(-) diff --git a/crates/bevy_a11y/Cargo.toml b/crates/bevy_a11y/Cargo.toml index 601f93ddbbf96..0037ccf29dc88 100644 --- a/crates/bevy_a11y/Cargo.toml +++ b/crates/bevy_a11y/Cargo.toml @@ -8,15 +8,73 @@ repository = "https://github.com/bevyengine/bevy" license = "MIT OR Apache-2.0" keywords = ["bevy", "accessibility", "a11y"] +[features] +default = ["std", "bevy_reflect", "bevy_ecs/async_executor"] + +# Functionality + +## Adds runtime reflection support using `bevy_reflect`. +bevy_reflect = [ + "dep:bevy_reflect", + "bevy_app/bevy_reflect", + "bevy_ecs/bevy_reflect", + "bevy_input_focus/bevy_reflect", +] + +## Adds serialization support through `serde`. +serialize = [ + "dep:serde", + "bevy_ecs/serialize", + "bevy_input_focus/serialize", + "accesskit/serde", +] + +# Platform Compatibility + +## Allows access to the `std` crate. Enabling this feature will prevent compilation +## on `no_std` targets, but provides access to certain additional features on +## supported platforms. +std = [ + "bevy_app/std", + "bevy_ecs/std", + "bevy_reflect/std", + "bevy_input_focus/std", +] + +## `critical-section` provides the building blocks for synchronization primitives +## on all platforms, including `no_std`. +critical-section = [ + "bevy_app/critical-section", + "bevy_ecs/critical-section", + "bevy_reflect?/critical-section", + "bevy_input_focus/critical-section", +] + +## `portable-atomic` provides additional platform support for atomic types and +## operations, even on targets without native support. +portable-atomic = [ + "bevy_app/portable-atomic", + "bevy_ecs/portable-atomic", + "bevy_reflect?/portable-atomic", + "bevy_input_focus/portable-atomic", +] + +## Uses the `libm` maths library instead of the one provided in `std` and `core`. +libm = ["bevy_input_focus/libm"] + [dependencies] # bevy -bevy_app = { path = "../bevy_app", version = "0.16.0-dev" } +bevy_app = { path = "../bevy_app", version = "0.16.0-dev", default-features = false } bevy_derive = { path = "../bevy_derive", version = "0.16.0-dev" } -bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev" } -bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev" } -bevy_input_focus = { path = "../bevy_input_focus", version = "0.16.0-dev" } +bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev", default-features = false } +bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", default-features = false, optional = true } +bevy_input_focus = { path = "../bevy_input_focus", version = "0.16.0-dev", default-features = false } -accesskit = "0.17" +# other +accesskit = { version = "0.17", default-features = false } +serde = { version = "1", default-features = false, features = [ + "alloc", +], optional = true } [lints] workspace = true diff --git a/crates/bevy_a11y/src/lib.rs b/crates/bevy_a11y/src/lib.rs index 651236d876b2e..ccc7edf536c3c 100644 --- a/crates/bevy_a11y/src/lib.rs +++ b/crates/bevy_a11y/src/lib.rs @@ -4,6 +4,7 @@ html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] +#![no_std] //! Accessibility for Bevy //! @@ -13,6 +14,9 @@ //! //! Make sure to use the same version of `accesskit` as Bevy. +#[cfg(feature = "std")] +extern crate std; + extern crate alloc; use alloc::sync::Arc; @@ -27,8 +31,21 @@ use bevy_ecs::{ schedule::SystemSet, }; +#[cfg(feature = "bevy_reflect")] +use { + bevy_ecs::reflect::ReflectResource, bevy_reflect::std_traits::ReflectDefault, + bevy_reflect::Reflect, +}; + +#[cfg(feature = "serialize")] +use serde::{Deserialize, Serialize}; + +#[cfg(all(feature = "bevy_reflect", feature = "serialize"))] +use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; + /// Wrapper struct for [`accesskit::ActionRequest`]. Required to allow it to be used as an `Event`. #[derive(Event, Deref, DerefMut)] +#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct ActionRequest(pub accesskit::ActionRequest); /// Resource that tracks whether an assistive technology has requested @@ -37,6 +54,7 @@ pub struct ActionRequest(pub accesskit::ActionRequest); /// Useful if a third-party plugin needs to conditionally integrate with /// `AccessKit` #[derive(Resource, Default, Clone, Debug, Deref, DerefMut)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Default, Resource))] pub struct AccessibilityRequested(Arc); impl AccessibilityRequested { @@ -59,6 +77,12 @@ impl AccessibilityRequested { /// accessibility updates instead. Without this, the external library and ECS /// will generate conflicting updates. #[derive(Resource, Clone, Debug, Deref, DerefMut)] +#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Resource))] +#[cfg_attr( + all(feature = "bevy_reflect", feature = "serialize"), + reflect(Serialize, Deserialize) +)] pub struct ManageAccessibilityUpdates(bool); impl Default for ManageAccessibilityUpdates { @@ -88,6 +112,7 @@ impl ManageAccessibilityUpdates { /// If the entity doesn't have a parent, or if the immediate parent doesn't have /// an `AccessibilityNode`, its node will be an immediate child of the primary window. #[derive(Component, Clone, Deref, DerefMut)] +#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct AccessibilityNode(pub Node); impl From for AccessibilityNode { @@ -98,6 +123,12 @@ impl From for AccessibilityNode { /// Set enum for the systems relating to accessibility #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)] +#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect))] +#[cfg_attr( + all(feature = "bevy_reflect", feature = "serialize"), + reflect(Serialize, Deserialize) +)] pub enum AccessibilitySystem { /// Update the accessibility tree Update, diff --git a/tools/ci/src/commands/compile_check_no_std.rs b/tools/ci/src/commands/compile_check_no_std.rs index cb28163a99053..12e0dd88b4961 100644 --- a/tools/ci/src/commands/compile_check_no_std.rs +++ b/tools/ci/src/commands/compile_check_no_std.rs @@ -131,7 +131,7 @@ impl Prepare for CompileCheckNoStdCommand { sh, "cargo check -p bevy_window --no-default-features --features libm,bevy_reflect,serialize --target {target}" ), - "Please fix compiler errors in output above for bevy_state no_std compatibility.", + "Please fix compiler errors in output above for bevy_window no_std compatibility.", )); commands.push(PreparedCommand::new::( @@ -147,7 +147,7 @@ impl Prepare for CompileCheckNoStdCommand { sh, "cargo check -p bevy_time --no-default-features --features bevy_reflect,serialize --target {target}" ), - "Please fix compiler errors in output above for bevy_transform no_std compatibility.", + "Please fix compiler errors in output above for bevy_time no_std compatibility.", )); commands.push(PreparedCommand::new::( @@ -155,7 +155,15 @@ impl Prepare for CompileCheckNoStdCommand { sh, "cargo check -p bevy_input_focus --no-default-features --features libm,serialize,bevy_reflect --target {target}" ), - "Please fix compiler errors in output above for bevy_input no_std compatibility.", + "Please fix compiler errors in output above for bevy_input_focus no_std compatibility.", + )); + + commands.push(PreparedCommand::new::( + cmd!( + sh, + "cargo check -p bevy_a11y --no-default-features --features libm,serialize,bevy_reflect --target {target}" + ), + "Please fix compiler errors in output above for bevy_a11y no_std compatibility.", )); commands