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: add the ability to specify a default member #1926

Merged
merged 5 commits into from Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 13 additions & 0 deletions crates/nargo/src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ pub struct Workspace {
}

#[derive(Default, Debug, Deserialize, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct WorkspaceConfig {
pub members: Vec<String>,
pub default_member: Option<String>,
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
}

#[allow(dead_code)]
Expand Down Expand Up @@ -107,3 +109,14 @@ fn parse_workspace_toml() {

assert!(Manifest::from_toml_str(src).is_ok());
}

#[test]
fn parse_workspace_default_member_toml() {
let src = r#"
[workspace]
members = ["a", "b"]
default-member = "a"
"#;

assert!(Manifest::from_toml_str(src).is_ok());
}
15 changes: 11 additions & 4 deletions crates/nargo_cli/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,22 @@ pub(crate) fn resolve_root_manifest(
resolve_manifest(&mut context, crate_id, package, pkg_root)?;
}
Manifest::Workspace(workspace) => {
let members = workspace.config.members;
let root = match members.last() {
Some(member) => dir_path.join(member),
let config = workspace.config;
let members = config.members;

let maybe_local = config
.default_member
.or_else(|| members.last().cloned())
.map(|member| dir_path.join(member));

let default_member = match maybe_local {
Some(member) => member,
None => {
return Err(DependencyResolutionError::EmptyWorkspace { path: manifest_path })
}
};

let (entry_path, _crate_type) = super::lib_or_bin(root)?;
let (entry_path, _crate_type) = super::lib_or_bin(default_member)?;
let _local = create_local_crate(&mut context, entry_path, CrateType::Workspace);

for member in members {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
members = ["a"]
default-member = "a"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "1"
y = "2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.8.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn main(x : Field, y : pub Field) {
assert(x != y);
}

#[test]
fn test_main() {
main(1, 2);

// Uncomment to make test fail
// main(1, 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
members = ["a"]
default-member = "a"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "1"
y = "2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.8.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn main(x : Field, y : pub Field) {
assert(x != y);
}

#[test]
fn test_main() {
main(1, 2);

// Uncomment to make test fail
// main(1, 1);
}
5 changes: 4 additions & 1 deletion crates/noirc_frontend/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ impl Context {

// Check the crate type
// We don't panic here to allow users to `evaluate` libraries which will do nothing
if self.crate_graph[*crate_id].crate_type == CrateType::Binary {
if matches!(
self.crate_graph[*crate_id].crate_type,
CrateType::Binary | CrateType::Workspace
) {
// All Binaries should have a main function
local_crate.main_function()
} else {
Expand Down