From aa5e93d0bf67b4d979421ae548524736e9448383 Mon Sep 17 00:00:00 2001 From: Zachary Harrold Date: Fri, 11 Oct 2024 21:54:44 +1100 Subject: [PATCH] Add `compile-check-no-std` Command to CI Tool (#15843) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 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 --- .github/workflows/ci.yml | 25 +++++++++++ tools/ci/src/ci.rs | 3 ++ tools/ci/src/commands/compile_check_no_std.rs | 41 +++++++++++++++++++ tools/ci/src/commands/mod.rs | 2 + 4 files changed, 71 insertions(+) create mode 100644 tools/ci/src/commands/compile_check_no_std.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b8bcf4454dc4..0191064131d45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/tools/ci/src/ci.rs b/tools/ci/src/ci.rs index beaab08e09093..043a887e37ec7 100644 --- a/tools/ci/src/ci.rs +++ b/tools/ci/src/ci.rs @@ -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)); @@ -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), @@ -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), diff --git a/tools/ci/src/commands/compile_check_no_std.rs b/tools/ci/src/commands/compile_check_no_std.rs new file mode 100644 index 0000000000000..86109c6279bb1 --- /dev/null +++ b/tools/ci/src/commands/compile_check_no_std.rs @@ -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> { + let target = self.target.as_str(); + vec![PreparedCommand::new::( + 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::( + 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::( + 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.", + ) + ] + } +} diff --git a/tools/ci/src/commands/mod.rs b/tools/ci/src/commands/mod.rs index 9c9f19e01a6d2..696155aee96ca 100644 --- a/tools/ci/src/commands/mod.rs +++ b/tools/ci/src/commands/mod.rs @@ -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::*; @@ -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;