Hey. Apologies if this has been answered already, but I keep finding the question online, but not the answer.
Is it possible to set up Cargo rules to only build binaries or examples if the target is a specific OS or set of Operating Systems?
I tried variations of this with no luck:
name = "my-linux-util"
required-features = ["utils"]
target_os = ["linux", "android"]
No, it's not possible. Only dependencies can be platform-specific.
If you already have a Linux-only crate, then Cargo's natural solution is just not try to build it on other platforms.
If you want to be thorough, you can use
compile_error! to break compilation early on other platforms. Or wrap everything in
cfg(linux) and make it compile to nothing on other platforms.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.