rust-lang / rust-lang/rfcs

Remove the restriction on the `links` attribute in Cargo.toml

Open
#1,386 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-dev-tools
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the Cargo pull request #2159 and the dependency scenarios described in this issue, including the links entries in the relevant Cargo.toml files. The work would need a decided design for allowing multiple versions that link the same native library, with builds no longer failing solely because incompatible dependency versions are present.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.