Skip to content

Commit 4fd09ff

Browse files
authored
Replace cfg_if! with cfg_select! (#23896)
# Objective Implements: #23828 I've also increased the MSRV of the top level bevy crate to `1.95.0`
1 parent a74ad33 commit 4fd09ff

7 files changed

Lines changed: 20 additions & 18 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"]
1010
license = "MIT OR Apache-2.0"
1111
repository = "https://github.com/bevyengine/bevy"
1212
documentation = "https://docs.rs/bevy"
13-
rust-version = "1.92.0"
13+
rust-version = "1.95.0"
1414

1515
[workspace]
1616
resolver = "3"

crates/bevy_app/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ thiserror = { version = "2", default-features = false }
9494
variadics_please = "1.1"
9595
tracing = { version = "0.1", default-features = false, optional = true }
9696
log = { version = "0.4", default-features = false }
97-
cfg-if = "1.0.0"
9897
dioxus-devtools = { version = "0.7.0-alpha.1", optional = true }
9998
crossbeam-channel = { version = "0.5.0", optional = true }
10099

crates/bevy_app/src/panic_handler.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ impl Plugin for PanicHandlerPlugin {
4343
{
4444
static SET_HOOK: std::sync::Once = std::sync::Once::new();
4545
SET_HOOK.call_once(|| {
46-
cfg_if::cfg_if! {
47-
if #[cfg(all(target_arch = "wasm32", feature = "web"))] {
46+
cfg_select! {
47+
all(target_arch = "wasm32", feature = "web") => {
4848
// This provides better panic handling in JS engines (displays the panic message and improves the backtrace).
4949
std::panic::set_hook(alloc::boxed::Box::new(console_error_panic_hook::hook));
50-
} else if #[cfg(feature = "error_panic_hook")] {
50+
}
51+
feature = "error_panic_hook" => {
5152
let current_hook = std::panic::take_hook();
5253
std::panic::set_hook(alloc::boxed::Box::new(
5354
bevy_ecs::error::bevy_error_panic_hook(current_hook),

crates/bevy_app/src/schedule_runner.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ impl Plugin for ScheduleRunnerPlugin {
118118
Ok(None)
119119
};
120120

121-
cfg_if::cfg_if! {
122-
if #[cfg(all(target_arch = "wasm32", feature = "web"))] {
121+
cfg_select! {
122+
all(target_arch = "wasm32", feature = "web") => {
123123
fn set_timeout(callback: &Closure<dyn FnMut()>, dur: Duration) {
124124
web_sys::window()
125125
.unwrap()
@@ -156,7 +156,8 @@ impl Plugin for ScheduleRunnerPlugin {
156156
set_timeout(base_tick_closure.borrow().as_ref().unwrap(), asap);
157157

158158
exit.take()
159-
} else {
159+
}
160+
_ =>{
160161
loop {
161162
match tick(&mut app, wait) {
162163
Ok(Some(delay)) => {

crates/bevy_app/src/task_pool_plugin.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use bevy_tasks::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool, TaskPoolBuil
66
use core::fmt::Debug;
77
use log::trace;
88

9-
cfg_if::cfg_if! {
10-
if #[cfg(not(all(target_arch = "wasm32", feature = "web")))] {
9+
cfg_select! {
10+
not(all(target_arch = "wasm32", feature = "web")) => {
1111
use {crate::Last, bevy_tasks::tick_global_task_pools_on_main_thread};
1212
use bevy_ecs::system::NonSendMarker;
1313

@@ -19,6 +19,7 @@ cfg_if::cfg_if! {
1919
tick_global_task_pools_on_main_thread();
2020
}
2121
}
22+
_ => {}
2223
}
2324

2425
/// Setup of default task pools: [`AsyncComputeTaskPool`], [`ComputeTaskPool`], [`IoTaskPool`].

crates/bevy_winit/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ accesskit_winit = { version = "0.32", default-features = false, features = [
6868
"rwh_06",
6969
] }
7070
approx = { version = "0.5", default-features = false }
71-
cfg-if = "1.0"
7271
accesskit = "0.24"
7372
tracing = { version = "0.1", default-features = false, features = ["std"] }
7473

crates/bevy_winit/src/state.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -682,13 +682,13 @@ impl WinitAppRunnerState {
682682
// per winit's docs on [Window::is_visible](https://docs.rs/winit/latest/winit/window/struct.Window.html#method.is_visible),
683683
// we cannot use the visibility to drive rendering on these platforms
684684
// so we cannot discern whether to beneficially use `Poll` or not?
685-
cfg_if::cfg_if! {
686-
if #[cfg(not(any(
685+
cfg_select! {
686+
not(any(
687687
target_arch = "wasm32",
688688
target_os = "android",
689689
target_os = "ios",
690690
all(target_os = "linux", any(feature = "x11", feature = "wayland"))
691-
)))]
691+
)) =>
692692
{
693693
let visible = WINIT_WINDOWS.with_borrow(|winit_windows| {
694694
winit_windows.windows.iter().any(|(_, w)| {
@@ -702,7 +702,7 @@ impl WinitAppRunnerState {
702702
ControlFlow::Poll
703703
});
704704
}
705-
else {
705+
_ => {
706706
event_loop.set_control_flow(ControlFlow::Wait);
707707
}
708708
}
@@ -903,11 +903,12 @@ pub fn winit_runner(mut app: App, event_loop: EventLoop<WinitUserEvent>) -> AppE
903903
trace!("starting winit event loop");
904904
// The winit docs mention using `spawn` instead of `run` on Wasm.
905905
// https://docs.rs/winit/latest/winit/platform/web/trait.EventLoopExtWebSys.html#tymethod.spawn_app
906-
cfg_if::cfg_if! {
907-
if #[cfg(target_arch = "wasm32")] {
906+
cfg_select! {
907+
target_arch = "wasm32" => {
908908
event_loop.spawn_app(runner_state);
909909
AppExit::Success
910-
} else {
910+
}
911+
_ => {
911912
let mut runner_state = runner_state;
912913
if let Err(err) = event_loop.run_app(&mut runner_state) {
913914
bevy_log::error!("winit event loop returned an error: {err}");

0 commit comments

Comments
 (0)