From 020d082617c9c61ddd78b8ced84f758db51a2bf9 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:09:31 -0500 Subject: [PATCH] Fix "Unrecognized Option" error when using Criterion-specific arguments in benchmarks (#17222) # Objective - Commands like `cargo bench -- --save-baseline before` do not work because the default `libtest` is intercepting Criterion-specific CLI arguments. - Fixes #17200. ## Solution - Disable the default `libtest` benchmark harness for the library crate, as per [the Criterion book](https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options). ## Testing - `cargo bench -p benches -- --save-baseline before` - You don't need to run the entire benchmarks, just make sure that they start without any errors. :) --- benches/Cargo.toml | 7 +++++++ crates/bevy_render/src/extract_resource.rs | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/benches/Cargo.toml b/benches/Cargo.toml index becb6cff4e..ea1992f648 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -60,6 +60,13 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(docsrs_dep)'] } unsafe_op_in_unsafe_fn = "warn" unused_qualifications = "warn" +[lib] +# This fixes the "Unrecognized Option" error when running commands like +# `cargo bench -- --save-baseline before` by disabling the default benchmark harness. +# See +# for more information. +bench = false + [[bench]] name = "ecs" path = "benches/bevy_ecs/main.rs" diff --git a/crates/bevy_render/src/extract_resource.rs b/crates/bevy_render/src/extract_resource.rs index 62c25aef17..cec8647ffc 100644 --- a/crates/bevy_render/src/extract_resource.rs +++ b/crates/bevy_render/src/extract_resource.rs @@ -4,7 +4,6 @@ use bevy_app::{App, Plugin}; use bevy_ecs::prelude::*; pub use bevy_render_macros::ExtractResource; use bevy_utils::once; -use tracing::{error, warn}; use crate::{Extract, ExtractSchedule, RenderApp}; @@ -36,7 +35,7 @@ impl Plugin for ExtractResourcePlugin { if let Some(render_app) = app.get_sub_app_mut(RenderApp) { render_app.add_systems(ExtractSchedule, extract_resource::); } else { - once!(error!( + once!(tracing::error!( "Render app did not exist when trying to add `extract_resource` for <{}>.", core::any::type_name::() )); @@ -58,12 +57,13 @@ pub fn extract_resource( } else { #[cfg(debug_assertions)] if !main_resource.is_added() { - once!(warn!( + once!(tracing::warn!( "Removing resource {} from render world not expected, adding using `Commands`. This may decrease performance", core::any::type_name::() )); } + commands.insert_resource(R::extract_resource(main_resource)); } }