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

chore: adds a new option only-acir #3683

Merged
merged 15 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
4 changes: 4 additions & 0 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ pub struct CompileOptions {
#[arg(long, conflicts_with = "deny_warnings")]
pub silence_warnings: bool,

guipublic marked this conversation as resolved.
Show resolved Hide resolved
/// Output ACIR gzipped bytecode instead of the JSON artefact
#[arg(long, hide = true)]
pub only_acir: bool,

/// Disables the builtin macros being used in the compiler
#[arg(long, hide = true)]
pub disable_macros: bool,
Expand Down
17 changes: 9 additions & 8 deletions docs/docs/reference/nargo_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ You can also use "build" as an alias for compile (e.g. `nargo build`).

### Options

| Option | Description |
| --------------------- | ------------------------------------------------------------ |
| `--package <PACKAGE>` | The name of the package to compile |
| `--workspace` | Compile all packages in the workspace |
| `--print-acir` | Display the ACIR for compiled circuit |
| `--deny-warnings` | Treat all warnings as errors |
| `--silence-warnings` | Suppress warnings |
| `-h, --help` | Print help |
| Option | Description |
| --------------------- | ----------------------------------------------------------------------------|
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
| `--package <PACKAGE>` | The name of the package to compile |
| `--workspace` | Compile all packages in the workspace |
| `--print-acir` | Display the ACIR for compiled circuit |
| `--deny-warnings` | Treat all warnings as errors |
| `--silence-warnings` | Suppress warnings |
| `--only-acir` | generates ACIR representation into acir.gz, instead of JSON build artifact |
| `-h, --help` | Print help |
kevaundray marked this conversation as resolved.
Show resolved Hide resolved

## `nargo new <PATH>`

Expand Down
12 changes: 1 addition & 11 deletions test_programs/rebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,7 @@ process_dir() {
if [ -d ./target/ ]; then
rm -r ./target/
fi
nargo compile && nargo execute witness

if [ -f ./target/witness.tr ]; then
mv ./target/witness.tr ./target/witness.gz
fi

if [ -f ./target/${dir_name}.json ]; then
jq -r '.bytecode' ./target/${dir_name}.json | base64 -d > ./target/acir.gz
fi

rm ./target/${dir_name}.json
cargo run compile --only-acir && cargo run execute witness

if [ -d "$current_dir/acir_artifacts/$dir_name/target" ]; then
rm -r "$current_dir/acir_artifacts/$dir_name/target"
Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ pub const PKG_FILE: &str = "Nargo.toml";
/// The extension for files containing circuit proofs.
pub const PROOF_EXT: &str = "proof";
/// The extension for files containing proof witnesses.
pub const WITNESS_EXT: &str = "tr";
pub const WITNESS_EXT: &str = "gz";
19 changes: 14 additions & 5 deletions tooling/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use clap::Args;
use crate::backends::Backend;
use crate::errors::CliError;

use super::fs::program::only_acir;
use super::fs::program::{
read_debug_artifact_from_file, read_program_from_file, save_contract_to_file,
save_debug_artifact_to_file, save_program_to_file,
Expand Down Expand Up @@ -215,8 +216,8 @@ fn compile_program(
// Apply backend specific optimizations.
let optimized_program = nargo::ops::optimize_program(program, np_language, is_opcode_supported)
.expect("Backend does not support an opcode that is in the IR");

save_program(optimized_program.clone(), package, &workspace.target_directory_path());
let only_acir = compile_options.only_acir;
save_program(optimized_program.clone(), package, &workspace.target_directory_path(), only_acir);

(context.file_manager, Ok((optimized_program, warnings)))
}
Expand Down Expand Up @@ -244,16 +245,24 @@ fn compile_contract(
(context.file_manager, Ok((optimized_contract, warnings)))
}

fn save_program(program: CompiledProgram, package: &Package, circuit_dir: &Path) {
fn save_program(
program: CompiledProgram,
package: &Package,
circuit_dir: &Path,
only_acir_opt: bool,
) {
let preprocessed_program = PreprocessedProgram {
hash: program.hash,
backend: String::from(BACKEND_IDENTIFIER),
abi: program.abi,
noir_version: program.noir_version,
bytecode: program.circuit,
};

save_program_to_file(&preprocessed_program, &package.name, circuit_dir);
if only_acir_opt {
only_acir(&preprocessed_program, circuit_dir);
} else {
save_program_to_file(&preprocessed_program, &package.name, circuit_dir);
}

let debug_artifact = DebugArtifact {
debug_symbols: vec![program.debug],
Expand Down
14 changes: 14 additions & 0 deletions tooling/nargo_cli/src/cli/fs/program.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::path::{Path, PathBuf};

use acvm::acir::circuit::Circuit;
use nargo::artifacts::{
contract::PreprocessedContract, debug::DebugArtifact, program::PreprocessedProgram,
};
Expand All @@ -18,6 +19,19 @@ pub(crate) fn save_program_to_file<P: AsRef<Path>>(
save_build_artifact_to_file(compiled_program, &circuit_name, circuit_dir)
}

/// Writes the bytecode as acir.gz
pub(crate) fn only_acir<P: AsRef<Path>>(
compiled_program: &PreprocessedProgram,
circuit_dir: P,
) -> PathBuf {
create_named_dir(circuit_dir.as_ref(), "target");
let circuit_path = circuit_dir.as_ref().join("acir").with_extension("gz");
let bytes = Circuit::serialize_circuit(&compiled_program.bytecode);
write_to_file(&bytes, &circuit_path);

circuit_path
}

pub(crate) fn save_contract_to_file<P: AsRef<Path>>(
compiled_contract: &PreprocessedContract,
circuit_name: &str,
Expand Down
Loading