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

dependency error when building external dependency from github #7964

Closed
fifc opened this issue Mar 4, 2020 · 6 comments
Closed

dependency error when building external dependency from github #7964

fifc opened this issue Mar 4, 2020 · 6 comments
Labels
C-bug Category: bug

Comments

@fifc
Copy link

fifc commented Mar 4, 2020

Problem

actix-web has a patched dependency of actix-http in [path.crates-io] and it is ok to build inside actix-web source tree. but it failed when build outside of actix-web source tree as a dependency to my soure code. in such case, cargo introduced two different version of actix-http to cause an error to build.
Steps

  1. create a application and introduce dependency of actix-web,
    [dependencies]
    actix-rt = "*"
    actix-web = { git = "https://github.com/actix/actix-web" }
  2. build, an error occured
    PS C:\my-server> cargo build
    Compiling actix-web v2.0.0 (C:\git\actix-web)
    error[E0308]: mismatched types
    --> C:\git\actix-web\src\test.rs:928:9
    |
    928 | connect.await.map(|(_, framed)| framed)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct actix_http::ws::codec::Codec, found a different struct actix_http::ws::codec::Codec |
    = note: expected enum std::result::Result<actix_codec::framed::Framed<_, actix_http::ws::codec::Codec>, _>
    found enum std::result::Result<actix_codec::framed::Framed<awc::connect::BoxedSocket, actix_http::ws::codec::Codec>, _>
    = note: perhaps two different versions of crate actix_http are being used?

error: aborting due to previous error

For more information about this error, try rustc --explain E0308.
error: could not compile actix-web.

Possible Solution(s)

seems like cargo got different dependency when building a external lib outside of the source tree of the lib. it might ignored [path.crates_io].

Notes

Output of cargo version:
cargo 1.43.0-nightly (bda5051 2020-03-02)

@fifc fifc added the C-bug Category: bug label Mar 4, 2020
@alexcrichton
Copy link
Member

Thanks for the report! This is an expected error message, however, due to how Cargo works and treat sources. It sounds like what you want, however, is to override a dependency rather than add a dependency.

@fifc
Copy link
Author

fifc commented Mar 4, 2020

but override dependency simply not work. i have to override dependencies of the dependency,which is not reasonable.

@alexcrichton
Copy link
Member

Sorry I'm not entirely sure I understand what you mean. If the actix project is using [patch] then you'll need to use it youself locally to get the same behavior. Given the error message above you do need to override the dependencies of your dependencies because they all need to be the same shared type.

@fifc
Copy link
Author

fifc commented Mar 4, 2020

if i dont patch the last 3 deps, it will not build. is this expected behavior? since the last 3 deps are actix-web's internal deps and has been patched inside the cargo.toml file of actix-web, i dont think i should bother to patch them one more time.

[patch.crates-io]
actix-web = { path = "../actix-web" }
awc = { path = "../actix-web/awc" }
actix-http = { path = "../actix-web/actix-http" }
actix-web-codegen = { path = "../actix-web/actix-web-codegen" }

@ehuss
Copy link
Contributor

ehuss commented Mar 4, 2020

[patch] tables only work in the root of a workspace. They will not be picked up via a dependency. The actix-web project can avoid this by using dual-source dependencies. Wherever it has something like this:

actix-http = "2.0.0-alpha.1"

It should have:

actix-http = {version="2.0.0-alpha.1", path="../actix-http"}

This would allow the project to remove the [patch] table, and allow git dependencies to work without a patch. See https://doc.rust-lang.org/nightly/cargo/reference/specifying-dependencies.html#multiple-locations for more.

It is known that managing a large number of inter-dependent crates in a workspace can be cumbersome (see #6126 and #3931).

@fifc
Copy link
Author

fifc commented Mar 5, 2020

not sure about all the detail. but it used to work well and breaks when i did a daily update of rust. so there must be some change in cargo, since actix-web has no commit records for days then. now it seems that i have to copy part of actix-web's [path] table into my own workspace, for those deps used only by actix-web itself.

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

No branches or pull requests

3 participants