Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OS-native config, cache home directories #1734

Open
Earnestly opened this issue Jun 19, 2015 · 64 comments
Open

Use OS-native config, cache home directories #1734

Earnestly opened this issue Jun 19, 2015 · 64 comments
Labels
A-configuration Area: cargo config files and env vars C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-hard Experience: Hard S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@Earnestly
Copy link

Earnestly commented Jun 19, 2015

For Linux-like systems, we should be using XDG. See arch's wiki for a non-exhaustive list of software with varying degrees of compliance.

For Windows, everything should go in ~/appdata/locallow or ~/appdata/local,since ~/.cargo is just a cache, AFAICT. This is FOLDERID_LocalAppData for SHGetKnownFolderPath, CSIDL_LOCAL_APPDATA for SHGetFolderPath, and %LOCALAPPDATA% in the environment.

@0X1A
Copy link

0X1A commented Jun 25, 2015

Have been stumped by this as well. Looked for Cargo's config in ~/.config/cargo only to find nothing. Don't really understand why Cargo places its config in ~/.cargo and the environment variable
CARGO_HOME, while nice is entirely useless. If the user's XDG is not set then it would be fine to place in ~/.cargo.

@Earnestly
Copy link
Author

@0X1A If the respective XDG_* variables are not set, they should fallback
to the appropriate defaults as defined by the specification. The unfortunate
legacy behaviour cargo needlessly introduced will likely just add the code
bloat.

@Yamakaky
Copy link

Yamakaky commented Sep 6, 2015

Is someone working on this ? The more we wait, the more difficult it will be to change the default.

@0X1A
Copy link

0X1A commented Sep 6, 2015

@Yamakaky AFAIK there isn't anything being done about it

@whitequark
Copy link
Member

You can use my xdg crate to implement this.

tbu- added a commit to tbu-/cargo that referenced this issue Nov 10, 2015
http://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
http://www.freedesktop.org/software/systemd/man/file-hierarchy.html

Strategy for backward-compatiblity:

When checking for the relevant cargo directories, check in the following
order of preference:

1) Use the environment variable `CARGO_HOME`.
2) Use the XDG directories if they exist.
3) Use the legacy location (~/.cargo) if it exists.
4) Fall back the XDG directories if everything else fails.

Fixes rust-lang#1734.
@nagisa
Copy link
Member

nagisa commented Dec 11, 2015

cargo install now installs into ~/.cargo/bin.

@whitequark
Copy link
Member

... and it really should use ~/.local/bin; there's precedent already in the behavior pip install --user, at least.

tbu- added a commit to tbu-/cargo that referenced this issue Jan 25, 2016
Strategy for backward-compatiblity:

When checking for the relevant Cargo directories, check in the following
order of preference:

1) Use the environment variable `CARGO_HOME`.
2) Use the platform-specific directories if they exist.
3) Use the legacy location (~/.cargo) if it exists.
4) Fall back to the platform-specific directories if everything else fails.

The new platform-specific directories are as follows:

On Windows, use `AppData\Local\Temp\Cargo` for cache files (obtained via
`GetTempPath`), `AppData\Roaming\Cargo` for the config files
(`FOLDERID_RoamingAppData`) and `AppData\Local\Programs\Cargo` for
installed binaries (`FOLDERID_UserProgramFiles`).

On Unixy systems, use the XDG spec: `~/.cache/cargo` for cache files,
`~/.config/cargo` for config, `~/.local/bin` for installed binaries.

http://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
http://www.freedesktop.org/software/systemd/man/file-hierarchy.html

On OS X, use `~/Library/Caches/Cargo` for cache files, `~/Library/Cargo`
for config files and `~/Library/Cargo/bin` for binary files.

Fixes rust-lang#1734. Fixes rust-lang#1976.
@Stebalien
Copy link
Contributor

@tbu- any progress?

@tbu-
Copy link
Contributor

tbu- commented Jul 31, 2016

@Stebalien Waiting for rust-lang/rfcs#1615.

@Abdillah
Copy link

Abdillah commented Oct 8, 2016

It's the only thing I missed in rust ecosystem!
Maybe we can rebase the patch to keep it synced with current development.

Or to separate the patch into three platform so that it will be available on partial inclusion.

@tbu-
Copy link
Contributor

tbu- commented Oct 8, 2016

I'll rebase the patch or the partial patch if this gets accepted. This won't be the problem.

