Hi magical rustaceans,
I'm trying to write a crate that compiles differently depending on the architecture. It should compile for x86_64
and wasm32
. Depending on the architecture, it needs to include some libraries with specific features. So I tried this in my Cargo.toml
:
[target.'cfg(target_arch = "x86_64")'.dependencies]
flnet-libc = {path = "../arch/flnet-libc", optional = true}
flmodules = {path = "../shared/flmodules", version = "0.6"}
[target.'cfg(target_arch = "wasm32")'.dependencies]
flnet-wasm = {path = "../arch/flnet-wasm", optional = true}
flmodules = {path = "../shared/flmodules", version = "0.6", features = ["nosend"]}
But I never got this to compile. cargo check
fails and the error message tells me that it tried to use flnet-libc
which uses the Send
trait with the flmodules/nosend
crate. Which doesn't work.
So in the end I used the following Cargo.toml
with features:
[features]
libc = ["flnet-libc"]
wasm = ["flnet-wasm", "flmodules/nosend"]
[dependencies]
flnet-libc = {path = "../arch/flnet-libc", optional = true}
flnet-wasm = {path = "../arch/flnet-wasm", optional = true}
flmodules = {path = "../shared/flmodules", version = "0.6"}
Which works. But it would be so much nicer if it would magically work with the target.*dependencies
.
I guess that rust is not happy because there are way more archs than x86_64
and wasm32
, but I don't get it why it includes flmodules/nosend
in the first example?
And sorry for the reduced code - I tried to write a minimal failing code to post here, but didn't manage to do so
Thanks if somebody has a hint,
Linus