Skip to content

build-std: explicit dependencies#3875

Open
davidtwco wants to merge 33 commits intorust-lang:masterfrom
davidtwco:build-std-part-three-explicit-dependencies
Open

build-std: explicit dependencies#3875
davidtwco wants to merge 33 commits intorust-lang:masterfrom
davidtwco:build-std-part-three-explicit-dependencies

Conversation

@davidtwco
Copy link
Member

@davidtwco davidtwco commented Oct 31, 2025

Allow users to add explicit dependencies on standard library crates in the Cargo.toml. This enables Cargo to determine which standard library crates are required by the crate graph without build-std-crates being set and for different crates to require different standard library crates.

This RFC is is part of the build-std project goal and a series of build-std RFCs:

  1. build-std context (build-std: context #3873)
  2. build-std="always" (build-std: always #3874)
  3. Explicit standard library dependencies (this RFC)
  4. build-std="compatible" (RFC not opened yet)
  5. build-std="match-profile" (RFC not opened yet)

There is also a Zulip channel where you can ask questions about any of the build-std RFCs. This series of RFCs was drafted over many months with the help of stakeholders from many Rust project teams, we thank them for their help!

There are some details that have been noted as being worth mentioning in any eventual tracking issues:

FCP

Rendered

@davidtwco davidtwco added T-cargo Relevant to the Cargo team, which will review and decide on the RFC. T-crates-io Relevant to the crates.io team, which will review and decide on the RFC. labels Oct 31, 2025
@Turbo87 Turbo87 moved this to For next meeting in crates.io team meetings Oct 31, 2025
@ehuss ehuss moved this from RFC needs review to FCP merge in Cargo status tracker Jan 13, 2026
@epage
Copy link
Contributor

epage commented Jan 20, 2026

@rfcbot fcp concern redundant-no-std

See #3875 (comment)

@Turbo87 Turbo87 moved this from For next meeting to Backlog in crates.io team meetings Jan 23, 2026
@ehuss ehuss moved this from FCP merge to FCP blocked in Cargo status tracker Jan 27, 2026
@epage
Copy link
Contributor

epage commented Feb 6, 2026

@rfcbot fcp resolve redundant-no-std

@ehuss ehuss moved this from FCP blocked to FCP merge in Cargo status tracker Feb 17, 2026
@LawnGnome LawnGnome moved this from Backlog to For next meeting in crates.io team meetings Feb 26, 2026
Comment on lines +1106 to +1114
### Should we support `build-dependencies`?
[unresolved-build-deps]: #should-we-support-build-dependencies

Allowing `builtin` dependencies to be used in `dependencies` and
`dev-dependencies` but not in `build-dependencies` is an inconsistency.

However, supporting `builtin` dependencies in `build-dependencies` would permit
no-std build scripts. It is unclear whether supporting no-std build scripts
would be desirable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should call out that the current behavior is a safe default because to change it is to turn an error case into a success case, making this a two-way door

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned this in 65431fc

Comment on lines +1118 to +1124
### Should `cargo metadata` include the standard library's dependencies?
[unresolved-cargo-metadata]: #should-cargo-metadata-include-the-standard-librarys-dependencies

`cargo metadata` is used by tools like rust-analyzer to determine the entire
crate graph and would benefit from knowledge of the standard library's
dependencies, but this leaks internal details of the standard library and is
counter to the intent behind opaque dependencies.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expand that the main concern for doing this is compatibility but

  • cargo pkgid and cargo build --message-format will unconditionally use the new pkgid spec
  • cargo_metadata does not currently parse the pkgid spec so this won't break all users
  • this will also show up in the source which is still opaque and cargo_metadata does not parse

So this is only a problem for users who are parsing pkgid specs using cargo-util-schemas or their own parser. The scope of that is likely small enough to not be too disruptive.

Copy link

@Skgland Skgland Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crater uses cargo-util-schemas to parse pkgid specs1.

Edit: Though failing to parse std internal dependencies shouldn't be a problem for crater.

Footnotes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this in b30e3f4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. T-cargo Relevant to the Cargo team, which will review and decide on the RFC. T-crates-io Relevant to the crates.io team, which will review and decide on the RFC.

Projects

Status: FCP merge

Development

Successfully merging this pull request may close these issues.