Skip to content

Commit

Permalink
Update downcast-rs to version 2 (#17223)
Browse files Browse the repository at this point in the history
# Objective & Solution

- Update `downcast-rs` to the latest version, 2.
- Disable (new) `sync` feature to improve compatibility with atomically
challenged platforms.
- Remove stub `downcast-rs` alternative code from `bevy_app`

## Testing

- CI

## Notes

The only change from version 1 to version 2 is the addition of a new
`sync` feature, which allows disabling the `DowncastSync` parts of
`downcast-rs`, which require access to `alloc::sync::Arc`, which is not
available on atomically challenged platforms. Since Bevy makes no use of
the functionality provided by the `sync` feature, I've disabled it in
all crates. Further details can be found
[here](marcianx/downcast-rs#22).
  • Loading branch information
bushrat011899 authored Jan 7, 2025
1 parent 8031d84 commit d607649
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 31 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_animation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ petgraph = { version = "0.6", features = ["serde-1"] }
ron = "0.8"
serde = "1"
blake3 = { version = "1.0" }
downcast-rs = "1.2.0"
downcast-rs = { version = "2", default-features = false, features = ["std"] }
thiserror = { version = "2", default-features = false }
derive_more = { version = "1", default-features = false, features = ["from"] }
either = "1.13"
Expand Down
9 changes: 3 additions & 6 deletions crates/bevy_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
default = ["std", "bevy_reflect", "bevy_tasks", "bevy_ecs/default", "downcast"]
default = ["std", "bevy_reflect", "bevy_tasks", "bevy_ecs/default"]

# Functionality

Expand All @@ -26,9 +26,6 @@ reflect_functions = [
## Adds support for running async background tasks
bevy_tasks = ["dep:bevy_tasks"]

## Adds `downcast-rs` integration for `Plugin`
downcast = ["dep:downcast-rs"]

# Debugging Features

## Enables `tracing` integration, allowing spans and other metrics to be reported
Expand All @@ -48,7 +45,7 @@ std = [
"bevy_reflect?/std",
"bevy_ecs/std",
"dep:ctrlc",
"downcast-rs?/std",
"downcast-rs/std",
"bevy_utils/std",
"bevy_tasks?/std",
]
Expand Down Expand Up @@ -81,7 +78,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev", default-features
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev", default-features = false, optional = true }

# other
downcast-rs = { version = "1.2.0", default-features = false, optional = true }
downcast-rs = { version = "2", default-features = false }
thiserror = { version = "2", default-features = false }
variadics_please = "1.1"
tracing = { version = "0.1", default-features = false, optional = true }
Expand Down
5 changes: 1 addition & 4 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
use alloc::{
boxed::Box,
string::{String, ToString},
vec::Vec,
};
pub use bevy_derive::AppLabel;
use bevy_ecs::{
Expand All @@ -29,9 +30,6 @@ use std::{
process::{ExitCode, Termination},
};

#[cfg(feature = "downcast")]
use alloc::vec::Vec;

bevy_ecs::define_label!(
/// A strongly-typed class of labels used to identify an [`App`].
AppLabel,
Expand Down Expand Up @@ -522,7 +520,6 @@ impl App {
/// # app.add_plugins(ImagePlugin::default());
/// let default_sampler = app.get_added_plugins::<ImagePlugin>()[0].default_sampler;
/// ```
#[cfg(feature = "downcast")]
pub fn get_added_plugins<T>(&self) -> Vec<&T>
where
T: Plugin,
Expand Down
17 changes: 1 addition & 16 deletions crates/bevy_app/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
// TODO: Upstream `portable-atomic` support to `downcast_rs` and unconditionally
// include it as a dependency.
// See https://github.com/marcianx/downcast-rs/pull/22 for details
#[cfg(feature = "downcast")]
use downcast_rs::{impl_downcast, Downcast};

use crate::App;
use core::any::Any;

/// Dummy trait with the same name as `downcast_rs::Downcast`. This is to ensure
/// the `Plugin: Downcast` bound can remain even when `downcast` isn't enabled.
#[cfg(not(feature = "downcast"))]
#[doc(hidden)]
pub trait Downcast {}

#[cfg(not(feature = "downcast"))]
impl<T: ?Sized> Downcast for T {}
use downcast_rs::{impl_downcast, Downcast};

/// A collection of Bevy app logic and configuration.
///
Expand Down Expand Up @@ -105,7 +91,6 @@ pub trait Plugin: Downcast + Any + Send + Sync {
}
}

#[cfg(feature = "downcast")]
impl_downcast!(Plugin);

impl<T: Fn(&mut App) + Send + Sync + 'static> Plugin for T {
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_app/src/sub_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ impl SubApp {
}

/// See [`App::get_added_plugins`].
#[cfg(feature = "downcast")]
pub fn get_added_plugins<T>(&self) -> Vec<&T>
where
T: Plugin,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async-fs = "2.0"
async-lock = "3.0"
bitflags = { version = "2.3", features = ["serde"] }
crossbeam-channel = "0.5"
downcast-rs = "1.2"
downcast-rs = { version = "2", default-features = false, features = ["std"] }
disqualified = "1.0"
either = "1.13"
futures-io = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_reflect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ erased-serde = { version = "0.4", default-features = false, features = [
"alloc",
] }
disqualified = { version = "1.0", default-features = false }
downcast-rs = { version = "1.2", default-features = false }
downcast-rs = { version = "2", default-features = false }
thiserror = { version = "2", default-features = false }
derive_more = { version = "1", default-features = false, features = ["from"] }
serde = { version = "1", default-features = false, features = ["alloc"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ wgpu = { version = "23.0.1", default-features = false, features = [
naga = { version = "23", features = ["wgsl-in"] }
serde = { version = "1", features = ["derive"] }
bytemuck = { version = "1.5", features = ["derive", "must_cast"] }
downcast-rs = "1.2.0"
downcast-rs = { version = "2", default-features = false, features = ["std"] }
thiserror = { version = "2", default-features = false }
derive_more = { version = "1", default-features = false, features = ["from"] }
futures-lite = "2.0.1"
Expand Down

0 comments on commit d607649

Please sign in to comment.