Cargo... Recompiling over and over


I am having a separate problem persuading cargo to do its thing and that is not my problem.

What is my problem is on each iteration when I run cargo... after making some change all the same packages are recompiled again. The same versions, the same rust compiler.

Is there some way that I can tell cargo to reuse what it compiled twenty minutes ago and not do it all again, every time?

Specific example:

I run cargo install cargo-generate, have a problem, some helpful recent comment on SO encourages me to run cargo install cargo-generate --locked cargo. The following is done both times:

   Compiling clap v2.33.3
   Compiling tar v0.4.30 
   Compiling cc v1.0.59  

Why? I am on a difficult part of the learning curve (been away from rust awhile... things have changed!) so I do not know what half the "magic incantations" mean.

But I cannot see why the same things need to be compiled over and over.

Unfortunately, cargo has only per-project/per-directory caches, and doesn't have any shared per-user/per-machine/net-wide caches. Every instance of a Cargo project (and every cargo install) is treated like an isolated island with all of its dependencies starting from zero.

I've tried fixing that in Cargo, but it's a thing that seems to be very easy to change, and turns out to be very tricky, breaking cargo in subtle ways.

For now the only thing you can do is to use sccache (GitHub - mozilla/sccache: sccache is ccache with cloud storage)

Interesting. I think I am understanding.

If I install sccache I can run every instance of cargo... as sccache cargo... and not have this problem? Golly, seems too good to be true.

Would save me a lot of time. It all seems a bit confusing as Rust caveats seems to contradict the rust section of their main readme. Specifically I am compilling to wasm and thus I have:

crate-type = ["cdylib"]

and it says " Crates that invoke the system linker cannot be cached. This includes bin , dylib , cdylib , and proc-macro crates", looks like only bin crates can be so cached

But still looks very helpful

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.