Skip to content

Ability to query the set of activated features #15932

@thesayyn

Description

@thesayyn

Problem

We are people interested in making rust support in Bazel better, and one of the requirements is we determine the dependency graph for a given workspace using the information provided by Cargo.

rules_rust implements a whole set of tools to accommodate for these shortcomings https://github.com/bazelbuild/rules_rust/tree/main/crate_universe

Proposed Solution

I am proposing to change cargo to record features in use for all the crates recorded in the lockfile.

[[package]]
name = "clap"
version = "4.5.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eccb054f56cbd38340b380d4a8e69ef1f02f1af43db2f0cc817a4774d80ae071"
dependencies = [
 "clap_builder",
 "clap_derive",
]
features = ["color", "default", "derive", "error-context", "help", "std", "suggestions", "usage", "wrap_help"]

Currently cargo.lock does not record the unified list of features (in use) for all the crates listed in the lockfile.

Listing clap in Cargo.toml

clap = { version = "4.5.37", features = ["derive", "env"] }

Gets recorded in the Cargo.lock as

[[package]]
name = "clap"
version = "4.5.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eccb054f56cbd38340b380d4a8e69ef1f02f1af43db2f0cc817a4774d80ae071"
dependencies = [
 "clap_builder",
 "clap_derive",
]

Currently, the lockfile entry does not record a crucial information about what features are in use by the crate making it not really useful for tools other than cargo itself.

Only place where the information about the features are recorded is target/<cfg>/.fingerprint/clap-<hash>/lib-clap.json, as a workaround we could read this file, due to nature of target folder being VCS ignored forces users to run cargo first whenever they invoke bazel.

Ideally Cargo.lock should be the only source of truth to go from set of dependencies into a full dependency graph.

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-featuresArea: features — conditional compilationA-lockfileArea: Cargo.lock issuesC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-metadataS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions