Skip to content

Commit 0928ec9

Browse files
bushrat011899mrchantey
authored andcommitted
Add no_std support to bevy_diagnostic (bevyengine#17507)
# Objective - Contributes to bevyengine#15460 ## Solution - Added required features - Switched from `tracing` to `log` - Fixed imports ## Testing - CI
1 parent 0a28298 commit 0928ec9

File tree

6 files changed

+97
-21
lines changed

6 files changed

+97
-21
lines changed

crates/bevy_diagnostic/Cargo.toml

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,80 @@ license = "MIT OR Apache-2.0"
99
keywords = ["bevy"]
1010

1111
[features]
12-
# Disables diagnostics that are unsupported when Bevy is dynamically linked
12+
default = ["std", "bevy_ecs/default"]
13+
14+
# Functionality
15+
16+
## Adds serialization support through `serde`.
17+
serialize = [
18+
"dep:serde",
19+
"bevy_ecs/serialize",
20+
"bevy_time/serialize",
21+
"bevy_utils/serde",
22+
]
23+
24+
## Disables diagnostics that are unsupported when Bevy is dynamically linked
1325
dynamic_linking = []
14-
sysinfo_plugin = ["sysinfo"]
15-
serialize = ["dep:serde"]
26+
27+
## Adds integration with `sysinfo`.
28+
sysinfo_plugin = ["sysinfo", "dep:bevy_tasks"]
29+
30+
# Platform Compatibility
31+
32+
## Allows access to the `std` crate. Enabling this feature will prevent compilation
33+
## on `no_std` targets, but provides access to certain additional features on
34+
## supported platforms.
35+
std = [
36+
"serde?/std",
37+
"bevy_ecs/std",
38+
"bevy_app/std",
39+
"bevy_platform_support/std",
40+
"bevy_time/std",
41+
"bevy_utils/std",
42+
"bevy_tasks?/std",
43+
]
44+
45+
## `critical-section` provides the building blocks for synchronization primitives
46+
## on all platforms, including `no_std`.
47+
critical-section = [
48+
"bevy_ecs/critical-section",
49+
"bevy_app/critical-section",
50+
"bevy_platform_support/critical-section",
51+
"bevy_time/critical-section",
52+
"bevy_utils/critical-section",
53+
"bevy_tasks?/critical-section",
54+
]
55+
56+
## `portable-atomic` provides additional platform support for atomic types and
57+
## operations, even on targets without native support.
58+
portable-atomic = [
59+
"bevy_ecs/portable-atomic",
60+
"bevy_app/portable-atomic",
61+
"bevy_platform_support/portable-atomic",
62+
"bevy_time/portable-atomic",
63+
"bevy_utils/portable-atomic",
64+
"bevy_tasks?/portable-atomic",
65+
]
1666

1767
[dependencies]
1868
# bevy
19-
bevy_app = { path = "../bevy_app", version = "0.16.0-dev" }
20-
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev" }
21-
bevy_time = { path = "../bevy_time", version = "0.16.0-dev" }
22-
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
23-
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev" }
69+
bevy_app = { path = "../bevy_app", version = "0.16.0-dev", default-features = false }
70+
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev", default-features = false }
71+
bevy_time = { path = "../bevy_time", version = "0.16.0-dev", default-features = false }
72+
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev", default-features = false, features = [
73+
"alloc",
74+
] }
75+
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev", default-features = false, optional = true }
2476
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
25-
"std",
77+
"alloc",
2678
] }
2779

2880
# other
2981
const-fnv1a-hash = "1.1.0"
30-
serde = { version = "1.0", optional = true }
31-
tracing = { version = "0.1", default-features = false, features = ["std"] }
82+
serde = { version = "1.0", default-features = false, features = [
83+
"alloc",
84+
], optional = true }
85+
log = { version = "0.4", default-features = false }
3286

3387
# macOS
3488
[target.'cfg(all(target_os="macos"))'.dependencies]

