{"id":26776165,"url":"https://github.com/dustinblackman/cargo-run-bin","last_synced_at":"2025-05-15T11:02:28.169Z","repository":{"id":57538339,"uuid":"370186241","full_name":"dustinblackman/cargo-run-bin","owner":"dustinblackman","description":"Build, cache, and run CLI tools scoped in Cargo.toml rather than installing globally. Stop the version drifts across your team, keep it all in sync within your project!","archived":false,"fork":false,"pushed_at":"2025-03-25T00:34:20.000Z","size":330,"stargazers_count":211,"open_issues_count":6,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T04:01:37.408Z","etag":null,"topics":["cache","cargo","cli","developer-tools","rust"],"latest_commit_sha":null,"homepage":"https://dustinblackman.com/posts/why-does-everyone-install-crates-globally/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dustinblackman.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-24T00:31:43.000Z","updated_at":"2025-04-03T03:44:22.000Z","dependencies_parsed_at":"2023-02-08T18:45:16.352Z","dependency_job_id":"18c198bd-7cb1-43c6-86b7-fddc42a4f442","html_url":"https://github.com/dustinblackman/cargo-run-bin","commit_stats":{"total_commits":30,"total_committers":2,"mean_commits":15.0,"dds":"0.033333333333333326","last_synced_commit":"2e0c46d4d5ae8e51d3e2d2ec4ea51b50e5ada7c8"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dustinblackman%2Fcargo-run-bin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dustinblackman%2Fcargo-run-bin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dustinblackman%2Fcargo-run-bin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dustinblackman%2Fcargo-run-bin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dustinblackman","download_url":"https://codeload.github.com/dustinblackman/cargo-run-bin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248530568,"owners_count":21119597,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","cargo","cli","developer-tools","rust"],"created_at":"2025-03-29T03:34:09.819Z","updated_at":"2025-04-12T07:02:07.213Z","avatar_url":"https://github.com/dustinblackman.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=center\u003ecargo-run-bin\u003c/h1\u003e\n\n![cargo-run-bin](.github/banner.png)\n\n[![Build status](https://github.com/dustinblackman/cargo-run-bin/workflows/ci/badge.svg)](https://github.com/dustinblackman/cargo-run-bin/actions)\n[![Coverage Status](https://coveralls.io/repos/github/dustinblackman/cargo-run-bin/badge.svg?branch=master)](https://coveralls.io/github/dustinblackman/cargo-run-bin?branch=master)\n[![Crates.io](https://img.shields.io/crates/v/cargo-run-bin.svg)](https://crates.io/crates/cargo-run-bin)\n\n\u003e Build, cache, and run CLI tools scoped in `Cargo.toml` rather than installing globally. Stop the version drifts across your team, keep it all in sync within your project!\n\n- [Overview](#overview)\n- [Install](#install)\n- [Usage](#usage)\n  - [cargo bin CRATE](#cargo-bin-crate)\n  - [cargo bin --sync-aliases](#cargo-bin---sync-aliases)\n  - [cargo bin --install](#cargo-bin---install)\n  - [Library](#library)\n- [License](#license)\n\n## Overview\n\nInstalling 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`](https://docs.npmjs.com/cli/v7/commands/npm-run-script) and [`gomodrun`](https://github.com/dustinblackman/gomodrun), and allows your teams to always be running the same tooling versions.\n\nFor 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!\n\n## Install\n\nMinimum Rust Version: 1.70.0\n\nThere are a few different ways you can install `cargo-run-bin`. I'd recommend giving each a read, and picking the best that suits you!\n\n### Global Install\n\nRun the following to install `cargo-run-bin`, and ignore the cache directory in your project.\n\n```sh\ncargo install cargo-run-bin\ncd my/rust/project\necho \".bin/\" \u003e\u003e .gitignore\n```\n\n### Using wrapper\n\nInstalling with a minimal wrapper and an alias in your project. This gives you the best onboarding experiance in to your project for you and your team as it does not require any global installs! Git pull, and you're ready to consume all your CLI tools!\n\nThese instructions assume you'd like to place the wrapper in `tools/cargo-bin` within your project. Change it to fit your needs!\n\n```sh\ncd my/rust/project\necho \".bin/\" \u003e\u003e .gitignore\ncargo new --vcs none --bin tools/cargo-bin\ncurl --output tools/cargo-bin/src/main.rs https://raw.githubusercontent.com/dustinblackman/cargo-run-bin/refs/tags/v1.7.4/src/main.rs\ncd tools/cargo-bin\ncargo add --features cli cargo-run-bin\n```\n\nEnsure the tool binary is added to the workspace within `Cargo.toml`.\n\n```toml\n[workspace]\nmembers = [\"tools/cargo-bin\"]\n```\n\nNow add an alias in `.cargo/config.toml`. If the file doesn't exist yet, then this will be the first entry!\n\n```toml\n[alias]\nbin = [\"run\", \"--package\", \"cargo-bin\", \"--\"]\n```\n\nDone! Now it can be used as if installed globally.\n\n```sh\ncargo bin --version\n```\n\n### As a library\n\nYou can also use it as a library within your existing logic.\n\n```toml\n[dependencies]\ncargo-run-bin = { version = \"1.7.4\", default-features = false }\n```\n\n### Distro packages\n\n\u003cdetails\u003e\n  \u003csummary\u003ePackaging status\u003c/summary\u003e\n\n[![Packaging status](https://repology.org/badge/vertical-allrepos/cargo-run-bin.svg)](https://repology.org/project/cargo-run-bin/versions)\n\n\u003c/details\u003e\n\nIf your distribution has packaged `cargo-run-bin`, you can use that package for the installation.\n\n### Arch Linux\n\nYou can use [pacman](https://wiki.archlinux.org/title/Pacman) to install from the [extra repository](https://archlinux.org/packages/extra/x86_64/cargo-run-bin/):\n\n```sh\npacman -S cargo-run-bin\n```\n\n### Alpine Linux\n\n`cargo-run-bin` is available for [Alpine Edge](https://pkgs.alpinelinux.org/packages?name=cargo-run-bin\u0026branch=edge). It can be installed via [apk](https://wiki.alpinelinux.org/wiki/Alpine_Package_Keeper) after enabling the [testing repository](https://wiki.alpinelinux.org/wiki/Repositories).\n\n```sh\napk add cargo-run-bin\n```\n\n## Usage\n\n`cargo-run-bin` keeps track of the binaries and their versions from within `Cargo.toml` under the `[package.metadata.bin]`.\ntable. A quick example taken from this repo:\n\n```toml\n[package.metadata.bin]\ncargo-binstall = { version = \"1.1.2\" }\ncargo-nextest = { version = \"0.9.57\", locked = true }\ndprint = { version = \"0.30.3\" }\ncargo-mobile2 = { version = \"0.5.2\", bins = [\"cargo-android\", \"cargo-mobile\"], locked = true }\n```\n\nOr if you're setting up in a workspace:\n\n```toml\n[workspace.metadata.bin]\ncargo-binstall = { version = \"1.1.2\" }\ncargo-nextest = { version = \"0.9.57\", locked = true }\n```\n\n| Parameter        | Type          | Required | Description                                                                                                                                                                                                                                                               |\n| ---------------- | ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| version          | `String`      | true     | Specifies the version of the crate. It is not treated as a caret requirement automatically. Corresponds to the `cargo install` [`--version`](https://doc.rust-lang.org/cargo/commands/cargo-install.html#install-options) argument.                                       |\n| bins             | `Vec\u003cString\u003e` | false    | An array of binaries that the crate contains that you wish to build. These can be found in a crates `Cargo.toml` file. See [`cargo-mobile2`](https://github.com/tauri-apps/cargo-mobile2/blob/a5f3783870f48886e3266e43f92a6768fb1eb3d4/Cargo.toml#L18-L28) as an example. |\n| locked           | `Boolean`     | false    | A parameter when set to `true` runs `cargo install` with the [`--locked`](https://doc.rust-lang.org/cargo/commands/cargo-install.html#dealing-with-the-lockfile) parameter.                                                                                               |\n| features         | `Vec\u003cString\u003e` | false    | An array of crate features to enable.                                                                                                                                                                                                                                     |\n| default-features | `Boolean`     | false    | When set to `false`, disables all default features.                                                                                                                                                                                                                       |\n| git              | String        | false    | A git URL to install from rather than from crates.io. This will also be used by Binstall to look up Cargo manifist if Binstall is available.                                                                                                                              |\n| branch           | String        | false    | A git branch to install from when `git` is set. This takes priority over `tag` and `rev`                                                                                                                                                                                  |\n| tag              | String        | false    | A git tag to install from when `git` is set. `branch` will take priority if set, and takes priority over `rev`.                                                                                                                                                           |\n| rev              | String        | false    | A git revision to install from when `git` is set. `branch` and `tag` will take priority if set.                                                                                                                                                                           |\n| path             | String        | false    | The path to a local crate to install.                                                                                                                                                                                                                                     |\n\nIf you're a fan of prebuilt binaries and fast downloads, run-bin will use [`cargo-binstall`](https://github.com/cargo-bins/cargo-binstall) if it's installed globally, or configured within `[package.metadata.bin]`, rather than building tools from source.\n\n### `cargo bin CRATE`\n\nTaking an example of `dprint`, running `cargo bin dprint --help` with install/build and cache the dprint binary with the\nspecified version in `Cargo.toml`. All future executions will run instantly without an install step, and dprint can be used\nas you wish!\n\n### `cargo bin --sync-aliases`\n\nWith the power of [cargo aliases](https://doc.rust-lang.org/cargo/reference/config.html#alias), `cargo bin --sync-aliases`\nwill create aliases for any `cargo-*` crate, allowing you to execute commands such `cargo nextest run` that will use\n`cargo bin` under the hood. Check out some of the example from [this repo](.cargo/config.toml).\n\n### `cargo bin --install`\n\nWhen pulling down a new repo, or adding a step to CI, `cargo bin --install` will install or build all binaries that have not been\ncached which are configured in `Cargo.toml`.\n\n### Library\n\n`run-bin` can also be used as a library and paired nicely with your `build.rs` or any other scripts. The following\nexample demos having `dprint` configured within `[package.metadata.bin]`, and executing `dprint --help`.\n\n```toml\n[package.metadata.bin]\ndprint = { version = \"0.40.2\" }\n```\n\n```rust\nuse anyhow::Result;\nuse cargo_run_bin::{binary, metadata};\n\nfn main() -\u003e Result\u003c()\u003e {\n    let binary_package = metadata::get_binary_packages()?\n        .iter()\n        .find(|e| e.package == \"dprint\")\n        .unwrap()\n        .to_owned();\n    let bin_path = binary::install(binary_package)?;\n    binary::run(bin_path, vec![\"--help\".to_string()])?;\n\n    return Ok(());\n}\n```\n\nUsing `binary::run` is optional. You can recreate it and make changes to your liking using `std::process`, with shims included!\n\n```rust\nuse std::process;\n\nuse anyhow::Result;\nuse cargo_run_bin::{binary, metadata, shims};\n\nfn main() -\u003e Result\u003c()\u003e {\n    let binary_package = metadata::get_binary_packages()?\n        .iter()\n        .find(|e| e.package == \"dprint\")\n        .unwrap()\n        .to_owned();\n    let bin_path = binary::install(binary_package)?;\n\n    let mut shell_paths = shims::get_shim_paths()?;\n    shell_paths.push(env::var(\"PATH\").unwrap_or(\"\".to_string()));\n\n    process::Command::new(bin_path)\n        .args([\"--help\"])\n        .env(\"PATH\", shell_paths.join(\":\"))\n        .spawn();\n\n    return Ok(());\n}\n```\n\n## [License](./LICENSE)\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdustinblackman%2Fcargo-run-bin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdustinblackman%2Fcargo-run-bin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdustinblackman%2Fcargo-run-bin/lists"}