Skip to content

Commit c7de4ab

Browse files
committed
Add no_std support to bevy_log
Currently requires a new release of `tracing-subscriber`. Once released, 2 lines needs to be uncommented in `Cargo.toml`, see `TODO`.
1 parent e203add commit c7de4ab

File tree

16 files changed

+120
-41
lines changed

16 files changed

+120
-41
lines changed

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ default_app = [
183183
"async_executor",
184184
"bevy_asset",
185185
"bevy_input_focus",
186-
"bevy_log",
187186
"bevy_state",
188187
"bevy_window",
189188
"custom_cursor",
@@ -392,9 +391,6 @@ pan_camera = ["bevy_internal/pan_camera"]
392391
# Enable the Bevy Remote Protocol
393392
bevy_remote = ["bevy_internal/bevy_remote"]
394393

395-
# Enable integration with `tracing` and `log`
396-
bevy_log = ["bevy_internal/bevy_log"]
397-
398394
# Enable input focus subsystem
399395
bevy_input_focus = ["bevy_internal/bevy_input_focus"]
400396

@@ -1737,7 +1733,6 @@ wasm = true
17371733
name = "headless"
17381734
path = "examples/app/headless.rs"
17391735
doc-scrape-examples = true
1740-
required-features = ["bevy_log"]
17411736

17421737
[package.metadata.example.headless]
17431738
name = "Headless"

crates/bevy_animation/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ tracing = { version = "0.1", default-features = false, features = ["std"] }
4848
[target.'cfg(target_arch = "wasm32")'.dependencies]
4949
# TODO: Assuming all wasm builds are for the browser. Require `no_std` support to break assumption.
5050
uuid = { version = "1.13.1", default-features = false, features = ["js"] }
51+
bevy_log = { path = "../bevy_log", version = "0.18.0-dev", default-features = false, features = [
52+
"web",
53+
] }
54+
bevy_app = { path = "../bevy_app", version = "0.18.0-dev", default-features = false, features = [
55+
"web",
56+
] }
57+
bevy_platform = { path = "../bevy_platform", version = "0.18.0-dev", default-features = false, features = [
58+
"web",
59+
] }
60+
bevy_reflect = { path = "../bevy_reflect", version = "0.18.0-dev", default-features = false, features = [
61+
"web",
62+
] }
5163

5264
[lints]
5365
workspace = true

crates/bevy_dylib/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
//! use bevy_dylib;
5454
//! ```
5555
56+
#![no_std]
57+
5658
// Force linking of the main bevy crate
5759
#[expect(
5860
unused_imports,

crates/bevy_gltf/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ tracing = { version = "0.1", default-features = false, features = ["std"] }
6969
[dev-dependencies]
7070
bevy_log = { path = "../bevy_log", version = "0.18.0-dev" }
7171

72+
[target.'cfg(target_arch = "wasm32")'.dependencies]
73+
# TODO: Assuming all wasm builds are for the browser. Require `no_std` support to break assumption.
74+
bevy_log = { path = "../bevy_log", version = "0.18.0-dev", default-features = false, features = [
75+
"web",
76+
] }
77+
bevy_app = { path = "../bevy_app", version = "0.18.0-dev", default-features = false, features = [
78+
"web",
79+
] }
80+
bevy_platform = { path = "../bevy_platform", version = "0.18.0-dev", default-features = false, features = [
81+
"web",
82+
] }
83+
bevy_reflect = { path = "../bevy_reflect", version = "0.18.0-dev", default-features = false, features = [
84+
"web",
85+
] }
86+
7287
[lints]
7388
workspace = true
7489

crates/bevy_internal/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ std = [
379379
"bevy_ecs/std",
380380
"bevy_input/std",
381381
"bevy_input_focus?/std",
382+
"bevy_log/std",
382383
"bevy_math/std",
383384
"bevy_platform/std",
384385
"bevy_reflect/std",
@@ -395,6 +396,7 @@ critical-section = [
395396
"bevy_app/critical-section",
396397
"bevy_diagnostic/critical-section",
397398
"bevy_ecs/critical-section",
399+
"bevy_log/critical-section",
398400
"bevy_input/critical-section",
399401
"bevy_input_focus?/critical-section",
400402
"bevy_platform/critical-section",
@@ -424,7 +426,7 @@ async_executor = [
424426

425427
# Enables use of browser APIs.
426428
# Note this is currently only applicable on `wasm32` architectures.
427-
web = ["bevy_app/web", "bevy_platform/web", "bevy_reflect/web"]
429+
web = ["bevy_app/web", "bevy_log/web", "bevy_platform/web", "bevy_reflect/web"]
428430

429431
# Input sources.
430432
mouse = ["bevy_input/mouse"]
@@ -452,6 +454,7 @@ bevy_ecs = { path = "../bevy_ecs", version = "0.18.0-dev", default-features = fa
452454
bevy_input = { path = "../bevy_input", version = "0.18.0-dev", default-features = false, features = [
453455
"bevy_reflect",
454456
] }
457+
bevy_log = { path = "../bevy_log", version = "0.18.0-dev", default-features = false }
455458
bevy_math = { path = "../bevy_math", version = "0.18.0-dev", default-features = false, features = [
456459
"bevy_reflect",
457460
"nostd-libm",
@@ -473,9 +476,6 @@ bevy_transform = { path = "../bevy_transform", version = "0.18.0-dev", default-f
473476
bevy_utils = { path = "../bevy_utils", version = "0.18.0-dev", default-features = false }
474477
bevy_tasks = { path = "../bevy_tasks", version = "0.18.0-dev", default-features = false }
475478

476-
# bevy (std required)
477-
bevy_log = { path = "../bevy_log", version = "0.18.0-dev", optional = true }
478-
479479
# bevy (optional)
480480
bevy_a11y = { path = "../bevy_a11y", optional = true, version = "0.18.0-dev", features = [
481481
"bevy_reflect",

crates/bevy_internal/src/default_plugins.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ plugin_group! {
44
/// This plugin group will add all the default plugins for a *Bevy* application:
55
pub struct DefaultPlugins {
66
bevy_app:::PanicHandlerPlugin,
7-
#[cfg(feature = "bevy_log")]
87
bevy_log:::LogPlugin,
98
bevy_app:::TaskPoolPlugin,
109
bevy_diagnostic:::FrameCountPlugin,

crates/bevy_internal/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub use bevy_input as input;
5656
pub use bevy_input_focus as input_focus;
5757
#[cfg(feature = "bevy_light")]
5858
pub use bevy_light as light;
59-
#[cfg(feature = "bevy_log")]
6059
pub use bevy_log as log;
6160
pub use bevy_math as math;
6261
#[cfg(feature = "bevy_mesh")]

crates/bevy_internal/src/prelude.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#[doc(hidden)]
22
pub use crate::{
3-
app::prelude::*, ecs::prelude::*, input::prelude::*, math::prelude::*, platform::prelude::*,
4-
reflect::prelude::*, time::prelude::*, transform::prelude::*, utils::prelude::*,
5-
DefaultPlugins, MinimalPlugins,
3+
app::prelude::*, ecs::prelude::*, input::prelude::*, log::prelude::*, math::prelude::*,
4+
platform::prelude::*, reflect::prelude::*, time::prelude::*, transform::prelude::*,
5+
utils::prelude::*, DefaultPlugins, MinimalPlugins,
66
};
77

8-
#[doc(hidden)]
9-
#[cfg(feature = "bevy_log")]
10-
pub use crate::log::prelude::*;
11-
128
#[doc(hidden)]
139
#[cfg(feature = "bevy_window")]
1410
pub use crate::window::prelude::*;

crates/bevy_log/Cargo.toml

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,55 @@ license = "MIT OR Apache-2.0"
99
keywords = ["bevy"]
1010

1111
[features]
12-
trace = ["tracing-error"]
13-
trace_tracy_memory = ["dep:tracy-client"]
12+
default = ["std"]
13+
trace = ["std", "dep:tracing-error"]
14+
trace_tracy_memory = ["std", "dep:tracy-client"]
15+
16+
# Platform Compatibility
17+
18+
# Allows access to the `std` crate. Enabling this feature will prevent compilation
19+
# on `no_std` targets, but provides access to certain additional features on
20+
# supported platforms.
21+
std = [
22+
"bevy_app/std",
23+
"bevy_utils/std",
24+
"bevy_ecs/std",
25+
"tracing/std",
26+
"tracing-subscriber/std",
27+
"tracing-log/std",
28+
]
29+
30+
## `critical-section` provides the building blocks for synchronization primitives
31+
## on all platforms, including `no_std`.
32+
critical-section = [
33+
# TODO: wait for `tracing-subscriber` release
34+
# "tracing-subscriber/critical-section"
35+
]
36+
37+
# Enables use of browser APIs.
38+
# Note this is currently only applicable on `wasm32` architectures.
39+
web = ["bevy_app/web", "dep:tracing-wasm"]
1440

1541
[dependencies]
1642
# bevy
17-
bevy_app = { path = "../bevy_app", version = "0.18.0-dev" }
18-
bevy_utils = { path = "../bevy_utils", version = "0.18.0-dev" }
19-
bevy_platform = { path = "../bevy_platform", version = "0.18.0-dev" }
20-
bevy_ecs = { path = "../bevy_ecs", version = "0.18.0-dev" }
43+
bevy_app = { path = "../bevy_app", version = "0.18.0-dev", default-features = false }
44+
bevy_utils = { path = "../bevy_utils", version = "0.18.0-dev", default-features = false }
45+
bevy_platform = { path = "../bevy_platform", version = "0.18.0-dev", default-features = false }
46+
bevy_ecs = { path = "../bevy_ecs", version = "0.18.0-dev", default-features = false }
2147

2248
# other
23-
tracing-subscriber = { version = "0.3.20", features = [
49+
tracing-subscriber = { version = "0.3.20", default-features = false, features = [
2450
"registry",
2551
"env-filter",
52+
"fmt",
53+
"tracing-log",
2654
] }
2755
tracing-chrome = { version = "0.7.0", optional = true }
28-
tracing-log = "0.2.0"
56+
tracing-log = { version = "0.2.0", default-features = false, features = [
57+
"log-tracer",
58+
] }
2959
tracing-error = { version = "0.2.0", optional = true }
30-
tracing = { version = "0.1", default-features = false, features = ["std"] }
60+
tracing = { version = "0.1", default-features = false }
3161

3262
# Tracy dependency compatibility table:
3363
# https://github.com/nagisa/rust_tracy_client
@@ -38,15 +68,17 @@ tracy-client = { version = "0.18.3", optional = true }
3868
android_log-sys = "0.3.0"
3969

4070
[target.'cfg(target_arch = "wasm32")'.dependencies]
41-
tracing-wasm = "0.2.1"
42-
# TODO: Assuming all wasm builds are for the browser. Require `no_std` support to break assumption.
43-
bevy_app = { path = "../bevy_app", version = "0.18.0-dev", default-features = false, features = [
44-
"web",
45-
] }
71+
tracing-wasm = { version = "0.2.1", optional = true }
4672

4773
[target.'cfg(target_os = "ios")'.dependencies]
4874
tracing-oslog = "0.3"
4975

76+
[target.'cfg(not(all(target_has_atomic = "8", target_has_atomic = "16", target_has_atomic = "32", target_has_atomic = "64", target_has_atomic = "ptr")))'.dependencies]
77+
tracing-subscriber = { version = "0.3.1", default-features = false, features = [
78+
# TODO: wait for `tracing-subscriber` release
79+
# "portable-atomic",
80+
] }
81+
5082
[lints]
5183
workspace = true
5284

crates/bevy_log/src/android_tracing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloc::ffi::CString;
1+
use alloc::{ffi::CString, format, string::String, vec::Vec};
22
use core::fmt::{Debug, Write};
33
use tracing::{
44
field::Field,

0 commit comments

Comments
 (0)