Skip to content

Allow partial support for bevy_log in no_std #18782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ default = [
"bevy_gizmos",
"bevy_gltf",
"bevy_input_focus",
"bevy_log",
"bevy_mesh_picking_backend",
"bevy_pbr",
"bevy_picking",
Expand All @@ -160,6 +159,7 @@ default = [
"smaa_luts",
"sysinfo_plugin",
"tonemapping_luts",
"tracing",
"vorbis",
"webgl2",
"x11",
Expand Down Expand Up @@ -285,9 +285,6 @@ bevy_dev_tools = ["bevy_internal/bevy_dev_tools"]
# Enable the Bevy Remote Protocol
bevy_remote = ["bevy_internal/bevy_remote"]

# Enable integration with `tracing` and `log`
bevy_log = ["bevy_internal/bevy_log"]

# Enable input focus subsystem
bevy_input_focus = ["bevy_internal/bevy_input_focus"]

Expand All @@ -314,7 +311,10 @@ trace_tracy_memory = [
]

# Tracing support
trace = ["bevy_internal/trace", "dep:tracing"]
tracing = ["bevy_internal/tracing", "dep:tracing"]

# Enables traces within Bevy using tracing
trace = ["bevy_internal/trace", "tracing"]

# Basis Universal compressed texture support
basis-universal = ["bevy_internal/basis-universal"]
Expand Down Expand Up @@ -1592,7 +1592,7 @@ wasm = true
name = "headless"
path = "examples/app/headless.rs"
doc-scrape-examples = true
required-features = ["bevy_log"]
required-features = []

[package.metadata.example.headless]
name = "Headless"
Expand Down
12 changes: 12 additions & 0 deletions crates/bevy_animation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ tracing = { version = "0.1", default-features = false, features = ["std"] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
# TODO: Assuming all wasm builds are for the browser. Require `no_std` support to break assumption.
uuid = { version = "1.13.1", default-features = false, features = ["js"] }
bevy_log = { path = "../bevy_log", version = "0.16.0-dev", default-features = false, features = [
"web",
] }
bevy_app = { path = "../bevy_app", version = "0.16.0-dev", default-features = false, features = [
"web",
] }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
"web",
] }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", default-features = false, features = [
"web",
] }

[lints]
workspace = true
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_dylib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
//! use bevy_dylib;
//! ```

#![no_std]

// Force linking of the main bevy crate
#[expect(
unused_imports,
Expand Down
18 changes: 18 additions & 0 deletions crates/bevy_gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ serde_json = "1"
smallvec = "1.11"
tracing = { version = "0.1", default-features = false, features = ["std"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
# TODO: Assuming all wasm builds are for the browser. Require `no_std` support to break assumption.
bevy_log = { path = "../bevy_log", version = "0.16.0-dev", default-features = false, features = [
"web",
] }
bevy_app = { path = "../bevy_app", version = "0.16.0-dev", default-features = false, features = [
"web",
] }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
"web",
] }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", default-features = false, features = [
"web",
] }
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev", default-features = false, features = [
"web",
] }

[dev-dependencies]
bevy_log = { path = "../bevy_log", version = "0.16.0-dev" }

Expand Down
23 changes: 17 additions & 6 deletions crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"]
categories = ["game-engines", "graphics", "gui", "rendering"]

[features]
tracing = ["bevy_log/tracing"]
trace = [
"tracing",
"bevy_app/trace",
"bevy_asset?/trace",
"bevy_core_pipeline?/trace",
Expand All @@ -21,10 +23,18 @@ trace = [
"bevy_render?/trace",
"bevy_winit?/trace",
]
trace_chrome = ["bevy_log/tracing-chrome"]
trace_tracy = ["bevy_render?/tracing-tracy", "bevy_log/tracing-tracy"]
trace_tracy_memory = ["bevy_log/trace_tracy_memory"]
detailed_trace = ["bevy_ecs/detailed_trace", "bevy_render?/detailed_trace"]
trace_chrome = ["tracing", "bevy_log/tracing-chrome"]
trace_tracy = [
"tracing",
"bevy_render?/tracing-tracy",
"bevy_log/tracing-tracy",
]
trace_tracy_memory = ["tracing", "bevy_log/trace_tracy_memory"]
detailed_trace = [
"tracing",
"bevy_ecs/detailed_trace",
"bevy_render?/detailed_trace",
]

sysinfo_plugin = ["bevy_diagnostic/sysinfo_plugin"]

Expand Down Expand Up @@ -293,6 +303,7 @@ std = [
"bevy_ecs/std",
"bevy_input/std",
"bevy_input_focus?/std",
"bevy_log/std",
"bevy_math/std",
"bevy_platform_support/std",
"bevy_reflect/std",
Expand Down Expand Up @@ -344,6 +355,7 @@ async_executor = [
# Note this is currently only applicable on `wasm32` architectures.
web = [
"bevy_app/web",
"bevy_log/web",
"bevy_platform_support/web",
"bevy_reflect/web",
"bevy_tasks/web",
Expand Down Expand Up @@ -385,8 +397,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev", default-features
] }
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev", default-features = false }

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

# bevy (optional)
bevy_a11y = { path = "../bevy_a11y", optional = true, version = "0.16.0-dev", features = [
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_internal/src/default_plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugin_group! {
/// This plugin group will add all the default plugins for a *Bevy* application:
pub struct DefaultPlugins {
bevy_app:::PanicHandlerPlugin,
#[cfg(feature = "bevy_log")]
#[cfg(feature = "tracing")]
bevy_log:::LogPlugin,
bevy_app:::TaskPoolPlugin,
bevy_diagnostic:::FrameCountPlugin,
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub use bevy_image as image;
pub use bevy_input as input;
#[cfg(feature = "bevy_input_focus")]
pub use bevy_input_focus as input_focus;
#[cfg(feature = "bevy_log")]
pub use bevy_log as log;
pub use bevy_math as math;
#[cfg(feature = "bevy_pbr")]
Expand Down
6 changes: 1 addition & 5 deletions crates/bevy_internal/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#[doc(hidden)]
pub use crate::{
app::prelude::*, ecs::prelude::*, input::prelude::*, math::prelude::*,
app::prelude::*, ecs::prelude::*, input::prelude::*, log::prelude::*, math::prelude::*,
platform_support::prelude::*, reflect::prelude::*, time::prelude::*, transform::prelude::*,
utils::prelude::*, DefaultPlugins, MinimalPlugins,
};

#[doc(hidden)]
#[cfg(feature = "bevy_log")]
pub use crate::log::prelude::*;

#[doc(hidden)]
#[cfg(feature = "bevy_window")]
pub use crate::window::prelude::*;
Expand Down
42 changes: 29 additions & 13 deletions crates/bevy_log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,44 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
trace = ["tracing-error"]
trace_tracy_memory = ["dep:tracy-client"]
default = ["std", "tracing"]

tracing = ["dep:tracing", "dep:tracing-subscriber", "dep:tracing-log"]
trace = ["tracing", "tracing-error"]
trace_tracy_memory = ["tracing", "dep:tracy-client"]
tracing-chrome = ["tracing", "dep:tracing-chrome"]
tracing-error = ["tracing", "dep:tracing-error"]
tracing-tracy = ["tracing", "dep:tracing-tracy"]

# Allows access to the `std` crate. Enabling this feature will prevent compilation
# on `no_std` targets, but provides access to certain additional features on
# supported platforms.
std = ["bevy_app/std", "bevy_utils/std", "bevy_ecs/std"]

# Enables use of browser APIs.
# Note this is currently only applicable on `wasm32` architectures.
web = ["bevy_app/web", "dep:tracing-wasm"]

[dependencies]
# bevy
bevy_app = { path = "../bevy_app", version = "0.16.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev" }
bevy_app = { path = "../bevy_app", version = "0.16.0-dev", default-features = false }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev", default-features = false, features = [
"alloc",
] }
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev", default-features = false }

# other
tracing-subscriber = { version = "0.3.1", features = [
log = { version = "0.4", default-features = false }
tracing-subscriber = { version = "0.3.1", optional = true, features = [
"registry",
"env-filter",
] }
tracing-chrome = { version = "0.7.0", optional = true }
tracing-log = "0.2.0"
tracing-log = { version = "0.2.0", optional = true }
tracing-error = { version = "0.2.0", optional = true }
tracing = { version = "0.1", default-features = false, features = ["std"] }
tracing = { version = "0.1", default-features = false, optional = true, features = [
"std",
] }

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

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

[target.'cfg(target_os = "ios")'.dependencies]
tracing-oslog = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_log/src/android_tracing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloc::ffi::CString;
use alloc::{ffi::CString, format, string::String, vec::Vec};
use core::fmt::{Debug, Write};
use tracing::{
field::Field,
Expand Down
Loading