Skip to content

Optional and unused dependencies that are renamed are pulled #2263

@pamaury

Description

@pamaury

Whenever a crate specified in Cargo.toml specifies an optional dependency that is not used but whose name does not match the original name of the crate, rules_rust still generates a dependency on that crate due to an alias. This can cause rules_rust to pull many unneeded dependencies. One such example is serde_with with indexmap:

indexmap_1 = {package = "indexmap", version = "1.8", optional = true, default-features = false, features = ["serde-1"]}

Even though serde_with does not require this dependency by default, it is still used in the generated BUILD file in aliases (not in the deps):

rust_library(
    name = "serde_with",
    srcs = glob(["**/*.rs"]),
    aliases = {
        "@crate_index__indexmap-1.9.3//:indexmap": "indexmap_1",
    },
   ...
)

I have a minimal reproduction of the problem here using rules_rust 0.30.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions