Cargo questions

What's stored in dir ~/.cargo (over 100 MB) ?

For each project created by command 'cargo new, cargo creates a directory under ~/project_name which supposedly contains code (binaries?) for all the project`s dependencies. If I have two projects, both of which use dependency 'A', is A included in both project directories ?

Or does cargo somehow use ~/.cargo to eliminate the need to store two duplicate versions of 'A' ?

The source code for all your dependencies is stored in .cargo/registry/src. At most one copy of each version of each dependency will be stored here. You can choose to purge it sometimes to get rid of old versions of libs.

In your project folder you will get a target directory. This directory will contain all build artifacts and can become quite big. It can be deleted at any time but will be recreated on the next build command.

If you are annoyed with the constant cleaning of the target directories, you can set the CARGO_TARGET_DIR environment variable to have all build artifacts in one place. I set it to /tmp/rs, so everytime I reboot it's gone, hurray. Building in memory also speeds up compilation times.

3 Likes

The Cargo Home chapter of The Cargo Book covers the contents of ~/.cargo/ in a fair amount of detail. If you are curious and want to know more, that document should give you plenty of links to click and keywords to search.

By the way, on most distros /tmp isn't a tmpfs, but it's a regular directory stored on disk.
It's just cleaned every boot.

many thanks... my /target directories were chewing up huge amounts of disk space