crates/bevy_diagnostic/src/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloc::{borrow::Cow, collections::VecDeque};
1+
use alloc::{borrow::Cow, collections::VecDeque, string::String};
22
use core::{
33
hash::{Hash, Hasher},
44
time::Duration,

crates/bevy_diagnostic/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
html_logo_url = "https://bevyengine.org/assets/icon.png",
66
html_favicon_url = "https://bevyengine.org/assets/icon.png"
77
)]
8+
#![no_std]
89

910
//! This crate provides a straightforward solution for integrating diagnostics in the [Bevy game engine](https://bevyengine.org/).
1011
//! It allows users to easily add diagnostic functionality to their Bevy applications, enhancing
1112
//! their ability to monitor and optimize their game's.
1213
14+
#[cfg(feature = "std")]
15+
extern crate std;
16+
1317
extern crate alloc;
1418

1519
mod diagnostic;

crates/bevy_diagnostic/src/log_diagnostics_plugin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use super::{Diagnostic, DiagnosticPath, DiagnosticsStore};
2+
use alloc::vec::Vec;
23
use bevy_app::prelude::*;
34
use bevy_ecs::prelude::*;
45
use bevy_time::{Real, Time, Timer, TimerMode};
56
use core::time::Duration;
6-
use tracing::{debug, info};
7+
use log::{debug, info};
78

89
/// An App Plugin that logs diagnostics to the console.
910
///

crates/bevy_diagnostic/src/system_information_diagnostics_plugin.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::DiagnosticPath;
2+
use alloc::string::String;
23
use bevy_app::prelude::*;
34
use bevy_ecs::resource::Resource;
45

@@ -56,18 +57,24 @@ pub struct SystemInfo {
5657
target_os = "android",
5758
target_os = "macos"
5859
),
59-
not(feature = "dynamic_linking")
60+
not(feature = "dynamic_linking"),
61+
feature = "std",
6062
))]
6163
pub mod internal {
62-
use alloc::sync::Arc;
63-
use bevy_ecs::{prelude::ResMut, system::Local};
64-
use std::{sync::Mutex, time::Instant};
65-
64+
use alloc::{
65+
format,
66+
string::{String, ToString},
67+
sync::Arc,
68+
vec::Vec,
69+
};
6670
use bevy_app::{App, First, Startup, Update};
6771
use bevy_ecs::resource::Resource;
72+
use bevy_ecs::{prelude::ResMut, system::Local};
73+
use bevy_platform_support::time::Instant;
6874
use bevy_tasks::{available_parallelism, block_on, poll_once, AsyncComputeTaskPool, Task};
75+
use log::info;
76+
use std::sync::Mutex;
6977
use sysinfo::{CpuRefreshKind, MemoryRefreshKind, RefreshKind, System};
70-
use tracing::info;
7178

7279
use crate::{Diagnostic, Diagnostics, DiagnosticsStore};
7380

@@ -200,17 +207,19 @@ pub mod internal {
200207
target_os = "android",
201208
target_os = "macos"
202209
),
203-
not(feature = "dynamic_linking")
210+
not(feature = "dynamic_linking"),
211+
feature = "std",
204212
)))]
205213
pub mod internal {
214+
use alloc::string::ToString;
206215
use bevy_app::{App, Startup};
207216

208217
pub(super) fn setup_plugin(app: &mut App) {
209218
app.add_systems(Startup, setup_system);
210219
}
211220

212221
fn setup_system() {
213-
tracing::warn!("This platform and/or configuration is not supported!");
222+
log::warn!("This platform and/or configuration is not supported!");
214223
}
215224

216225
impl Default for super::SystemInfo {

tools/ci/src/commands/compile_check_no_std.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ impl Prepare for CompileCheckNoStdCommand {
166166
"Please fix compiler errors in output above for bevy_a11y no_std compatibility.",
167167
));
168168

169+
commands.push(PreparedCommand::new::<Self>(
170+
cmd!(
171+
sh,
172+
"cargo check -p bevy_diagnostic --no-default-features --features serialize --target {target}"
173+
),
174+
"Please fix compiler errors in output above for bevy_diagnostic no_std compatibility.",
175+
));
176+
169177
commands
170178
}
171179
}

0 commit comments

Comments
 (0)