File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- // Benchmarks are only meaningful and should only run with release builds.
18- // Debug builds have different performance characteristics and would not provide
17+ // Benchmarks are only meaningful and should only run with optimized builds.
18+ // Unoptimized builds have different performance characteristics and would not provide
1919// useful benchmarking data for performance regression testing.
20- #[ cfg( debug_assertions ) ]
20+ #[ cfg( unoptimized_build ) ]
2121compile_error ! (
22- "Benchmarks must be run with release builds only. Use `cargo bench --release` or `just bench`."
22+ "Benchmarks must be run with optimized builds only. Use `cargo bench --release` or `just bench`."
2323) ;
2424
2525use criterion:: { Criterion , criterion_group, criterion_main} ;
Original file line number Diff line number Diff line change @@ -85,6 +85,24 @@ fn main() -> Result<()> {
8585 ) ;
8686 }
8787
88+ // Set a cfg flag based on optimization level for benchmarks
89+ // Benchmarks should only run with optimized builds (opt-level 1+)
90+ println ! ( "cargo:rustc-check-cfg=cfg(unoptimized_build)" ) ;
91+ println ! ( "cargo:rustc-check-cfg=cfg(optimized_build)" ) ;
92+
93+ if let Ok ( opt_level) = std:: env:: var ( "OPT_LEVEL" ) {
94+ if opt_level == "0" {
95+ // Unoptimized build - benchmarks should not run
96+ println ! ( "cargo:rustc-cfg=unoptimized_build" ) ;
97+ } else {
98+ // Optimized build - benchmarks can run
99+ println ! ( "cargo:rustc-cfg=optimized_build" ) ;
100+ }
101+ } else {
102+ // Fallback: if we can't determine opt level, assume unoptimized to be safe
103+ println ! ( "cargo:rustc-cfg=unoptimized_build" ) ;
104+ }
105+
88106 // Makes #[cfg(kvm)] == #[cfg(all(feature = "kvm", target_os = "linux"))]
89107 // and #[cfg(mshv)] == #[cfg(all(any(feature = "mshv2", feature = "mshv3"), target_os = "linux"))].
90108 // Essentially the kvm and mshv features are ignored on windows as long as you use #[cfg(kvm)] and not #[cfg(feature = "kvm")].
You can’t perform that action at this time.
0 commit comments