Skip to content

Commit 5b6f29e

Browse files
bjzhjingrbradford
authored andcommitted
loader: Condition crates import and usage by feature
We only need SeekFrom, Cursor, struct_util and mem when either ELF or bzImage are selected. We only need read_struct_slice for ELF. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent a2d63ed commit 5b6f29e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/loader/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ extern crate vm_memory;
1919
use std::error::{self, Error as KernelLoaderError};
2020
use std::ffi::CStr;
2121
use std::fmt::{self, Display};
22-
use std::io::{Read, Seek, SeekFrom};
22+
#[cfg(any(feature = "elf", feature = "bzimage"))]
23+
use std::io::SeekFrom;
24+
use std::io::{Read, Seek};
25+
#[cfg(feature = "elf")]
2326
use std::mem;
2427

2528
use vm_memory::{Address, Bytes, GuestAddress, GuestMemory, GuestUsize};
@@ -36,6 +39,7 @@ pub mod bootparam;
3639
#[allow(non_upper_case_globals)]
3740
#[cfg_attr(feature = "cargo-clippy", allow(clippy::all))]
3841
mod elf;
42+
#[cfg(any(feature = "elf", feature = "bzimage"))]
3943
mod struct_util;
4044

4145
#[derive(Debug, PartialEq)]
@@ -371,6 +375,7 @@ pub fn load_cmdline<M: GuestMemory>(
371375
#[cfg(test)]
372376
mod test {
373377
use super::*;
378+
#[cfg(any(feature = "elf", feature = "bzimage"))]
374379
use std::io::Cursor;
375380
use vm_memory::{Address, GuestAddress, GuestMemoryMmap};
376381

src/loader/struct_util.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub unsafe fn read_struct<T: Copy, F: Read>(f: &mut F, out: &mut T) -> Result<()
4040
///
4141
/// * `f` - The input to read from. Often this is a file.
4242
/// * `len` - The number of structs to fill with data read from `f`.
43+
#[cfg(feature = "elf")]
4344
pub unsafe fn read_struct_slice<T: Copy, F: Read>(f: &mut F, len: usize) -> Result<Vec<T>> {
4445
let mut out: Vec<T> = Vec::with_capacity(len);
4546
out.set_len(len);
@@ -114,6 +115,7 @@ mod tests {
114115
}
115116

116117
#[test]
118+
#[cfg(feature = "elf")]
117119
fn struct_slice_read() {
118120
let orig = vec![
119121
TestRead {

0 commit comments

Comments
 (0)