From d1615da29927236c0e68c5e1e8940e2a44529f8a Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Fri, 31 Jul 2026 16:22:54 +0200 Subject: [PATCH] Fix velocity_projection bench never compiling The velocity_projection bench target required a "test" feature that was never declared, so cargo skipped the bench and printed an invalid-feature warning on every build. Since the bench never compiled, it had also bit-rotted: it imported the since-removed avian3d::math::PI along with an unused Vec3. Declare the test feature in avian2d and avian3d, gate the shared test utilities module on cfg(any(test, feature = "test")) so benches can use QuasiRandomDirection, and drop the stale bench imports. Enable the feature in the CI clippy invocation so the bench keeps compiling. The bench now runs with: cargo bench -p avian3d --features test --- .github/workflows/rust.yaml | 2 +- crates/avian2d/Cargo.toml | 3 +++ crates/avian3d/Cargo.toml | 3 +++ crates/avian3d/benches/velocity_projection.rs | 9 +++------ src/character_controller/velocity_project.rs | 3 ++- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index e0c8c5092..427d0343f 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -166,4 +166,4 @@ jobs: - name: Run cargo fmt run: cargo fmt --all -- --check - name: Run cargo clippy - run: cargo clippy --locked --all-targets + run: cargo clippy --locked --all-targets --features avian2d/test,avian3d/test diff --git a/crates/avian2d/Cargo.toml b/crates/avian2d/Cargo.toml index ad4d4acee..2205345cc 100644 --- a/crates/avian2d/Cargo.toml +++ b/crates/avian2d/Cargo.toml @@ -65,6 +65,9 @@ diagnostic_ui = ["bevy_diagnostic", "bevy/bevy_ui"] # Enables additional correctness checks and validation at the cost of worse performance. validate = [] +# Exposes internal testing utilities. Only intended for use by benchmarks. +test = [] + [lib] name = "avian2d" path = "../../src/lib.rs" diff --git a/crates/avian3d/Cargo.toml b/crates/avian3d/Cargo.toml index cf04aaa67..84af07d95 100644 --- a/crates/avian3d/Cargo.toml +++ b/crates/avian3d/Cargo.toml @@ -67,6 +67,9 @@ diagnostic_ui = ["bevy_diagnostic", "bevy/bevy_ui"] # Enables additional correctness checks and validation at the cost of worse performance. validate = [] +# Exposes internal testing utilities. Only intended for use by benchmarks. +test = [] + [lib] name = "avian3d" path = "../../src/lib.rs" diff --git a/crates/avian3d/benches/velocity_projection.rs b/crates/avian3d/benches/velocity_projection.rs index a107956d0..38910bc36 100644 --- a/crates/avian3d/benches/velocity_projection.rs +++ b/crates/avian3d/benches/velocity_projection.rs @@ -1,12 +1,9 @@ -use bevy_math::{Dir3, Vec3}; +use bevy_math::Dir3; use core::hint::black_box; use criterion::{BenchmarkId, Criterion, PlotConfiguration, criterion_group, criterion_main}; -use avian3d::{ - character_controller::move_and_slide::{ - project_velocity, project_velocity_bruteforce, test::QuasiRandomDirection, - }, - math::PI, +use avian3d::character_controller::move_and_slide::{ + project_velocity, project_velocity_bruteforce, test::QuasiRandomDirection, }; fn bench_velocity_projection(c: &mut Criterion) { diff --git a/src/character_controller/velocity_project.rs b/src/character_controller/velocity_project.rs index ba36bb5c8..2b1b563c0 100644 --- a/src/character_controller/velocity_project.rs +++ b/src/character_controller/velocity_project.rs @@ -308,7 +308,7 @@ impl SimplicialCone { } } -#[cfg(test)] +#[cfg(any(test, feature = "test"))] pub mod test { //! Tests for velocity projection, notably the [`QuasiRandomDirection`] type used //! in testing and benchmarking functions on uniformly distributed input directions. @@ -316,6 +316,7 @@ pub mod test { //! This is used because the velocity projection edge cases may show up for relatively small //! subsets of input directions, both in terms of correctness and performance. + #[cfg(test)] use super::DOT_EPSILON; use crate::prelude::*; use core::f32::consts::PI;