diff --git a/miden/Cargo.toml b/miden/Cargo.toml index 121d02cc4e..61e678b885 100644 --- a/miden/Cargo.toml +++ b/miden/Cargo.toml @@ -39,11 +39,12 @@ path = "tests/integration/main.rs" [features] concurrent = ["prover/concurrent", "std"] default = ["std"] -executable = ["env_logger", "hex/std", "std", "serde/std", "serde_derive", "serde_json/std", "structopt", "rustyline"] +executable = ["env_logger", "hex/std", "std", "serde/std", "serde_derive", "serde_json/std", "clap", "rustyline"] std = ["assembly/std", "log/std", "processor/std", "prover/std", "verifier/std"] [dependencies] assembly = { package = "miden-assembly", path = "../assembly", version = "0.7", default-features = false } +clap = { version = "3.0", features = ["derive"], optional = true } env_logger = { version = "0.10", default-features = false, optional = true } hex = { version = "0.4", optional = true } log = { version = "0.4", default-features = false } @@ -54,7 +55,6 @@ serde = {version = "1.0.117", optional = true } serde_derive = {version = "1.0.117", optional = true } serde_json = {version = "1.0.59", optional = true } stdlib = { package = "miden-stdlib", path = "../stdlib", version = "0.6", default-features = false } -structopt = { version = "0.3", default-features = false, optional = true } verifier = { package = "miden-verifier", path = "../verifier", version = "0.7", default-features = false } [dev-dependencies] diff --git a/miden/src/cli/bundle.rs b/miden/src/cli/bundle.rs index 89819b81e3..d66f01e52a 100644 --- a/miden/src/cli/bundle.rs +++ b/miden/src/cli/bundle.rs @@ -1,21 +1,21 @@ use assembly::{LibraryNamespace, MaslLibrary, Version}; +use clap::Parser; use std::path::PathBuf; -use structopt::StructOpt; -#[derive(StructOpt, Debug)] -#[structopt( +#[derive(Debug, Clone, Parser)] +#[clap( 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))] + #[clap(value_parser)] dir: PathBuf, /// Defines the top-level namespace, e.g. `mylib`, otherwise the directory name is used. - #[structopt(short, long)] + #[clap(short, long)] namespace: Option, /// Version of the library, defaults to `0.1.0`. - #[structopt(short, long, default_value = "0.1.0")] + #[clap(short, long, default_value = "0.1.0")] version: String, } diff --git a/miden/src/cli/compile.rs b/miden/src/cli/compile.rs index 8510132b87..9eb5018b18 100644 --- a/miden/src/cli/compile.rs +++ b/miden/src/cli/compile.rs @@ -1,15 +1,16 @@ +use clap::Parser; + use super::data::{Debug, Libraries, ProgramFile}; use std::path::PathBuf; -use structopt::StructOpt; -#[derive(StructOpt, Debug)] -#[structopt(name = "Compile", about = "Compile a miden program")] +#[derive(Debug, Clone, Parser)] +#[clap(about = "Compile a miden program")] pub struct CompileCmd { /// Path to .masm assembly file - #[structopt(short = "a", long = "assembly", parse(from_os_str))] + #[clap(short = 'a', long = "assembly", value_parser)] assembly_file: PathBuf, /// Paths to .masl library files - #[structopt(short = "l", long = "libraries", parse(from_os_str))] + #[clap(short = 'l', long = "libraries", value_parser)] library_paths: Vec, } diff --git a/miden/src/cli/debug/mod.rs b/miden/src/cli/debug/mod.rs index ba588643a2..96d5c0a676 100644 --- a/miden/src/cli/debug/mod.rs +++ b/miden/src/cli/debug/mod.rs @@ -1,7 +1,7 @@ use super::data::{Debug, InputFile, Libraries, ProgramFile}; +use clap::Parser; use rustyline::{error::ReadlineError, Config, DefaultEditor, EditMode}; use std::path::PathBuf; -use structopt::StructOpt; mod command; use command::DebugCommand; @@ -9,20 +9,20 @@ use command::DebugCommand; mod executor; use executor::DebugExecutor; -#[derive(StructOpt, Debug)] -#[structopt(name = "Debug", about = "Debug a miden program")] +#[derive(Debug, Clone, Parser)] +#[clap(about = "Debug a miden program")] pub struct DebugCmd { /// Path to .masm assembly file - #[structopt(short = "a", long = "assembly", parse(from_os_str))] + #[clap(short = 'a', long = "assembly", value_parser)] assembly_file: PathBuf, /// Path to input file - #[structopt(short = "i", long = "input", parse(from_os_str))] + #[clap(short = 'i', long = "input", value_parser)] input_file: Option, /// Enable vi edit mode - #[structopt(short = "vi", long = "vim_edit_mode")] + #[clap(long = "vi", long = "vim_edit_mode")] vim_edit_mode: Option, /// Paths to .masl library files - #[structopt(short = "l", long = "libraries", parse(from_os_str))] + #[clap(short = 'l', long = "libraries", value_parser)] library_paths: Vec, } diff --git a/miden/src/cli/prove.rs b/miden/src/cli/prove.rs index 11e37893a7..0318e2b48b 100644 --- a/miden/src/cli/prove.rs +++ b/miden/src/cli/prove.rs @@ -1,51 +1,51 @@ use super::data::{Debug, InputFile, Libraries, OutputFile, ProgramFile, ProofFile}; +use clap::Parser; use miden::ProvingOptions; use processor::{ExecutionOptions, ExecutionOptionsError}; use std::{io::Write, path::PathBuf, time::Instant}; -use structopt::StructOpt; -// TODO check if structopt is supporting automatic generation of list values of hash function -#[derive(StructOpt, Debug)] -#[structopt(name = "Prove", about = "Prove a miden program")] +// TODO check if clap is supporting automatic generation of list values of hash function +#[derive(Debug, Clone, Parser)] +#[clap(about = "Prove a miden program")] pub struct ProveCmd { /// Path to .masm assembly file - #[structopt(short = "a", long = "assembly", parse(from_os_str))] + #[clap(short = 'a', long = "assembly", value_parser)] assembly_file: PathBuf, /// Number of cycles the program is expected to consume - #[structopt(short = "e", long = "exp-cycles", default_value = "64")] + #[clap(short = 'e', long = "exp-cycles", default_value = "64")] expected_cycles: u32, /// Path to input file - #[structopt(short = "i", long = "input", parse(from_os_str))] + #[clap(short = 'i', long = "input", value_parser)] input_file: Option, /// Paths to .masl library files - #[structopt(short = "l", long = "libraries", parse(from_os_str))] + #[clap(short = 'l', long = "libraries", value_parser)] library_paths: Vec, /// Maximum number of cycles a program is allowed to consume - #[structopt(short = "m", long = "max-cycles", default_value = "4294967295")] + #[clap(short = 'm', long = "max-cycles", default_value = "4294967295")] max_cycles: u32, /// Number of outputs - #[structopt(short = "n", long = "num-outputs", default_value = "16")] + #[clap(short = 'n', long = "num-outputs", default_value = "16")] num_outputs: usize, /// Path to output file - #[structopt(short = "o", long = "output", parse(from_os_str))] + #[clap(short = 'o', long = "output", value_parser)] output_file: Option, /// Path to proof file - #[structopt(short = "p", long = "proof", parse(from_os_str))] + #[clap(short = 'p', long = "proof", value_parser)] proof_file: Option, /// Enable generation of proofs suitable for recursive verification - #[structopt(short = "r", long = "recursive")] + #[clap(short = 'r', long = "recursive")] recursive: bool, /// Security level for execution proofs generated by the VM - #[structopt(short = "s", long = "security", default_value = "96bits")] + #[clap(short = 's', long = "security", default_value = "96bits")] security: String, } diff --git a/miden/src/cli/repl.rs b/miden/src/cli/repl.rs index 3b5ee5b749..4ce4d3ecce 100644 --- a/miden/src/cli/repl.rs +++ b/miden/src/cli/repl.rs @@ -1,8 +1,9 @@ +use clap::Parser; + use crate::repl::start_repl; -use structopt::StructOpt; -#[derive(StructOpt, Debug)] -#[structopt(name = "Repl", about = "Initiates the Miden REPL tool")] +#[derive(Debug, Clone, Parser)] +#[clap(about = "Initiates the Miden REPL tool")] pub struct ReplCmd {} impl ReplCmd { diff --git a/miden/src/cli/run.rs b/miden/src/cli/run.rs index c7fe6aba46..6f011c28fd 100644 --- a/miden/src/cli/run.rs +++ b/miden/src/cli/run.rs @@ -1,37 +1,37 @@ use super::data::{Debug, InputFile, Libraries, OutputFile, ProgramFile}; +use clap::Parser; use processor::ExecutionOptions; use std::{path::PathBuf, time::Instant}; -use structopt::StructOpt; -#[derive(StructOpt, Debug)] -#[structopt(name = "Run", about = "Run a miden program")] +#[derive(Debug, Clone, Parser)] +#[clap(about = "Run a miden program")] pub struct RunCmd { /// Path to .masm assembly file - #[structopt(short = "a", long = "assembly", parse(from_os_str))] + #[clap(short = 'a', long = "assembly", value_parser)] assembly_file: PathBuf, /// Number of cycles the program is expected to consume - #[structopt(short = "e", long = "exp-cycles", default_value = "64")] + #[clap(short = 'e', long = "exp-cycles", default_value = "64")] expected_cycles: u32, /// Path to input file - #[structopt(short = "i", long = "input", parse(from_os_str))] + #[clap(short = 'i', long = "input", value_parser)] input_file: Option, /// Paths to .masl library files - #[structopt(short = "l", long = "libraries", parse(from_os_str))] + #[clap(short = 'l', long = "libraries", value_parser)] library_paths: Vec, /// Maximum number of cycles a program is allowed to consume - #[structopt(short = "m", long = "max-cycles", default_value = "4294967295")] + #[clap(short = 'm', long = "max-cycles", default_value = "4294967295")] max_cycles: u32, /// Number of ouptuts - #[structopt(short = "n", long = "num-outputs", default_value = "16")] + #[clap(short = 'n', long = "num-outputs", default_value = "16")] num_outputs: usize, /// Path to output file - #[structopt(short = "o", long = "output", parse(from_os_str))] + #[clap(short = 'o', long = "output", value_parser)] output_file: Option, } diff --git a/miden/src/cli/verify.rs b/miden/src/cli/verify.rs index 5f36937cc9..9e81863b26 100644 --- a/miden/src/cli/verify.rs +++ b/miden/src/cli/verify.rs @@ -1,22 +1,22 @@ use super::data::{InputFile, OutputFile, ProgramHash, ProofFile}; +use clap::Parser; use miden::{Kernel, ProgramInfo}; use std::{path::PathBuf, time::Instant}; -use structopt::StructOpt; -#[derive(StructOpt, Debug)] -#[structopt(name = "Verify", about = "Verify a miden program")] +#[derive(Debug, Clone, Parser)] +#[clap(about = "Verify a miden program")] pub struct VerifyCmd { /// Path to input file - #[structopt(short = "i", long = "input", parse(from_os_str))] + #[clap(short = 'i', long = "input", value_parser)] input_file: Option, /// Path to output file - #[structopt(short = "o", long = "output", parse(from_os_str))] + #[clap(short = 'o', long = "output", value_parser)] output_file: Option, /// Path to proof file - #[structopt(short = "p", long = "proof", parse(from_os_str))] + #[clap(short = 'p', long = "proof", value_parser)] proof_file: PathBuf, /// Program hash (hex) - #[structopt(short = "h", long = "program-hash")] + #[clap(short = 'h', long = "program-hash")] program_hash: String, } diff --git a/miden/src/examples/mod.rs b/miden/src/examples/mod.rs index f22d92ccad..b3bceb9e4d 100644 --- a/miden/src/examples/mod.rs +++ b/miden/src/examples/mod.rs @@ -1,8 +1,8 @@ +use clap::Parser; use miden::{AdviceProvider, ExecutionProof, Program, ProgramInfo, ProvingOptions, StackInputs}; use processor::{ExecutionOptions, ExecutionOptionsError}; use std::io::Write; use std::time::Instant; -use structopt::StructOpt; pub mod fibonacci; @@ -23,36 +23,36 @@ where // EXAMPLE OPTIONS // ================================================================================================ -#[derive(StructOpt, Debug)] -#[structopt(name = "Examples", about = "Run an example miden program")] +#[derive(Debug, Clone, Parser)] +#[clap(about = "Run an example miden program")] pub struct ExampleOptions { - #[structopt(subcommand)] + #[clap(subcommand)] pub example: ExampleType, /// Number of cycles the program is expected to consume - #[structopt(short = "e", long = "exp-cycles", default_value = "64")] + #[clap(short = 'r', long = "exp-cycles", default_value = "64")] expected_cycles: u32, /// Maximum number of cycles a program is allowed to consume - #[structopt(short = "m", long = "max-cycles", default_value = "4294967295")] + #[clap(short = 'm', long = "max-cycles", default_value = "4294967295")] max_cycles: u32, /// Enable generation of proofs suitable for recursive verification - #[structopt(short = "r", long = "recursive")] + #[clap(short = 'r', long = "recursive")] recursive: bool, - /// Security level for execution proofs generated by the VM - #[structopt(short = "s", long = "security", default_value = "96bits")] + /// Security level for execution proofs generated by the VM + #[clap(short = 's', long = "security", default_value = "96bits")] security: String, } -#[derive(StructOpt, Debug)] -//#[structopt(about = "available examples")] +#[derive(Debug, Clone, Parser)] +//#[clap(about = "available examples")] pub enum ExampleType { /// Compute a Fibonacci sequence of the specified length Fib { /// Length of Fibonacci sequence - #[structopt(short = "n", default_value = "1024")] + #[clap(short = 'n', default_value = "1024")] sequence_length: usize, }, } diff --git a/miden/src/main.rs b/miden/src/main.rs index bc5e370bf6..cd3e8bb64b 100644 --- a/miden/src/main.rs +++ b/miden/src/main.rs @@ -1,6 +1,6 @@ +use clap::Parser; use core::fmt; use miden::{AssemblyError, ExecutionError}; -use structopt::StructOpt; mod cli; mod examples; @@ -8,15 +8,15 @@ mod repl; mod tools; /// Root CLI struct -#[derive(StructOpt, Debug)] -#[structopt(name = "Miden", about = "Miden CLI")] +#[derive(Parser, Debug)] +#[clap(name = "Miden", about = "Miden CLI", version, rename_all = "kebab-case")] pub struct Cli { - #[structopt(subcommand)] + #[clap(subcommand)] action: Actions, } /// CLI actions -#[derive(StructOpt, Debug)] +#[derive(Debug, Parser)] pub enum Actions { Analyze(tools::Analyze), Compile(cli::CompileCmd), @@ -51,7 +51,7 @@ impl Cli { /// Executable entry point pub fn main() { // read command-line args - let cli = Cli::from_args(); + let cli = Cli::parse(); // execute cli action if let Err(error) = cli.execute() { diff --git a/miden/src/tools/mod.rs b/miden/src/tools/mod.rs index a5fe8a0886..b4ee0f87c0 100644 --- a/miden/src/tools/mod.rs +++ b/miden/src/tools/mod.rs @@ -1,23 +1,23 @@ use super::{cli::InputFile, ProgramError}; +use clap::Parser; use core::fmt; use miden::{utils::collections::Vec, AdviceProvider, Assembler, Operation, StackInputs}; use processor::AsmOpInfo; use std::{fs, path::PathBuf}; use stdlib::StdLibrary; -use structopt::StructOpt; // CLI // ================================================================================================ /// Defines cli interface -#[derive(StructOpt, Debug)] -#[structopt(about = "Analyze a miden program")] +#[derive(Debug, Clone, Parser)] +#[clap(about = "Analyze a miden program")] pub struct Analyze { /// Path to .masm assembly file - #[structopt(short = "a", long = "assembly", parse(from_os_str))] + #[clap(short = 'a', long = "assembly", value_parser)] assembly_file: PathBuf, /// Path to .inputs file - #[structopt(short = "i", long = "input", parse(from_os_str))] + #[clap(short = 'i', long = "input", value_parser)] input_file: Option, }