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 run error: package(s) ... not found in workspace #13310

Closed
kzhui125 opened this issue Jan 17, 2024 · 7 comments · Fixed by #13335
Closed

cargo run error: package(s) ... not found in workspace #13310

kzhui125 opened this issue Jan 17, 2024 · 7 comments · Fixed by #13335
Assignees
Labels
C-bug Category: bug Command-run S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@kzhui125
Copy link

kzhui125 commented Jan 17, 2024

Problem

With cargo run --package time-core:10.0.0 --bin time-core in workspace folder, I get error error: package(s) ... not found in workspace.

image

workspace_0117.zip

cargo run --package time-core:10.0.0 --bin time-core 

expected: no error.

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.75.0 (1d8b05cdd 2023-11-20)
release: 1.75.0
commit-hash: 1d8b05cdd1287c64467306cf3ca2c8ac60c11eb0
commit-date: 2023-11-20
host: aarch64-apple-darwin
libgit2: 1.7.1 (sys:0.18.1 vendored)
libcurl: 8.4.0 (sys:0.4.68+curl-8.4.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1u  30 May 2023
os: Mac OS 14.2.1 [64-bit]
@kzhui125 kzhui125 added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Jan 17, 2024
@kzhui125
Copy link
Author

If cargo don't support the same name for my crate and dependency crate. The error message should change and vscode rust extension should give error.

If cargo support the same name for my crate and dependency crate. cargo run should work.

What if my crate and dependency crate have the same name and same version?

@Rustin170506
Copy link
Member

It seems to work if we don't use a package name. For example:

cargo run                           
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/time-core`
Hello world

@kzhui125
Copy link
Author

VSCode extension will use cargo run --package time-core:10.0.0 --bin time-core, and it will fail.

@epage
Copy link
Contributor

epage commented Jan 17, 2024

It looks like we are passing the spec unchanged as a package name. In my quick glance, not seeing why cargo check translates the spec into a package id but cargo run doesn't. cargo run does do somethings differently.

@epage epage added Command-run S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. and removed S-triage Status: This issue is waiting on initial triage. labels Jan 17, 2024
@Rustin170506
Copy link
Member

@rustbot claim

Let me try to fix it.

@weihanglo weihanglo added S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. labels Jan 19, 2024
@Rustin170506
Copy link
Member

After some debugging:

I think the problem is here:

  1. We store the spec as the name in this function: https://github.com/hi-rustin/cargo/blob/aa6444734d0049b3534fa1ae623c55dfbef63412/src/cargo/ops/cargo_compile/packages.rs#L201
  2. But we use it here to match only the name of the package: https://github.com/hi-rustin/cargo/blob/aa6444734d0049b3534fa1ae623c55dfbef63412/src/cargo/ops/cargo_compile/packages.rs#L128

So [email protected] does not match with foo. So it said there is no [email protected] in the workspace.

@CSEwkm
Copy link

CSEwkm commented Apr 1, 2024

Try running cargo build first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug Command-run S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants