From d6b966774047f61e9b51b29770a0324f99cd555b Mon Sep 17 00:00:00 2001 From: Bruce Leidl Date: Fri, 20 Sep 2019 18:15:10 -0400 Subject: [PATCH] Build everything with cargo --- .gitignore | 4 ++++ Cargo.toml | 8 -------- Makefile | 29 ----------------------------- build.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ rust/.gitignore | 4 ---- src/vm/mod.rs | 2 +- 6 files changed, 50 insertions(+), 42 deletions(-) delete mode 100644 Makefile create mode 100644 build.rs delete mode 100644 rust/.gitignore diff --git a/.gitignore b/.gitignore index c75d582..7499a56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ pH +*.iml +.idea/ +target/ +sommelier/ diff --git a/Cargo.toml b/Cargo.toml index 41bfbdd..404e117 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,14 +4,6 @@ version = "0.1.0" authors = ["Bruce Leidl "] edition = "2018" -[[bin]] -name="pH" -path="src/main.rs" - -[[bin]] -name="ph-init" -path="src/init/main.rs" - [dependencies] byteorder="1.0.0" libc = "*" diff --git a/Makefile b/Makefile deleted file mode 100644 index 2051c33..0000000 --- a/Makefile +++ /dev/null @@ -1,29 +0,0 @@ - -RUST_BUILD_RELEASE = rust/target/release - -RUST_PH = $(RUST_BUILD_RELEASE)/pH - -CARGO = cargo -CARGO_OPTS = --manifest-path rust/Cargo.toml --release - -KERNEL = kernel/ph_linux - -CP = cp - -.PHONY: all clean $(RUST_PH) - -all: pH $(KERNEL) - -$(KERNEL): - $(MAKE) -C kernel/ - -pH: $(RUST_PH) - $(CP) $(RUST_PH) pH - -$(RUST_PH): - $(CARGO) build --bins $(CARGO_OPTS) - -clean: - rm -f pH - $(CARGO) clean $(CARGO_OPTS) - diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..f9de6e6 --- /dev/null +++ b/build.rs @@ -0,0 +1,45 @@ +use std::path::{Path, PathBuf}; +use std::env; +use std::io::Result; +use std::process::Command; + +fn main() -> Result<()> { + build_phinit()?; + run_simple_make("sommelier")?; + run_simple_make("kernel")?; + Ok(()) +} + +fn build_phinit() -> Result<()> { + run_command_in_directory( + "ph-init", + "cargo", + &["build", "--release"] + )?; + run_command_in_directory( + "ph-init", + "strip", + &["target/release/ph-init"] + )?; + Ok(()) +} + +fn run_simple_make>(directory: P) -> Result<()> { + run_command_in_directory(directory, "make", &[]) +} + +fn run_command_in_directory>(directory: P, cmd: &str, args: &[&str]) -> Result<()> { + let saved = push_directory(directory)?; + Command::new(cmd).args(args).status()?; + env::set_current_dir(saved) +} + +fn push_directory>(directory: P) -> Result { + let current = env::current_dir()?; + env::set_current_dir(directory.as_ref())?; + Ok(current) +} + + + + diff --git a/rust/.gitignore b/rust/.gitignore deleted file mode 100644 index b35f243..0000000 --- a/rust/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.iml -.idea/ -target/ - diff --git a/src/vm/mod.rs b/src/vm/mod.rs index 44c07ae..709c43c 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -9,7 +9,7 @@ use crate::memory::{GuestRam, KVM_KERNEL_LOAD_ADDRESS, MemoryManager, SystemAllo use crate::kvm::*; static KERNEL: &[u8] = include_bytes!("../../kernel/ph_linux"); -static PHINIT: &[u8] = include_bytes!("../../target/release/ph-init"); +static PHINIT: &[u8] = include_bytes!("../../ph-init/target/release/ph-init"); static SOMMELIER: &[u8] = include_bytes!("../../sommelier/sommelier"); mod run;