Skip to content

Commit c39807d

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 c0eb89e commit c39807d

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
@@ -145,7 +145,6 @@ default = [
145145
"bevy_gizmos",
146146
"bevy_gltf",
147147
"bevy_input_focus",
148-
"bevy_log",
149148
"bevy_mesh_picking_backend",
150149
"bevy_pbr",
151150
"bevy_picking",
@@ -309,9 +308,6 @@ bevy_dev_tools = ["bevy_internal/bevy_dev_tools"]
309308
# Enable the Bevy Remote Protocol
310309
bevy_remote = ["bevy_internal/bevy_remote"]
311310

312-
# Enable integration with `tracing` and `log`
313-
bevy_log = ["bevy_internal/bevy_log"]
314-
315311
# Enable input focus subsystem
316312
bevy_input_focus = ["bevy_internal/bevy_input_focus"]
317313

@@ -1710,7 +1706,6 @@ wasm = true
17101706
name = "headless"
17111707
path = "examples/app/headless.rs"
17121708
doc-scrape-examples = true
1713-
required-features = ["bevy_log"]
17141709

17151710
[package.metadata.example.headless]
17161711
name = "Headless"

crates/bevy_animation/Cargo.toml

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

4961
[lints]
5062
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
@@ -66,6 +66,21 @@ smallvec = { version = "1", default-features = false }
6666
tracing = { version = "0.1", default-features = false, features = ["std"] }
6767
bevy_log = { path = "../bevy_log", version = "0.17.0-dev" }
6868

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

crates/bevy_internal/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ std = [
332332
"bevy_ecs/std",
333333
"bevy_input/std",
334334
"bevy_input_focus?/std",
335+
"bevy_log/std",
335336
"bevy_math/std",
336337
"bevy_platform/std",
337338
"bevy_reflect/std",
@@ -348,6 +349,7 @@ critical-section = [
348349
"bevy_app/critical-section",
349350
"bevy_diagnostic/critical-section",
350351
"bevy_ecs/critical-section",
352+
"bevy_log/critical-section",
351353
"bevy_input/critical-section",
352354
"bevy_input_focus?/critical-section",
353355
"bevy_platform/critical-section",
@@ -377,7 +379,7 @@ async_executor = [
377379

378380
# Enables use of browser APIs.
379381
# Note this is currently only applicable on `wasm32` architectures.
380-
web = ["bevy_app/web", "bevy_platform/web", "bevy_reflect/web"]
382+
web = ["bevy_app/web", "bevy_log/web", "bevy_platform/web", "bevy_reflect/web"]
381383

382384
hotpatching = ["bevy_app/hotpatching", "bevy_ecs/hotpatching"]
383385

@@ -400,6 +402,7 @@ bevy_ecs = { path = "../bevy_ecs", version = "0.17.0-dev", default-features = fa
400402
bevy_input = { path = "../bevy_input", version = "0.17.0-dev", default-features = false, features = [
401403
"bevy_reflect",
402404
] }
405+
bevy_log = { path = "../bevy_log", version = "0.17.0-dev", default-features = false }
403406
bevy_math = { path = "../bevy_math", version = "0.17.0-dev", default-features = false, features = [
404407
"bevy_reflect",
405408
"nostd-libm",
@@ -421,9 +424,6 @@ bevy_transform = { path = "../bevy_transform", version = "0.17.0-dev", default-f
421424
bevy_utils = { path = "../bevy_utils", version = "0.17.0-dev", default-features = false }
422425
bevy_tasks = { path = "../bevy_tasks", version = "0.17.0-dev", default-features = false }
423426

424-
# bevy (std required)
425-
bevy_log = { path = "../bevy_log", version = "0.17.0-dev", optional = true }
426-
427427
# bevy (optional)
428428
bevy_a11y = { path = "../bevy_a11y", optional = true, version = "0.17.0-dev", features = [
429429
"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
@@ -54,7 +54,6 @@ pub use bevy_input as input;
5454
pub use bevy_input_focus as input_focus;
5555
#[cfg(feature = "bevy_light")]
5656
pub use bevy_light as light;
57-
#[cfg(feature = "bevy_log")]
5857
pub use bevy_log as log;
5958
pub use bevy_math as math;
6059
#[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.17.0-dev" }
18-
bevy_utils = { path = "../bevy_utils", version = "0.17.0-dev" }
19-
bevy_platform = { path = "../bevy_platform", version = "0.17.0-dev" }
20-
bevy_ecs = { path = "../bevy_ecs", version = "0.17.0-dev" }
43+
bevy_app = { path = "../bevy_app", version = "0.17.0-dev", default-features = false }
44+
bevy_utils = { path = "../bevy_utils", version = "0.17.0-dev", default-features = false }
45+
bevy_platform = { path = "../bevy_platform", version = "0.17.0-dev", default-features = false }
46+
bevy_ecs = { path = "../bevy_ecs", version = "0.17.0-dev", default-features = false }
2147

2248
# other
23-
tracing-subscriber = { version = "0.3.1", features = [
49+
tracing-subscriber = { version = "0.3.1", 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.0", 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.17.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)