Report crate size in cargo publish
#11251
Labels
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Command-publish
Problem
npm publish
creates output like this:This output includes some metrics about the package, notably:
Information about the size of the package is useful for package maintainers. Having it displayed at publish time gives maintainers a simple way to periodically audit the size of their published packages.
There is (to my knowledge) currently no tool included in
cargo
that will produce this kind of information.cargo package
only produces a normalcargo build
compilation log; the package is then available undertarget/package/package-name-1.0.0.crate
but this is not obvious and the size is only visible by explicitly seeking it out.cargo package --list
is useful but only outputs the names of the included files, meaning maintainers would still have to build custom logic to get the corresponding sizes and add them together.Many Rust repositories contain additional content (test harnesses and data, CI/CD config, example code, READMEs and other non-
rustdoc
documentation, etc.) that is not useful when crates are added as dependencies. It's possible to add them to theexclude
list in the crate'sCargo.toml
if a maintainer is aware of this mechanic and remembers to do so, but there's currently nothing nudging maintainers towards it.Small crates help everyone, improving the speed of downloading dependencies (especially for users with poor internet connections), and reducing the bandwidth/storage requirements of crates.io and other related infrastructure.
Proposed Solution
Adding an additional package size summary to
cargo package
andcargo publish
would be a great step in pushing package maintainers to be mindful of the size of their packages and make proper use of theexclude
list.The number of files, uncompressed size, and compressed size could easily fit on a single summary line, decorated with a bold green
Packaged
prefix to match the general style ofcargo
output. A simple mockup forcargo publish
:The
cargo package
output would be similar, just differing by the missingUploading
line as it already does today:Notes
Related work
#9058 proposes a warning when large files are included into the package. It makes sense, but requires some agreement on what should be considered "too large". Displaying the total size of the package will at least put package sizes onto maintainers' radars, allowing them to be mindful of it and craft their
exclude
list accordingly to their own standards of "too large."The text was updated successfully, but these errors were encountered: