Plumb rustc -Zhint-mostly-unused flag through as a profile option by joshtriplett · Pull Request #15643 · rust-lang/cargo (original) (raw)

The rustc -Zhint-mostly-unused flag tells rustc that most of a crate will go unused. This is useful for speeding up compilation of large dependencies from which you only use a few items. Plumb that option through as a profile option, to allow specifying it for specific dependencies:

[profile.dev.package.huge-mostly-unused-dependency] hint-mostly-unused = true

To enable this feature, pass -Zprofile-hint-mostly-unused. However, since this option is a hint, using it without passing -Zprofile-hint-mostly-unused will only warn and ignore the profile option. Versions of Cargo prior to the introduction of this feature will give an "unused manifest key" warning, but will otherwise function without erroring. This allows using the hint in a crate's Cargo.toml without mandating the use of a newer Cargo to build it.

Add a test verifying that the profile option gets ignored with a warning without passing -Zprofile-hint-mostly-unused, and another test verifying that it gets handled when passing -Zprofile-hint-mostly-unused.

How to test and review this PR?

The tests in the testsuite demonstrate both that the option works as expected and that it gets ignored with a warning if not passing -Zprofile-hint-mostly-unused.

This will remain a draft until rust-lang/rust#135656 gets merged in rustc; once that happens, the "nightly" jobs will pass in CI.