Skip to content

Commit

Permalink
add --output arg to hvmc compile (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfvi authored Mar 4, 2024
1 parent a607118 commit fe58407
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ fn main() {
if cfg!(feature = "_full_cli") {
let cli = FullCli::parse();
match cli.mode {
CliMode::Compile { file } => {
CliMode::Compile { file, output } => {
let output = output.as_deref().or_else(|| file.strip_suffix(".hvmc")).unwrap_or_else(|| {
eprintln!("file missing `.hvmc` extension; explicitly specify an output path with `--output`.");
process::exit(1);
});
let host = load_files(&[file.clone()]);
compile_executable(&file, &host.lock().unwrap()).unwrap();
compile_executable(output, &host.lock().unwrap()).unwrap();
}
CliMode::Run { opts, file, args } => {
let host = load_files(&[file]);
Expand Down Expand Up @@ -120,6 +124,9 @@ enum CliMode {
Compile {
/// hvm-core file to compile.
file: String,
#[arg(short = 'o', long = "output")]
/// Output path; defaults to the input file with `.hvmc` stripped.
output: Option<String>,
},
/// Run a program, optionally passing a list of arguments to it.
Run {
Expand Down Expand Up @@ -251,7 +258,7 @@ fn pretty_num(n: u64) -> String {
.collect()
}

fn compile_executable(file_name: &str, host: &host::Host) -> Result<(), io::Error> {
fn compile_executable(target: &str, host: &host::Host) -> Result<(), io::Error> {
let gen = compile::compile_host(host);
let outdir = ".hvm";
if Path::new(&outdir).exists() {
Expand Down Expand Up @@ -327,8 +334,6 @@ fn compile_executable(file_name: &str, host: &host::Host) -> Result<(), io::Erro
process::exit(1);
}

let target = file_name.strip_suffix(".hvmc").unwrap_or(file_name);

fs::copy(".hvm/target/release/hvmc", target)?;

Ok(())
Expand Down

0 comments on commit fe58407

Please sign in to comment.