Skip to content

support feature gated package metadata #14770

Open
@nfejzic

Description

@nfejzic

Problem

Hello everyone! Sorry if similar issue already exists, I could not find something like this.

While discussing the MSRV in tqwewe/kameo#76, we figured out that the currently MSRV could be lower, but a certain non-default feature requires the higher version.

Would it be possible for cargo to support package metadata that is feature gated? For example, rust-version is set to 1.65 per default, but if feature feat-a is enabled, that sets the rust-version to 1.75.

Proposed Solution

Syntax for dependencies already exists, as described in the Cargo book:

[dependencies]
ravif = { version = "0.6.3", optional = true }
rgb = { version = "0.8.25", optional = true }

[features]
avif = ["dep:ravif", "dep:rgb"]

Maybe similar syntax can be used for other tables:

[features]
avif = ["package:rust-version=1.75", "dep:ravif", "dep:rgb"]

Alternatively, we could extend features to support (inline) tables:

# inline tables
[features]
avif = { dependencies = ["ravif", "rgb"], package = { rust-version = "1.75" } }

# or regular tables:
[features.avif]
dependencies = ["ravif", "rgb"]
# override top-level [package] section:
package = { rust-version = "1.75" }

# maybe even with subtables:
[features.avif.dependencies]
ravif = "x.x.x" # override [dependencies] table to use specific version
rgb = true # or enable optional dependency from [dependencies] table

[features.avif.package]
# override [package] table fields
rust-version = "1.75"

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-featuresArea: features — conditional compilationA-manifestArea: Cargo.toml issuesC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions