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

Compile errors when building tests for a crate that depends on its own library #130

Closed
pikajude opened this issue Jul 14, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@pikajude
Copy link

You can check the example here: https://github.com/pikajude/cargo2nix/tree/circular-dep-demonstration/examples/4-circular-dependency

The dependency "graph" looks like lib-crate cfg(test) => util-crate => lib-crate (lib).

If you run nix-build examples/4-circular-dependency:

building
   Compiling lib-crate v0.1.0 (/build/lib-crate)
error[E0308]: mismatched types
 --> src/lib.rs:6:33
  |
6 |     assert_eq!(util_crate::show(&LibFoo), "Libfoo");
  |                                 ^^^^^^^ expected struct `lib_crate::LibFoo`, found struct `LibFoo`
  |
  = note: expected reference `&lib_crate::LibFoo`
             found reference `&LibFoo`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `lib-crate`.

cargo2nix strips out all the dependency info from Cargo.toml when it builds crates, since the tool itself is the one managing dependency resolution. However, when building a crate like this, we can't prevent Cargo from discovering that lib-crate's source code is available alongside the tests, meaning that, even though the version we intend to use is already being picked up by the rustc wrapper, Cargo then recompiles the lib before building the tests.

The error above reads strangely but just means that it can't unify lib_crate-$metadata_for_lib::LibFoo with lib_crate-$metadata_for_test::LibFoo.

@ebkalderon ebkalderon added the bug Something isn't working label Jul 15, 2020
@pikajude
Copy link
Author

Sorry, my suggested repro here is actually meaningless, because it has the same error with regular cargo builds. I'm going to close this for now and reopen once I can get a proper repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants