I'm getting some strange behaviour trying to create setup different dependencies depending on the cargo build --target
while cross compiling.
I'm on Linux and trying to both build for Linux which works fine if I omit --target
and cross-compile for Windows by including --target=x86_64-pc-windows-gnu
.
To some up I've been trying to set up a pair of either or dependencies along the lines of (as described in this post):
[dependencies]
# snip
termion = { version = "1.5", optional = true }
crossterm = { version = "0.17", optional = true }
[target.'cfg(not(windows))'.dependencies]
tui = { version = "0.10.0", features = ["termion", "crossterm"], default-features = false }
[target.'cfg(windows)'.dependencies]
tui = { version = "0.10.0", features = ["crossterm"], default-features = false }
Having failed to get that and several variations on that working I'm obviously not understanding how this works because using the following
[target.'cfg(target_os = "blimey")'.dependencies]
termion = { version = "1.5", optional = true }
tui = { version = "0.10.0", features = ["termion", "crossterm"], default-features = false }
[target.'cfg(target_os = "linux")'.dependencies]
tui = { version = "0.10.0", features = ["crossterm"], default-features = false }
The first set of dependencies for my new OS 'blimey' is used regardless of whether I provide --target=x86_64-pc-windows-gnu
or not.
But if I remove the first target dependencies and just have this:
[target.'cfg(target_os = "linux")'.dependencies]
tui = { version = "0.10.0", features = ["crossterm"], default-features = false }
tui is only available if I omit --target=x86_64-pc-windows-gnu
.
And if change to just this rule:
[target.'cfg(target_os = "windows")'.dependencies]
tui = { version = "0.10.0", features = ["crossterm"], default-features = false }
tui is only available when I use --target=x86_64-pc-windows-gnu
.
And if I only have the 'blimey' dependencies tui is never available and I can't build with or without --target
.
So if I have just one target dependency, I can select it or not with --target
, but if I have two, even if the first one is for an OS called 'blimey', then that set of dependencies are active. But if I only have one set, for an invalid OS 'blimey' then that can't be selected (as expected).
Any ideas what's going on here?! I can't figure out the logic or what I might be doing wrong.