Skip to content

How I Reclaimed 23 GB of Storage from Rust & Tauri Projects in 5 Minutes

Harry

If you build desktop or web apps with Tauri or Rust, you’ve probably had this moment:

You open system settings or a disk analyzer to figure out why your Mac or laptop is suddenly low on disk space, only to find a mysterious cluster of massive folders inside your project repositories.

~/code/nextai-translator/src-tauri/target   --->  8.00 GB
~/code/lingoloop/src-tauri/target           --->  7.53 GB
~/code/yolo/src-tauri/target                --->  7.50 GB

That’s over 23 GB taken up by just three projects!

If this sounds familiar, don’t panic β€” your code isn’t bloated. This is actually a feature of Rust’s build system, Cargo. But left unmanaged, Cargo will happily devour your entire SSD.

In this post, we’ll look at why this happens and the 1-line configuration that will stop Cargo from creating multi-gigabyte target folders in every single project.


πŸ” Why Does Cargo Take Up So Much Space?

Rust prioritizes fast compilation over minimal disk usage. When you run cargo build or pnpm dev-tauri, Cargo does several heavy computations:

  1. deps/ (Dependency Cache): Compiles every crate in your dependency tree (tokio, serde, tauri, etc.) into static object files (.rlib, .dylib). Crucially, Cargo never automatically deletes older versions of dependencies. If you update a library, both the old and new compiled files sit side-by-side in deps/.
  2. Debug Symbols: Debug builds include massive symbol maps so stack traces point back to exact line numbers across third-party crates.
  3. incremental/ (Incremental Compiler Cache): Saves function-level compilation states so changing one line of code rebuilds in 1 second instead of 30.
  4. build/: Stores intermediate C/C++ native build artifacts (like WebView or OpenSSL bindings).

Multiply this across 4 or 5 projects, and you are easily losing 30 to 50 GB.


πŸš€ The Solution: Global Shared Target Directory

By default, every project creates its own isolated target/ directory. That means if Project A and Project B both use serde and tauri, Cargo compiles them twice into two separate 7 GB folders.

We can fix this permanently by telling Cargo to use a central shared target directory for all projects.

Step 1: Add a Global Cargo Config

Create or edit your global Cargo config at ~/.cargo/config.toml:

[build]
target-dir = "/Users/yourusername/.cargo/shared-target"

Or run this single terminal command (replace yourusername with your username):

mkdir -p ~/.cargo && echo '[build]\ntarget-dir = "'"$HOME"'/.cargo/shared-target"' >> ~/.cargo/config.toml

What happens now?


🧹 Step 2: Delete Old Target Folders & Reclaim Space

Now that your global configuration is active, you can safely wipe out all the old, isolated target folders sitting in your project directories:

# Delete project-level target folders
rm -rf ~/code/*/src-tauri/target
rm -rf ~/code/*/target

Boom! 23+ GB freed in seconds. πŸŽ‰


πŸ› οΈ Bonus Tip: Automated Multi-Project Cleaning

If you develop lots of Rust projects and want an automated tool to scan and sweep old build files, install cargo-clean-all:

cargo install cargo-clean-all

# Scan and clean all Rust projects in ~/code
cargo-clean-all ~/code

Summary

BeforeAfter
Every project has a ~7–10 GB target/ folder0 GB inside project folders
Duplicate dependencies compiled for every projectDependencies compiled once in shared cache
Hard to find which project is hoarding spaceAll build cache centralized in ~/.cargo/shared-target

If your SSD is crying for space, spend 2 minutes setting up ~/.cargo/config.toml β€” your disk will thank you!


Found this helpful? Share it with fellow Rust & Tauri developers! πŸ¦€

Next
Programmatic Tool Calling in Yolo: Running LLM JavaScript in a QuickJS WASM Sandbox