Skip to content

cargo add doesn't work with local and directory registries #10926

Open
@jonhoo

Description

@jonhoo

Problem

cargo add is unable to add crates when told to use a registry that is a local or directory registry.

Steps

  1. cargo new --lib foo && cd foo
  2. cargo add libc
  3. cargo check
  4. mkdir .cargo
  5. cargo local-registry -s Cargo.lock local-registry > .cargo/config.toml
  6. sed '/itoa/d' Cargo.toml
  7. cargo add --registry local-registry itoa

Produces

error: no index found for registry: `local-registry`

Alternatively, if registry.default is set to local-registry in .cargo/config.toml, the same error occurs without passing --registry local-registry.

Possible Solution(s)

cargo add --registry foo bar should (assuming that bar exists in the registry foo) add

bar = { version = "...", registry = "foo" }

to Cargo.toml.

Ideally, I think if there's a source replacement of crates-io to foo, cargo add should be smart enough to realize the registry = "foo" part should not be necessary.

Notes

No response

Version

cargo 1.62.1 (a748cf5a3 2022-06-08)
release: 1.62.1
commit-hash: a748cf5a3e666bc2dcdf54f37adef8ef22196452
commit-date: 2022-06-08
host: aarch64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.80.0-DEV (sys:0.4.51+curl-7.80.0 vendored ssl:OpenSSL/1.1.1n)
os: Amazon Linux AMI 2.0.0 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugCommand-addS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions