Skip to content

Cargo allows you to have a different name in [lib] and [package] when publishing #6827

Open
@Manishearth

Description

Problem

In Cargo, currently the crate name you use in [dependencies] marks where the crate is supposed to come from; it matches the package.name key in the dependency's Cargo.toml.

The crate name you use in extern crate foo or foo:: has to match the actual on-disk compiled artifact name. This is not the package name, but is instead the lib.name key in the dependency's Cargo.toml.

If these don't match, you can have unexpected behavior (being unable to use crates by the name you'd expect them to use) as well as nonlocal bugs where one transitive dependency can break another by choosing the same [lib]

Steps

  1. Publish two crates with different package keys but the same lib key
  2. Try to use both in a single crate
  3. Get this multiple rlib candidates error:
error[E0465]: multiple rlib candidates for `manish_test_crate_clashes` found
 --> src/main.rs:1:1
  |
1 | extern crate manish_test_crate_clashes;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: candidate #1: /home/manishearth/sand/bar/crates/manish_test/target/debug/deps/libmanish_test_crate_clashes-6647f0eb7f7797e9.rlib
 --> src/main.rs:1:1
  |
1 | extern crate manish_test_crate_clashes;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: candidate #2: /home/manishearth/sand/bar/crates/manish_test/target/debug/deps/libmanish_test_crate_clashes-a2862f19598a10de.rlib
 --> src/main.rs:1:1
  |
1 | extern crate manish_test_crate_clashes;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Possible Solution(s)

I'm not actually sure if this is a bug: Having this ability doesn't seem completely useless. And for unpublished git/path packages the lib name does matter.

It may be worth forbidding crates with a lib.name that doesn't match package.name from being published, after checking crates.io for any offenders. https://github.com/messense/rustc-test is one (and is how I discovered this bug, we've been confused about a libtest thing for a while and it seems like this crate is the culprit)

Notes

Output of cargo version: cargo 1.34.0-nightly (5c6aa46 2019-02-22)

Metadata

Assignees

No one assigned

    Labels

    A-cargo-targetsArea: selection and definition of targets (lib, bins, examples, tests, benches)A-manifestArea: Cargo.toml issuesC-bugCategory: bugS-needs-team-inputStatus: Needs input from team on whether/how to proceed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions