Skip to content

Commit 2855be1

Browse files
andreeaflorescualexandruag
authored andcommitted
remove build.rs
Download the needed resources before running the tests. Do not use include_bytes! macro because it makes cargo check fail when the bzimage path does not work. Signed-off-by: Andreea Florescu <fandree@amazon.com>
1 parent b18d387 commit 2855be1

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

benches/x86_64/mod.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
extern crate linux_loader;
1111
extern crate vm_memory;
1212

13+
use std::fs::File;
14+
use std::io::{Cursor, Read};
15+
1316
use linux_loader::configurator::pvh::PvhBootConfigurator;
1417
use linux_loader::configurator::{BootConfigurator, BootParams};
1518
#[cfg(feature = "bzimage")]
@@ -19,8 +22,6 @@ use linux_loader::loader::elf::Elf;
1922
use linux_loader::loader::KernelLoader;
2023
use vm_memory::{Address, GuestAddress, GuestMemoryMmap};
2124

22-
use std::io::Cursor;
23-
2425
use criterion::{black_box, Criterion};
2526

2627
const MEM_SIZE: usize = 0x100_0000;
@@ -67,13 +68,29 @@ fn build_pvh_boot_params() -> BootParams {
6768
boot_params
6869
}
6970

71+
#[cfg(feature = "bzimage")]
72+
fn download_resources() {
73+
use std::process::Command;
74+
75+
let command = "./.buildkite/download_resources.sh";
76+
let status = Command::new(command).status().unwrap();
77+
if !status.success() {
78+
panic!("Cannot run build script");
79+
}
80+
}
81+
7082
#[cfg(feature = "bzimage")]
7183
fn create_bzimage() -> Vec<u8> {
72-
include_bytes!(concat!(
84+
download_resources();
85+
let mut v = Vec::new();
86+
let path = concat!(
7387
env!("CARGO_MANIFEST_DIR"),
7488
"/src/loader/x86_64/bzimage/bzimage"
75-
))
76-
.to_vec()
89+
);
90+
let mut f = File::open(path).unwrap();
91+
f.read_to_end(&mut v).unwrap();
92+
93+
v
7794
}
7895

7996
pub fn criterion_benchmark(c: &mut Criterion) {

build.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/loader/x86_64/bzimage/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ impl KernelLoader for BzImage {
173173
mod tests {
174174
use super::*;
175175

176+
use std::fs::File;
176177
use std::io::Cursor;
178+
use std::process::Command;
177179
use vm_memory::{Address, GuestAddress, GuestMemoryMmap};
178180

179181
const MEM_SIZE: u64 = 0x100_0000;
@@ -182,9 +184,24 @@ mod tests {
182184
GuestMemoryMmap::from_ranges(&[(GuestAddress(0x0), (MEM_SIZE as usize))]).unwrap()
183185
}
184186

187+
fn download_resources() {
188+
let command = "./.buildkite/download_resources.sh";
189+
let status = Command::new(command).status().unwrap();
190+
if !status.success() {
191+
panic!("Cannot run build script");
192+
}
193+
}
194+
185195
fn make_bzimage() -> Vec<u8> {
196+
download_resources();
186197
let mut v = Vec::new();
187-
v.extend_from_slice(include_bytes!("bzimage"));
198+
let path = concat!(
199+
env!("CARGO_MANIFEST_DIR"),
200+
"/src/loader/x86_64/bzimage/bzimage"
201+
);
202+
let mut f = File::open(path).unwrap();
203+
f.read_to_end(&mut v).unwrap();
204+
188205
v
189206
}
190207

src/loader_gen/x86_64/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//! Bindgen autogenerated structs for `x86_64` boot parameters.
1111
1212
#![cfg(any(target_arch = "x86", target_arch = "x86_64"))]
13-
1413
#![cfg_attr(feature = "cargo-clippy", allow(clippy::all))]
1514
#![allow(dead_code)]
1615
#![allow(missing_docs)]

0 commit comments

Comments
 (0)