-
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.
cli: add command to compile libraries
- Loading branch information
1 parent
3022d25
commit a284829
Showing
3 changed files
with
46 additions
and
0 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
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(()) | ||
} | ||
} |
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