Skip to content

Commit

Permalink
Add compile-check-no-std Command to CI Tool (#15843)
Browse files Browse the repository at this point in the history
# Objective

- Fixes #15840

## Solution

Added a new subcommand to the CI tool, `compile-check-no-std`, which
will attempt to compile each `no_std` crate in Bevy with the appropriate
features (no-defaults, `libm`, etc.) for `x86_64-unknown-none`. The
exact target chosen could be changed to any reasonable platform which
does not include the `std` library.

The currently tested crates are:

- `bevy_ptr`
- `bevy_utils`
- `bevy_mikktspace`

As more crates have `no_std` support added, they _should_ be added to
this CI command. Once Bevy itself can be `no_std`, the individual checks
can be replaced with just checking Bevy, since it will transiently check
all other crates as appropriate.

## Testing

- Ran CI. From a clean target directory (`cargo clean`), these new
checks take approximately 10 seconds total.

---------

Co-authored-by: François Mockers <francois.mockers@vleue.com>
  • Loading branch information
bushrat011899 and mockersf authored Oct 11, 2024
1 parent 6a39c33 commit aa5e93d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,31 @@ jobs:
- name: Check Compile
# See tools/ci/src/main.rs for the commands this runs
run: cargo run -p ci -- compile

check-compiles-no-std:
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-${{ hashFiles('**/Cargo.toml') }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-none
- name: Install Linux dependencies
uses: ./.github/actions/install-linux-deps
- name: Check Compile
run: cargo run -p ci -- compile-check-no-std

build-wasm:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions tools/ci/src/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl CI {
cmds.append(&mut commands::DocCheckCommand::default().prepare(sh, flags));
cmds.append(&mut commands::DocTestCommand::default().prepare(sh, flags));
cmds.append(&mut commands::CompileCheckCommand::default().prepare(sh, flags));
cmds.append(&mut commands::CompileCheckNoStdCommand::default().prepare(sh, flags));
cmds.append(&mut commands::CompileFailCommand::default().prepare(sh, flags));
cmds.append(&mut commands::BenchCheckCommand::default().prepare(sh, flags));
cmds.append(&mut commands::ExampleCheckCommand::default().prepare(sh, flags));
Expand All @@ -102,6 +103,7 @@ enum Commands {
DocCheck(commands::DocCheckCommand),
DocTest(commands::DocTestCommand),
CompileCheck(commands::CompileCheckCommand),
CompileCheckNoStd(commands::CompileCheckNoStdCommand),
CompileFail(commands::CompileFailCommand),
BenchCheck(commands::BenchCheckCommand),
ExampleCheck(commands::ExampleCheckCommand),
Expand All @@ -121,6 +123,7 @@ impl Prepare for Commands {
Commands::DocCheck(subcommand) => subcommand.prepare(sh, flags),
Commands::DocTest(subcommand) => subcommand.prepare(sh, flags),
Commands::CompileCheck(subcommand) => subcommand.prepare(sh, flags),
Commands::CompileCheckNoStd(subcommand) => subcommand.prepare(sh, flags),
Commands::CompileFail(subcommand) => subcommand.prepare(sh, flags),
Commands::BenchCheck(subcommand) => subcommand.prepare(sh, flags),
Commands::ExampleCheck(subcommand) => subcommand.prepare(sh, flags),
Expand Down
41 changes: 41 additions & 0 deletions tools/ci/src/commands/compile_check_no_std.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::{Flag, Prepare, PreparedCommand};
use argh::FromArgs;
use xshell::cmd;

/// Checks that the project compiles for a `no_std` target.
#[derive(FromArgs, Default)]
#[argh(subcommand, name = "compile-check-no-std")]
pub struct CompileCheckNoStdCommand {
/// the target to check against.
/// Defaults to "x86_64-unknown-none"
#[argh(option, default = "String::from(\"x86_64-unknown-none\")")]
target: String,
}

impl Prepare for CompileCheckNoStdCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _flags: Flag) -> Vec<PreparedCommand<'a>> {
let target = self.target.as_str();
vec![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.",
),
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.",
),
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.",
)
]
}
}
2 changes: 2 additions & 0 deletions tools/ci/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub use bench_check::*;
pub use clippy::*;
pub use compile::*;
pub use compile_check::*;
pub use compile_check_no_std::*;
pub use compile_fail::*;
pub use doc::*;
pub use doc_check::*;
Expand All @@ -16,6 +17,7 @@ mod bench_check;
mod clippy;
mod compile;
mod compile_check;
mod compile_check_no_std;
mod compile_fail;
mod doc;
mod doc_check;
Expand Down

0 comments on commit aa5e93d

Please sign in to comment.