Skip to content

Transitive dependencies are considered when using Cargo.lock #15

@Calsign

Description

@Calsign

As part of properly supporting Cargo.lock (# gazelle:rust_cargo_lockfile Cargo.lock) from cargo in #14, the logic for extracting the list of dependencies from Cargo.lock changed to include all packages, including transitive dependencies:

for pkg in lockfile.packages {
if !is_workspace_target(pkg.name.as_str()) {
let mut package = Package::default();
package.name = pkg.name.as_str().to_string();
package.crate_name = package.name.replace('-', "_");
package.proc_macro = pkg
.dependencies
.iter()
.any(|dep| is_proc_macro_dep(dep.name.as_str()));
crates.push(package);
}
}

This causes two issues when using gazelle:rust_cargo_lockfile:

  • unused dependency reporting (only enabled if a patch to gazelle is applied) incorrectly lists all transitive dependencies as unused
  • if user code newly depends on a crate which is not listed as a top-level dependency but is a transitive dependency, gazelle will incorrectly add a dependency on the non-existent target for that crate which will break the build

Options for trying to fix this include:

  • Using direct-cargo-bazel-deps when it exists
  • Determining the set up workspace crates and only adding their dependencies to the list
  • Parsing Cargo.toml to determine the set of top-level dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions