-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #997 from 0xPolygonMiden/hacka-cli-compile-library
cli: add command to compile libraries
- Loading branch information
Showing
5 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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 containing the `.masm` files which are part of the library. | ||
#[structopt(parse(from_os_str))] | ||
dir: PathBuf, | ||
/// Defines the top-level namespace, e.g. `mylib`, otherwise the directory name is used. | ||
#[structopt(short, long)] | ||
namespace: Option<String>, | ||
/// Version of the library, defaults to `0.1.0`. | ||
#[structopt(short, long, default_value = "0.1.0")] | ||
version: String, | ||
} | ||
|
||
impl BundleCmd { | ||
pub fn execute(&self) -> Result<(), String> { | ||
println!("============================================================"); | ||
println!("Build library"); | ||
println!("============================================================"); | ||
|
||
let namespace = match &self.namespace { | ||
Some(namespace) => namespace.to_string(), | ||
None => self | ||
.dir | ||
.file_name() | ||
.expect("dir must be a folder") | ||
.to_string_lossy() | ||
.into_owned(), | ||
}; | ||
|
||
let library_namespace = | ||
LibraryNamespace::try_from(namespace.clone()).expect("invalid base namespace"); | ||
let version = Version::try_from(self.version.as_ref()).expect("invalid cargo version"); | ||
let with_source_locations = true; | ||
let stdlib = MaslLibrary::read_from_dir( | ||
self.dir.clone(), | ||
library_namespace, | ||
with_source_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!("Built library {}", namespace); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters