-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Allow setting cargo home from .cargo/home #9154
Conversation
This patch allows users to set the Cargo home directory through the file system using a pointer file in `.cargo/home`. As with `.cargo/config`, the file is searched for recursively up the tree from the current working directory. Unlike with `.cargo/config`, the search terminates when a matching file is found. The search for `.cargo/home` happens before any `.cargo/config` files are read, as that may be affected by the choice of Cargo home directory. The `CARGO_HOME` environment variable is preferred over `.cargo/home`. Fixes rust-lang#6452.
r? @Eh2406 (rust-highfive has picked a reviewer for you, use r? to override) |
I'm guessing this will also have to go through the RFC process before being stabilized. Unfortunately, given that this a change to code that runs before parsing experimental flags, I'm not quite sure how to avoid it being insta-stable? |
I'm the author of a crate that uses the |
@matthiaskrgr That's a good point — this change should probably be made to |
This will have to be tested on windows. Lookin up the |
It may be that |
We talked about this in the Cargo team meeting today, and we were interested in trying to address the underlying use case, rather than jumping to solution space right away. We had a number of concerns about this kind of "double lookup" approach. I'm also curious if symlinks might help for your use case. |
Ah, sure, let me give some context. In my case, I have a separate build system that builds Rust packages using The build system sets There is a third reason too that is somewhat more minor, and that is that it's considered a feature of the build system that everything is contained inside the build directory. If we read configuration files outside of the build directory, it's harder to debug failing builds as they may fail due to "unmanaged configuration" in the user's setup. And if we write outside of the build directory, then it may no longer be sufficient to blow away the build directory to get a fresh build, or worse yet, we may end up corrupting some of the user's non-build files (though that's less of a risk with cargo). The reason why I'd like to be able to set |
A different solution for this is rust-lang/rustup#2458 (comment), which would let the build system inject a "wrapper" toolchain that sets |
Could this perhaps be altered for your use case to only change the cache directories? For example the registry directory or git checkout directory. It sounds like that would still solve the duplicate-checkouts or duplicate-caches problem that you'd like to prevent, and it wouldn't require a new feature for changing the home directory. Cargo reading configuration hierarchically up to the root of the filesystem and unconditionally in the home directory is sort of a known issue and bug at this point. I would like to get to a world where Cargo doesn't hierarchically look up for configuration really all that often and there are at least CLI flags to disable configuration detection if desired (e.g. in your build system integration use case). A downside of changing just the cache directory, however, is that this starts to get caught up in design with features like #9178 which has languished for quite a long time at this point. It seems reasonable to at least add unstable support for a feature like this for the time being though since we'll inevitably always want the ability to configure where the cache directories are located somehow. |
Yes, I think being able to just override the cache directories would also get us pretty far. If that happens though, I'm not sure what else remains in Between that and the rustup solution, I'm going to close this, since either of those will be better than the large change that this CR proposes. |
#9021 (comment). |
This patch allows users to set the Cargo home directory through the file
system using a pointer file in
.cargo/home
. As with.cargo/config
,the file is searched for recursively up the tree from the current
working directory. Unlike with
.cargo/config
, the search terminateswhen a matching file is found.
The search for
.cargo/home
happens before any.cargo/config
filesare read, as that may be affected by the choice of Cargo home directory.
The
CARGO_HOME
environment variable is preferred over.cargo/home
.Fixes #6452.