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(nargo): Version info in nargo and wasm #802

Merged
merged 5 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion crates/nargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition.workspace = true
[build-dependencies]
dirs.workspace = true
rustc_version = "0.4.0"
build-data = "0.1.3"

[dependencies]
dirs.workspace = true
Expand All @@ -25,7 +26,6 @@ serde.workspace = true
thiserror.workspace = true
clap = "2.33.3"
const_format = "0.2.30"
git-version = "0.3.5"
hex = "0.4.2"
termcolor = "1.1.2"
tempdir = "0.3.7"
Expand Down
6 changes: 6 additions & 0 deletions crates/nargo/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ pub fn copy<U: AsRef<Path>, V: AsRef<Path>>(from: U, to: V) -> Result<(), std::i

fn main() {
check_rustc_version();

build_data::set_GIT_COMMIT();
build_data::set_GIT_DIRTY();
build_data::set_SOURCE_TIMESTAMP();
kobyhallx marked this conversation as resolved.
Show resolved Hide resolved
build_data::no_debug_rebuilds();

let stdlib_src_dir = Path::new("../../noir_stdlib/");
rerun_if_stdlib_changes(stdlib_src_dir);
let target = dirs::config_dir().unwrap().join("noir-lang").join("std");
Expand Down
9 changes: 6 additions & 3 deletions crates/nargo/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use acvm::{
pub use check_cmd::check_from_path;
use clap::{App, AppSettings, Arg};
use const_format::formatcp;
use git_version::git_version;
use noirc_abi::{
input_parser::{Format, InputValue},
Abi,
Expand Down Expand Up @@ -33,8 +32,12 @@ mod prove_cmd;
mod test_cmd;
mod verify_cmd;

const SHORT_GIT_HASH: &str = git_version!(prefix = "git:");
const VERSION_STRING: &str = formatcp!("{} ({})", env!("CARGO_PKG_VERSION"), SHORT_GIT_HASH);
const GIT_HASH: &str = env!("GIT_COMMIT");
const IS_DIRTY: &str = env!("GIT_DIRTY");
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");

static VERSION_STRING: &str =
formatcp!("{} (git version hash: {}, is dirty: {})", CARGO_PKG_VERSION, GIT_HASH, IS_DIRTY);
kobyhallx marked this conversation as resolved.
Show resolved Hide resolved

/// A map from the fields in an TOML/JSON file which correspond to some ABI to their values
pub type InputMap = BTreeMap<String, InputValue>;
Expand Down
4 changes: 4 additions & 0 deletions crates/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ crate-type = ["cdylib"]
acvm.workspace = true
noirc_driver.workspace = true
wasm-bindgen.workspace = true
serde.workspace = true

console_error_panic_hook = "0.1.7"
getrandom = { version = "0.2.4", features = ["js"] }
Expand All @@ -23,3 +24,6 @@ js-sys = "0.3.55"

[dev-dependencies]
wasm-bindgen-test.workspace = true

[build-dependencies]
build-data = "0.1.3"
6 changes: 6 additions & 0 deletions crates/wasm/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
build_data::set_GIT_COMMIT();
build_data::set_GIT_DIRTY();
build_data::set_SOURCE_TIMESTAMP();
build_data::no_debug_rebuilds();
}
20 changes: 20 additions & 0 deletions crates/wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
use acvm::acir::circuit::Circuit;
use gloo_utils::format::JsValueSerdeExt;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use wasm_bindgen::prelude::*;

#[derive(Serialize, Deserialize)]
pub struct BuildInfo {
git_hash: &'static str,
version: &'static str,
dirty: &'static str,
}

const BUILD_INFO: BuildInfo = BuildInfo {
git_hash: env!("GIT_COMMIT"),
version: env!("CARGO_PKG_VERSION"),
dirty: env!("GIT_DIRTY"),
};

// Returns a compiled program which is the ACIR circuit along with the ABI
#[wasm_bindgen]
pub fn compile(src: String) -> JsValue {
Expand All @@ -27,3 +41,9 @@ pub fn acir_to_bytes(acir: JsValue) -> Vec<u8> {
let circuit: Circuit = JsValueSerdeExt::into_serde(&acir).unwrap();
circuit.to_bytes()
}

#[wasm_bindgen]
pub fn build_info() -> JsValue {
console_error_panic_hook::set_once();
<JsValue as JsValueSerdeExt>::from_serde(&BUILD_INFO).unwrap()
}