Skip to content

Commit e8589fd

Browse files
pizzacat83roypat
authored andcommitted
fix(benches): add cfg guards for configurator features
The benches modules were unconditionally importing from the configurator module, which is only available when at least one of the elf, pe, or bzimage features is enabled. This caused compilation failures when building with --no-default-features or other feature combinations that don't enable any loader features. Added appropriate #[cfg(any(feature = "..."))] guards to all benchmark modules and a no-op fallback benchmark function for when no configurator features are enabled. Fixes #215 Signed-off-by: pizzacat83 <17941141+pizzacat83@users.noreply.github.com>
1 parent c71d161 commit e8589fd

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

benches/fdt.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
// found in the LICENSE-BSD-3-Clause file.
55
//
66
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
7+
8+
#![cfg(any(feature = "elf", feature = "pe", feature = "bzimage"))]
9+
710
extern crate criterion;
811
extern crate linux_loader;
912
extern crate vm_memory;

benches/main.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,32 @@ extern crate vm_memory;
1111

1212
use criterion::{criterion_group, criterion_main, Criterion};
1313

14-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
14+
#[cfg(all(
15+
any(target_arch = "x86", target_arch = "x86_64"),
16+
any(feature = "elf", feature = "pe", feature = "bzimage")
17+
))]
1518
mod x86_64;
16-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
19+
#[cfg(all(
20+
any(target_arch = "x86", target_arch = "x86_64"),
21+
any(feature = "elf", feature = "pe", feature = "bzimage")
22+
))]
1723
use x86_64::*;
1824

19-
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
25+
#[cfg(all(
26+
any(target_arch = "aarch64", target_arch = "riscv64"),
27+
any(feature = "elf", feature = "pe", feature = "bzimage")
28+
))]
2029
mod fdt;
21-
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
30+
#[cfg(all(
31+
any(target_arch = "aarch64", target_arch = "riscv64"),
32+
any(feature = "elf", feature = "pe", feature = "bzimage")
33+
))]
2234
pub use fdt::*;
2335

36+
// No-op benchmark when configurator module is not available
37+
#[cfg(not(any(feature = "elf", feature = "pe", feature = "bzimage")))]
38+
fn criterion_benchmark(_c: &mut Criterion) {}
39+
2440
criterion_group! {
2541
name = benches;
2642
config = Criterion::default().sample_size(500);

benches/x86_64/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
77

88
#![cfg(any(target_arch = "x86", target_arch = "x86_64"))]
9+
#![cfg(any(feature = "elf", feature = "pe", feature = "bzimage"))]
910

1011
extern crate linux_loader;
1112
extern crate vm_memory;

0 commit comments

Comments
 (0)