cargo-size
Tool to check and compare binary sizes of Rust projects. Interact with Cargo APIs to analyze and track binary size changes over time.
Features
- Size Analysis: Check binary sizes for individual packages or entire workspaces
- Comparison: Compare sizes between different packages, builds, or versions
- History Tracking: View size history and trends over time
- Multiple Output Formats: Table, JSON, and CSV output formats
- Build Type Support: Analyze both debug and release builds
- Cross-Platform: Support for different target architectures
Installation
Or build from source:
Usage
Check Package Size
Check the size of a specific package or all packages in the workspace:
# Check current package size (debug build)
# Check specific package
# Check release build
# Check with specific target
Compare Package Sizes
Compare sizes between different packages or builds:
# Compare two packages
# Compare with specific baseline
# Compare release builds
View Size History
Track size changes over time:
# View size history for current package
# View history for specific package
# Limit history entries
Output Formats
Choose from different output formats:
# Table format (default)
# JSON format
# CSV format
Examples
Basic Size Check
Size Comparison
JSON Output
[
{
}
Command Reference
Global Options
--output-format <FORMAT>: Output format (table, json, csv)
Subcommands
check
Check the size of packages.
--package <NAME>: Package name to check--manifest-path <PATH>: Path to Cargo.toml--release: Check release build instead of debug--target <TRIPLE>: Target triple to build for
compare
Compare sizes between packages or builds.
--packages <NAMES>...: Package names to compare--manifest-path <PATH>: Path to Cargo.toml--release: Compare release builds--target <TRIPLE>: Target triple to build for--baseline <NAME>: Use specific package as baseline
history
Show size history for a package.
--package <NAME>: Package name to check history for--manifest-path <PATH>: Path to Cargo.toml--target <TRIPLE>: Target triple to build for--limit <NUMBER>: Limit number of history entries (default: 10)
Integration with CI/CD
You can integrate cargo-size into your CI/CD pipeline to track binary size changes:
# GitHub Actions example
- name: Check binary size
run: |
cargo size check --release --output-format json > size-report.json
# Compare with baseline or fail if size increase is too large
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Setup
- Clone the repository
- Install dependencies:
cargo build - Run tests:
cargo test - Run the tool:
cargo run -- check
License
This project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgments
Inspired by the webbrowser crate's approach to consistent behavior across platforms and comprehensive documentation.