Speed up Rust workflow / Save a disk space with sccache

Compilation of the programs in Rust can increase in time and disk space and if you are working on many projects, you have almost full SSD disk you may need to setup Mozilla's sccache (Shared Compilation Cache) to speed your workflow and save a disk space. Below solution has been tested on Windows, but for other operating systems should work similarly.

Let's setup the sccache with rust (rustup+cargo)

code $profile # Edit profile file eg in vscode or any favourite editor of your choice.

Add below to your profile:

# Below you at to the "$profile" -> C:\Users\<username>\Documents\PowerShell\
# Let say your ssd is G drive.
$env:RUSTUP_HOME = "g:/_RustLang/.rustup"
$env:CARGO_HOME = "g:/_RustLang/.cargo"
# To safe space and speed up compilation time add
$env:SCCACHE_DIR = "g:/_RustLang/sccache"
$env:RUSTC_WRAPPER = "g:\_RustLang\.cargo\bin\sccache.exe"

Install rustup

Go to the https://rustup.rs/ and install rustup. You also can install it by scoop.

scoop install rustup
# You may need to add enviroment path. use native commands or nexss programmer
nexss System/Env/EnsurePath g:\_RustLang\.cargo\bin\

After all directories setup above install rust and sccache through cargo

rustup install stable
cargo install sccache

More about environment variables in cargo you can find here: https://doc.rust-lang.org/cargo/reference/environment-variables.html

If you found it valuable, please join to the nexss.com supporters at: Support Nexss.com