Skip to content

Remove the restriction on the links attribute in Cargo.toml #1386

Open
@tomaka

Description

@tomaka

Let's say for example that:

  • Your project depends on both libraries A and B.
  • Library A depends on library foo 0.1, and library B depends on library foo 0.2
  • foo 0.1 depends on foo-sys 0.1, and foo 0.2 depends on foo-sys 0.2
  • foo-sys has a links attribute in its Cargo.toml.

This raises an error from Cargo telling you that only one library can simultaneously link to the same native library.

More generally, whenever a library that has a links attribute bumps its version in an incompatible way, and libraries start to use the new version, builds can break. This is notably what happened to the winapi crate a few weeks ago and that broke half of the ecosystem. I'm personally opening this issue following a similar problem with openssl-sys (foo being openssl, A being postgres-rs and B being tiny_http (but B could also be hyper)).

In addition to this, this means that if you randomly pick two crates from crates.io that work separately, you can't even be sure that you can use them at the same time.

A recent Cargo pull request changed the error message to suggest people to update or pin their dependencies. Forcing people to always use the latest version of a crate promotes the inverse of stability. Once you use a specific version of a library, you shouldn't be forced to update it just because another of your dependencies is incompatible with it. It also means that all the reverse dependencies of all -sys crates must be immediately updated by their maintainers.

I see two solutions:

  • Forcing crates with a links attribute to never ever bump their major version. This is obviously not practical.
  • Removing the restriction of the links attribute, so that multiple crates can link to the same native library. This is the less bad of the two.

cc @alexcrichton

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-dev-toolsRelevant to the development tools team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions