Skip to content

Support --filter-platform=host for cargo metadata #9423

@jonhoo

Description

@jonhoo

Describe the problem you are trying to solve

The cargo metadata command, unlike other cargo commands, defaults to fetching information for dependencies across all target platforms. This in turn means that any tool that calls cargo metadata and doesn't supply --filter-platform ends up downloading a potentially large number of dependencies for targets that other cargo commands wouldn't have fetched. This is usually unintended on the part of the tools that invoke cargo metadata, as they are often fine with just getting the metadata filtered to the current platform.

Unfortunately, the current state of affairs requires users of cargo metadata to determine the host triple to pass to --filter-platform, which usually means invoking rustc -vV and parsing out the host: line if the user hasn't passed in an explicit target tuple (mozilla/cbindgen#676, rust-lang/rust-analyzer#6912, intellij-rust/intellij-rust#7185). That is cumbersome, error-prone, and doesn't pick up things like reconfiguration of rustc through .cargo/config.toml and the like.

Describe the solution you'd like

The cargo metadata --filter-platform flag should support a new value, host, that uses the target triple for the current host platform. Callers can then use that value rather than try to determine that value themselves.

Metadata

Metadata

Assignees

Labels

C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-metadataE-easyExperience: EasyS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions