bevy/tools/ci/src/commands/compile_check_no_std.rs
Zachary Harrold 72f096c91e
Add no_std support to bevy_tasks (#15464)
# Objective

- Contributes to #15460

## Solution

- Added the following features:
  - `std` (default)
  - `async_executor` (default)
  - `edge_executor`
  - `critical-section`
  - `portable-atomic`
- Added [`edge-executor`](https://crates.io/crates/edge-executor) as a
`no_std` alternative to `async-executor`.
- Updated the `single_threaded_task_pool` to work in `no_std`
environments by gating its reliance on `thread_local`.

## Testing

- Added to `compile-check-no-std` CI command

## Notes

- In previous iterations of this PR, a custom `async-executor`
alternative was vendored in. This raised concerns around maintenance and
testing. In this iteration, an existing version of that same vendoring
is now used, but _only_ in `no_std` contexts. For existing `std`
contexts, the original `async-executor` is used.
- Due to the way statics work, certain `TaskPool` operations have added
restrictions around `Send`/`Sync` in `no_std`. This is because there
isn't a straightforward way to create a thread-local in `no_std`. If
these added constraints pose an issue we can revisit this at a later
date.
- If a user enables both the `async_executor` and `edge_executor`
features, we will default to using `async-executor`. Since enabling
`async_executor` requires `std`, we can safely assume we are in an `std`
context and use the original library.

---------

Co-authored-by: Mike <2180432+hymm@users.noreply.github.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
2024-12-06 02:14:54 +00:00

100 lines
3.4 KiB
Rust

use crate::{Flag, Prepare, PreparedCommand};
use argh::FromArgs;
use xshell::cmd;
/// Checks that the project compiles for a `no_std` target.
/// Note that this tool will attempt to install the target via rustup.
/// This can be skipped by passing the "--skip-install" flag.
#[derive(FromArgs)]
#[argh(subcommand, name = "compile-check-no-std")]
pub struct CompileCheckNoStdCommand {
/// the target to check against.
/// Defaults to "x86_64-unknown-none"
#[argh(option, default = "Self::default().target")]
target: String,
/// skip attempting the installation of the target.
#[argh(switch)]
skip_install: bool,
}
impl Default for CompileCheckNoStdCommand {
fn default() -> Self {
Self {
target: String::from("x86_64-unknown-none"),
skip_install: false,
}
}
}
impl Prepare for CompileCheckNoStdCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _flags: Flag) -> Vec<PreparedCommand<'a>> {
let target = self.target.as_str();
let mut commands = Vec::new();
if !self.skip_install {
commands.push(PreparedCommand::new::<Self>(
cmd!(sh, "rustup target add {target}"),
"Unable to add the required target via rustup, is it spelled correctly?",
));
}
commands.push(PreparedCommand::new::<Self>(
cmd!(
sh,
"cargo check -p bevy_ptr --no-default-features --target {target}"
),
"Please fix compiler errors in output above for bevy_ptr no_std compatibility.",
));
commands.push(PreparedCommand::new::<Self>(
cmd!(
sh,
"cargo check -p bevy_utils --no-default-features --target {target}"
),
"Please fix compiler errors in output above for bevy_utils no_std compatibility.",
));
commands.push(PreparedCommand::new::<Self>(
cmd!(
sh,
"cargo check -p bevy_mikktspace --no-default-features --features libm --target {target}"
),
"Please fix compiler errors in output above for bevy_mikktspace no_std compatibility.",
));
commands.push(PreparedCommand::new::<Self>(
cmd!(
sh,
"cargo check -p bevy_reflect --no-default-features --target {target}"
),
"Please fix compiler errors in output above for bevy_reflect no_std compatibility.",
));
commands.push(PreparedCommand::new::<Self>(
cmd!(
sh,
"cargo check -p bevy_math --no-default-features --features libm --target {target}"
),
"Please fix compiler errors in output above for bevy_math no_std compatibility.",
));
commands.push(PreparedCommand::new::<Self>(
cmd!(
sh,
"cargo check -p bevy_color --no-default-features --features libm --target {target}"
),
"Please fix compiler errors in output above for bevy_color no_std compatibility.",
));
commands.push(PreparedCommand::new::<Self>(
cmd!(
sh,
"cargo check -p bevy_tasks --no-default-features --features edge_executor,critical-section --target {target}"
),
"Please fix compiler errors in output above for bevy_tasks no_std compatibility.",
));
commands
}
}