1

I need to use a crate which is hosted in my company's GitHub repo. There are two versions of this same crate for different OSes, namely vxworks and linux. In my application I have added this crate in the Cargo.toml like below depending on the target_os:

[target.'cfg(target_os = "vxworks")'.dependencies]
dep1= { git = "https://repo_url", branch = "vxworks", default-features = false }
[target.'cfg(not(target_os = "vxworks"))'.dependencies]
dep1= { git = "https://repo_url", branch = "linux", default-features = false }

When I compile I'm getting the below error:

Dependency 'dep1' has different source paths depending on the build target. Each dependency must have a single canonical source path irrespective of build target.

jonrsharpe
124k32 gold badges290 silver badges493 bronze badges
asked Jun 29 at 9:27
11
  • Use different names for both dependencies: dep1_vxworks and dep1_linux, then have a dep1 module that imports one or the other depending on the target, and re-exports it for the rest of your code. Commented Jun 29 at 9:44
  • See: stackoverflow.com/a/79200237/5397009 Commented Jun 29 at 9:48
  • @Jmb can you elaborate the issue? I was of the assumption that cargo will conditionally download and compile the platform specified crate but looks like that's not the case. Does it download both of them? Commented Jun 29 at 9:53
  • @Harry it will conditionally download and compile. But this doesn't mean that two different dependencies can have the same name, they can't. Even when their conditions do not overlap. Commented 2 days ago
  • 1
    The problem isn't about checking if your specific configuration conflicts. The problem is checking if there exists a possible configuration that conflicts. Commented yesterday

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.