Skip to content

Commit

Permalink
cli: add command to compile libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
hackaugusto committed Jul 13, 2023
1 parent 3022d25 commit a284829
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
42 changes: 42 additions & 0 deletions miden/src/cli/bundle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use assembly::{LibraryNamespace, MaslLibrary, Version};
use std::path::PathBuf;
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(
name = "Compile Library",
about = "Bundles .masm files into a single .masl library"
)]
pub struct BundleCmd {
/// Path to a directory containg the `.masm` files which are part of the library
#[structopt(parse(from_os_str))]
dir: PathBuf,
/// Name of the top-level namespace, e.g. `mylib`.
#[structopt()]
namespace: String,
/// Version of you library, defaults to `0.1`.
#[structopt(short, long, default_value = "0.1")]
version: String,
}

impl BundleCmd {
pub fn execute(&self) -> Result<(), String> {
println!("============================================================");
println!("Compile library");
println!("============================================================");

let namespace =
LibraryNamespace::try_from(self.namespace.to_string()).expect("invalid base namespace");
let version = Version::try_from(self.version.as_ref()).expect("invalid cargo version");
let locations = true; // store & load locations by default
let stdlib = MaslLibrary::read_from_dir(self.dir.clone(), namespace, locations, version)
.map_err(|e| e.to_string())?;

// write the masl output
stdlib.write_to_dir(self.dir.clone()).map_err(|e| e.to_string())?;

println!("Compiled library {}", self.namespace);

Ok(())
}
}
2 changes: 2 additions & 0 deletions miden/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod bundle;
mod compile;
mod data;
mod debug;
Expand All @@ -6,6 +7,7 @@ mod repl;
mod run;
mod verify;

pub use bundle::BundleCmd;
pub use compile::CompileCmd;
pub use data::InputFile;
pub use debug::DebugCmd;
Expand Down
2 changes: 2 additions & 0 deletions miden/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Cli {
pub enum Actions {
Analyze(tools::Analyze),
Compile(cli::CompileCmd),
Bundle(cli::BundleCmd),
Debug(cli::DebugCmd),
Example(examples::ExampleOptions),
Prove(cli::ProveCmd),
Expand All @@ -35,6 +36,7 @@ impl Cli {
match &self.action {
Actions::Analyze(analyze) => analyze.execute(),
Actions::Compile(compile) => compile.execute(),
Actions::Bundle(compile) => compile.execute(),
Actions::Debug(debug) => debug.execute(),
Actions::Example(example) => example.execute(),
Actions::Prove(prove) => prove.execute(),
Expand Down

0 comments on commit a284829

Please sign in to comment.