Skip to content

Commit

Permalink
feat: compile workspace packages in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Sep 8, 2023
1 parent 3f21387 commit 9248088
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
1 change: 1 addition & 0 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_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ toml.workspace = true
serde.workspace = true
serde_json.workspace = true
prettytable-rs = "0.10"
rayon = "1.7.0"
thiserror.workspace = true
tower.workspace = true
async-lsp = { version = "0.0.5", default-features = false, features = [
Expand Down
56 changes: 37 additions & 19 deletions crates/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use nargo::artifacts::contract::PreprocessedContract;
use nargo::artifacts::contract::PreprocessedContractFunction;
use nargo::artifacts::debug::DebugArtifact;
use nargo::artifacts::program::PreprocessedProgram;
use nargo::package::Package;
use nargo::package::{Package, PackageType};
use nargo::prepare_package;
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_driver::{
Expand All @@ -26,6 +26,7 @@ use super::fs::program::{
save_contract_to_file, save_debug_artifact_to_file, save_program_to_file,
};
use super::NargoConfig;
use rayon::prelude::*;

// TODO(#1388): pull this from backend.
const BACKEND_IDENTIFIER: &str = "acvm-backend-barretenberg";
Expand Down Expand Up @@ -66,24 +67,41 @@ pub(crate) fn run(
let circuit_dir = workspace.target_directory_path();

let (np_language, is_opcode_supported) = backend.get_backend_info()?;
for package in &workspace {
// If `contract` package type, we're compiling every function in a 'contract' rather than just 'main'.
if package.is_contract() {
let (file_manager, contracts) = compile_contracts(
package,
&args.compile_options,
np_language,
&is_opcode_supported,
)?;
save_contracts(&file_manager, contracts, package, &circuit_dir, args.output_debug);
} else {
let (file_manager, program) =
compile_package(package, &args.compile_options, np_language, &is_opcode_supported)?;
save_program(&file_manager, program, package, &circuit_dir, args.output_debug);
}
}

Ok(())
workspace
.members
.par_iter()
.map(|package| -> Result<(), CliError> {
match package.package_type {
PackageType::Binary => {
let (file_manager, program) = compile_package(
package,
&args.compile_options,
np_language,
&is_opcode_supported,
)?;
save_program(&file_manager, program, package, &circuit_dir, args.output_debug);
Ok(())
}
PackageType::Contract => {
let (file_manager, contracts) = compile_contracts(
package,
&args.compile_options,
np_language,
&is_opcode_supported,
)?;
save_contracts(
&file_manager,
contracts,
package,
&circuit_dir,
args.output_debug,
);
Ok(())
}
PackageType::Library => Ok(()), // Skip
}
})
.collect()
}

pub(crate) fn compile_package(
Expand Down

0 comments on commit 9248088

Please sign in to comment.