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:
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 indeps/.- Debug Symbols: Debug builds include massive symbol maps so stack traces point back to exact line numbers across third-party crates.
incremental/(Incremental Compiler Cache): Saves function-level compilation states so changing one line of code rebuilds in 1 second instead of 30.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?
- π§Ή Clean Project Directories: Running
pnpm dev-tauriorcargo buildin any project will no longer create atarget/folder inside your code repo! - β‘ Faster Builds: Shared dependencies (
tauri,tokio, etc.) are compiled once and reused across all your projects. - π¦ Centralized Cleanup: All build artifacts live in one place (
~/.cargo/shared-target), making future disk management dead simple.
π§Ή 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
| Before | After |
|---|---|
Every project has a ~7β10 GB target/ folder | 0 GB inside project folders |
| Duplicate dependencies compiled for every project | Dependencies compiled once in shared cache |
| Hard to find which project is hoarding space | All 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! π¦