cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Support the XDG Base Directory Specification.

Open Earnestly opened this issue 9 years ago • 30 comments

This is a continuation from the previous (https://github.com/rust-lang/cargo/pull/148) pull request which your bot apparently merged, but in effect did not.

As there is no open issue about this, I've decided to open one so it is publicly known.

Much has been said in the previous pull request so I won't repeat it here.

For reference, here is a non-exhaustive list of software with varying degrees of compliance.

Earnestly avatar Jun 19 '15 17:06 Earnestly

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.

0X1A avatar Jun 25 '15 04:06 0X1A

@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.

Earnestly avatar Jun 25 '15 12:06 Earnestly

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

Yamakaky avatar Sep 06 '15 08:09 Yamakaky

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

0X1A avatar Sep 06 '15 17:09 0X1A

You can use my xdg crate to implement this.

whitequark avatar Sep 21 '15 03:09 whitequark

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

nagisa avatar Dec 11 '15 13:12 nagisa

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

whitequark avatar Dec 11 '15 13:12 whitequark

@tbu- any progress?

Stebalien avatar Jul 31 '16 20:07 Stebalien

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

tbu- avatar Jul 31 '16 20:07 tbu-

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.

Abdillah avatar Oct 08 '16 11:10 Abdillah

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

tbu- avatar Oct 08 '16 11:10 tbu-

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/ . :confused:

sanmai-NL avatar Feb 22 '18 10:02 sanmai-NL

@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.

genodeftest avatar Feb 24 '18 12:02 genodeftest

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.

sanmai-NL avatar Feb 24 '18 14:02 sanmai-NL

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…

Glandos avatar Mar 10 '18 22:03 Glandos

cc https://github.com/rust-lang/cargo/pull/5183 and https://github.com/rust-lang/rfcs/pull/1615

Eh2406 avatar Mar 28 '18 17:03 Eh2406

Any progress on this?

soredake avatar Apr 18 '20 08:04 soredake

@whitequark

... and it really should use ~/.local/bin;

~/.local/bin is not specified by the XDG spec.

hasufell avatar Jul 28 '20 05:07 hasufell

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

~/.local/bin is not specified by the XDG spec.

FWIW, there is XDG_BIN_HOME that sadly never got commited to the spec, lost due to bad maintainership. I'd still recommend to use this, because at least it has defined (and agreed on) semantics.

piegamesde avatar Jul 28 '20 19:07 piegamesde

@piegamesde Not that it matters too much, as we'll probably just put things in ~/.local/bin if there's no spec, but I've opened an issue with XDG re: $XDG_BIN_HOME.

eode avatar Jul 29 '20 22:07 eode

Another advantage of complying with XDG: when trying to get some space off of your disks you can often trash ~/.cache.

So I'm asking for cargo to put a project's target/ under ~/.cache/cargo/sha256(project path)/target. This would replace tools such as https://github.com/mihai-dinculescu/cargo-wipe

fenollp avatar Nov 03 '20 15:11 fenollp

If anyone would like to help, I'm going to try to have XDG_BIN_HOME or its equivalent merged: https://gitlab.freedesktop.org/xdg/xdg-specs/-/issues/14#note_682259

christianbundy avatar Nov 03 '20 15:11 christianbundy

@christianbundy Lent my support as much as possible.

However, of note is this: one way or the other, they will be documenting ~/.local (with ~/.local/bin) as the official 'default' location. So at the very least, this is a reasonable default for rust.

eode avatar Nov 13 '20 20:11 eode

I've made a PR with Lennart's original patchset related to this issue (which stalled and languished after all-around approval).

eode avatar Nov 23 '20 17:11 eode

Ok! the PR was merged (issue, pr). The result is that the official location for user-specific executables is as follows:

There is a single base directory relative to which user-specific executable files may be written.

User-specific executable files may be stored in $HOME/.local/bin. Distributions should ensure this directory shows up in the UNIX $PATH environment variable, at an appropriate place.

Since $HOME</literal> might be shared between systems of different achitectures, installing compiled binaries to $HOME/.local/bincould cause problems when used on systems of differing architectures. This is often not a problem, but the fact that$HOME` becomes partially achitecture-specific if compiled binaries are placed in it should be kept in mind.

This has been merged, but has not yet been released. I have no clue what the XDG release schedule is.

Edit of course, this was anticipated, as it's the reasonable default, but they opted not to have an env-var for the location. I.e., it is architecture-specific, and if the user is using their homedir across architectures, they can just go figure it out themselves.

eode avatar Dec 02 '20 17:12 eode

but they opted not to have an env-var for the location

I am mildy confused about realizing this only now, there were way too many similar patches in discussion – this is the first directory location whose path is hardcoded in the spec :/

Anyway, this really isn't a show stopper. Cargo shouldn't place any binaries directly into the .local/bin folder, but rather some script wrappers that gracefully fail when on a non-native architecture.

This has been merged, but has not yet been released.

Given the circumstances, it is fair to assume no breaking changes will happen to the spec between now and an eventual release. (A release would still be great though.)

piegamesde avatar Dec 02 '20 17:12 piegamesde

@piegamesde I fully agree that it's a bad idea not to have an env var for this. I've added your point to the XDG conversation on closing that issue.

I don't even think that the XDG people were expecting dev tools to handle that -- I think it's more along the lines of "If the user/distro is going to try to support multiple architectures for a homedir, that should be detected and handled by links set in ~/.profile or equivalent". Asking every dev tool / local user software (once installed) to fail gracefully if the architecture changes is.. ..well.. ..too much. They'd never get multiple projects, systems, etc to go along with that, even though it might just be a matter of wrapping executables in a short script.

Given the circumstances, it is fair to assume no breaking changes will happen to the spec between now and an eventual release. (A release would still be great though.)

Agreed. At this point, even if they decide to use an env var, it would default to ~/.local/bin.

eode avatar Dec 02 '20 17:12 eode

Six years.

ddevault avatar Jun 29 '21 01:06 ddevault

Please add support for XDG...

luis-guimaraes-exoawk avatar Jul 11 '22 10:07 luis-guimaraes-exoawk

I pinged the XDG spec in case they're willing to move on XDG_BIN_DIR (there has been some input from other projects in the mean time). I do think that supporting it if it exists without expecting it to exist might be a reasonable step. The only reason for anyone to create an XDG_BIN_DIR env var is for that specific purpose, anyways.

eode avatar Jul 14 '22 18:07 eode