bin+lib cargo-wizard

Cargo subcommand for applying Cargo profile templates

4 releases

0.2.2 Mar 11, 2024
0.2.1 Mar 10, 2024
0.2.0 Mar 8, 2024
0.1.0 Mar 3, 2024

#170 in Cargo plugins

Download history 65/week @ 2024-07-19 36/week @ 2024-07-26 27/week @ 2024-08-02 17/week @ 2024-08-09 14/week @ 2024-08-16 25/week @ 2024-08-23 27/week @ 2024-08-30 31/week @ 2024-09-06 17/week @ 2024-09-13 44/week @ 2024-09-20 34/week @ 2024-09-27 44/week @ 2024-10-04 37/week @ 2024-10-11 31/week @ 2024-10-18 21/week @ 2024-10-25 39/week @ 2024-11-01

132 downloads per month

MIT license

90KB
2.5K SLoC

cargo-wizard Build Status Latest Version

Cargo subcommand that applies profile and config templates to your Cargo project to configure it for maximum performance, fast compile times or minimal binary size.

Demo of cargo-wizard

Motivation

I often see Rust users asking online about how can they best configure Cargo get e.g. the fastest compilation times, best runtime performance or minimal binary size. While this information can be found in various books, repositories or blog posts, it is annoying to hunt for it everytime we want to configure a new Cargo project.

This tool tries to automate that process to make it easier.

Installation

$ cargo install cargo-wizard

Usage

  • Interactive mode (CLI dialog that guides you through the process):
    $ cargo wizard
    
  • Non-interactive mode (directly apply a predefined template to your Cargo workspace):
    $ cargo wizard apply <template> <profile>
    # For example, apply `fast-runtime` template to the `dist` profile
    $ cargo wizard apply fast-runtime dist
    

You can enable additional configuration options that require a nightly compiler by running cargo-wizard with a nightly Cargo (e.g. cargo +nightly wizard) or by using the --nightly flag.

Note that you should be executing cargo wizard inside a directory that is a part of a Cargo workspace. It will then apply the configuration options to that workspace.

Features

cargo-wizard can create or modify Cargo profiles in your Cargo.toml manifest and RUSTFLAGS in the .cargo/config.toml file) based on a set of predefined templates:

  • fast-compile - minimizes compilation times
  • fast-runtime - maximizes runtime performance
    • Enables LTO and other settings designed to maximize runtime performance.
  • min-size - minimizes binary size
    • Similar to fast-runtime, but uses optimization flags designed for small binary size.

You can also modify these templates in the interactive mode to build your own custom template.

Caveats

  • The configuration applied by this tool is quite opinionated and might not fit all use-cases perfectly. cargo-wizard mostly serves to improve discoverability of possible Cargo profile and config options, to help you find the ideal settings for your use-cases.
  • cargo-wizard currently only modifies Cargo.toml and config.toml. There are other things that can be configured to achieve e.g. even smaller binaries, but these are out of scope for this tool, at least at the moment.
  • cargo-wizard currently ignores Cargo settings that are not relevant to performance.
  • Cargo config (config.toml) changes are applied to the global build.hostflags setting, because per-profile RUSTFLAGS are still unstable.

Inspiration

Why wizard? The name is inspired by GUI wizards that guide you through some process using a series of dialogs.

Contributing

Contributions are welcome :)

Possible future features:

  • Allow configuring the memory allocator.
  • Load/store templates on disk to make them easier to share

Acknowledgements

  • toml_edit: awesome crate that can modify TOML files while keeping their original formatting.
  • inquire: pretty slick crate for building interactive TUI dialogs and prompts.

License

MIT

Dependencies

~8–19MB
~275K SLoC