-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Make Cargo obey platform-specific directory standards #2127
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @huonw (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Probably doesn't compile on Windows, because the |
Passes all tests now, ready to get merged! |
Since XDG is higher priority than the original one, isn't that going to cause issues? People who work on systems which follow XDG are gonna see their existing |
The XDG only has higher priority if it exists (~/.cache/cargo). This could help with deprecating ~/.cargo completely in the future. EDIT: Systems which follow XDG might have ~/.cache, but they won't have ~/.cache/cargo. |
Thanks for the PR @tbu-! It looks like there was also quite a bit of legwork in getting everything to work across all platforms, so thanks for that as well! Some thoughts of mine:
I wonder if it would be possible to have this still be opt-in, but perhaps have the opt-in to be very easy to set? |
Thanks for looking over the pull request!
I suppose, but I don't have a Windows machine right now.
Yea, the points about OS X and *BSD are fair, I haven't researched the situation there yet.
Fragmentation isn't really worse, you can find the configuration in ~/.config/cargo and the cache in ~/.cache/cargo, unless you set environment values, like before.
Update the tutorials to point to ~/.config/cargo instead of ~/.cargo/config (With a mention that the legacy location ~/.cargo/config is still supported).
I think making standard compliance an opt-in is basically not having standard compliance at all. The standards exist to give common behavior across many different programs, and if you have to configure each of them anyway, then the benefit of having that standard is lost. The issues with the XDG crate ( |
I can't tell you about BSD, but for OSX: https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html TL;DR: very much not XDG. |
Ah yeah sorry to be clear I'm not worried about fragmentation within a platform, but rather across platforms. For example we can't really just update the tutorials to list different paths because now it's a different path for every platform. In that sense I think the fragmentation gets worse because as someone who works across OSX/Windows/Linux I've now got to always be conscious of where I'm at if I want to find these directories. |
☔ The latest upstream changes (presumably #2154) made this pull request unmergeable. Please resolve the merge conflicts. |
So, I researched a little and found out that the BSDs should probably get XDG handling, OS X caches go into |
I'm personally still worried about the fragmentation problem. It looks like this is basically going to end up with almost a different location for directories per OS rather than "windows" and "non windows", and at some point it seems like the benefit perhaps isn't that large? This is why I was thinking that an opt-in may suffice for now in some form. |
@alexcrichton I guess if we want non-fragmentation, we should probably go for XDG on unixy systems (including Mac), and for AppData on Windows. This would give us a pretty consistent story that interacts well with the OSs, as well as separating caches from configs. |
That seems like not a great situation to be in though, unfortunately. There's still fragmentation between Windows and non-Windows, and Cargo would be favoring Linux/Windows over all other OSes by saying they need to be slotted into one of those buckets. Overall it seems like it doesn't really reduce the net number of issues? |
Let's collect a list of advantages and disadvantages:
So by just looking at the advantages/disadvantage (tell me if I missed any!), I'd say that 2) and 3) are both favorable to 1). In fact, the only advantage of 1) over 2) seems to be that there is cross-platform consistency between Windows and unixy operating systems, which I'd argue is very much not expected for Windows users. |
Thanks for working on this! Following XDG is a huge win and it would be much nicer if all applications did this. Primarily the clean separation of cache vs user data (config and data). Especially since cargo does not clean up its old caches, having them separated out for easy & confident removal is a win for the user. (The user will be safer to know it's only cache). |
I think that if we take this route we'd want to do the "best thing for the platform" in each case, so I wouldn't take the route of XDG everywhere on Unix (ignoring what OSX conventions are). To me any fragmentation is just as bad as lots of fragmentation, so I'm not worried about the degree of fragmentation along those lines. I also think that it may not quite be as black-and-white as listing out pros/cons and seeing which bucket is bigger. The existence of fragmentation can have a multiplicative effect where all of Cargo's decisions affect downstream users and such. For example anyone wanting to write a tool against Cargo's directory layout or something like that would end up having to work with all this logic somehow as well to work across platforms. I'd be curious on some other opinions from @rust-lang/tools as well, I have a feeling that @wycats in particular may have thoughts on this. |
Unless Cargo's directory layout is considered a stable interface, wouldn't any such tool have to invoke Cargo or use it as a library anyway? |
@alexcrichton I didn't want to suggest to compare the number of pros and cons, as they can certainly be split up in different ways. I do however, still think that the benefits of 2) and 3) outweigh the solution for 1), especially 2) which is basically a pure improvement IMO (I think that 1) is consistency at the cost of Windows users, because there is virtually no program that stores its configuration in something like |
Yes, the exact type of link to use in this case seems irrelevant. |
☔ The latest upstream changes (presumably #2339) made this pull request unmergeable. Please resolve the merge conflicts. |
@Alexander-- Not part of the XDG spec, but the second link in the PR: http://www.freedesktop.org/software/systemd/man/file-hierarchy.html. |
This is an example of possible breakage from following these sorts of environment variables. It could be the case that someone invokes |
Mh, fair enough, that's definitely a breakage from starting to follow XDG specifications where you previously did not. "The sooner the better?" Your link might even provide some more motivation, even git is doing it (which definitely isn't a desktop application). |
To me, being able to backup your cargo folder without copying cache files is the best reason to want this, and that could be achieved by changing the cache location to be platform-specific, possibly optionally. There's less reason to care where cargo stores its internal cache than its configuration.
@Alexander-- I like this point, that encouraging $PATH to include somewhere user-writable weakens security (probably, I'm not sure). I assume that there are precedents in dynamic language package managers that default to non-global installation, but don't know that. We're definitely are encouraging |
It'd be strange to use Cocoa conventions on OS X for something that isn't built with Cocoa and isn't pretending to be a native |
Yeah, on OSX, |
I've just discovered this PR; on Linux I like the old behaviour better (being able to wipe or backup a single directory) so hopefully it all ends up on an opt-in/opt-out basis. A use case on an SD based ARM system - operate entirely in ramdisk after decompressing a cargo tarball ( |
@petevine It's opt-out, you can use the environment variable |
@alexcrichton What's the status of this pull request? It seems that there's quite some controversy on changing the Linux behavior. Could we land the Windows version? The situation there is worse than the Linux one: We use the standards from a different platform (dot directories, |
@tbu- Of course you can name a file with a leading period, you just have to trick explorer into doing it by naming it |
@retep998 Oh, nice trick. I did not know that one when I tried to create .gitignores. :) |
Some people in this thread have wondered whether Cargo would be the first package-manager to follow the XDG spec for per-user installation, and whether that would cause user confusion. For what it's worth, Python has looked for installed libraries in As for |
You expect people to be using Cargo, a program that exists to download source code and drive a compiler, on embedded controllers? |
@notriddle The standard uses a hardcoded directory |
I'm on OS X. How is this an improvement? I don't really care where my cache files end up, but what's the justification for moving my config files out of |
I don't understand why people are concerned about cargo working on embedded Linux anyway. You need to be able to run the resulting binaries, but this won't affect them. |
@frewsxcv These paths would still be inside your home directory (note the |
I meant directly in the home directory, not a subdirectory. |
Things are never installed directly in the home directory. Currently they are installed in subdirectory called |
@jan-hudec Please go to rust-lang/rfcs#1615, the discussion is happening there. |
Closing in favor of the RFC for now (clearing out the queue) |
Strategy for backward-compatiblity:
When checking for the relevant Cargo directories, check in the following
order of preference:
CARGO_HOME
.The new platform-specific directories are as follows:
On Windows, use
AppData\Local\Temp\Cargo
for cache files (obtained viaGetTempPath
),AppData\Roaming\Cargo
for the config files(
FOLDERID_RoamingAppData
) andAppData\Local\Programs\Cargo
forinstalled 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 #1734. Fixes #1976.