Debate: cargo install (ala npm install) for fresh project clone

It is a question / proposal / discussion. I am looking for alternatives to initialize (install / make available) tools required for a development and management of a rust project, without actually installing them manually :slight_smile:

Let’s say there is a Rust source code based project in a repository. As any other Rust based project, it would require rustup and cargo binaries available on the development machine. These are expected to be installed by every rust developer.

Next this project opts into using various 3rd party tools, which are installed by cargo install. Examples of this could be outdated or cargo-make, etc… Next the project can have automated aliases to invoke typical commands, like it is described here.

As a result we have got a project, which supports natively via cargo or via 3rd party tools, workflows like:

cargo build
cargo test
cargo check-updates
cargo release
cargo review
cargo approve
# and so on, depending on what a project might require to have

Now the problem is: when a fresh clone (or pull) of a project is done with newly required dependencies to 3rd party tools, it is expected that all developers stay in sync and install these tools manually. And here could be variations with versions being installed and so on.

Ideally, I would like the project to declare dependencies to the required tools and versions, like NPM does. It requires dependencies declared in dev dependencies section of package.json and requires running npm install to keep things in sync after clone or pull.

I understand this is not currently possible with cargo and cargo.toml.? However, if it was possible, I would not like to run cargo install (analogy of npm install) after every clone or pull. I would prefer cargo to figure out what and if tools need to be installed based on tool dependencies declaration, current state of my system / workspace / project and command being invoked.

So, what are the options available? Where is rust heading in relation to this?


I think you can have this behavior using a customized script (with build dependencies). It is not exactly as simple as npm but it should work.

Could you please point out to an example where it is done using the method you suggested?

I don’t have exact examples but I believe something similar to the examples in the doc should be enough.

Sorry, do not see how I could use this to install cargo extensions to enable commands before they are invoked…

1 Like

As an aside; I think readers here will misunderstand you when you mention cargo install, because that’s already a thing, and it has a significantly different purpose than what npm install is used for.

I do feel your pain. There’s currently no nice way to have per-project custom cargo commands that are built and run automatically. Even keeping global commands up to date is basically not implemented.

Cargo doesn’t support post-build steps and anything that is not strictly build-related. is totally inadequate for project-wide operations and built products.

Maybe it could be enough to have cargo commands in build dependencies?

cargo-some-command = "*"

Then if you run cargo some-command, cargo would also check current project’s Cargo.toml and build and install it locally (./target/bin or such), if necessary.

1 Like

Does it require a ticket?

I have submitted ticket