@carols10cents carols10cents added A-configuration Area: cargo config files and env vars C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` labels Sep 10, 2017
@sanmai-NL
Copy link

I don’t know where this came from, but on Linux I apparently have both

  • CARGO_HOME being ~/.cargo/bin/ as well as
  • CARGO_HOME2 being ~/.cargo/bin/bin/ . 😕

@genodeftest
Copy link

@sanmai-NL Where does your CARGO_HOME2 come from? I only have CARGO_HOME, which I set to "$XDG_DATA_HOME"/cargo in my ~/.bashrc.

@sanmai-NL
Copy link

sanmai-NL commented Feb 24, 2018

I have no idea, probably just some leftover from messing around when there was no Arch Linux package for Cargo yet. Note that my CARGO_HOME was also wrong, the bin path component should only be appended to CARGO_HOME within the PATH env var instead.

@Glandos
Copy link

Glandos commented Mar 10, 2018

Another issue with not respecting XDG: backups. My current backup profiles knows that it should avoid ~/.cache/ directory. And cargo is creating a lot of things into ~/.cargo that is only cache data, not useful to backup…

@bbkane

This comment was marked as off-topic.

@eode

This comment was marked as off-topic.

@Managor

This comment was marked as off-topic.

@utkarshgupta137
Copy link
Contributor

In case someone isn't aware, you can set RUSTUP_HOME & CARGO_HOME.

@soc

This comment was marked as off-topic.

@epage

This comment was marked as off-topic.

@Managor

This comment was marked as off-topic.

@whitequark

This comment was marked as off-topic.

@eode

This comment was marked as off-topic.

@weihanglo
Copy link
Member

It would be much appreciated if people can take look at and share their user stories in the pre-RFC. That's one way out to address this long-standing issue.

@eode
Copy link

eode commented Jan 26, 2024

Good to know!

@eirnym
Copy link

eirnym commented Jan 26, 2024

@weihanglo thank you for a link

@epage

This comment was marked as off-topic.

@Glandos
Copy link

Glandos commented Jan 26, 2024

In case someone isn't aware, you can set RUSTUP_HOME & CARGO_HOME.

This is not the same. XDG defines configuration in $HOME/.config/ and cache in $HOME/.cache (and other directories). As far as I know, you can't do that with CARGO_HOME.

@Lokathor

This comment was marked as off-topic.

@epage

This comment was marked as off-topic.

@oxalica
Copy link

oxalica commented Jan 26, 2024

@utkarshgupta137

In case someone isn't aware, you can set RUSTUP_HOME & CARGO_HOME.

I'd say that mostly does not fulfill the need of people coming to this issue, who usually want to split managing caches, configs and data. It's also stated in the previous postponed RFC rust-lang/rfcs#1615.

  • Putting caches in designated cache directories allows backup tools to ignore
    them. (Linux, Windows, macOS. Example: Time Machine ignores the cache
    directory on macOS.)
  • It makes it easier for users to manage, share and version-control their
    configuraton files, as configuration files from different applications end up

As a NixOS user who manages immutable cargo config with Nix, I have to do dirty symlink tricks to split $CARGO_HOME/{registry,git,config.toml} to different targets, so that cargo will not try to write to ro-mounted /nix/store and fail. That's all no issue if the RFC is actually implemented since we can set XDG_*_PATH separately.

In this time, I strongly agree this comment from previous RFC

The core problem is that those who are interested in fixing this don't make the decisions, and those making decisions aren't interested.

This issue is bothering a lot for us as cargo users, who may or may not have cargo development skills, while many (maybe only little?) cargo developer more lean towards keeping the current non-ergonomic situation with the reason of "compatibility"1 or "always has been". So the only way left for us users to do is ranting out and gaining attention to show that the current situation is not as good as they think.

Footnotes

  1. In one of several relevant issues (sorry I cannot find it immediately), I saw someone treat cargo-audit storing their database inside $CARGO_HOME as compatibility concerns. That's blowing my mind that a "security tool" is writing random private stuff into cargo dedicated path without consent, which is taken as a positive example. I'd treat that operation itself as security issue, and hope they won't modify $CARGO_HOME/config.toml next time. Thankfully I'm using Nix so the config file is ro-mounted.

@epage

This comment was marked as off-topic.

@rust-lang rust-lang locked as too heated and limited conversation to collaborators Jan 26, 2024
@epage
Copy link
Contributor

epage commented Jan 30, 2024

I'm unlocking this and hiding the most of the recent posts.

I would ask that people be respectful to others and that includes not assigning intent to others I think a general assumption we can make is that we all want what is best for the users of cargo.

A summary of the conversation from some of the hidden posts:

  • A use case raised is "non-rust users", whether as a side effect of system or other language package managers building from source. As Rust is adopted in more places, this will grow to become a bigger problem. This affects more than this issue but also issues like Tracking Issue for garbage collection #12633.
  • Concern was raised over the wider ecosystem drag Cargo is adding to the effort for adopting XDG in the wider ecosystem
  • CARGO_HOME can be used to move ~/.cargo but this won't get the full benefit if you have config in that location or depending on how strict you are about the different paths
  • You could symlink the different locations. This could likely be improved (cargo auto-detecting certain symlink targets don't exist and creating them).

@totikom
Copy link

totikom commented Feb 3, 2024

I think, that I know a hacky solution for locating build directory (target) in the XDG-compliant way.

target is actually a default value for $CARGO_TARGET_DIR, so you can add:

alias cargo = 'CARGO_TARGET_DIR=$XDG_CACHE_DIR/rust-builds/$(cargo metadata --no-deps --offline | extract_name_magic) cargo'

Where extract_name_magic is a combination of grep and sed which will extract the package name.

By using this alias, you'll get all the cargo commands working as expected with separate XDG-compliant build directories for each project.

Tomorrow I'll implement extract_name_magic for completeness.

@epage
Copy link
Contributor

epage commented Feb 4, 2024

FYI this is about everything in the home directory today. There is a separate issue (and an open RFC!) about centralizing target dirs. On mobile or I'd get you the linksd

@weihanglo
Copy link
Member

FYI this is about everything in the home directory today. There is a separate issue (and an open RFC!) about centralizing target dirs. On mobile or I'd get you the linksd

See rust-lang/rfcs#3371 and #11156 (if I got it correctly).

@asasine
Copy link

asasine commented Feb 15, 2024

In one of several relevant issues (sorry I cannot find it immediately), I saw someone treat cargo-audit storing their database inside $CARGO_HOME as compatibility concerns. That's blowing my mind that a "security tool" is writing random private stuff into cargo dedicated path without consent, which is taken as a positive example. I'd treat that operation itself as security issue, and hope they won't modify $CARGO_HOME/config.toml next time. Thankfully I'm using Nix so the config file is ro-mounted.

@oxalica

I believe this was from the Pre RFC thread https://internals.rust-lang.org/t/pre-rfc-split-cargo-home/19747/26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-configuration Area: cargo config files and env vars C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-hard Experience: Hard S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests