Tips
Chester Wyke February 08, 2024 Updated: April 15, 2025 #rustConditional Compilation
Install
Crate Serde
References
Cargo
Toolchain (Nightly)
String Formatting
Time
Crate Tokio
Publish Crate
rustfmt
Single file script
Snippets
CI
Pattern Type State
WASM
Create New Crate
Documentation
JSON
Pattern Builder
Testing
Working with collections of bytes
Thoughts about rust
Are we yet
OnceLock
Crate Actix Web
Stack Overflow
Crate Clap
Crate Poll Promise
Crate Insta
Tips
Create new egui project
Crate CSV
Crate egui
Iterators
Crate Tracing Subscriber
Regex
vscode
Enum Conversion
Macros
lettre
Google APIs
Recovering Storage Space
- Sharing a Cargo Build Folder
- Remove unused toolchains (Recovered about 4gb removing 1.58.1, 1.61, 1.65, 1.70 and 1.71)
- See list of toolchains
rustup toolchain list
- Remove a toolchain
rustup toolchain uninstall <VALUE FROM LAST LIST>
- See list of toolchains
- Cargo Sweep (Suggested by Conrad Ludgate)
- [Not tested yet] Run cargo clean on all projects
find ~ -type d -name target -exec sh -c 'cd {} && cd .. && cargo clean' \
from timClicks notes
Sharing a Cargo Build Folder
Sources:
Back story on why I looked into this in the first place
Over time I’d worked on several projects, and compiled many more that I was looking into and after a while I noticed that the folder where I kept my projects was several gigs larger than I expected.
So, I checked what the largest folders were and noticed all of them were target
folders in rust projects.
I needed the space at the time so I manually cleaned it up.
Time passed and it built up again… so needed a better solution.
I remembered that Jon Gjengset used a shared build folder from one of his streams and inquired if he’d run into any issues.
Based on him not having had any issues using it I decided to try it and found that it worked out pretty well for me.
It has made it much easier to see how much space is being used by the build folder and much easier to delete it if needed. It also reduce the total size as multiple projects that required the same crates wouldn’t each need to have their own copy which sped up build times and saved space.
I’ve since heard of cargo sweep from Conrad Ludgate. I found this relevant post while looking for the project’s crate.io page.
Cargo looks for a folder called .cargo
in the project folder or a parent folder then a file called config.toml
and inside of that build.target-dir
to determine what build folder to use.
By default this is just target
which uses a folder called target
in the root of the project but instead you can create a shared .cargo
folder above where you have your projects and set one folder for them all to share.
For example it could be something like below. Note comment is only there to show where file goes not actually needed in file.
# .cargo/config.toml
[]
= "/home/one/build/cargo/target"