Does `sccache` work with `cargo install`?

I like to install stuff with cargo install (ripgrep, lsd, zoxide etc). But the compilation time is really hard when trying to bring up a new system from scratch. Does sccache work with cargo install to reduce the compilation time?

It should do. All cargo commands respect the rustc-wrapper field in your ~/.cargo/config and use that instead of rustc when specified.

What about if I set it via the RUSTC_WRAPPER environment variable?

Is there a way to tell when a crate build was skipped due to the cache? its not obvious just by looking at the time spent.

Yes, all environment variables should be inherited by any processes spawned by cargo.

I think sccache would try to deliberately not print anything to stdout/stderr in case it messes up legitimate compiler output.

You can print out stats showing how many hits and misses you get, though.

$ sccache --show-stats
Compile requests                    186
Compile requests executed           159
Cache hits                          157
Cache hits (Rust)                   157          <---------------
Cache misses                          2
Cache misses (Rust)                   2
Cache timeouts                        0
Cache read errors                     0
Forced recaches                       0
Cache write errors                    0
Compilation failures                  0
Cache errors                          0
Non-cacheable compilations            0
Non-cacheable calls                  27
Non-compilation calls                 0
Unsupported compiler calls            0
Average cache write               0.001 s
Average cache read miss           2.251 s
Average cache read hit            0.001 s
Failed distributed compilations       0

Non-cacheable reasons:
crate-type                           27

Cache location                  Local disk: "/home/michael/.cache/sccache"
Cache size                            3 GiB
Max cache size                       10 GiB

Oh "show-stats" looks perfect. One last question do you know if it's possible to run "cargo install for multiple packages in parallel? The final linking step always takes a while and it's fully single threaded, theoretically multiple programs could be linked in parallel

Why don't you try it and find out?

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.