-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Platform specific dependencies failing to resolve dependencies with different path #7753
Comments
Hmm, at a minimum the documentation is wrong. I'm not sure what the feasibility is of supporting that use case. It can be tricky to ensure that different target expressions are mutually exclusive. For example, Maybe @Eh2406 can comment on the feasibility of the resolver supporting that. But I suspect overall this would be hard to support reliably. |
@Nazariglez Thanks for such a high quality report! My main question is why do the docs say that!? Did it ever work!? Git blame thinks it goes back to 4d590f9 The mutual exclusivity also needs to be global, the question is not the straightforward "does this computer have both of these flags" but the much harder "is there a computer that has both of these flags". |
We can guarantee exclusive if the (this fails)
to something along the lines of
As there seems to be no orthodox solution, I'll just continue to ugly through it. |
I think it would make sense to allow this and error only when there is a conflict for the specific target you are actually building. |
The Cargo book still gives this as a valid example: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies In the meantime we have used this simple workaround: Cargo.toml # Compile with the simulator on Windows and Unix (dev machines)
[target.'cfg(any(windows, unix))'.dependencies]
simulator = { path = "../simulator" }
# Compile with real remote bindings on other targets
[target.'cfg(not(any(windows, unix)))'.dependencies]
real = { path = "../real" } lib.rs #[cfg(not(any(windows, unix)))]
pub use real as remote;
#[cfg(any(windows, unix))]
pub use simulator as remote; Maybe this might be a good enough solution to propose in the documentation? |
I just ran into this issue as well. It should be updated to say that you have to name each crate differently and then import them conditionally. |
Remove invalid target-specific dependency example. The example with disjoint target configs does not work (and AFAIK has never worked). It fails with the error: ``` Dependency 'native' has different source paths depending on the build target. Each dependency must have a single canonical source path irrespective of build target. ``` This removes it to avoid confusion. cc #7753
hello. im trying to use a workaround with git. # linux
[target.'cfg(all(not(target_family = "wasm"), target_os = "linux"))'.dependencies]
dioxus = { version = "0.3.0", git = "https://github.com/DioxusLabs/dioxus", rev = "faf94c7b4e44edcdf2a04506122cf8ba6a1587e3" }
# android
[target.'cfg(all(not(target_family = "wasm"), target_os = "android"))'.dependencies]
dioxus = { version = "0.2.4", git = "https://github.com/DioxusLabs/dioxus", rev = "1e99e355" } doesnt seem to work Caused by:
Dependency 'dioxus' has different source paths depending
on the build target. Each dependency must have a single
canonical source path irrespective of build target. why this example doesnt work? its not a different source path, its the same repository but a different state of the source code. and so im using a different state of the source code depending on the how can i fix this? thanks. |
this is a good solution. i've tried this. but this solution i've experienced this with the and doesnt work because i was importing dioxus as so there was no |
As far as I can tell, the documentation side to this is resolved. |
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
This is my code:
I think that this should compile and use inside the code
web-backend
asbackend
for wasm32 andnative-backend
asbackend
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
The text was updated successfully, but these errors were encountered: