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 version string to build artifacts #3156

Closed
wants to merge 5 commits into from
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
5 changes: 5 additions & 0 deletions compiler/wasm/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ use crate::errors::JsCompileError;

const BACKEND_IDENTIFIER: &str = "acvm-backend-barretenberg";

const NOIR_ARTIFACT_VERSION_STRING: &str =
concat!(env!("CARGO_PKG_VERSION"), "-", env!("GIT_COMMIT"));

Comment on lines 18 to +22
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two being here seems a bit odd -- I think versioning could probably go into the driver/nargo and then have it be shared between nargo_cli and wasm

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Array, js_name = "StringArray", typescript_type = "string[]")]
Expand Down Expand Up @@ -119,6 +122,7 @@ fn preprocess_program(program: CompiledProgram) -> PreprocessedProgram {
backend: String::from(BACKEND_IDENTIFIER),
abi: program.abi,
bytecode: program.circuit,
nargo_version: String::from(NOIR_ARTIFACT_VERSION_STRING),
}
}

Expand All @@ -140,6 +144,7 @@ fn preprocess_contract(contract: CompiledContract) -> PreprocessedContract {
backend: String::from(BACKEND_IDENTIFIER),
functions: preprocessed_functions,
events: contract.events,
nargo_version: String::from(NOIR_ARTIFACT_VERSION_STRING),
}
}

Expand Down
2 changes: 2 additions & 0 deletions tooling/nargo/src/artifacts/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use serde::{Deserialize, Serialize};
/// - Proving and verification keys have been pregenerated based on this ACIR.
#[derive(Serialize, Deserialize)]
pub struct PreprocessedContract {
/// Version of nargo used to compile this contract
pub nargo_version: String,
/// The name of the contract.
pub name: String,
/// The identifier of the proving backend which this contract has been compiled for.
Expand Down
6 changes: 4 additions & 2 deletions tooling/nargo/src/artifacts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! to generate them using these artifacts as a starting point.
use acvm::acir::circuit::Circuit;
use base64::Engine;
use serde::{de::Error as DeserializationError, ser::Error as SerializationError};
use serde::{Deserializer, Serializer};

pub mod contract;
Expand All @@ -17,7 +18,7 @@ where
S: Serializer,
{
let mut circuit_bytes: Vec<u8> = Vec::new();
circuit.write(&mut circuit_bytes).unwrap();
circuit.write(&mut circuit_bytes).map_err(|err| S::Error::custom(err.to_string()))?;
let encoded_b64 = base64::engine::general_purpose::STANDARD.encode(circuit_bytes);
s.serialize_str(&encoded_b64)
}
Expand All @@ -28,6 +29,7 @@ where
{
let bytecode_b64: String = serde::Deserialize::deserialize(deserializer)?;
let circuit_bytes = base64::engine::general_purpose::STANDARD.decode(bytecode_b64).unwrap();
let circuit = Circuit::read(&*circuit_bytes).unwrap();
let circuit =
Circuit::read(&*circuit_bytes).map_err(|err| D::Error::custom(err.to_string()))?;
Ok(circuit)
}
3 changes: 3 additions & 0 deletions tooling/nargo/src/artifacts/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub struct PreprocessedProgram {
/// Used to short-circuit compilation in the case of the source code not changing since the last compilation.
pub hash: u64,

/// Version of nargo used to compile this contract
pub nargo_version: String,

pub backend: String,
pub abi: Abi,

Expand Down
23 changes: 15 additions & 8 deletions tooling/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use super::fs::program::{
save_contract_to_file, save_debug_artifact_to_file, save_program_to_file,
};
use super::NargoConfig;
use super::NOIR_ARTIFACT_VERSION_STRING;
use rayon::prelude::*;

// TODO(#1388): pull this from backend.
Expand Down Expand Up @@ -198,14 +199,18 @@ fn compile_program(
let cached_program = if let Ok(preprocessed_program) =
read_program_from_file(workspace.package_build_path(package))
{
// TODO: Load debug information.
Some(CompiledProgram {
hash: preprocessed_program.hash,
circuit: preprocessed_program.bytecode,
abi: preprocessed_program.abi,
debug: DebugInfo::default(),
file_map: BTreeMap::new(),
})
if preprocessed_program.nargo_version != NOIR_ARTIFACT_VERSION_STRING {
None
} else {
// TODO: Load debug information.
Some(CompiledProgram {
hash: preprocessed_program.hash,
circuit: preprocessed_program.bytecode,
abi: preprocessed_program.abi,
debug: DebugInfo::default(),
file_map: BTreeMap::new(),
})
}
} else {
None
};
Expand Down Expand Up @@ -271,6 +276,7 @@ fn save_program(
output_debug: bool,
) {
let preprocessed_program = PreprocessedProgram {
nargo_version: String::from(NOIR_ARTIFACT_VERSION_STRING),
hash: program.hash,
backend: String::from(BACKEND_IDENTIFIER),
abi: program.abi,
Expand Down Expand Up @@ -311,6 +317,7 @@ fn save_contract(
});

let preprocessed_contract = PreprocessedContract {
nargo_version: String::from(NOIR_ARTIFACT_VERSION_STRING),
name: contract.name,
backend: String::from(BACKEND_IDENTIFIER),
functions: preprocessed_functions,
Expand Down
4 changes: 4 additions & 0 deletions tooling/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const GIT_HASH: &str = env!("GIT_COMMIT");
const IS_DIRTY: &str = env!("GIT_DIRTY");
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");

/// Version string that gets placed in artifacts that Noir builds
pub(crate) const NOIR_ARTIFACT_VERSION_STRING: &str =
concat!(env!("CARGO_PKG_VERSION"), "-", env!("GIT_COMMIT"));

static VERSION_STRING: &str =
formatcp!("{} (git version hash: {}, is dirty: {})", CARGO_PKG_VERSION, GIT_HASH, IS_DIRTY);

Expand Down