silly cargo, stop using all my disk space!

This commit is contained in:
R Tyler Croy 2020-08-04 13:02:15 -07:00
parent c9ba60a781
commit df3d82f7c5
No known key found for this signature in database
GPG Key ID: E5C92681BEF6CEA2
1 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,31 @@
---
layout: post
title: "Reclaiming disk space from cargo's target/ directories"
tags:
- rust
---
You never really appreciate disk space until it's all gone. This morning I
noticed that my laptop had come perilously close to exhausting all its
available disk space. Oops! Normally I would prune some Docker images with
`docker system prune -f` but this time around I couldn't blame Docker, the
wasted space was due to [cargo](https://doc.rust-lang.org/cargo/index.html),
critical part of the Rust development toolchain.
When `cargo` does _anything_ within a project directory, it will store all it's
working state (dependencies, etc), inside of the `./target/` directory. The
more projects you work on, the more `target/` directories you will accrue, each
taking up tens or _hundreds_ of megabytes of disk.
I have adopted [cargo-sweep](https://github.com/holmgr/cargo-sweep) to help
grapple with the sprawling disk utilization of my local Rust projects. `cargo
sweep` can be run on a per-project basis or recursively for a file system
subtree with `-r`. In my case, `cron` is going to make sure that my future free
space problems will not be cargo's fault!
```
15 1 * * * ~/.cargo/bin/cargo sweep -r -t 30 ~/source
```