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 add to package within a virtual workspace behaves differently when translating package name #13702

Open
dohse opened this issue Apr 4, 2024 · 1 comment · May be fixed by #13765
Open
Labels
C-bug Category: bug Command-add S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@dohse
Copy link

dohse commented Apr 4, 2024

Problem

cargo add behaves differently when operating on a package in a virtual workspace depending whether the package name is not translated or translated (cargo shows warning: translating …).

In the first case cargo adds a reference to dependency declared in [workspace.dependencies] - which I believe is the desired result.

In the later case cargo adds the dependency and the version, but does not reference [workspace.dependencies] - I believe this is not desired.

Steps

Reproduction script when adding parking-lot:

> mkdir workspace
> cd workspace
> cat > Cargo.toml
[workspace]
resolver = "2"

[workspace.dependencies]
parking_lot = "0.12.1"
> cargo new x
     Created binary (application) `x` package
> cargo add -p x parking-lot
    Updating crates.io index
warning: translating `parking-lot` to `parking_lot`
      Adding parking_lot v0.12.1 to dependencies.
             Features:
             - arc_lock
             - deadlock_detection
             - hardware-lock-elision
             - nightly
             - owning_ref
             - send_guard
             - serde
    Updating crates.io index
> cat x/Cargo.toml
[package]
name = "x"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
parking_lot = "0.12.1"

Reproduction script when adding parking_lot:

> mkdir workspace
> cd workspace
> cat > Cargo.toml
[workspace]
resolver = "2"

[workspace.dependencies]
parking_lot = "0.12.1"
> cargo new x
     Created binary (application) `x` package
> cargo add -p x parking_lot
    Updating crates.io index
      Adding parking_lot (workspace) to dependencies.
             Features as of v0.12.1:
             - arc_lock
             - deadlock_detection
             - hardware-lock-elision
             - nightly
             - owning_ref
             - send_guard
             - serde
    Updating crates.io index
> cat x/Cargo.toml
[package]
name = "x"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
parking_lot.workspace = true

Possible Solution(s)

No response

Notes

I tested this with the latest rust release.

This might be related to this issue: #10680

Version

> cargo version --verbose
cargo 1.77.1 (e52e36006 2024-03-26)
release: 1.77.1
commit-hash: e52e360061cacbbeac79f7f1215a7a90b6f08442
commit-date: 2024-03-26
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.2 vendored)
libcurl: 8.5.0-DEV (sys:0.4.70+curl-8.5.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Ubuntu 20.04 (focal) [64-bit]
@dohse dohse added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Apr 4, 2024
@epage epage added Command-add S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-triage Status: This issue is waiting on initial triage. labels Apr 10, 2024
@epage
Copy link
Contributor

epage commented Apr 10, 2024

The root cause is the same as #10680. See that for more insight

dohse pushed a commit to dohse/cargo that referenced this issue Apr 13, 2024
dohse pushed a commit to dohse/cargo that referenced this issue Apr 17, 2024
dohse pushed a commit to dohse/cargo that referenced this issue Apr 17, 2024
dohse added a commit to dohse/cargo that referenced this issue Apr 17, 2024
dohse added a commit to dohse/cargo that referenced this issue Apr 17, 2024
@dohse dohse linked a pull request Apr 17, 2024 that will close this issue
4 tasks
dohse added a commit to dohse/cargo that referenced this issue Apr 17, 2024
dohse added a commit to dohse/cargo that referenced this issue Apr 17, 2024
dohse added a commit to dohse/cargo that referenced this issue Apr 17, 2024
dohse added a commit to dohse/cargo that referenced this issue Apr 17, 2024
dohse added a commit to dohse/cargo that referenced this issue May 1, 2024
dohse added a commit to dohse/cargo that referenced this issue May 1, 2024
dohse added a commit to dohse/cargo that referenced this issue May 1, 2024
dohse added a commit to dohse/cargo that referenced this issue May 2, 2024
dohse added a commit to dohse/cargo that referenced this issue May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug Command-add 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.

2 participants