-
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
Target configuration for binaries #9208
Comments
I think the usual solution here is to place the cfg_if! {
if #[cfg(target_os = "android")] {
mod impl_android;
use impl_android::*;
} else {
mod impl_default;
use impl_default::*;
}
} Or some variant of that. I'm not sure I follow the comment about using I would maybe lean more towards having some kind of requirements specification for the binary definition instead of using something like the Also, unfortunately the word |
Thanks for the help @ehuss! I've updated the issue description. I will try to create an example to show what using the I also tried searching for an existing issue but didn't find any. Do you know of anybody who might know how to find the issue or RFC? |
Hi, I was looking for a solution to that with a slightly different use case. Building a library targetting embedded devices. An example demonstrates the features using linux-embedded-hal. This example cannot build for windows or macos so I was hoping that I could "disable" the example using something along: [[example]]
name = "demo"
required-features = ["use_std"]
target = 'cfg(target_os = "linux")' Although If I ever come to add support for windows or mac, I don't necessarily need the name to be the same. |
btw there is #6179 for doing this on the package level Like my proposal there, I'd suggest we call the field |
I think this should be possible without anything in A lot of The naïve approach I think most developers would reach for in this case is to just put
There isn't a simple solution for this error. If you try to include If there were some way for a bare |
I would like to be able to specify different main files depending on the operating system. I ran into this problem in Servo where there are two main files. The main.rs file is for Android and includes the main2.rs file for the desktop using the
include
macro:Using the
include
macro is not great because it breaks my IDE. I am not able to easily jump to the code. I also suspect using macros adds a small compile time overhead.It could be solved using cfg_if crate (see my Servo cfg_if-main branch), and the code is not that nested, but it could be simpler with cargo support.
Another use case could be something like BusyBox but where certain system binaries are only needed on specific platforms. For example, something that queries Linux settings would only be compiled for Linux.
The
Cargo.toml
file shows how I would like the feature to work:It currently results in the following error message:
You can clone the example from https://github.com/MichaelMcDonnell/target-cfg-bin-example
UPDATE 1: I changed the
Cargo.toml
proposal to add atarget
key/value pair on the binary definition instead of using the target array. Thanks to @ehuss for the suggestions. It became apparent to me too when I tried to implement it. For dependencies the target has to be applied to each dependency key/value pair so it make sense it is defined for the table/array that has them. For binaries it needs to be applied to the table but not to each key/value pair, so having it as a key/value pair makes sense.UPDATE 2: I tried getting rid of the
include
macro using the cfg_if crate (see my Servo cfg_if-main branch), and the code is not that nested, but it could be simpler with cargo support. I've updated issue description with this information.See also
The text was updated successfully, but these errors were encountered: