Skip to content
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

Tracking Issue: MVP no_std Bevy #15460

Open
20 of 49 tasks
bushrat011899 opened this issue Sep 26, 2024 · 5 comments
Open
20 of 49 tasks

Tracking Issue: MVP no_std Bevy #15460

bushrat011899 opened this issue Sep 26, 2024 · 5 comments
Assignees
Labels
A-Cross-Cutting Impacts the entire engine C-Dependencies A change to the crates that Bevy depends on C-Feature A new feature, making something new possible C-Tracking-Issue An issue that collects information about a broad development initiative D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes X-Contentious There are nontrivial implications that should be thought through

Comments

@bushrat011899
Copy link
Contributor

bushrat011899 commented Sep 26, 2024

This is a tracking issue for progress on a no_std compatible subset of Bevy. The tasks are ordered roughly in sequence (bevy_app can't be no_std until bevy_ecs is for example).

Core Tasks

These tasks must be completed for a no_std Bevy to become usable at all.

Bonus Features

These tasks aren't strictly required, but should be completed to close the gap between no_std and std Bevy. The more functionality we can provide in no_std, the more the community can develop for it.

Not Planned

These crates can't be ported to no_std because they are highly platform specific. If you see something on this list that could be ported, please let me know!

General Notes

thiserror

thiserror is currently not available in a no_std form due to its use of the ::std::error::Error path for Error (which it continues to use for MSRV backwards compatibility). There is a PR to add no_std support to thiserror which preserves that MSRV requirement, but it's unclear if/when that will be merged and released.

One alternative is to link against the PR instead of the published version of thiserror:

thiserror = {
  git = "https://github.com/quartiq/thiserror",
  rev = "515bd36da54dbc346250026ddc349c88851e4bb1",
  default-features = false,
}

Another alternative is to switch to using derive_more. This would require adding explicit calls to derive(From, Display) as well, which adds to the noise. Additionally, it isn't already in the dependency tree, so its inclusion may be contentious.

Due to delays in thiserror's no_std support, we have decided to use derive_more.

Platform Support

Being no_std is necessary for certain platforms, but it is not always sufficient. Below is a table of platforms that I have tested:

Name Target Builds Notes
UEFI x86_64-unknown-uefi Compiles Boots on emulated and real hardware, supported by the uefi crate.
GameBoy Advance thumbv4t-none-eabi Partially The platform does not support all atomic operations (e.g., CAS), which Bevy directly and transiently relies on. Moving from tracing to log, and using portable_atomics is sufficient to make this platform compile.
Nintendo Switch aarch64-nintendo-switch-freestanding Compiles I cannot test the binary produced by cargo nx on real hardware or an emulator to confirm it actually works.
PlayStation One mipsel-sony-psx Partially The platform does not support all atomic operations (e.g., CAS), which Bevy directly and transiently relies on. Moving from tracing to log, and using portable_atomics is sufficient to make this platform compile.
MSP430 msp430-none-elf No This platform is 16-bit, which breaks too many assumptions made by dependencies like zerocopy.

I have a prototype of no_std compatible Bevy available on this branch. It's not being actively maintained, as it is a proof of concept for upstream no_std support (use at your own risk, etc.). However, if anyone has a particular platform they'd like to use Bevy on, please feel free to test using this branch and let me know what kind of compatibility you have. In general:

  • You must be able to compile a Rust project for this platform. (I hope this goes without saying!)
  • You must have alloc and core available.
  • Your platform must support Atomic CAS (hoping to relax this in the future!)
  • Only the bevy_app, bevy_ecs, bevy_utils, and bevy_tasks are compatible in this branch, and must be imported directly (e.g., you can't use bevy;, instead use bevy_app;). Additionally, you must disable default features for no_std compatibility.
  • Your platform must be 32-bit or higher due to safety concerns in bevy_ecs. For further information, see [Merged by Bors] - Fail to compile on 16-bit platforms #4736.
@bushrat011899 bushrat011899 added C-Feature A new feature, making something new possible C-Dependencies A change to the crates that Bevy depends on C-Tracking-Issue An issue that collects information about a broad development initiative A-Cross-Cutting Impacts the entire engine X-Contentious There are nontrivial implications that should be thought through D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Sep 26, 2024
@BD103
Copy link
Member

BD103 commented Sep 27, 2024

Looks like there is some effort to make thiserror support #![no_std] in dtolnay/thiserror#304. Looks like it's on hold until the author responds, though.

@bushrat011899
Copy link
Contributor Author

Yeah that's where I got the (temporary) fix from:

thiserror = {
  git = "https://github.com/quartiq/thiserror",
  rev = "515bd36da54dbc346250026ddc349c88851e4bb1",
  default-features = false,
}

I'm hoping the PR is merged sooner rather than later, but there's a similar issue with petgraph where there does exist a no_std compatible version, but it's waiting in the wings.

In both cases we have options for how to proceed. Either waiting for those crates to get updated, replacing them with something equivalent, or developing a replacement based on these prior efforts.

github-merge-queue bot pushed a commit that referenced this issue Sep 27, 2024
# Objective

- Contributes to #15460

## Solution

- Wrap `derive_label` `quote!` in an anonymous constant which contains
an `extern crate alloc` statement, allowing use of the `alloc` namespace
even when a user has not brought in the crate themselves.

## Testing

- CI passed locally.

## Notes

We can't generate code that uses `::std::boxed::Box` in `no_std`
environments, but we also can't rely on `::alloc::boxed::Box` either,
since the user might not have declared `extern crate alloc`. To resolve
this, the generated code is wrapped in an anonymous constant which
contains the `extern crate alloc` invocation.

This does mean the macro is no longer hygienic against cases where the
user provides an alternate `alloc` crate, however I believe this is an
acceptable compromise.

Additionally, this crate itself doesn't need to be `no_std`, it just
needs to _generate_ `no_std` compatible code.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
rudderbucky pushed a commit to rudderbucky/bevy that referenced this issue Sep 27, 2024
)

# Objective

- Contributes to bevyengine#15460

## Solution

- Wrap `derive_label` `quote!` in an anonymous constant which contains
an `extern crate alloc` statement, allowing use of the `alloc` namespace
even when a user has not brought in the crate themselves.

## Testing

- CI passed locally.

## Notes

We can't generate code that uses `::std::boxed::Box` in `no_std`
environments, but we also can't rely on `::alloc::boxed::Box` either,
since the user might not have declared `extern crate alloc`. To resolve
this, the generated code is wrapped in an anonymous constant which
contains the `extern crate alloc` invocation.

This does mean the macro is no longer hygienic against cases where the
user provides an alternate `alloc` crate, however I believe this is an
acceptable compromise.

Additionally, this crate itself doesn't need to be `no_std`, it just
needs to _generate_ `no_std` compatible code.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
github-merge-queue bot pushed a commit that referenced this issue Sep 30, 2024
# Objective

- Contributes to #15460
- Allows `bevy_mikktspace` to be used in `no_std` contexts.

## Solution

- Added `std` (default) and `libm` features which control the inclusion
of the standard library. To use `bevy_mikktspace` in `no_std`
environments, enable the `libm` feature.

## Testing

- CI
- `cargo clippy -p bevy_mikktspace --target "x86_64-unknown-none"
--no-default-features --features libm`
@bushrat011899 bushrat011899 self-assigned this Oct 4, 2024
robtfm pushed a commit to robtfm/bevy that referenced this issue Oct 4, 2024
)

# Objective

- Contributes to bevyengine#15460

## Solution

- Wrap `derive_label` `quote!` in an anonymous constant which contains
an `extern crate alloc` statement, allowing use of the `alloc` namespace
even when a user has not brought in the crate themselves.

## Testing

- CI passed locally.

## Notes

We can't generate code that uses `::std::boxed::Box` in `no_std`
environments, but we also can't rely on `::alloc::boxed::Box` either,
since the user might not have declared `extern crate alloc`. To resolve
this, the generated code is wrapped in an anonymous constant which
contains the `extern crate alloc` invocation.

This does mean the macro is no longer hygienic against cases where the
user provides an alternate `alloc` crate, however I believe this is an
acceptable compromise.

Additionally, this crate itself doesn't need to be `no_std`, it just
needs to _generate_ `no_std` compatible code.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
robtfm pushed a commit to robtfm/bevy that referenced this issue Oct 4, 2024
# Objective

- Contributes to bevyengine#15460
- Allows `bevy_mikktspace` to be used in `no_std` contexts.

## Solution

- Added `std` (default) and `libm` features which control the inclusion
of the standard library. To use `bevy_mikktspace` in `no_std`
environments, enable the `libm` feature.

## Testing

- CI
- `cargo clippy -p bevy_mikktspace --target "x86_64-unknown-none"
--no-default-features --features libm`
github-merge-queue bot pushed a commit that referenced this issue Oct 4, 2024
# 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`
@bushrat011899
Copy link
Contributor Author

After some discussion on the Discord, I'm going to open PRs to replace thiserror with derive_more for at least bevy_ecs and bevy_app in the near-term. A quick experiment on bevy_ecs made the change look pretty minor, and the crate does offer more functionality than thiserror does on its own.

@alice-i-cecile
Copy link
Member

Can cargo-deny work on "our" dependencies only? If so, please add a line for thiserror, since derive-more tackles everything we need.

github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_time`

## Notes

`thiserror` actually wasn't even used in this crate.
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_animation`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_app`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_color`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_core_pipeline`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_ecs`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_gilrs`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_gltf`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_input`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_math`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_image`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_mesh`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_pbr`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_reflect`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_render`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_text`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_transform`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_ui`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_scene`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_sprite`
github-merge-queue bot pushed a commit that referenced this issue Oct 9, 2024
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_asset`
@bushrat011899
Copy link
Contributor Author

Can cargo-deny work on "our" dependencies only? If so, please add a line for thiserror, since derive-more tackles everything we need.

Unfortunately no. Currently cargo deny treats direct and transitive dependencies identically. We could make a CI job that uses a crate like toml to check if thiserror is present in the dependency table for each Cargo.toml in the crates folder. I suspect we would want to do something like this anyway as a part of a broader no_std CI task.

In the interim, if a user adds thiserror back into Bevy inadvertently we at least have derive_more in-tree ready to go to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Cross-Cutting Impacts the entire engine C-Dependencies A change to the crates that Bevy depends on C-Feature A new feature, making something new possible C-Tracking-Issue An issue that collects information about a broad development initiative D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

No branches or pull requests

3 participants