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

override "current package believes it's in a workspace" #5418

Closed
durka opened this issue Apr 26, 2018 · 9 comments · Fixed by #6805
Closed

override "current package believes it's in a workspace" #5418

durka opened this issue Apr 26, 2018 · 9 comments · Fixed by #6805
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@durka
Copy link
Contributor

durka commented Apr 26, 2018

If you create a crate inside another one, sometimes you get the above quoted error when trying to build it.

As far as I can tell, there's no solution. You can never build the crate because it's not really in the workspace, yet you can't build it separately either. The only recourse is to move the whole thing to another directory.

I propose a new flag, called something like --no-workspace or --believe-nothing--reality-is-fake--just-build-here, that would ignore the surrounding workspace and build the crate as it would have done before workspaces were invented. Does this make sense?

@sfackler
Copy link
Member

It sounds like workspace.exclude? https://doc.rust-lang.org/cargo/reference/manifest.html#the-workspace-section

@durka
Copy link
Contributor Author

durka commented Apr 26, 2018

I guess that's a workaround, but modifying the outer crate (the one that's interfering with my ability to build the one I just created) is not an ideal solution. The error message is non-intuitive (the crate "believes"? based on what evidence? since when do TOML files have beliefs??) and hampers quick experimentation.

@alexcrichton alexcrichton added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Apr 26, 2018
@gnzlbg
Copy link
Contributor

gnzlbg commented Apr 27, 2018

I ran into this here, #5421 which arnavion suggested on IRC is a duplicate of this one. I worked around the issue by adding a:

[workspace]
members = []

to the crate in question.

@matklad
Copy link
Member

matklad commented Apr 27, 2018

Yeah, the current solutions to this are

  • add exclude to the parent crate

  • add

    [workspace]
    

    to the current crate (note that members = []) is not really required.

I wonder if cargo new should add an empty workspace key by default?

@gnzlbg
Copy link
Contributor

gnzlbg commented Apr 27, 2018

The error message should at least mention the current solutions, I did not know about exclude, it would have been an option for me as well.

@durka
Copy link
Contributor Author

durka commented Jan 12, 2019

This still gets me every time. Would a PR to change the behavior of cargo new as @matklad suggested be accepted?

@dwijnand
Copy link
Member

I think if it's conditional on being nested in another crate, then yes, allowing regular cargo new to remain unaffected.

bors added a commit that referenced this issue Apr 1, 2019
Add more suggestions on how to deal with excluding a package from a workspace.

Closes #5418
@bors bors closed this as completed in #6805 Apr 1, 2019
bors added a commit to rust-lang/rust-clippy that referenced this issue Jun 5, 2020
Fix cargo tests when running inside the rustlang/rust repo

It seems we hit rust-lang/cargo#5418, so I've applied the suggested solution. Also added some more info when cargo-metadata fails to execute.

(there was no open issue for this)

changelog: none
@vjgaur
Copy link

vjgaur commented Apr 6, 2022

I encountered similar error where I added flipper smart contract folder cargo contract new flipper as I was working on this tutorial Smart Contract using ink!
After adding this folder I did not add flipper as member in Cargo.toml workspace of substrate node template. If any one going through the same tutorial you will probably come across the same error. Use the below solution.
[workspace] members = [ 'node', 'pallets/template', 'runtime', 'flipper' // added flipper smart contract folder ] [profile.release] panic = 'unwind'

@brson
Copy link
Contributor

brson commented Jun 3, 2024

I hit this problem today and modifying either manifest is not an option (setting an environment variable would be). It seems the only workaround for me is to make the directory structures of the two projects disjoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants