Build, cache, and run binaries scoped in
Cargo.toml
rather than installing globally.
Installing tooling globally when working in teams or on CI is a silly problem to manage. cargo-run-bin
builds, caches, and executes binaries from their locked down versions in Cargo.toml
. This acts similarly to npm run
and gomodrun
, and allows your teams to always be running the same tooling versions.
For command lines that extend cargo such as cargo-nextest
, run-bin will create and manage cargo aliases to allow using cargo extensions without any changes to your command line scripts! cargo-run-bin
gets out of your way, and you'll forget you're even using it!
Run the following to install cargo-run-bin
, and ignore the cache directory in your project.
sh
cargo install cargo-run-bin
cd my/rust/project
echo ".bin/" >> .gitignore
cargo-run-bin
keeps track of the binaries and their versions from within Cargo.toml
under the package.metadata.bin
table. A quick example taken from this repo:
toml
[package.metadata.bin]
cargo-nextest = { version = "0.9.57", locked = true }
dprint = { version = "0.30.3" }
tauri-mobile = { version = "0.5.2", bins = ["cargo-android", "cargo-mobile"], locked = true }
version
specifies the version of the crate.bins
(optional) is an array of binaries that the crate contains that you wish to build. These can be found in a crates
Cargo.toml
file. See tauri-mobile
as an example.locked
(optional) is a parameter when set to true
runs cargo install
with --locked
parameter.cargo bin CRATE
Taking an example of dprint
, running cargo bin dprint --help
with build and cache the dprint binary with the
specified version in Cargo.toml
. All future executions will run instantly without a build step, and dprint can be used
as you wish!
cargo bin --sync-aliases
With the power of cargo aliases, cargo bin --sync-aliases
will create aliases for any cargo-*
crate, allowing you to execute commands such cargo nextest run
that will use
cargo bin
under the hood. Check out some of the example from this repo.
cargo bin --build
When pulling down a new repo, or adding a step to CI, cargo bin --build
will build all binaries that have not been
cached which are configured in Cargo.toml
.
MIT.