bevyengine/bevy
bevy_platform
Cross-platform shims. Wraps std-only types so other Bevy crates compile under no_std, including the Wasm-without-atomics target.
Purpose
Bevy supports no_std and Wasm. Several types are usually provided by std — Instant, HashMap, Mutex, Arc, atomics — and have to be replaced with crate-level alternatives on these platforms. bevy_platform is the place that picks the right alternative based on cargo features.
Directory layout
crates/bevy_platform/src/
├── lib.rs # Re-exports
├── time.rs # Instant, Duration shims (uses web-time on wasm)
├── collections/ # HashMap, HashSet, BTreeMap, BTreeSet aliases
├── hash.rs # PassHasher, FixedHasher (deterministic hashers)
├── sync/ # Mutex, RwLock, Arc shims
├── thread.rs # spawn / thread_local on no_std
├── cell/ # SyncCell, SyncUnsafeCell
├── prelude.rs
└── …Key abstractions
| Type | File | Description |
|---|---|---|
Instant |
crates/bevy_platform/src/time.rs |
Monotonic timestamp; web-time on wasm, std::time::Instant on native. |
HashMap, HashSet |
crates/bevy_platform/src/collections/ |
hashbrown::HashMap with a fixed hasher. |
Arc, Mutex, RwLock |
crates/bevy_platform/src/sync/ |
Re-exports of std::sync or portable-atomic-backed analogues. |
FixedHasher, PassHasher |
crates/bevy_platform/src/hash.rs |
Hashers without DoS protection (faster, deterministic). |
Why deterministic hashers
Bevy uses FixedHasher for ECS internal maps because the standard RandomState introduces frame-to-frame randomness that defeats deterministic replays. Game state hashes — used by netcode and rollback — need to be stable across runs and platforms.
Integration points
- Depends on:
hashbrown,web-time(wasm),portable-atomic(no_std). - Depended on by: Almost every Bevy crate.
bevy_ecs,bevy_app,bevy_reflect,bevy_render, etc. importInstant,HashMap, and friends from here.
Entry points for modification
- New platform target: identify which
std::types break and add a shim here. - Hasher tweak:
hash.rs. TheFixedHasheris the workspace default; changing it has performance and determinism implications. - Sync primitive bug:
sync/. Theportable-atomicintegration handles wasm-without-atomics.
See also
bevy_utils— sister crate of higher-level helpers.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.