Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When building a workspace, cargo will report that multiple packages link to a native library when it should not. #8550

Closed
0xc0deface opened this issue Jul 28, 2020 · 2 comments
Labels
A-links Area: `links` native library links setting C-bug Category: bug

Comments

@0xc0deface
Copy link

Problem

Steps
See test repo here for example.
https://github.com/0xc0deface/cargo_workspace_issue

  1. Make a project with two libs, one (lib1) should depend on the other (lib2)
  2. Make lib1 link a native library. i did this by adding the the diesel crate with the sqlite feature.
  3. Make lib2 link the same native library, but only in its dev-dependencies. i did this using the sqlite crate with default-features off, then on for the dev-dependencies.

This will result in cargo build and cargo test not working due to

error: multiple packages link to native library `sqlite3`, but a native library can be linked only once

however if you build and test the libs seperately you will not get any errors suggesting there is actually no problem, and the error message is incorrect.

Possible Solution(s)

Notes

Output of cargo version: cargo 1.45.0 (744bd1fbb 2020-06-15)

@0xc0deface 0xc0deface added the C-bug Category: bug label Jul 28, 2020
@ehuss ehuss added the A-links Area: `links` native library links setting label Jul 28, 2020
@0xc0deface
Copy link
Author

0xc0deface commented Aug 3, 2020

Cargo should be able to work this out itself, however a workaround for this issue is to put this build.rs file in lib2:

fn main()
{
	pkg_config::Config::new().probe("sqlite3").unwrap();
	println!("cargo:rerun-if-changed=build.rs");
}

and to comment out these lines from Cargo.toml in lib2:

[dev-dependencies]
sqlite = { version="0.25.3", default-features = true }

@ehuss
Copy link
Contributor

ehuss commented Aug 19, 2020

Thanks for the report! In this particular case, this is a consequence of feature unification. Running with -Zfeatures=all breaks the restriction (#8088), though this is only because it is a post-resolver "links" check.

I'm consolidating links collisions in workspaces in #7880, so I am going to close in favor of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-links Area: `links` native library links setting C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants