Skip to content

Commit

Permalink
Merge pull request #46 from Waridley/root_workspace_deps
Browse files Browse the repository at this point in the history
Support workspace dependencies in the root crate of a workspace
  • Loading branch information
bkchr committed Jan 17, 2024
2 parents c9671b5 + 15534c7 commit dc71186
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ fn read_cargo_toml(

let workspace_dependencies = if manifest_path != workspace_manifest_path {
let workspace_manifest = open_cargo_toml(workspace_manifest_path)?;
extract_workspace_dependencies(workspace_manifest)?
extract_workspace_dependencies(&workspace_manifest)?
} else {
Default::default()
extract_workspace_dependencies(&manifest)?
};

let crate_names = extract_crate_names(&manifest, workspace_dependencies)?;
Expand All @@ -289,7 +289,7 @@ fn read_cargo_toml(
/// Returns a hash map that maps from dep name to the package name. Dep name
/// and package name can be the same if there doesn't exist any rename.
fn extract_workspace_dependencies(
workspace_toml: Document,
workspace_toml: &Document,
) -> Result<BTreeMap<String, String>, Error> {
Ok(workspace_dep_tables(&workspace_toml)
.into_iter()
Expand Down Expand Up @@ -400,7 +400,7 @@ mod tests {
let workspace_cargo_toml = $workspace_toml.parse::<Document>()
.expect("Parses workspace `Cargo.toml`");

let workspace_deps = extract_workspace_dependencies(workspace_cargo_toml)
let workspace_deps = extract_workspace_dependencies(&workspace_cargo_toml)
.expect("Extracts workspace dependencies");

match extract_crate_names(&cargo_toml, workspace_deps)
Expand Down Expand Up @@ -539,17 +539,4 @@ mod tests {
"#,
Ok(Some(FoundCrate::Name(name))) if name == "my_crate_cool"
}

create_test! {
workspace_deps_twice_renamed,
r#"
[dependencies]
my_crate_cool_renamed = { package = "my-crate-cool", workspace = true }
"#,
r#"
[workspace.dependencies]
my-crate-cool = { package = "my_crate" }
"#,
Ok(Some(FoundCrate::Name(name))) if name == "my_crate_cool_renamed"
}
}
8 changes: 8 additions & 0 deletions tests/workspace_deps/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[package]
name = "test-workspace-root-crate"
version = "0.1.0"
edition = "2021"

[workspace]
members = ["my-cool-dep", "test-crate"]
resolver = "2"
Expand All @@ -6,3 +11,6 @@ resolver = "2"
[workspace.dependencies]
my-cool-dep = { package = "my-cool-dep-real-name", path = "my-cool-dep" }
proc-macro-crate = { path = "../.." }

[dependencies]
my-cool-dep = { workspace = true }
3 changes: 3 additions & 0 deletions tests/workspace_deps/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn use_it() {
my_cool_dep::do_something!()
}

0 comments on commit dc71186

Please sign in to comment.