Skip to content

Add [hints] table in Cargo.toml, and a hints.mostly-unused hint #15673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 13, 2025

Conversation

joshtriplett
Copy link
Member

The [hints] table in a Cargo.toml manifest provides optional
information that Cargo can use for building the package, and will use
even when using the package as a dependency. All hints can be safely
ignored, and Cargo only warns about unknown hints, but does not error.
This allows packages to use hints without depending on new Cargo.

Add a mostly-unused hint, which allows a package to hint that most
users of the package will not use most of its items. This is useful for
improving the build performance of crates with large dependencies.

Crates can override this hint using hint-mostly-unused = false in
their profile for a dependency.


In the future, this same mechanism could be used for other hints, such as
min-opt-level.

How to test and review this PR?

This PR is built atop #15643 . I'd
suggest reviewing that PR separately, then just reviewing the new commits in
this PR.

The new "hints" testsuite module demonstrates the expected behavior of hints.

Like #15643 , the nightly-only tests
will only pass once rust-lang/rust#135656 has been
merged into Rust.

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues A-profiles Area: profiles A-unstable Area: nightly unstable support labels Jun 16, 2025
@jeffparsons
Copy link

Sorry if this is the wrong place for this, but I'd love to see how this affects a simple binary using the aws-sdk-ec2 crate. I think if it is able to shave much time / memory consumption off those "worst offenders" then that would make a pretty compelling case for its value.

@joshtriplett
Copy link
Member Author

Note: should add a test for [hints] parsing to robustly handle a key it knows but syntax it doesn't know (because it might be future syntax).

@joshtriplett
Copy link
Member Author

joshtriplett commented Jun 17, 2025

Sorry if this is the wrong place for this, but I'd love to see how this affects a simple binary using the aws-sdk-ec2 crate. I think if it is able to shave much time / memory consumption off those "worst offenders" then that would make a pretty compelling case for its value.

For a crate depending on aws-sdk-ec2, a release build went from 4m07s to 2m04s, and a non-release build went from 2m26s to 1m28s.

@epage epage added the T-cargo Team: Cargo label Jun 17, 2025
@joshtriplett joshtriplett force-pushed the hints branch 5 times, most recently from 02f4153 to 9812504 Compare June 18, 2025 07:01
Copy link
Contributor

@epage epage left a comment

Choose a reason for hiding this comment

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

Just waiting on #15643

@epage
Copy link
Contributor

epage commented Jun 18, 2025

@rfcbot fcp merge

This insta-stabilizes a new [hints] table to Cargo.toml that affects building this as a dependency. As these are just hints, there are no guarantees about what will actually be done, including us removing the table completely. As such, unstable fields do not error and wrongly-shaped fields do not error.

While this is blocked on rustc, I figured we could run our FCP in parallel.

@rfcbot
Copy link
Collaborator

rfcbot commented Jun 18, 2025

Team member @epage has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

Comment on lines +1653 to +1657
#[cfg_attr(
feature = "unstable-schema",
schemars(with = "Option<TomlValueWrapper>")
)]
pub mostly_unused: Option<toml::Value>,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you could do schemars(with = "Option<bool>") to communicate the effective schema even if the types take the long way around to get to it

Copy link
Member Author

@joshtriplett joshtriplett Jul 12, 2025

Choose a reason for hiding this comment

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

If I do that, the schema then says it takes a boolean or null, and I think that's incorrect; anyone relying on that schema would become fragile and potentially break if we introduce new possible values for this field. I think the schema should say that it takes a TomlValue or null.

The schema shouldn't encourage people to be brittle, when cargo is going out of its way to be permissive and allow for future evolution without it being a breaking change.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think its dependent on how the schema is being used, whether its prescriptively match our compatibility guarantees or to describe the behavior at this time. For example, some editors support reading these schemas and applying completions off of it.

I lean towards the latter but not going to push it. We can always adjust later.

Copy link
Member Author

Choose a reason for hiding this comment

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

@epage I really don't know how the schemas are intended to be used. I don't object to this change, I just don't know how we expect people to handle compatibility with anything that gets generated based on this.

@epage
Copy link
Contributor

epage commented Jul 12, 2025

Sorry for the last minute finds

@epage epage added this pull request to the merge queue Jul 13, 2025
Merged via the queue into rust-lang:master with commit 6833aa7 Jul 13, 2025
26 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 13, 2025
@joshtriplett joshtriplett deleted the hints branch July 13, 2025 03:29
bors added a commit to rust-lang/rust that referenced this pull request Jul 16, 2025
Update cargo

1 commits in eabb4cd923deb73e714f7ad3f5234d68ca284dbe..6833aa715d724437dc1247d0166afe314ab6854e
2025-07-09 22:07:55 +0000 to 2025-07-13 02:25:52 +0000
- Add `[hints]` table in `Cargo.toml`, and a `hints.mostly-unused` hint (rust-lang/cargo#15673)
@rustbot rustbot added this to the 1.90.0 milestone Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues A-profiles Area: profiles A-registries Area: registries A-unstable Area: nightly unstable support disposition-merge FCP with intent to merge finished-final-comment-period FCP complete T-cargo Team: Cargo to-announce
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

8 participants