Skip to content

Commit

Permalink
feat(build dir): Create a build directory to store compilation artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
andystopia committed Sep 27, 2023
1 parent a275455 commit d3d572c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gb"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
repository = "https://github.com/andystopia/gb"

Expand Down
56 changes: 46 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,20 @@ fn validate(commands: &Commands) -> Result<(), GbError> {

match commands {
Commands::Run { target: _, vcd } => {
eprintln!(" {} {}", "[1/3]".blue().bold(), "Analyzing Solution...".green().bold());
let file_to_exec = file_to_execute.fatal("must have a file chosen to execute")?;
eprintln!(
" {} {}",
"[1/3]".blue().bold(),
"Analyzing Solution...".green().bold()
);
compile_vhd_files(files)?;

eprintln!(" {} {}", "[2/3]".blue().bold(), "Analyzing Solution...".green().bold());
eprintln!(
" {} {}",
"[2/3]".blue().bold(),
"Elaborating Solution...".green().bold()
);
let file_to_exec = file_to_execute.fatal("must have a file chosen to execute")?;

let child = Command::new("ghdl")
.arg("-e")
.arg(
Expand All @@ -187,7 +196,11 @@ fn validate(commands: &Commands) -> Result<(), GbError> {

await_vhdl_process(child, "couldn't await ghdl elaborate subprocess, is ghdl installed correctly, and do you have run permissions?")?;

eprintln!(" {} {}", "[3/3]".blue().bold(), "Executing Solution...".green().bold());
eprintln!(
" {} {}",
"[3/3]".blue().bold(),
"Executing Solution...".green().bold()
);
let child = Command::new("ghdl")
.arg("-r")
.arg(
Expand All @@ -205,9 +218,17 @@ fn validate(commands: &Commands) -> Result<(), GbError> {
await_vhdl_process(child, "couldn't await ghdl run subprocess, is ghdl installed correctly, and do you have run permissions?")?;
}
Commands::Compile { target: _ } => {
eprintln!(" {} {}", "[1/1]".blue().bold(), "Analyzing Solution...".green().bold());
eprintln!(
" {} {}",
"[1/1]".blue().bold(),
"Analyzing Solution...".green().bold()
);
compile_vhd_files(files)?;
eprintln!(" {} {}", "[1/1]".blue().bold(), "Successfully Analyzed.".green().bold());
eprintln!(
" {} {}",
"[1/1]".blue().bold(),
"Successfully Analyzed.".green().bold()
);
}
}

Expand All @@ -217,19 +238,34 @@ fn validate(commands: &Commands) -> Result<(), GbError> {
fn compile_vhd_files(files: Vec<&str>) -> Result<(), GbError> {
let child = Command::new("ghdl")
.arg("-a")
.args(files)
.args(&files)
.spawn()
.fatal("couldn't spawn ghdl subprocess")?;
await_vhdl_process(
child,
"couldn't await ghdl analyze subprocess, is ghdl installed?",
)?;

std::fs::create_dir_all("build/root/").fatal("could not create build directory")?;
for file_str in files {
let file = std::path::Path::new(file_str);

let stem = file
.file_stem()
.fatal(format!("could not get file stem for {file_str}"))?;
// TODO: Might need to not add the .o on some systems.

let path = std::path::PathBuf::from(stem).with_extension(".o");

std::fs::rename(&path, std::path::PathBuf::from("build/root/").join(&path))
.fatal("could not move generated build artifact to build dir")?;
}
Ok(())
}


fn create_build_src() -> Result<(), GbError>{
std::fs::create_dir_all("build/src/").fatal("could not construct directory for build source files")
fn create_build_src() -> Result<(), GbError> {
std::fs::create_dir_all("build/src/")
.fatal("could not construct directory for build source files")
}
fn await_vhdl_process(mut child: std::process::Child, message: &str) -> Result<(), GbError> {
let waiting = child.wait().fatal(message)?;
Expand Down

0 comments on commit d3d572c

Please sign in to comment.