-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Put Searching Parent Directories for Cargo.toml
Behind Logical Gate
#7871
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
Comments
Cargo.toml
Behind Logical Gate
Just curious if we could chat about this issue? I’m happy to put in a PR :) |
Just want to mention another situation where this “feature” can cause problems. When running cargo in a directory which resides on an NFS mount which is auto mounted, where e.g. /net is the automounter top level. Cargo searches parent directories until it reaches /net/Cargo.toml, which causes automounter to try to find an NFS export for this name. Depending on the config this can take quite some time before it times out. |
This also caused me problems when bringing up It is surprising to me that something in the Rust ecosystem is so vulnerable to environment side-effects when Rust the language is so very tight about that sort of thing. |
rust-lang/rfcs#3279 is also related to this |
Is there any solution for this? On our universities HPC cluster (with 4000+ users), the home directories are mounted via an automounter script in the path /cluster/home/$USER, which basically makes rust unusable:
When cargo tries to access /cluster/home/Cargo.toml, then the automounter tries to mount a home directory for the inexistent user "Cargo.toml", which causes cargo to fail creating any new project. Is there any workaround to make rust usable on systems that use an automounter? |
Could it be a workaround to create an empty Cargo.toml file in $HOME?
|
The most recent stable release (1.85.0) still has this problem that makes it unusable on our HPC cluster:
Any idea for a workaround? Help on this matter would be appreciated a lot. |
I am trying to start moving to rust for my scientific research on a university cluster, and am running in the same issue as @samfux84 above. It would be great if you could do something about this! I'd be happy to assist in any way I can. |
A very quick and dirty hack as a workaround: |
This seems like there is some place where cargo distinguishes different error codes, and if we could teach it to treat "permission denied" as equivalent to "not found" while doing the workspace root search, that would fix the problem? (Well, it could still be slow if the automounter takes a while to determine that this file cannot be mounted, but hopefully it would cache that result. And better slow than broken. ;) I dug through the codebase a bit but couldn't find where "not found" is treated specially. @epage do you think this could be an option? |
What about if it's a genuine permissions issue? The user may intend for the root to be read but some issue with permissions or some other access issue prevents it and the failure mode is to just silently ignore the error? |
The failure mode is to assume that the current crate is the workspace root, rather than being part of an outer workspace. The user may also have typo'd the root file name and then we can't find the root -- there's tons of failures we'll not be able to diagnose. And the current alternative here is to make cargo essentially impossible to use on a range of university and HPC clusters, so... that seems worse?^^ |
Right but "ignore errors" and "the status quo" hopefully aren't the only two possible options. |
"ignore more errors", we're alreading ignoring ENOENT, obviously. I have a hard time imagining other options. It turns out the reality is that EPERM can be a completely normal error code for missing files near the root of the directory tree, so we really shouldn't treat that as fatal. Obviously if the toml file the user explicitly asked to open via Arguably the automounter should return ENOENT rather than EPERM, but well, that might be hard to change... |
For existing packages that don't already define a workspace, based on https://doc.rust-lang.org/cargo/reference/workspaces.html#root-package it should be sufficient to add an otherwise empty Though fixing the problem to not require a workaround would still be good. |
So that means everyone on the cluster has to patch every Rust package they download from the web before they can build it? I don't think that can count as an acceptable work-around.^^
That seems likely to break a lot of things as it will make the entire user dir a single huge workspace. |
It's not a fix and definitely not ideal, but better than nothing in my opinion.
I currently don't have access to a computer to test. But based on https://doc.rust-lang.org/cargo/reference/workspaces.html#the-members-and-exclude-fields cargo init adds created packages automatically to the workspace by adding it to the member list, as demonstrated in #7871 (comment), so after initializing a new package that explicit entry would need to be removed and then I would expect it to work as described in the previous paragraph. |
Update: I installed rust 1.85.0 on my cluster/home/user. I will try to run it with slurm tomorrow morning with my data. That's on a different machine. |
I'd caution relying on this too much. This seems odd enough for this to be supported by design and may be in a gray area where behavior may change in the future.
The place where the logic lives is in
I also am hesitant to read too much into specific errors. The line between "we should ignore an error" and "the error is preventing loading important information" is subtle.
rust-lang/rfcs#3279 is one. We have some built-in stop-paths
I wonder if we should also have
|
At present I don't think |
See cargo/src/cargo/core/workspace.rs Lines 2053 to 2065 in c746f16
That is for |
Yeah I found that, but nowhere there does not treat NotFound different from PermissionDenied. I couldn't find an
I don't see anything in that RFC that would change behavior on EPERM, or that would stop the search when leaving the user's home dir. All I could find is that it introduces new errors when encountering a file owned by a different user.
Right, adding |
I think at this point, I'd have to debug it to understand it. We have an exists check at cargo/src/cargo/core/workspace.rs Line 2067 in c746f16
I forgot it only errored and included an option to keep going rather than error, instead of stop.
Sorry I wasn't clear. That wasn't intended as a complete solution but one that would at least cover this case and likely lead to fewer problems generally so that if/when we have a more general solution, fewer people will need it. |
Ah! That's probably it, thanks. So there's a TOCTOU issue here, if a file gets deleted between that check and when cargo tries to open the file. But that's orthogonal to this issue.
👍 |
Hi, a quick status update from our side. Our system administrator has now implemented an exception in the automounter script for Cargo.toml, such that it will return a "file not found" instead of "permission denied". Now cargo works on the cluster. |
See also rust-lang/rfcs#3279
Describe the problem you are trying to solve
In
cargo-outdated
we are seeing an issue (we build the project under/tmp
) where if there's acargo.toml
that was moved to/tmp/
cargo build will fail.Describe the solution you'd like
Either a seperate
find_root()
(link)that we can trigger fromworkspace::new()
, or a config option to stop the function from crawling upwards (link) in the directory ancestors.Notes
This was mentioned in #4992 (comment)
I understand this is necessary for cargo and it's the intended function; however, using cargo as an API there should be a way to avoid this :)
The text was updated successfully, but these errors were encountered: