Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Add option to specify output directory on codegen cmd and use generic names #4479

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use super::fs::{create_named_dir, write_to_file};
use super::NargoConfig;
use crate::backends::Backend;
use crate::errors::CliError;
use std::fs::create_dir_all;
use std::path::PathBuf;

use clap::Args;
use nargo::ops::{compile_program, report_errors};
Expand All @@ -21,6 +23,16 @@ pub(crate) struct CodegenVerifierCommand {
#[clap(long, conflicts_with = "package")]
workspace: bool,

/// The path of the directory to save the contract
///
/// If not specified, the contract will be saved in the contracts directory of the package.
#[clap(
short,
long,
value_hint = clap::ValueHint::DirPath,
)]
output_directory: Option<PathBuf>,

#[clap(flatten)]
compile_options: CompileOptions,
}
Expand Down Expand Up @@ -66,9 +78,15 @@ pub(crate) fn run(

let smart_contract_string = backend.eth_contract(&program.circuit)?;

let contract_dir = workspace.contracts_directory_path(package);
create_named_dir(&contract_dir, "contract");
let contract_path = contract_dir.join("plonk_vk").with_extension("sol");
let contract_path = if let Some(ref loc) = args.output_directory {
create_dir_all(loc)
.unwrap_or_else(|_| panic!("failed to create directories for {:?}", loc));
PathBuf::from(loc).join(format!("{}_verifier", package.name)).with_extension("sol")
} else {
let contract_dir = workspace.contracts_directory_path(package);
create_named_dir(&contract_dir, "contract");
contract_dir.join(format!("{}_verifier", package.name)).with_extension("sol")
};

let path = write_to_file(smart_contract_string.as_bytes(), &contract_path);
println!("[{}] Contract successfully created and located at {path}", package.name);
Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_cli/tests/codegen-verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ fn simple_verifier_codegen() {
project_dir
.child("contract")
.child("hello_world")
.child("plonk_vk.sol")
.child("hello_world_verifier.sol")
.assert(predicate::path::is_file());
}