# sccache ### Setup - Github (has instructions): https://github.com/mozilla/sccache - Cargo Book instructions: https://doc.rust-lang.org/cargo/guide/build-cache.html#shared-cache Install ```bash cargo install sccache ``` Find path ```bash which sccache ``` Configure in Cargo config file `$HOME/.cargo/config.toml` - Must be absolute path from `/`; cannot use `~` in path ```toml [build] rustc-wrapper = "/path/to/sccache" ``` One-liner for the above, but which also overwrites the entirety of `~/.cargo/config.toml`: ```bash echo "[build]\nrustc-wrapper = \"$(which sccache)\"" | tee ~/.cargo/config.toml cat ~/.cargo/config.toml ``` Alternatively, set environment variable ``` RUSTC_WRAPPER=sccache ``` ## Debugging ## "Mismatch of client/server versions" / "Failed to fill whole buffer" If you see an error like: ``` > sccache: error: failed to get stats from server > sccache: caused by: Failed to send data to or receive data from server. Mismatch of client/server versions? > sccache: caused by: Failed to read response header > sccache: caused by: failed to fill whole buffer For full logs, run 'nix log /nix/store/kznz9zhhykjpf68fgvyalmpraqc91wv0-secretctl-deps-0.1.0.drv'. ``` In my experience this is likely a cache corruption issue - consider clearing the cache. For example, ours is configured at `/var/cache/lexe`; delete the `sccache` folder within: ```bash # Need root priveleges $ sudo bash $ cd /var/cache/lexe $ ls sccache $ rm -rf sccache $ exit ``` ## General ### Known Caveats General - Absolute paths to files must match to get a cache hit. This means that even if you are using a shared cache, everyone will have to build at the same absolute path (i.e. not in `$HOME`) in order to benefit each other. In Rust this includes the source for third party crates which are stored in `$HOME/.cargo/registry/cache` by default. Rust - Crates that invoke the system linker cannot be cached. This includes `bin`, `dylib`, `cdylib`, and `proc-macro` crates. You may be able to improve compilation time of large `bin` crates by converting them to a `lib` crate with a thin `bin` wrapper. - Incrementally compiled crates cannot be cached. By default, in the debug profile Cargo will use incremental compilation for workspace members and path dependencies. [You can disable incremental compilation.](https://doc.rust-lang.org/cargo/reference/profiles.html#incremental)