Created
January 10, 2026 17:30
-
-
Save iberi22/9d21d6693810730a334ab97c982cf4b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| **Stop wasting disk space.** This configuration implements a centralized build cache, significantly reducing disk usage and build times across all your Rust projects. | |
| ## 1. Global Configuration (`~/.cargo/config.toml`) | |
| *Windows: `C:\Users\%USERNAME%\.cargo\config.toml`* | |
| *Linux/Mac: `~/.cargo/config.toml`* | |
| This sets up a unified target directory and enables `sccache` and the sparse registry protocol. | |
| ```toml | |
| [build] | |
| # 1. Centralize build artifacts (Deduplicates common dependencies like tokio/serde) | |
| # Change path to your preferred fast SSD location. | |
| target-dir = "C:\\Users\\belal\\.cargo\\target_global" | |
| # 2. Use sccache to cache intermediate compiled objects | |
| rustc-wrapper = "sccache" | |
| [net] | |
| git-fetch-with-cli = true | |
| [registries.crates-io] | |
| # 3. Use Sparse protocol (Downloads metadata only for what you use, saves ~300MB) | |
| protocol = "sparse" | |
| ``` | |
| > **Note:** You must install sccache first: `cargo install sccache --locked` | |
| --- | |
| ## 2. Project Optimization (`Cargo.toml`) | |
| *Apply this to your project's root `Cargo.toml`.* | |
| This disables debug symbols for dependencies. You rarely need to step-debug into external libraries, and this reduces the `target/` size by roughly **40-60%**. | |
| ```toml | |
| [profile.dev] | |
| opt-level = 0 | |
| debug = true | |
| # β‘ Professional Optimization | |
| # Disables debug info for all dependencies. | |
| # Keeps your code debuggable, but makes 'target/' lightweight. | |
| [profile.dev.package."*"] | |
| debug = false | |
| opt-level = 1 # Moderate optimization for dependencies (faster runtime) | |
| ``` | |
| ## The Results | |
| - **Disk Space**: ~99GB reclaimed in my workspace immediately. | |
| - **Build Times**: Incremental builds are nearly instant thanks to `sccache`. | |
| - **Network**: instant crate resolution via Sparse Registry. | |
| Enjoy your lean, mean Rust machine. π¦π¨ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment