# Report on platform-compliance for cargo directories

**URL:** <https://internals.rust-lang.org/t/report-on-platform-compliance-for-cargo-directories/18866>\
**Category:** cargo\
**Created:** [May 23, 2023, 11:22am UTC](https://internals.rust-lang.org/t/report-on-platform-compliance-for-cargo-directories/18866 "2023-05-23T11:22:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![PoignardAzur](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/poignardazur/32/6464_2.png) [@PoignardAzur](https://internals.rust-lang.org/u/PoignardAzur)\
**Post date:** [May 23, 2023, 11:22am UTC](https://internals.rust-lang.org/t/report-on-platform-compliance-for-cargo-directories/18866/1 "2023-05-23T11:22:30Z")

</div>

> **[Report on platform-compliance for cargo directories](https://poignardazur.github.io/2023/05/23/platform-compliance-in-cargo/)**
>
> When you use the Rust programming language toolchain, usually through a cargo command, it needs a place to store a bunch of config files, caches, and the cargo binary itself. By default, that place will be your operating system’s user directory,...

Discussion on r/rust: [Reddit - Dive into anything](https://www.reddit.com/r/rust/comments/13plkf0/report_on_platformcompliance_for_cargo_directories/)

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [May 23, 2023, 4:40pm UTC](https://internals.rust-lang.org/t/report-on-platform-compliance-for-cargo-directories/18866/2 "2023-05-23T16:40:37Z")

</div>

Would there be a benefit in only moving cache dirs at first? That seems like it would be easier as it doesn't strictly need every cargo version to agree. At worst it doubles disk space usage (which already happens anyway due to the move to the sparse registry protocol using a different directory for everything). It will make it easier for users to clear all caches including cargo's caches. Unlike the config and bin dir duplication of the cache dir doesn't mess up any user observable state.

---

<div class="post-metadata">

**Author:** ![epage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/epage/32/3171_2.png) [@epage](https://internals.rust-lang.org/u/epage)\
**Post date:** [May 23, 2023, 5:00pm UTC](https://internals.rust-lang.org/t/report-on-platform-compliance-for-cargo-directories/18866/3 "2023-05-23T17:00:41Z")

</div>

Not having caught up on everything, I was wondering why we wouldn't go in a direction like this

- Diverge the cache dirs
- Read both config dirs
- Maybe write bins to both locations (if present)

One concern would be the extra space / sync time for the git index but sparse index being default will help.

---

<div class="post-metadata">

**Author:** ![bascule](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bascule/32/3057_2.png) [@bascule](https://internals.rust-lang.org/u/bascule)\
**Post date:** [May 23, 2023, 7:48pm UTC](https://internals.rust-lang.org/t/report-on-platform-compliance-for-cargo-directories/18866/4 "2023-05-23T19:48:20Z")

</div>

Regarding interop between tools: I can't speak to all of them, but `cargo-audit` uses the [`home` crate](https://docs.rs/home/).

Perhaps the `home` crate could provide a finer-grained API like `cargo_cache_home`, `cargo_config_home`, `cargo_bin_home`?

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [May 24, 2023, 1:14pm UTC](https://internals.rust-lang.org/t/report-on-platform-compliance-for-cargo-directories/18866/5 "2023-05-24T13:14:58Z")

</div>

> [@bascule](#):
>
> Perhaps the `home` crate could provide a finer-grained API like `cargo_cache_home`, `cargo_config_home`, `cargo_bin_home`?

There is the directories crate for that already.

---

<div class="post-metadata">

**Author:** ![bascule](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bascule/32/3057_2.png) [@bascule](https://internals.rust-lang.org/u/bascule)\
**Post date:** [May 24, 2023, 1:40pm UTC](https://internals.rust-lang.org/t/report-on-platform-compliance-for-cargo-directories/18866/6 "2023-05-24T13:40:13Z")

</div>

That's a generic cross-platform implementation of XDG.

I'm talking about having a cargo-specific API, as the `home` crate does today, which would make it possible to migrate from the current `~/.cargo` to XDG (possibly via environment variable-based configuration?)

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [May 24, 2023, 4:48pm UTC](https://internals.rust-lang.org/t/report-on-platform-compliance-for-cargo-directories/18866/7 "2023-05-24T16:48:42Z")

</div>

I didn't know the home crate has a cargo-specific API.

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [May 24, 2023, 11:01pm UTC](https://internals.rust-lang.org/t/report-on-platform-compliance-for-cargo-directories/18866/8 "2023-05-24T23:01:08Z")

</div>

If someone creates a fresh install of rust and cargo using rustup, and subsequently installs and runs an older version of cargo, it seems fine if the older version of cargo doesn't share `~/.cargo` by default. The index will need re-downloading, but that's going to be the case anyway if you run an older version that uses the non-sparse index. Crates will need re-downloading, but that doesn't seem like that big a deal either. And users won't have cargo configuration by default, unless they've manually created it.

Given all that, I wonder if we need new cargo to still default to the old `~/.cargo` directory if no directories exist, or if it could default to the new locations?

---

<div class="post-metadata">

**Author:** ![bascule](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bascule/32/3057_2.png) [@bascule](https://internals.rust-lang.org/u/bascule)\
**Post date:** [May 25, 2023, 1:39am UTC](https://internals.rust-lang.org/t/report-on-platform-compliance-for-cargo-directories/18866/9 "2023-05-25T01:39:10Z")

</div>

It defines [`cargo_home`](https://docs.rs/home/latest/home/fn.cargo_home.html) which is the canonical function for locating `~/.cargo` which is used by Cargo itself

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [August 23, 2023, 1:39am UTC](https://internals.rust-lang.org/t/report-on-platform-compliance-for-cargo-directories/18866/10 "2023-08-23T01:39:29Z")

</div>

Closed on August 23, 2023, 1:39am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
