Skip to content

Commit 53adcd7

Browse files
Minor fixes for bevy_utils in no_std (#15463)
# Objective - Contributes to #15460 ## Solution - Made `web-time` a `wasm32`-only dependency. - Moved time-related exports to its own module for clarity. - Feature-gated allocator requirements for `hashbrown` behind `alloc`. - Enabled compile-time RNG for `ahash` (runtime RNG will preferentially used in `std` environments) - Made `thread_local` optional by feature-gating the `Parallel` type. ## Testing - Ran CI locally. - `cargo build -p bevy_utils --target "x86_64-unknown-none" --no-default-features`
1 parent d0edbda commit 53adcd7

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

crates/bevy_utils/Cargo.toml

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

1111
[features]
12-
default = ["std"]
13-
std = ["alloc", "tracing/std", "ahash/std"]
14-
alloc = []
12+
default = ["std", "serde"]
13+
std = [
14+
"alloc",
15+
"tracing/std",
16+
"ahash/std",
17+
"dep:thread_local",
18+
"ahash/runtime-rng",
19+
]
20+
alloc = ["hashbrown/default"]
1521
detailed_trace = []
22+
serde = ["hashbrown/serde"]
1623

1724
[dependencies]
1825
ahash = { version = "0.8.7", default-features = false, features = [
19-
"runtime-rng",
26+
"compile-time-rng",
2027
] }
2128
tracing = { version = "0.1", default-features = false }
22-
web-time = { version = "1.1" }
23-
hashbrown = { version = "0.14.2", features = ["serde"] }
29+
hashbrown = { version = "0.14.2", default-features = false }
2430
bevy_utils_proc_macros = { version = "0.15.0-dev", path = "macros" }
25-
thread_local = "1.0"
31+
thread_local = { version = "1.0", optional = true }
2632

2733
[dev-dependencies]
2834
static_assertions = "1.1.0"
2935

3036
[target.'cfg(target_arch = "wasm32")'.dependencies]
3137
getrandom = { version = "0.2.0", features = ["js"] }
38+
web-time = { version = "1.1" }
3239

3340
[lints]
3441
workspace = true

crates/bevy_utils/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ mod default;
3131
mod object_safe;
3232
pub use object_safe::assert_object_safe;
3333
mod once;
34+
#[cfg(feature = "std")]
3435
mod parallel_queue;
36+
mod time;
3537

3638
pub use ahash::{AHasher, RandomState};
3739
pub use bevy_utils_proc_macros::*;
3840
pub use default::default;
3941
pub use hashbrown;
42+
#[cfg(feature = "std")]
4043
pub use parallel_queue::*;
44+
pub use time::*;
4145
pub use tracing;
42-
pub use web_time::{Duration, Instant, SystemTime, SystemTimeError, TryFromFloatSecsError};
4346

4447
#[cfg(feature = "alloc")]
4548
use alloc::boxed::Box;

crates/bevy_utils/src/time.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#[cfg(target_arch = "wasm32")]
2+
pub use web_time::{Duration, Instant, SystemTime, SystemTimeError, TryFromFloatSecsError};
3+
4+
#[cfg(all(not(target_arch = "wasm32"), feature = "std"))]
5+
pub use {
6+
core::time::{Duration, TryFromFloatSecsError},
7+
std::time::{Instant, SystemTime, SystemTimeError},
8+
};
9+
10+
#[cfg(all(not(target_arch = "wasm32"), not(feature = "std")))]
11+
pub use core::time::{Duration, TryFromFloatSecsError};

0 commit comments

Comments
 (0)