Skip to content

Commit

Permalink
feat!: Add semver checks for the compiler version in Nargo.toml (#3336)
Browse files Browse the repository at this point in the history
Co-authored-by: guipublic <guipublic@gmail.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: kek kek kek <andriy.n@obox.systems>
Co-authored-by: guipublic <47281315+guipublic@users.noreply.github.com>
Co-authored-by: José Pedro Sousa <jose@aztecprotocol.com>
  • Loading branch information
6 people authored Oct 30, 2023
1 parent c9673ed commit 0e530cf
Show file tree
Hide file tree
Showing 276 changed files with 340 additions and 397 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions compiler/integration-tests/circuits/main/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
name = "main"
type = "bin"
authors = [""]
compiler_version = "0.9.0"

[dependencies]
2 changes: 0 additions & 2 deletions compiler/integration-tests/circuits/recursion/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
name = "recursion"
type = "bin"
authors = [""]
compiler_version = "0.9.0"

[dependencies]
1 change: 0 additions & 1 deletion compiler/wasm/fixtures/deps/lib-a/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
name="lib_a"
type="lib"
authors = [""]
compiler_version = "0.1"

[dependencies]
lib_b = { path = "../lib-b" }
1 change: 0 additions & 1 deletion compiler/wasm/fixtures/deps/lib-b/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
name="lib_b"
type="lib"
authors = [""]
compiler_version = "0.1"

[dependencies]
1 change: 0 additions & 1 deletion compiler/wasm/fixtures/deps/noir-script/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
name="noir_wasm_testing"
type="bin"
authors = [""]
compiler_version = "0.1"

[dependencies]
lib_a = { path="../lib-a" }
1 change: 0 additions & 1 deletion compiler/wasm/fixtures/simple/noir-script/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
name="noir_wasm_testing"
type="bin"
authors = [""]
compiler_version = "0.1"

[dependencies]
2 changes: 1 addition & 1 deletion docs/docs/getting_started/02_breakdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The package section requires a number of fields including:
- `name` (**required**) - the name of the package
- `type` (**required**) - can be "bin", "lib", or "contract" to specify whether its a binary, library or Aztec contract
- `authors` (optional) - authors of the project
- `compiler_version` (optional) - specifies the version of the compiler to use. This is not currently enforced by the compiler, but will be in future versions.
- `compiler_version` - specifies the version of the compiler to use. This is enforced by the compiler and follow's [Rust's versioning](https://doc.rust-lang.org/cargo/reference/manifest.html#the-version-field), so a `compiler_version = 0.18.0` will enforce Nargo version 0.18.0, `compiler_version = ^0.18.0` will enforce anything above 0.18.0 but below 0.19.0, etc. For more information, see how [Rust handles these operators](https://docs.rs/semver/latest/semver/enum.Op.html)
- `description` (optional)
- `entry` (optional) - a relative filepath to use as the entry point into your package (overrides the default of `src/lib.nr` or `src/main.nr`)
- `backend` (optional)
Expand Down
8 changes: 8 additions & 0 deletions docs/docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ keywords: [Noir, notes, migration, updating, upgrading]

Noir is in full-speed development. Things break fast, wild, and often. This page attempts to leave some notes on errors you might encounter when upgrading and how to resolve them until proper patches are built.

## ≥0.19

### Enforcing `compiler_version`

From this version on, the compiler will check for the `compiler_version` field in `Nargo.toml`, and will error if it doesn't match the current Nargo version in use.

To update, please make sure this field in `Nargo.toml` matches the output of `nargo --version`.

## ≥0.14

The index of the [for loops](./language_concepts/02_control_flow.md#loops) is now of type `u64` instead of `Field`. An example refactor would be:
Expand Down
2 changes: 0 additions & 2 deletions noir_stdlib/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
name = "std"
type = "lib"
authors = [""]
compiler_version = "0.1"

[dependencies]
8 changes: 6 additions & 2 deletions tooling/lsp/src/notifications/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ops::ControlFlow;
use async_lsp::{ErrorCode, LanguageClient, ResponseError};
use nargo::prepare_package;
use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_driver::check_crate;
use noirc_driver::{check_crate, NOIR_ARTIFACT_VERSION_STRING};
use noirc_errors::{DiagnosticKind, FileDiagnostic};

use crate::types::{
Expand Down Expand Up @@ -88,7 +88,11 @@ pub(super) fn on_did_save_text_document(
return ControlFlow::Continue(());
}
};
let workspace = match resolve_workspace_from_toml(&toml_path, PackageSelection::All) {
let workspace = match resolve_workspace_from_toml(
&toml_path,
PackageSelection::All,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
) {
Ok(workspace) => workspace,
Err(err) => {
// If we found a manifest, but the workspace is invalid, we raise an error about it
Expand Down
16 changes: 10 additions & 6 deletions tooling/lsp/src/requests/code_lens_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_lsp::{ErrorCode, LanguageClient, ResponseError};

use nargo::{package::Package, prepare_package, workspace::Workspace};
use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_driver::check_crate;
use noirc_driver::{check_crate, NOIR_ARTIFACT_VERSION_STRING};
use noirc_frontend::hir::FunctionNameMatch;

use crate::{
Expand Down Expand Up @@ -67,11 +67,15 @@ fn on_code_lens_request_inner(
return Ok(None);
}
};
let workspace =
resolve_workspace_from_toml(&toml_path, PackageSelection::All).map_err(|err| {
// If we found a manifest, but the workspace is invalid, we raise an error about it
ResponseError::new(ErrorCode::REQUEST_FAILED, err)
})?;
let workspace = resolve_workspace_from_toml(
&toml_path,
PackageSelection::All,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)
.map_err(|err| {
// If we found a manifest, but the workspace is invalid, we raise an error about it
ResponseError::new(ErrorCode::REQUEST_FAILED, err)
})?;

let mut lenses: Vec<CodeLens> = vec![];

Expand Down
17 changes: 10 additions & 7 deletions tooling/lsp/src/requests/test_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use nargo::{
prepare_package,
};
use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_driver::{check_crate, CompileOptions};
use noirc_driver::{check_crate, CompileOptions, NOIR_ARTIFACT_VERSION_STRING};
use noirc_frontend::hir::FunctionNameMatch;

use crate::{
Expand Down Expand Up @@ -38,12 +38,15 @@ fn on_test_run_request_inner(
let crate_name = params.id.crate_name();
let function_name = params.id.function_name();

let workspace =
resolve_workspace_from_toml(&toml_path, PackageSelection::Selected(crate_name.clone()))
.map_err(|err| {
// If we found a manifest, but the workspace is invalid, we raise an error about it
ResponseError::new(ErrorCode::REQUEST_FAILED, err)
})?;
let workspace = resolve_workspace_from_toml(
&toml_path,
PackageSelection::Selected(crate_name.clone()),
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)
.map_err(|err| {
// If we found a manifest, but the workspace is invalid, we raise an error about it
ResponseError::new(ErrorCode::REQUEST_FAILED, err)
})?;

// Since we filtered on crate name, this should be the only item in the iterator
match workspace.into_iter().next() {
Expand Down
16 changes: 10 additions & 6 deletions tooling/lsp/src/requests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_lsp::{ErrorCode, LanguageClient, ResponseError};
use lsp_types::{LogMessageParams, MessageType};
use nargo::prepare_package;
use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_driver::check_crate;
use noirc_driver::{check_crate, NOIR_ARTIFACT_VERSION_STRING};

use crate::{
get_non_stdlib_asset, get_package_tests_in_crate,
Expand Down Expand Up @@ -40,11 +40,15 @@ fn on_tests_request_inner(
}
};

let workspace =
resolve_workspace_from_toml(&toml_path, PackageSelection::All).map_err(|err| {
// If we found a manifest, but the workspace is invalid, we raise an error about it
ResponseError::new(ErrorCode::REQUEST_FAILED, err)
})?;
let workspace = resolve_workspace_from_toml(
&toml_path,
PackageSelection::All,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)
.map_err(|err| {
// If we found a manifest, but the workspace is invalid, we raise an error about it
ResponseError::new(ErrorCode::REQUEST_FAILED, err)
})?;

let package_tests: Vec<_> = workspace
.into_iter()
Expand Down
2 changes: 2 additions & 0 deletions tooling/nargo/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ impl Dependency {

#[derive(Clone)]
pub struct Package {
// A semver string which specifies the compiler version required to compile this package
pub compiler_required_version: Option<String>,
pub root_dir: PathBuf,
pub package_type: PackageType,
pub entry_path: PathBuf,
Expand Down
10 changes: 8 additions & 2 deletions tooling/nargo_cli/src/cli/check_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use iter_extended::btree_map;
use nargo::{package::Package, prepare_package};
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_abi::{AbiParameter, AbiType, MAIN_RETURN_NAME};
use noirc_driver::{check_crate, compute_function_abi, CompileOptions};
use noirc_driver::{
check_crate, compute_function_abi, CompileOptions, NOIR_ARTIFACT_VERSION_STRING,
};
use noirc_frontend::{
graph::{CrateId, CrateName},
hir::Context,
Expand Down Expand Up @@ -39,7 +41,11 @@ pub(crate) fn run(
let default_selection =
if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll };
let selection = args.package.map_or(default_selection, PackageSelection::Selected);
let workspace = resolve_workspace_from_toml(&toml_path, selection)?;
let workspace = resolve_workspace_from_toml(
&toml_path,
selection,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)?;

for package in &workspace {
check_package(package, &args.compile_options)?;
Expand Down
8 changes: 6 additions & 2 deletions tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use clap::Args;
use nargo::package::Package;
use nargo::workspace::Workspace;
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_driver::CompileOptions;
use noirc_driver::{CompileOptions, NOIR_ARTIFACT_VERSION_STRING};
use noirc_frontend::graph::CrateName;

/// Generates a Solidity verifier smart contract for the program
Expand All @@ -40,7 +40,11 @@ pub(crate) fn run(
let default_selection =
if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll };
let selection = args.package.map_or(default_selection, PackageSelection::Selected);
let workspace = resolve_workspace_from_toml(&toml_path, selection)?;
let workspace = resolve_workspace_from_toml(
&toml_path,
selection,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)?;

let (np_language, opcode_support) = backend.get_backend_info()?;
for package in &workspace {
Expand Down
7 changes: 6 additions & 1 deletion tooling/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ pub(crate) fn run(
let default_selection =
if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll };
let selection = args.package.map_or(default_selection, PackageSelection::Selected);
let workspace = resolve_workspace_from_toml(&toml_path, selection)?;

let workspace = resolve_workspace_from_toml(
&toml_path,
selection,
Some(NOIR_ARTIFACT_VERSION_STRING.to_owned()),
)?;
let circuit_dir = workspace.target_directory_path();

let (binary_packages, contract_packages): (Vec<_>, Vec<_>) = workspace
Expand Down
8 changes: 6 additions & 2 deletions tooling/nargo_cli/src/cli/debug_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use nargo::package::Package;
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_abi::input_parser::{Format, InputValue};
use noirc_abi::InputMap;
use noirc_driver::{CompileOptions, CompiledProgram};
use noirc_driver::{CompileOptions, CompiledProgram, NOIR_ARTIFACT_VERSION_STRING};
use noirc_frontend::graph::CrateName;

use super::compile_cmd::compile_bin_package;
Expand Down Expand Up @@ -41,7 +41,11 @@ pub(crate) fn run(
) -> Result<(), CliError> {
let toml_path = get_package_manifest(&config.program_dir)?;
let selection = args.package.map_or(PackageSelection::DefaultOrAll, PackageSelection::Selected);
let workspace = resolve_workspace_from_toml(&toml_path, selection)?;
let workspace = resolve_workspace_from_toml(
&toml_path,
selection,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)?;
let target_dir = &workspace.target_directory_path();
let (np_language, opcode_support) = backend.get_backend_info()?;

Expand Down
8 changes: 6 additions & 2 deletions tooling/nargo_cli/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use nargo::package::Package;
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_abi::input_parser::{Format, InputValue};
use noirc_abi::InputMap;
use noirc_driver::{CompileOptions, CompiledProgram};
use noirc_driver::{CompileOptions, CompiledProgram, NOIR_ARTIFACT_VERSION_STRING};
use noirc_frontend::graph::CrateName;

use super::compile_cmd::compile_bin_package;
Expand Down Expand Up @@ -48,7 +48,11 @@ pub(crate) fn run(
let default_selection =
if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll };
let selection = args.package.map_or(default_selection, PackageSelection::Selected);
let workspace = resolve_workspace_from_toml(&toml_path, selection)?;
let workspace = resolve_workspace_from_toml(
&toml_path,
selection,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)?;
let target_dir = &workspace.target_directory_path();

let (np_language, opcode_support) = backend.get_backend_info()?;
Expand Down
7 changes: 6 additions & 1 deletion tooling/nargo_cli/src/cli/fmt_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{fs::DirEntry, path::Path};
use clap::Args;
use fm::FileManager;
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_driver::NOIR_ARTIFACT_VERSION_STRING;
use noirc_errors::CustomDiagnostic;
use noirc_frontend::hir::def_map::parse_file;

Expand All @@ -15,7 +16,11 @@ pub(crate) struct FormatCommand {}

pub(crate) fn run(_args: FormatCommand, config: NargoConfig) -> Result<(), CliError> {
let toml_path = get_package_manifest(&config.program_dir)?;
let workspace = resolve_workspace_from_toml(&toml_path, PackageSelection::All)?;
let workspace = resolve_workspace_from_toml(
&toml_path,
PackageSelection::All,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)?;

let config = nargo_fmt::Config::read(&config.program_dir)
.map_err(|err| CliError::Generic(err.to_string()))?;
Expand Down
10 changes: 8 additions & 2 deletions tooling/nargo_cli/src/cli/info_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use clap::Args;
use iter_extended::vecmap;
use nargo::package::Package;
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_driver::{CompileOptions, CompiledContract, CompiledProgram};
use noirc_driver::{
CompileOptions, CompiledContract, CompiledProgram, NOIR_ARTIFACT_VERSION_STRING,
};
use noirc_frontend::graph::CrateName;
use prettytable::{row, table, Row};
use rayon::prelude::*;
Expand Down Expand Up @@ -47,7 +49,11 @@ pub(crate) fn run(
let default_selection =
if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll };
let selection = args.package.map_or(default_selection, PackageSelection::Selected);
let workspace = resolve_workspace_from_toml(&toml_path, selection)?;
let workspace = resolve_workspace_from_toml(
&toml_path,
selection,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)?;

let (binary_packages, contract_packages): (Vec<_>, Vec<_>) = workspace
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_cli/src/cli/init_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub(crate) fn initialize_project(
name = "{package_name}"
type = "{package_type}"
authors = [""]
compiler_version = "{NOIRC_VERSION}"
compiler_version = ">={NOIRC_VERSION}"
[dependencies]"#
);
Expand Down
8 changes: 6 additions & 2 deletions tooling/nargo_cli/src/cli/prove_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use nargo::package::Package;
use nargo::workspace::Workspace;
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_abi::input_parser::Format;
use noirc_driver::{CompileOptions, CompiledProgram};
use noirc_driver::{CompileOptions, CompiledProgram, NOIR_ARTIFACT_VERSION_STRING};
use noirc_frontend::graph::CrateName;

use super::compile_cmd::compile_bin_package;
Expand Down Expand Up @@ -51,7 +51,11 @@ pub(crate) fn run(
let default_selection =
if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll };
let selection = args.package.map_or(default_selection, PackageSelection::Selected);
let workspace = resolve_workspace_from_toml(&toml_path, selection)?;
let workspace = resolve_workspace_from_toml(
&toml_path,
selection,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)?;

let (np_language, opcode_support) = backend.get_backend_info()?;
for package in &workspace {
Expand Down
Loading

0 comments on commit 0e530cf

Please sign in to comment.