rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.55k stars 2.38k forks source link

cargo install --dry-run #11123

Open epage opened 1 year ago

epage commented 1 year ago

--dry-run is an important feature for commands with side effects to help

weihanglo commented 1 year ago

This is a feature to pursue. We can make it as an unstable feature behind -Zunstale-options. However, it is not really in a high priority, so label it as S-needs-mentor for now.

PaulDance commented 7 months ago

Just thought about this and it would seem nice indeed. My personal use case would be to be able to detect whether a package needs:

or something along those lines, as long as it has the necessary information, at least these.

Indeed, if I'm not mistaken, the install command currently performs its duties linearly one package at a time if multiple are given. Therefore, when giving a good bunch of them that are already installed, the version check can take quite a bit of time and end up not starting any kind of actual installation if all are already up-to-date for example. As this specific part is mostly IO-bound, then performing it concurrently gives an easy performance boost. The option would thus enable that easily as well.

Although it not high priority for me either, as the buggy version check that I currently have based on cargo search will call cargo install on some packages just for nothing but without any consequence, I would therefore be pleased to at least attempt some things towards implementing this. The mentoring part would definitely be of use to me however, so if you have time in the near future, it would be great.

weihanglo commented 7 months ago

Hey @PaulDance. Thanks for being interested in this.

Thinking backwards from what users want, here is my idea that the initial version of --dry-run could have:

There might be somethings hard to do in the first PR, like programming interface for scripting, or checking if yanked versions will block the installation. That's fine, since we plan to put it behind -Zunstable-options (the process of adding it can be found here). It is benefical for maintainers to review the implementation, if we can break down a feature a into several small PRs. It also increases the chance to merge them sooner.

For the implementation, it might not be as easy as it looks like at first glance. It depends on how acurate we want for cargo install --dry-run. The best option we have is collecting the info after Cargo computing all the necessary build tasks.

If you have any question, find us on Zulip t-cargo or in the office hours. Cheers!

epage commented 7 months ago

@weihanglo I think I'm missing where you are going with talking about Context::compile. Could you clarify the connection?

epage commented 7 months ago

My personal use case would be to be able to detect whether a package needs:

For querying the state (needs install, needs update, updated), we have the data (crates2.json) but we a cargo install --dry-run wouldn't have the programmatic API to access that information except through whatever errors via combinations of existing flags we already provide. Waiting on #4379 for more programmatic output might take a while. I wonder if the better route would be to tie these questions into more general version management in #9527

weihanglo commented 7 months ago

@weihanglo I think I'm missing where you are going with talking about Context::compile. Could you clarify the connection?

To learn where Cargo will install the binaries, we need output infos that are computed in Context::compile.

LuuuXXX commented 6 months ago

claim first, question it later~ @rustbot claim

PaulDance commented 6 months ago

As long as it ends up being implemented with things I care for or that I could add easily, I don't mind, please go ahead. I simply didn't find the time for it yet.

LuuuXXX commented 6 months ago

hi~, If there are any good implementations and plans, I'd love to see them happen.

PaulDance commented 5 months ago

but a cargo install --dry-run wouldn't have the programmatic API to access that information except through whatever errors via combinations of existing flags we already provide.

Wouldn't the standard error stream's content be enough to achieve this for now, even if there wouldn't be any stability guarantee?

Waiting on #4379 for more programmatic output might take a while. I wonder if the better route would be to tie these questions into more general version management in #9527.

These would be better indeed, but as you said, they might take a while. I'm therefore looking for some middle ground that could be easier and quicker to integrate in the meantime.

PaulDance commented 5 months ago

@rustbot claim

epage commented 5 months ago

Was going to comment on #13598 but as this is on more fundamental requirements, posting it here.

We have a couple different points where we can stub out behavior for dry-run

Install is more complete at the cost of more time to perform (and less invasive). The challenge is each user might come to dry-run with different needs. In terms of precedence, we do the full work in cargo publish --dry-run.

epage commented 3 months ago

@PaulDance are you still working on this?

PaulDance commented 3 months ago

Not at the moment, no, sorry. You can probably unassign me from here and close the PR since a full rewrite is required anyway.

Flowrey commented 1 month ago

@rustbot claim