Skip to content

Commit 0d0be23

Browse files
guipublicTomAFrenchkek kek kekkevaundray
committed
fix: recompile artefacts from a different noir version (#3248)
Co-authored-by: Tom French <[email protected]> Co-authored-by: kek kek kek <[email protected]> Co-authored-by: kevaundray <[email protected]>
1 parent e9956cf commit 0d0be23

File tree

15 files changed

+73
-25
lines changed

15 files changed

+73
-25
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/noirc_driver/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ license.workspace = true
77

88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

10+
[build-dependencies]
11+
build-data = "0.1.3"
12+
1013
[dependencies]
1114
clap.workspace = true
1215
noirc_errors.workspace = true

compiler/noirc_driver/build.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const GIT_COMMIT: &&str = &"GIT_COMMIT";
2+
3+
fn main() {
4+
// Rebuild if the tests have changed
5+
println!("cargo:rerun-if-changed=tests");
6+
7+
// Only use build_data if the environment variable isn't set
8+
// The environment variable is always set when working via Nix
9+
if std::env::var(GIT_COMMIT).is_err() {
10+
build_data::set_GIT_COMMIT();
11+
build_data::set_GIT_DIRTY();
12+
build_data::no_debug_rebuilds();
13+
}
14+
}

compiler/noirc_driver/src/contract.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub enum ContractFunctionType {
2828

2929
#[derive(Serialize, Deserialize)]
3030
pub struct CompiledContract {
31+
pub noir_version: String,
32+
3133
/// The name of the contract.
3234
pub name: String,
3335
/// Each of the contract's functions are compiled into a separate `CompiledProgram`

compiler/noirc_driver/src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ pub use program::CompiledProgram;
2828

2929
const STD_CRATE_NAME: &str = "std";
3030

31+
pub const GIT_COMMIT: &str = env!("GIT_COMMIT");
32+
pub const GIT_DIRTY: &str = env!("GIT_DIRTY");
33+
pub const NOIRC_VERSION: &str = env!("CARGO_PKG_VERSION");
34+
35+
/// Version string that gets placed in artifacts that Noir builds. This is semver compatible.
36+
/// Note: You can't directly use the value of a constant produced with env! inside a concat! macro.
37+
pub const NOIR_ARTIFACT_VERSION_STRING: &str =
38+
concat!(env!("CARGO_PKG_VERSION"), "+", env!("GIT_COMMIT"));
39+
3140
#[derive(Args, Clone, Debug, Default, Serialize, Deserialize)]
3241
pub struct CompileOptions {
3342
/// Emit debug information for the intermediate SSA IR
@@ -305,6 +314,7 @@ fn compile_contract_inner(
305314
.collect(),
306315
functions,
307316
file_map,
317+
noir_version: NOIR_ARTIFACT_VERSION_STRING.to_string(),
308318
})
309319
} else {
310320
Err(errors)
@@ -342,5 +352,12 @@ pub fn compile_no_check(
342352

343353
let file_map = filter_relevant_files(&[debug.clone()], &context.file_manager);
344354

345-
Ok(CompiledProgram { hash, circuit, debug, abi, file_map })
355+
Ok(CompiledProgram {
356+
hash,
357+
circuit,
358+
debug,
359+
abi,
360+
file_map,
361+
noir_version: NOIR_ARTIFACT_VERSION_STRING.to_string(),
362+
})
346363
}

compiler/noirc_driver/src/program.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use super::debug::DebugFile;
1212

1313
#[derive(Debug, Serialize, Deserialize, Clone)]
1414
pub struct CompiledProgram {
15+
pub noir_version: String,
1516
/// Hash of the [`Program`][noirc_frontend::monomorphization::ast::Program] from which this [`CompiledProgram`]
1617
/// was compiled.
1718
///

compiler/wasm/build.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
const GIT_COMMIT: &&str = &"GIT_COMMIT";
2-
31
fn main() {
4-
// Only use build_data if the environment variable isn't set
5-
// The environment variable is always set when working via Nix
6-
if std::env::var(GIT_COMMIT).is_err() {
7-
build_data::set_GIT_COMMIT();
8-
build_data::set_GIT_DIRTY();
9-
build_data::no_debug_rebuilds();
10-
}
11-
122
build_data::set_SOURCE_TIMESTAMP();
133
build_data::no_debug_rebuilds();
144
}

compiler/wasm/src/compile.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use nargo::artifacts::{
77
};
88
use noirc_driver::{
99
add_dep, compile_contract, compile_main, prepare_crate, prepare_dependency, CompileOptions,
10-
CompiledContract, CompiledProgram,
10+
CompiledContract, CompiledProgram, NOIR_ARTIFACT_VERSION_STRING,
1111
};
1212
use noirc_frontend::{graph::CrateGraph, hir::Context};
1313
use std::path::Path;
@@ -118,6 +118,7 @@ fn preprocess_program(program: CompiledProgram) -> PreprocessedProgram {
118118
hash: program.hash,
119119
backend: String::from(BACKEND_IDENTIFIER),
120120
abi: program.abi,
121+
noir_version: NOIR_ARTIFACT_VERSION_STRING.to_string(),
121122
bytecode: program.circuit,
122123
}
123124
}
@@ -136,6 +137,7 @@ fn preprocess_contract(contract: CompiledContract) -> PreprocessedContract {
136137
.collect();
137138

138139
PreprocessedContract {
140+
noir_version: String::from(NOIR_ARTIFACT_VERSION_STRING),
139141
name: contract.name,
140142
backend: String::from(BACKEND_IDENTIFIER),
141143
functions: preprocessed_functions,

compiler/wasm/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use getrandom as _;
77

88
use gloo_utils::format::JsValueSerdeExt;
99
use log::Level;
10+
use noirc_driver::{GIT_COMMIT, GIT_DIRTY, NOIRC_VERSION};
1011
use serde::{Deserialize, Serialize};
1112
use std::str::FromStr;
1213
use wasm_bindgen::prelude::*;
@@ -37,11 +38,8 @@ pub fn init_log_level(level: String) {
3738
});
3839
}
3940

40-
const BUILD_INFO: BuildInfo = BuildInfo {
41-
git_hash: env!("GIT_COMMIT"),
42-
version: env!("CARGO_PKG_VERSION"),
43-
dirty: env!("GIT_DIRTY"),
44-
};
41+
const BUILD_INFO: BuildInfo =
42+
BuildInfo { git_hash: GIT_COMMIT, version: NOIRC_VERSION, dirty: GIT_DIRTY };
4543

4644
#[wasm_bindgen]
4745
pub fn build_info() -> JsValue {

release-tests/test/version.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ test("promise resolved", async () => {
2121

2222
test("prints version", async () => {
2323
const processOutput = (await $`${NARGO_BIN} --version`).toString();
24-
assert.match(processOutput, /nargo\s\d{1,2}.\d{1,2}/);
24+
25+
// Regex to match the "nargo version" part of the output
26+
assert.match(processOutput, /nargo version = \d{1,2}\.\d{1,2}\.\d{1,2}/);
2527
});
2628

29+
2730
test("reports a clean commit", async () => {
2831
const processOutput = (await $`${NARGO_BIN} --version`).toString();
2932
assert.not.match(processOutput, /is dirty: true/)

0 commit comments

Comments
 (0)