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 · 78 comments
Open

Use OS-native config, cache home directories #1734

Earnestly opened this issue Jun 19, 2015 · 78 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

Maintainer's notes:

  • A Pre-RFC has been started that splits out the first half of t his work (making the paths configurable) to have a smaller, more focused conversation

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…

@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

@poscat0x04
Copy link

FWIW cabal (The haskell counterpart of cargo) migrated to XDG directories on version 3.10. The behavior is that if CABAL_DIR (equivalent to CARGO_HOME, present before 3.10) is set, cabal will fall back to the old behavior, i.e., storing everything in CABAL_DIR, otherwise cabal will follow the XDG spec.

@LunarLambda
Copy link

I would at absolute minimum like to see ability to use $XDG_CONFIG_HOME/cargo/config.toml.

I keep CARGO_HOME in ~/.local/share/cargo (and RUSTUP_HOME similarly). Generally anything in ~/.local/share should be things I don't need to backup or track and can simply re-download/reinstall if needed. Whereas my config directory is fully tracked, and right now i need to take extra steps with symlinks.

@mutech

This comment has been minimized.

@soc

This comment has been minimized.

@Managor

This comment has been minimized.

@weihanglo

This comment has been minimized.

@weihanglo
Copy link
Member

If anyone wants to help, the already-mentioned pre-RFC is the first step toward a solution, though it is still under discussion and hasn't reached a consensus yet. The original author of that post (epage) doesn't seem to have time to work on it, so it probably needs some other folks to take care of it.

@mutech

This comment has been minimized.

@epage

This comment has been minimized.

@epage
Copy link
Contributor

epage commented Jan 6, 2025

To make it more discoverable, I've added a link to my Pre-RFC to the issue. I've also updated the Pre-RFC Motivation section with additional constraints XDG support is operating under that make this non-trivial.

@ddevault

This comment has been minimized.

@soc

This comment has been minimized.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 7, 2025

Moderator note: It's ok to be angry and frustrated. So are the maintainers at the sheer number of things that need doing and fixing and that they don't get to. Priorities and maintainers change, things fall under the bus. That's life. It's not as easy as just deciding to fix this issue, even if it may seems so from the outside.

Please stay on topic, this meta discussion serves no point other than venting, use your private spaces for that.

I'm aware a multi hundred comment issue with a linked RFC with lots of comments is not enjoyable to read to get the full picture. So a contribution that needs no rust knowledge would be to write a summary of the RFC discussion and open discussion items on the RFC.

@mutech
Copy link

mutech commented Jan 19, 2025

@epage Thank you for commenting. I see how meta discussions like this don't necessarily contribute to solve this, I would much rather have a private word with you. My intention is not to be rough, hurt or harm you and most of all I really don't want to be create trouble. English is not my native language. It's also not my culture. I'm German, and we have our reputation for a reason (the one about rudeness, the other one even more so). My intention is not to be rude, but to be understood.

Look at it from my side. You're stepping on my toes. I don't believe you do that to hurt or annoy me, but it hurts, even if only a little. Every time I come here commenting, it's because I spend between 10-30m of - as I see it - clean up after you.

I think it would actually be better if you would close this issue refusing to implement it. That would not prevent you from eventually doing something about it. It would not provoke me or others to try to accelerate the process. But keeping a ticket open for 10 years is really offensive. Not to you, but to me and people like me.

@oli-obk You make a good point. I feel a bit guilty making myself part of the problem. At the same time, I think this particular issue is a special case, because of it's age.

I feel strongly about ethics. This is a complicated case, because I'm not a paying customer, you have no obligations to me in regard of what you do in this project. For the most part. But you are not completely free from responsibility to people whom your decisions impact. The extreme example would be if you added virus to your product. You don't, but you could and if you did, that would be trouble. This case is a grey area, where you clearly have no malicious intend, but you create an impact that is felt by some as damaging. I keep having to spend time to clean up after you, even though I'm not even directly using your software.

If I interpret epage correctly, he saw that argument as a valid point or at least one deserving of some consideration. If it's a valid point, it deserves a consequence, and "be patient" on a ticket that's up for 10 years is not really something that makes me feel any better while I'm cleaning up.

We all live in an era that is defined by divisions and unnecessary conflicts. I am old enough to remember a time when there was a whole lot more of respect and cooperation. Even at that time, people were rough. But that didn't necessarily mean disrespect, Sometimes people are angry for a reason and it's not always the only option to call "language", sometimes considering a dissonant contribution might be valuable.

I miss the time when controversy triggered a desire to start a discussion and work towards a common understanding. If we can only talk if we first agree, what's the purpose of talking?

I reread this post before sending. Nothing I wrote here is intended to inflame conflict or even be rough. I actually respect you. I am just plainly writing exactly what I'm thinking. If this is rough, then I should better be banned from github, because I just can't be smoother than this without pretending to be something I'm not.

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