Conditional binaries in cargo.toml


To specify a dependency that only exists on a certain platform, you can write this in your Cargo.toml file:

winreg = "0.3"

Let’s say I have a binary that uses winreg :


How do I tell Cargo to not even attempt to build windows_only_bin on non-windows platforms?


Anyone ever manage to figure this out? I have exactly this problem now with a bin I don’t want to build on android. I tried:

[[target.'cfg(not(target_os = "android"))'.bin]]
name = "cmd_client"
path = "bin/"

But that just gave me the warning:

warning: unused manifest key: target.cfg(not(target_os = "android")).bin

Is it possible for me to conditionally build a bin?