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

Cargo confused about broken Cargo.toml in $HOME #6706

Open
vorner opened this issue Feb 28, 2019 · 4 comments
Open

Cargo confused about broken Cargo.toml in $HOME #6706

vorner opened this issue Feb 28, 2019 · 4 comments
Labels
A-manifest Area: Cargo.toml issues C-bug Category: bug S-needs-team-input Status: Needs input from team on whether/how to proceed.

Comments

@vorner
Copy link

vorner commented Feb 28, 2019

Problem

Sometimes, I just temporarily copy or move files to my $HOME (during a rebase or something). I did that with Cargo.toml today.

If I try to run cargo build in any project, it then tries to load the Cargo.toml in the $HOME too ‒ which is likely unrelated to the current project and is likely broken (because $HOME/src does not exist, so it can't decide what to compile there). That is quite confusing behaviour.

$ cargo new stuff
     Created binary (application) `stuff` package
$ cd stuff/
$ cargo build
   Compiling stuff v0.1.0 (/home/vorner/stuff)
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
$ cp Cargo.toml ~
$ cargo build
error: failed to parse manifest at `/home/vorner/Cargo.toml`

Caused by:
  no targets specified in the manifest
  either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present

Notes

Output of cargo version:

cargo 1.34.0-nightly (5c6aa46e6 2019-02-22) (but happens with stable too, so I guess it's there for a while)

@vorner vorner added the C-bug Category: bug label Feb 28, 2019
@lukaslueg
Copy link
Contributor

This is because core::workspace::find_root() first tries to figure out if the current crate is part of a workspace and then falls for the orphaned manifest in $HOME.

There is a legitimate use case for having a ws-manifest in $HOME (e.g. a container image being built) so we can't ignore this case. Maybe find_root() should be modified to identify a manifest as the root if and only if it's an actual workspace-manifest (and ignore it if it's a stray package manifest).

@vorner
Copy link
Author

vorner commented Mar 2, 2019

Maybe somehow make the errors from parsing/interpretting that one a soft error or warning? If it doesn't look like toml (or package manifest at all), then warn about its existence, but don't fail. Would that be possible?

lukaslueg added a commit to lukaslueg/cargo that referenced this issue Mar 5, 2019
Stray manifests in parent paths will otherwise be discovered greedily. Fixes rust-lang#6706
@ehuss ehuss added the A-manifest Area: Cargo.toml issues label Apr 6, 2020
@epage
Copy link
Contributor

epage commented Oct 27, 2023

My concern about a warning is that if the actual workspace had an error in it then that would be silently incorrect at worse and product a lot of unrelated errors at best.

Workaround: add a [workspace] to your manifest to prevent searching for the workspace.

rust-lang/rfcs#3279 will allow some control over finding an implied Cargo.toml or a workspace root.

I have considered the idea of allowing package.workspace = false to opt-out of workspace detection for "cargo script".

@epage
Copy link
Contributor

epage commented Oct 27, 2023

See also #6646 which is a more specialized version of this problem.

@epage epage added S-triage Status: This issue is waiting on initial triage. S-needs-team-input Status: Needs input from team on whether/how to proceed. and removed S-triage Status: This issue is waiting on initial triage. labels Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-manifest Area: Cargo.toml issues C-bug Category: bug S-needs-team-input Status: Needs input from team on whether/how to proceed.
Projects
None yet
Development

No branches or pull requests

4 participants