Skip to content

Commit ac52cca

Browse files
Allow partial support for bevy_log in no_std (#18782)
# Objective - Fixes #18781 ## Solution - Moved `LogPlugin` into its own file gated behind a new `tracing` feature. - Used `log` instead of `tracing` where possible. - Exposed a new `tracing` feature in `bevy` which enables `bevy_log/tracing`. - Gated `LogPlugin` from `DefaultPlugins` on `tracing` feature. ## Testing - CI --- ## Migration Guide - If you were previously using `bevy_log` with default features disabled, enable the new `std` and `tracing` features. - If you were using `bevy` with the default features disabled, enable the new `tracing` feature. ## Notes Almost all of the diffs in this PR come from moving `LogPlugin` into its own file. This just makes the PR less noisy, since the alternative is excessive `#[cfg(feature = "tracing")]` directives all over the plugin. --------- Co-authored-by: François Mockers <[email protected]>
1 parent 24baf32 commit ac52cca

File tree

16 files changed

+475
-375
lines changed

16 files changed

+475
-375
lines changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ default = [
138138
"bevy_gizmos",
139139
"bevy_gltf",
140140
"bevy_input_focus",
141-
"bevy_log",
142141
"bevy_mesh_picking_backend",
143142
"bevy_pbr",
144143
"bevy_picking",
@@ -160,6 +159,7 @@ default = [
160159
"smaa_luts",
161160
"sysinfo_plugin",
162161
"tonemapping_luts",
162+
"tracing",
163163
"vorbis",
164164
"webgl2",
165165
"x11",
@@ -285,9 +285,6 @@ bevy_dev_tools = ["bevy_internal/bevy_dev_tools"]
285285
# Enable the Bevy Remote Protocol
286286
bevy_remote = ["bevy_internal/bevy_remote"]
287287

288-
# Enable integration with `tracing` and `log`
289-
bevy_log = ["bevy_internal/bevy_log"]
290-
291288
# Enable input focus subsystem
292289
bevy_input_focus = ["bevy_internal/bevy_input_focus"]
293290

@@ -314,7 +311,10 @@ trace_tracy_memory = [
314311
]
315312

316313
# Tracing support
317-
trace = ["bevy_internal/trace", "dep:tracing"]
314+
tracing = ["bevy_internal/tracing", "dep:tracing"]
315+
316+
# Enables traces within Bevy using tracing
317+
trace = ["bevy_internal/trace", "tracing"]
318318

319319
# Basis Universal compressed texture support
320320
basis-universal = ["bevy_internal/basis-universal"]
@@ -1592,7 +1592,7 @@ wasm = true
15921592
name = "headless"
15931593
path = "examples/app/headless.rs"
15941594
doc-scrape-examples = true
1595-
required-features = ["bevy_log"]
1595+
required-features = []
15961596

15971597
[package.metadata.example.headless]
15981598
name = "Headless"

crates/bevy_animation/Cargo.toml

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

5163
[lints]
5264
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ serde_json = "1"
6565
smallvec = "1.11"
6666
tracing = { version = "0.1", default-features = false, features = ["std"] }
6767

68+
[target.'cfg(target_arch = "wasm32")'.dependencies]
69+
# TODO: Assuming all wasm builds are for the browser. Require `no_std` support to break assumption.
70+
bevy_log = { path = "../bevy_log", version = "0.16.0-dev", default-features = false, features = [
71+
"web",
72+
] }
73+
bevy_app = { path = "../bevy_app", version = "0.16.0-dev", default-features = false, features = [
74+
"web",
75+
] }
76+
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
77+
"web",
78+
] }
79+
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", default-features = false, features = [
80+
"web",
81+
] }
82+
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev", default-features = false, features = [
83+
"web",
84+
] }
85+
6886
[dev-dependencies]
6987
bevy_log = { path = "../bevy_log", version = "0.16.0-dev" }
7088

crates/bevy_internal/Cargo.toml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"]
1010
categories = ["game-engines", "graphics", "gui", "rendering"]
1111

1212
[features]
13+
tracing = ["bevy_log/tracing"]
1314
trace = [
15+
"tracing",
1416
"bevy_app/trace",
1517
"bevy_asset?/trace",
1618
"bevy_core_pipeline?/trace",
@@ -21,10 +23,18 @@ trace = [
2123
"bevy_render?/trace",
2224
"bevy_winit?/trace",
2325
]
24-
trace_chrome = ["bevy_log/tracing-chrome"]
25-
trace_tracy = ["bevy_render?/tracing-tracy", "bevy_log/tracing-tracy"]
26-
trace_tracy_memory = ["bevy_log/trace_tracy_memory"]
27-
detailed_trace = ["bevy_ecs/detailed_trace", "bevy_render?/detailed_trace"]
26+
trace_chrome = ["tracing", "bevy_log/tracing-chrome"]
27+
trace_tracy = [
28+
"tracing",
29+
"bevy_render?/tracing-tracy",
30+
"bevy_log/tracing-tracy",
31+
]
32+
trace_tracy_memory = ["tracing", "bevy_log/trace_tracy_memory"]
33+
detailed_trace = [
34+
"tracing",
35+
"bevy_ecs/detailed_trace",
36+
"bevy_render?/detailed_trace",
37+
]
2838

2939
sysinfo_plugin = ["bevy_diagnostic/sysinfo_plugin"]
3040

@@ -293,6 +303,7 @@ std = [
293303
"bevy_ecs/std",
294304
"bevy_input/std",
295305
"bevy_input_focus?/std",
306+
"bevy_log/std",
296307
"bevy_math/std",
297308
"bevy_platform_support/std",
298309
"bevy_reflect/std",
@@ -344,6 +355,7 @@ async_executor = [
344355
# Note this is currently only applicable on `wasm32` architectures.
345356
web = [
346357
"bevy_app/web",
358+
"bevy_log/web",
347359
"bevy_platform_support/web",
348360
"bevy_reflect/web",
349361
"bevy_tasks/web",
@@ -385,8 +397,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev", default-features
385397
] }
386398
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev", default-features = false }
387399

388-
# bevy (std required)
389-
bevy_log = { path = "../bevy_log", version = "0.16.0-dev", optional = true }
400+
bevy_log = { path = "../bevy_log", version = "0.16.0-dev", default-features = false }
390401

391402
# bevy (optional)
392403
bevy_a11y = { path = "../bevy_a11y", optional = true, version = "0.16.0-dev", features = [

crates/bevy_internal/src/default_plugins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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")]
7+
#[cfg(feature = "tracing")]
88
bevy_log:::LogPlugin,
99
bevy_app:::TaskPoolPlugin,
1010
bevy_diagnostic:::FrameCountPlugin,

crates/bevy_internal/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub use bevy_image as image;
4444
pub use bevy_input as input;
4545
#[cfg(feature = "bevy_input_focus")]
4646
pub use bevy_input_focus as input_focus;
47-
#[cfg(feature = "bevy_log")]
4847
pub use bevy_log as log;
4948
pub use bevy_math as math;
5049
#[cfg(feature = "bevy_pbr")]

crates/bevy_internal/src/prelude.rs

Lines changed: 1 addition & 5 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::*,
3+
app::prelude::*, ecs::prelude::*, input::prelude::*, log::prelude::*, math::prelude::*,
44
platform_support::prelude::*, reflect::prelude::*, time::prelude::*, transform::prelude::*,
55
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: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,44 @@ 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", "tracing"]
13+
14+
tracing = ["dep:tracing", "dep:tracing-subscriber", "dep:tracing-log"]
15+
trace = ["tracing", "tracing-error"]
16+
trace_tracy_memory = ["tracing", "dep:tracy-client"]
17+
tracing-chrome = ["tracing", "dep:tracing-chrome"]
18+
tracing-error = ["tracing", "dep:tracing-error"]
19+
tracing-tracy = ["tracing", "dep:tracing-tracy"]
20+
21+
# Allows access to the `std` crate. Enabling this feature will prevent compilation
22+
# on `no_std` targets, but provides access to certain additional features on
23+
# supported platforms.
24+
std = ["bevy_app/std", "bevy_utils/std", "bevy_ecs/std"]
25+
26+
# Enables use of browser APIs.
27+
# Note this is currently only applicable on `wasm32` architectures.
28+
web = ["bevy_app/web", "dep:tracing-wasm"]
1429

1530
[dependencies]
1631
# bevy
17-
bevy_app = { path = "../bevy_app", version = "0.16.0-dev" }
18-
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
19-
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev" }
32+
bevy_app = { path = "../bevy_app", version = "0.16.0-dev", default-features = false }
33+
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev", default-features = false, features = [
34+
"alloc",
35+
] }
36+
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev", default-features = false }
2037

2138
# other
22-
tracing-subscriber = { version = "0.3.1", features = [
39+
log = { version = "0.4", default-features = false }
40+
tracing-subscriber = { version = "0.3.1", optional = true, features = [
2341
"registry",
2442
"env-filter",
2543
] }
2644
tracing-chrome = { version = "0.7.0", optional = true }
27-
tracing-log = "0.2.0"
45+
tracing-log = { version = "0.2.0", optional = true }
2846
tracing-error = { version = "0.2.0", optional = true }
29-
tracing = { version = "0.1", default-features = false, features = ["std"] }
47+
tracing = { version = "0.1", default-features = false, optional = true, features = [
48+
"std",
49+
] }
3050

3151
# Tracy dependency compatibility table:
3252
# https://github.com/nagisa/rust_tracy_client
@@ -37,11 +57,7 @@ tracy-client = { version = "0.18.0", optional = true }
3757
android_log-sys = "0.3.0"
3858

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

4662
[target.'cfg(target_os = "ios")'.dependencies]
4763
tracing-oslog = "0.2"

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)