Skip to content

Platform specific dependencies failing to resolve dependencies with different path #7753

@Nazariglez

Description

@Nazariglez

Problem
Adding different dependencies using the same name and different path for different platforms display this error:
Dependency 'backend' has different source paths depending on the build target. Each dependency must have a single canonical source path irrespective of build target.

The book says that this is allowed here: https://doc.rust-lang.org/1.32.0/cargo/reference/specifying-dependencies.html#platform-specific-dependencies

[target.'cfg(target_arch = "x86")'.dependencies]
native = { path = "native/i686" }

[target.'cfg(target_arch = "x86_64")'.dependencies]
native = { path = "native/x86_64" }

This is my code:

[target.'cfg(target_arch = "wasm32")'.dependencies]
backend = { path = "./web-backend", package = "web-backend"}

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
backend = { path = "./native-backend", package = "native-backend"}

[workspace]
members = [
    "web-backend",
    "native-backend"
]

I think that this should compile and use inside the code web-backend as backend for wasm32 and native-backend as backend for different targets.

Steps
I made a simple test project: https://github.com/Nazariglez/cargo-dep-bug

Possible Solution(s)
Not sure how to fix this, or what is the solution, but maybe is related to this other (closed) issue: #5345

Notes
Output of cargo version: cargo 1.40.0 (bc8e4c8 2019-11-22)
Output of rustc --version: rustc 1.40.0 (73528e339 2019-12-16)
OS: MacOS Mojave 10.14.6
Target: wasm32-unknown-unknown and default
Channel: Stable and nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-target-dependenciesArea: [target.'cfg(foo)'.dependencies]C-bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions