Skip to content

Commit

Permalink
build: feature to download kernel into a tmp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
vapourismo committed Jul 9, 2024
1 parent d744794 commit e654c02
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions hermit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ shell = []
idle-poll = []
mmap = []

# Download the HermitOS kernel into a temporary directory
download-kernel-into-tmp = []

[build-dependencies]
flate2 = "1"
ureq = "2.4"
tar = "0.4"
tempfile = "3"
24 changes: 20 additions & 4 deletions hermit/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{env, str};

use flate2::read::GzDecoder;
use tar::Archive;
use tempfile::TempDir;

fn main() {
let targets_hermit =
Expand All @@ -22,19 +23,31 @@ fn main() {

struct KernelSrc {
src_dir: PathBuf,
_tmp_dir_handle: Option<TempDir>,
}

impl KernelSrc {
fn local() -> Option<Self> {
let mut src_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
src_dir.set_file_name("kernel");
src_dir.exists().then_some(Self { src_dir })
src_dir.exists().then_some(Self {
src_dir,
_tmp_dir_handle: None,
})
}

fn download() -> Self {
let version = "0.8.0";
let out_dir = out_dir();
let src_dir = out_dir.join(format!("kernel-{version}"));

let (src_dir, _tmp_dir_handle) = if has_feature("download-kernel-into-tmp") {
let out_dir = tempfile::tempdir().unwrap();
let src_dir = out_dir.path().join(format!("kernel-{version}"));
(src_dir, Some(out_dir))
} else {
let out_dir = out_dir();
let src_dir = out_dir.join(format!("kernel-{version}"));
(src_dir, None)
};

if !src_dir.exists() {
let url =
Expand All @@ -45,7 +58,10 @@ impl KernelSrc {
archive.unpack(src_dir.parent().unwrap()).unwrap();
}

Self { src_dir }
Self {
src_dir,
_tmp_dir_handle,
}
}

fn build(self) {
Expand Down

0 comments on commit e654c02

Please sign in to comment.