Shared target directory

2024-01-30

Rust stores all compiler outputs (including compiled dependencies and intermediate files) in the “target” directory. By default, each workspace (typically, the cloned repo of a collection of related crates) has its own target directory, called ‘target’ and stored as a direct child of the workspace root. (This is why you typically see ‘/target/’ as an entry in a Rust repo's ‘.gitignore’ file.)

Target directories can get very large, because there is no garbage collection applied to it by default. This can become especially problematic if you work on several workspaces that have shared dependencies, since each target directory will include its own copy of those dependencies.

There is a config option that lets you use a shared target directory instead. Put this in your ‘~/.cargo/config.toml’ file:

[build]
target-dir = ".cache/cargo/target"

(Note that relative paths are relative to the parent of the directory containing the config file — i.e., your home directory for your global ‘~/.cargo/config.toml’.)

=> Build cache [Cargo book] | ‘build.target-dir’ [Cargo book]

=> » Languages » Rust

Proxy Information
Original URL
gemini://dcreager.net/languages/rust/shared-target-directory.gmi
Status Code
Success (20)
Meta
text/gemini;lang=en
Capsule Response Time
404.843645 milliseconds
Gemini-to-HTML Time
0.681382 milliseconds

This content has been proxied by September (3851b).