Skip to content

cargo add fails when dependency is also listed in dev-dependencies #16101

@leighmcculloch

Description

@leighmcculloch

Problem

I have a place I am trying to use cargo add to modify an existing dependency that exists both in dependencies and dev-dependencies. Today with cargo add it errors whenever trying to update a dependency that lives in more than one sections of the toml.

Steps

For example, for the following toml, I experience the following errors with the following commands.

$ cat Cargo.toml
[package]
name = "soroban-fuzzing-contract"
version = "0.0.0"
edition = "2021"
publish = false
rust-version = "1.89.0"

[lib]
crate-type = ["cdylib", "rlib"]
doctest = false

[features]
testutils = []

[dependencies]
soroban-sdk = { version = "23.0.1" }

[dev-dependencies]
soroban-sdk = { version = "23.0.1", features = ["testutils"] }
arbitrary = { version = "1.1.3", features = ["derive"] }
proptest = "1.2.0"
proptest-arbitrary-interop = "0.1.0"

[profile.release]
opt-level = "z"
overflow-checks = true
debug = 0
strip = "symbols"
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true

[profile.release-with-logs]
inherits = "release"
debug-assertions = true

$ cargo add soroban-sdk --path ../../rs-soroban-sdk/soroban-sdk
      Adding soroban-sdk (local) to dependencies
             Features:
             - alloc
             - curve25519-dalek
             - docs
             - hazmat
             - testutils
error: failed to parse manifest at `/Users/leighmcculloch/Code/soroban-examples/fuzzing/Cargo.toml`

Caused by:
  Dependency 'soroban-sdk' has different source paths depending on the build target. Each dependency must have a single canonical source path irrespective of build target.

$ cargo add soroban-sdk --path ../../rs-soroban-sdk/soroban-sdk --dev
error: failed to parse manifest at `/Users/leighmcculloch/Code/soroban-examples/fuzzing/Cargo.toml`

Caused by:
  Dependency 'soroban-sdk' has different source paths depending on the build target. Each dependency must have a single canonical source path irrespective of build target.

$ git diff
diff --git i/Cargo.toml w/Cargo.toml
index af6a029..63b8572 100644
--- i/fuzzing/Cargo.toml
+++ w/fuzzing/Cargo.toml
@@ -13,7 +13,7 @@ doctest = false
 testutils = []
 
 [dependencies]
-soroban-sdk = { version = "23.0.1" }
+soroban-sdk = { version = "23.0.2", path = "../../rs-soroban-sdk/soroban-sdk" }
 
 [dev-dependencies]
 soroban-sdk = { version = "23.0.1", features = ["testutils"] }

The command errors both times, although does appear to successfully make the change at the first command. Whichever command I run first seems to succeed at making the change even if its exit code is non-zero, as if the first command is succeeding then failing some validation that is running after the change is made. The second command fails prior to doing any work.

Possible Solution(s)

I'd like to be able to run either a command once, or both commands separately, and result in all locations being updated:

diff --git i/Cargo.toml w/Cargo.toml
index af6a029..25912b8 100644
--- i/fuzzing/Cargo.toml
+++ w/fuzzing/Cargo.toml
@@ -13,10 +13,10 @@ doctest = false
 testutils = []
 
 [dependencies]
-soroban-sdk = { version = "23.0.1" }
+soroban-sdk = { version = "23.0.2", path = "../../rs-soroban-sdk/soroban-sdk" }
 
 [dev-dependencies]
-soroban-sdk = { version = "23.0.1", features = ["testutils"] }
+soroban-sdk = { version = "23.0.2", features = ["testutils"], path = "../../rs-soroban-sdk/soroban-sdk" }

Notes

No response

Version

cargo 1.90.0 (840b83a10 2025-07-30)
release: 1.90.0
commit-hash: 840b83a10fb0e039a83f4d70ad032892c287570a
commit-date: 2025-07-30
host: aarch64-apple-darwin
libgit2: 1.9.1 (sys:0.20.2 vendored)
libcurl: 8.7.1 (sys:0.4.82+curl-8.14.1 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 3.5.0 8 Apr 2025
os: Mac OS 15.6.1 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugCommand-addS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions