Build everything with cargo

This commit is contained in:
Bruce Leidl 2019-09-20 18:15:10 -04:00
parent 3b168d5db5
commit d6b9667740
6 changed files with 50 additions and 42 deletions

4
.gitignore vendored
View File

@ -1,2 +1,6 @@
pH
*.iml
.idea/
target/
sommelier/

View File

@ -4,14 +4,6 @@ version = "0.1.0"
authors = ["Bruce Leidl <bruce@subgraph.com>"]
edition = "2018"
[[bin]]
name="pH"
path="src/main.rs"
[[bin]]
name="ph-init"
path="src/init/main.rs"
[dependencies]
byteorder="1.0.0"
libc = "*"

View File

@ -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)

45
build.rs Normal file
View File

@ -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<P: AsRef<Path>>(directory: P) -> Result<()> {
run_command_in_directory(directory, "make", &[])
}
fn run_command_in_directory<P: AsRef<Path>>(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<P: AsRef<Path>>(directory: P) -> Result<PathBuf> {
let current = env::current_dir()?;
env::set_current_dir(directory.as_ref())?;
Ok(current)
}

4
rust/.gitignore vendored
View File

@ -1,4 +0,0 @@
*.iml
.idea/
target/

View File

@ -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;