Skip to content

Add no_std support to bevy #17955

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 19 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f9c57fa
Add `no_std` support to `bevy`
bushrat011899 Feb 20, 2025
8ea1787
Fix `thumbv6m-none-eabi` Compatibility and add to CI
bushrat011899 Feb 21, 2025
1999297
Merge branch 'main' into NoSTDForBevyItselfV2
bushrat011899 Feb 21, 2025
3295da6
Merge remote-tracking branch 'upstream/main' into NoSTDForBevyItselfV2
bushrat011899 Feb 23, 2025
52ee47f
Merge remote-tracking branch 'upstream/main' into NoSTDForBevyItselfV2
bushrat011899 Feb 24, 2025
9931f17
Merge remote-tracking branch 'upstream/main' into NoSTDForBevyItselfV2
bushrat011899 Feb 24, 2025
7b49b9c
Simplify features now that `portable-atomic` is removed
bushrat011899 Feb 24, 2025
5991069
Update ci.yml
bushrat011899 Feb 24, 2025
e3ac49d
Fix `bevy_color` feature gates
bushrat011899 Feb 25, 2025
c6c7a60
Formatting
bushrat011899 Feb 25, 2025
70b6c5b
Merge remote-tracking branch 'upstream/main' into NoSTDForBevyItselfV2
bushrat011899 Feb 25, 2025
0755b51
Fix arbitrary self types issue
bushrat011899 Feb 25, 2025
184ef80
Merge remote-tracking branch 'upstream/main' into NoSTDForBevyItselfV2
bushrat011899 Mar 1, 2025
e3262ce
Merge branch 'main' into NoSTDForBevyItselfV2
alice-i-cecile Mar 6, 2025
f5af460
Inline `edge-executor`
bushrat011899 Mar 6, 2025
b5d3762
cargo fmt
bushrat011899 Mar 6, 2025
13fabea
Refactor features to allow `--no-default-features` to compile
bushrat011899 Mar 7, 2025
d032c2e
Merge remote-tracking branch 'upstream/main' into NoSTDForBevyItselfV2
bushrat011899 Mar 7, 2025
3d09e4b
Update cargo_features.md
bushrat011899 Mar 7, 2025
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
26 changes: 25 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,31 @@ jobs:
- name: Install Linux dependencies
uses: ./.github/actions/install-linux-deps
- name: Check Compile
run: cargo run -p ci -- compile-check-no-std
run: cargo check -p bevy --no-default-features --features default_no_std --target x86_64-unknown-none
check-compiles-no-std-portable-atomic:
runs-on: ubuntu-latest
timeout-minutes: 30
needs: ci
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
crates/bevy_ecs_compile_fail_tests/target/
crates/bevy_reflect_compile_fail_tests/target/
key: ${{ runner.os }}-cargo-check-compiles-no-std-portable-atomic-${{ hashFiles('**/Cargo.toml') }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: thumbv6m-none-eabi
- name: Install Linux dependencies
uses: ./.github/actions/install-linux-deps
- name: Check Compile
run: cargo check -p bevy --no-default-features --features default_no_std --target thumbv6m-none-eabi

build-wasm:
runs-on: ubuntu-latest
Expand Down
25 changes: 25 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ unused_qualifications = "warn"

[features]
default = [
"std",
"async_executor",
"android-game-activity",
"android_shared_stdcxx",
"animation",
Expand All @@ -130,6 +132,8 @@ default = [
"bevy_gilrs",
"bevy_gizmos",
"bevy_gltf",
"bevy_input_focus",
"bevy_log",
"bevy_mesh_picking_backend",
"bevy_pbr",
"bevy_picking",
Expand All @@ -156,6 +160,9 @@ default = [
"x11",
]

# Recommended defaults for no_std applications
default_no_std = ["libm", "critical-section", "bevy_color", "bevy_state"]

# Provides an implementation for picking meshes
bevy_mesh_picking_backend = [
"bevy_picking",
Expand Down Expand Up @@ -263,6 +270,12 @@ 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"]

# Enable passthrough loading for SPIR-V shaders (Only supported on Vulkan, shader capabilities and extensions must agree with the platform implementation)
spirv_shader_passthrough = ["bevy_internal/spirv_shader_passthrough"]

Expand Down Expand Up @@ -488,6 +501,18 @@ custom_cursor = ["bevy_internal/custom_cursor"]
# Experimental support for nodes that are ignored for UI layouting
ghost_nodes = ["bevy_internal/ghost_nodes"]

# Uses `async-executor` as a task execution backend.
async_executor = ["std", "bevy_internal/async_executor"]

# Allows access to the `std` crate.
std = ["bevy_internal/std"]

# `critical-section` provides the building blocks for synchronization primitives on all platforms, including `no_std`.
critical-section = ["bevy_internal/critical-section"]

# Uses the `libm` maths library instead of the one provided in `std` and `core`.
libm = ["bevy_internal/libm"]

[dependencies]
bevy_internal = { path = "crates/bevy_internal", version = "0.16.0-dev", default-features = false }
tracing = { version = "0.1", default-features = false, optional = true }
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_animation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ bevy_derive = { path = "../bevy_derive", version = "0.16.0-dev" }
bevy_log = { path = "../bevy_log", version = "0.16.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.16.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", features = [
"bevy",
"petgraph",
] }
bevy_render = { path = "../bevy_render", version = "0.16.0-dev" }
Expand Down
17 changes: 4 additions & 13 deletions crates/bevy_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
default = [
"std",
"bevy_reflect",
"bevy_tasks",
"bevy_ecs/default",
"error_panic_hook",
]
default = ["std", "bevy_reflect", "bevy_ecs/default", "error_panic_hook"]

# Functionality

Expand All @@ -29,9 +23,6 @@ reflect_functions = [
"bevy_ecs/reflect_functions",
]

## Adds support for running async background tasks
bevy_tasks = ["dep:bevy_tasks"]

# Debugging Features

## Enables `tracing` integration, allowing spans and other metrics to be reported
Expand All @@ -57,14 +48,14 @@ std = [
"dep:ctrlc",
"downcast-rs/std",
"bevy_utils/std",
"bevy_tasks?/std",
"bevy_tasks/std",
"bevy_platform_support/std",
]

## `critical-section` provides the building blocks for synchronization primitives
## on all platforms, including `no_std`.
critical-section = [
"bevy_tasks?/critical-section",
"bevy_tasks/critical-section",
"bevy_ecs/critical-section",
"bevy_platform_support/critical-section",
"bevy_reflect?/critical-section",
Expand All @@ -78,7 +69,7 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", default-featu
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev", default-features = false, features = [
"alloc",
] }
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev", default-features = false, optional = true }
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev", default-features = false }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false }

# other
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ type RunnerFn = Box<dyn FnOnce(App) -> AppExit>;

fn run_once(mut app: App) -> AppExit {
while app.plugins_state() == PluginsState::Adding {
#[cfg(all(not(target_arch = "wasm32"), feature = "bevy_tasks"))]
#[cfg(not(target_arch = "wasm32"))]
bevy_tasks::tick_global_task_pools_on_main_thread();
}
app.finish();
Expand Down
8 changes: 1 addition & 7 deletions crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ mod plugin;
mod plugin_group;
mod schedule_runner;
mod sub_app;
#[cfg(feature = "bevy_tasks")]
mod task_pool_plugin;
#[cfg(all(any(unix, windows), feature = "std"))]
mod terminal_ctrl_c_handler;
Expand All @@ -42,7 +41,6 @@ pub use plugin::*;
pub use plugin_group::*;
pub use schedule_runner::*;
pub use sub_app::*;
#[cfg(feature = "bevy_tasks")]
pub use task_pool_plugin::*;
#[cfg(all(any(unix, windows), feature = "std"))]
pub use terminal_ctrl_c_handler::*;
Expand All @@ -60,10 +58,6 @@ pub mod prelude {
RunFixedMainLoopSystem, SpawnScene, Startup, Update,
},
sub_app::SubApp,
Plugin, PluginGroup,
NonSendMarker, Plugin, PluginGroup, TaskPoolOptions, TaskPoolPlugin,
};

#[cfg(feature = "bevy_tasks")]
#[doc(hidden)]
pub use crate::{NonSendMarker, TaskPoolOptions, TaskPoolPlugin};
}
2 changes: 1 addition & 1 deletion crates/bevy_app/src/schedule_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Plugin for ScheduleRunnerPlugin {
let plugins_state = app.plugins_state();
if plugins_state != PluginsState::Cleaned {
while app.plugins_state() == PluginsState::Adding {
#[cfg(all(not(target_arch = "wasm32"), feature = "bevy_tasks"))]
#[cfg(not(target_arch = "wasm32"))]
bevy_tasks::tick_global_task_pools_on_main_thread();
}
app.finish();
Expand Down
4 changes: 1 addition & 3 deletions crates/bevy_audio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ bevy_app = { path = "../bevy_app", version = "0.16.0-dev" }
bevy_asset = { path = "../bevy_asset", version = "0.16.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.16.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", features = [
"bevy",
] }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev" }
bevy_transform = { path = "../bevy_transform", version = "0.16.0-dev" }
bevy_derive = { path = "../bevy_derive", version = "0.16.0-dev" }

Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_diagnostic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ serialize = [
dynamic_linking = []

## Adds integration with `sysinfo`.
sysinfo_plugin = ["sysinfo", "dep:bevy_tasks"]
sysinfo_plugin = ["sysinfo"]

# Platform Compatibility

Expand All @@ -40,7 +40,7 @@ std = [
"bevy_platform_support/std",
"bevy_time/std",
"bevy_utils/std",
"bevy_tasks?/std",
"bevy_tasks/std",
]

## `critical-section` provides the building blocks for synchronization primitives
Expand All @@ -51,7 +51,7 @@ critical-section = [
"bevy_platform_support/critical-section",
"bevy_time/critical-section",
"bevy_utils/critical-section",
"bevy_tasks?/critical-section",
"bevy_tasks/critical-section",
]

[dependencies]
Expand All @@ -62,7 +62,7 @@ bevy_time = { path = "../bevy_time", version = "0.16.0-dev", default-features =
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev", default-features = false, features = [
"alloc",
] }
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev", default-features = false, optional = true }
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev", default-features = false }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
"alloc",
] }
Expand Down
10 changes: 3 additions & 7 deletions crates/bevy_ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ track_location = []

## Uses `async-executor` as a task execution backend.
## This backend is incompatible with `no_std` targets.
async_executor = ["dep:bevy_tasks", "std", "bevy_tasks/async_executor"]

## Uses `edge-executor` as a task execution backend.
## Use this instead of `async-executor` if working on a `no_std` target.
edge_executor = ["dep:bevy_tasks", "bevy_tasks/edge_executor"]
async_executor = ["std", "bevy_tasks/async_executor"]

# Platform Compatibility

Expand All @@ -90,7 +86,7 @@ std = [
## `critical-section` provides the building blocks for synchronization primitives
## on all platforms, including `no_std`.
critical-section = [
"bevy_tasks?/critical-section",
"bevy_tasks/critical-section",
"bevy_platform_support/critical-section",
"bevy_reflect?/critical-section",
]
Expand All @@ -100,7 +96,7 @@ bevy_ptr = { path = "../bevy_ptr", version = "0.16.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", features = [
"smallvec",
], default-features = false, optional = true }
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev", default-features = false, optional = true }
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev", default-features = false }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev", default-features = false, features = [
"alloc",
] }
Expand Down
7 changes: 4 additions & 3 deletions crates/bevy_ecs/src/entity/unique_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ use alloc::{
boxed::Box,
collections::{BTreeSet, BinaryHeap, LinkedList, VecDeque},
rc::Rc,
sync::Arc,
vec::Vec,
};

use bevy_platform_support::sync::Arc;

use super::{unique_slice, TrustedEntityBorrow, UniqueEntityIter, UniqueEntitySlice};

/// An array that contains only unique entities.
Expand Down Expand Up @@ -73,9 +74,9 @@ impl<T: TrustedEntityBorrow, const N: usize> UniqueEntityArray<T, N> {
}

/// Casts `self` to the inner array.
pub fn into_arc_inner(self: Arc<Self>) -> Arc<[T; N]> {
pub fn into_arc_inner(this: Arc<Self>) -> Arc<[T; N]> {
// SAFETY: UniqueEntityArray is a transparent wrapper around [T; N].
unsafe { Arc::from_raw(Arc::into_raw(self).cast()) }
unsafe { Arc::from_raw(Arc::into_raw(this).cast()) }
}

// Constructs a `Rc<UniqueEntityArray>` from a [`Rc<[T; N]>`] unsafely.
Expand Down
7 changes: 4 additions & 3 deletions crates/bevy_ecs/src/entity/unique_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ use alloc::{
boxed::Box,
collections::VecDeque,
rc::Rc,
sync::Arc,
vec::Vec,
};

use bevy_platform_support::sync::Arc;

use super::{
unique_vec, EntitySet, EntitySetIterator, FromEntitySetIterator, TrustedEntityBorrow,
UniqueEntityArray, UniqueEntityIter, UniqueEntityVec,
Expand Down Expand Up @@ -86,9 +87,9 @@ impl<T: TrustedEntityBorrow> UniqueEntitySlice<T> {
}

/// Casts `self` to the inner slice.
pub fn into_arc_inner(self: Arc<Self>) -> Arc<[T]> {
pub fn into_arc_inner(this: Arc<Self>) -> Arc<[T]> {
// SAFETY: UniqueEntitySlice is a transparent wrapper around [T].
unsafe { Arc::from_raw(Arc::into_raw(self) as *mut [T]) }
unsafe { Arc::from_raw(Arc::into_raw(this) as *mut [T]) }
}

// Constructs a `UniqueEntitySlice` from a [`Rc<[T]>`] unsafely.
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_ecs/src/entity/unique_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ use alloc::{
boxed::Box,
collections::{BTreeSet, BinaryHeap, TryReserveError, VecDeque},
rc::Rc,
sync::Arc,
vec::{self, Vec},
};

use bevy_platform_support::sync::Arc;

use super::{
unique_slice, EntitySet, FromEntitySetIterator, TrustedEntityBorrow, UniqueEntityArray,
UniqueEntityIter, UniqueEntitySlice,
Expand Down
4 changes: 1 addition & 3 deletions crates/bevy_gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev" }
bevy_image = { path = "../bevy_image", version = "0.16.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.16.0-dev" }
bevy_pbr = { path = "../bevy_pbr", version = "0.16.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", features = [
"bevy",
] }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev" }
bevy_render = { path = "../bevy_render", version = "0.16.0-dev" }
bevy_scene = { path = "../bevy_scene", version = "0.16.0-dev", features = [
"bevy_render",
Expand Down
4 changes: 1 addition & 3 deletions crates/bevy_image/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ bevy_color = { path = "../bevy_color", version = "0.16.0-dev", features = [
"wgpu-types",
] }
bevy_math = { path = "../bevy_math", version = "0.16.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", features = [
"bevy",
], optional = true }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", optional = true }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
"std",
Expand Down
Loading