Skip to content

Commit

Permalink
chore: Move the remaining nargo_cli lib funcs into nargo core
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Aug 8, 2023
1 parent 1a82c16 commit db40235
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 65 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/nargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rustc_version = "0.4.0"

[dependencies]
acvm.workspace = true
fm.workspace = true
noirc_abi.workspace = true
noirc_driver.workspace = true
noirc_frontend.workspace = true
Expand Down
39 changes: 39 additions & 0 deletions crates/nargo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,43 @@ pub mod ops;
pub mod package;
pub mod workspace;

use std::collections::BTreeMap;

use fm::FileManager;
use noirc_driver::{add_dep, prepare_crate};
use noirc_frontend::{
graph::{CrateGraph, CrateId, CrateName},
hir::Context,
};
use package::{Dependency, Package};

pub use self::errors::NargoError;

pub fn prepare_dependencies(
context: &mut Context,
parent_crate: CrateId,
dependencies: &BTreeMap<CrateName, Dependency>,
) {
for (dep_name, dep) in dependencies.iter() {
match dep {
Dependency::Remote { package } | Dependency::Local { package } => {
let crate_id = prepare_crate(context, &package.entry_path);
add_dep(context, parent_crate, crate_id, dep_name.clone());
prepare_dependencies(context, crate_id, &package.dependencies);
}
}
}
}

pub fn prepare_package(package: &Package) -> (Context, CrateId) {
// TODO: FileManager continues to leak into various crates
let fm = FileManager::new(&package.root_dir);
let graph = CrateGraph::default();
let mut context = Context::new(fm, graph);

let crate_id = prepare_crate(&mut context, &package.entry_path);

prepare_dependencies(&mut context, crate_id, &package.dependencies);

(context, crate_id)
}
4 changes: 1 addition & 3 deletions crates/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ build-data = "0.1.3"
toml.workspace = true

[dependencies]
cfg-if.workspace = true
clap.workspace = true
dirs.workspace = true
url.workspace = true
iter-extended.workspace = true
nargo.workspace = true
nargo_toml.workspace = true
Expand All @@ -31,7 +29,6 @@ noirc_frontend.workspace = true
noirc_abi.workspace = true
noirc_errors.workspace = true
acvm.workspace = true
fm.workspace = true
toml.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand All @@ -56,6 +53,7 @@ tempdir = "0.3.7"
assert_cmd = "2.0.8"
assert_fs = "1.0.10"
predicates = "2.1.5"
fm.workspace = true

[features]
default = ["plonk_bn254"]
Expand Down
7 changes: 2 additions & 5 deletions crates/nargo_cli/src/cli/check_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use crate::{
errors::{CliError, CompileError},
prepare_package,
};
use crate::errors::{CliError, CompileError};
use acvm::Backend;
use clap::Args;
use iter_extended::btree_map;
use nargo::package::Package;
use nargo::{package::Package, prepare_package};
use nargo_toml::{find_package_manifest, resolve_workspace_from_toml};
use noirc_abi::{AbiParameter, AbiType, MAIN_RETURN_NAME};
use noirc_driver::{check_crate, compute_function_signature, CompileOptions};
Expand Down
2 changes: 1 addition & 1 deletion crates/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use acvm::{acir::circuit::Circuit, Backend};
use iter_extended::try_vecmap;
use iter_extended::vecmap;
use nargo::package::Package;
use nargo::prepare_package;
use nargo::{artifacts::contract::PreprocessedContract, NargoError};
use nargo_toml::{find_package_manifest, resolve_workspace_from_toml};
use noirc_driver::{
Expand All @@ -16,7 +17,6 @@ use clap::Args;
use nargo::ops::{preprocess_contract_function, preprocess_program};

use crate::errors::{CliError, CompileError};
use crate::prepare_package;

use super::fs::{
common_reference_string::{
Expand Down
2 changes: 1 addition & 1 deletion crates/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ enum NargoCommand {
Lsp(lsp_cmd::LspCommand),
}

pub fn start_cli() -> eyre::Result<()> {
pub(crate) fn start_cli() -> eyre::Result<()> {
let NargoCli { command, mut config } = NargoCli::parse();

// Search through parent directories to find package root if necessary.
Expand Down
4 changes: 2 additions & 2 deletions crates/nargo_cli/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use std::io::Write;

use acvm::{acir::native_types::WitnessMap, Backend};
use clap::Args;
use nargo::{ops::execute_circuit, package::Package};
use nargo::{ops::execute_circuit, package::Package, prepare_package};
use nargo_toml::{find_package_manifest, resolve_workspace_from_toml};
use noirc_driver::{compile_no_check, CompileOptions};
use noirc_frontend::{graph::CrateName, hir::Context, node_interner::FuncId};
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};

use crate::{cli::check_cmd::check_crate_and_report_errors, errors::CliError, prepare_package};
use crate::{cli::check_cmd::check_crate_and_report_errors, errors::CliError};

use super::{compile_cmd::optimize_circuit, NargoConfig};

Expand Down
49 changes: 0 additions & 49 deletions crates/nargo_cli/src/lib.rs

This file was deleted.

14 changes: 12 additions & 2 deletions crates/nargo_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#![forbid(unsafe_code)]
#![warn(unused_extern_crates)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]

//! Nargo is the package manager for Noir
//! This name was used because it sounds like `cargo` and
//! Noir Package Manager abbreviated is npm, which is already taken.

mod backends;
mod cli;
mod errors;

use color_eyre::{config::HookBuilder, eyre};
use nargo_cli::cli::start_cli;

const PANIC_MESSAGE: &str = "This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.\nIf there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml";

Expand All @@ -11,5 +21,5 @@ fn main() -> eyre::Result<()> {
HookBuilder::default().display_env_section(false).panic_section(PANIC_MESSAGE).into_hooks();
panic_hook.install();

start_cli()
cli::start_cli()
}

0 comments on commit db40235

Please sign in to comment.