Skip to content

Cargo fails to add dependency if it is renamed, gated, and in private registry #14365

@sukhmel

Description

@sukhmel

Problem

When a dependency is renamed (e.g. http@0.2 is referred as http_0_2 to be able to add compatibility features), gated behind a feature (e.g. compat-http), and published to a private registry, this dependency does not make it into Cargo.lock, output of cargo tree, and fails to compile with a message about undeclared module, e.g.:

8 |  pub use http_0_2::{
  |         ^^^^^^^^ use of undeclared crate or module `http_0_2`

Steps

  1. Add renamed optional dependency
    http_0_2 = { package = "http", version = "0.2", optional = true }
  2. use it from another crate
    example-dependency = { registry = "kellnr", version = "0.1", features = ["compat-http"] }
  3. Run kellnr locally:
    docker run --rm -it \
        -p 8000:8000 \
        -e "KELLNR_ORIGIN__HOSTNAME=localhost" ghcr.io/kellnr/kellnr:5.0.0
  4. Publish example-dependency:
    cargo publish --registry kellnr -p example-dependency
  5. Build a dependent crate:
    cargo build -p usage-registry

Example repository: https://github.com/sukhmel/renamed-dependency-missing-for-feature

Possible Solution(s)

I think, this may be mitigated by adding a crate that reimports the crate that was supposed to be renamed (or several crates at once)

Notes

both feature gate and rename are required to produce a failure:

# feature gated, but not renamed - OK
http = { package = "http", version = "1.0", optional = true }
# feature gated and renamed - does not work
http_0_2 = { package = "http", version = "0.2", optional = true }
# renamed, but not feature gated - OK
either_1_13 = { package = "either", version = "1.13" }
# not renamed, not feature gated - OK
void = "1.0"

Possibly a bug in https://github.com/kellnr/kellnr but Cargo.toml for the package seems correct: example-dependency-0.1.1-Cargo.toml

Version

▷ cargo version --verbose
cargo 1.79.0 (ffa9cf99a 2024-06-03)
release: 1.79.0
commit-hash: ffa9cf99a594e59032757403d4c780b46dc2c43a
commit-date: 2024-06-03
host: aarch64-apple-darwin
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.8.0 (sys:0.4.72+curl-8.6.0 system ssl:OpenSSL/3.0.14)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Mac OS 14.6.0 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugS-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