How to skip library examples depending on the target platform?

I have a Rust crate library that I only use on Linux, but I don’t know why it should not work on Windows; however, one example is Unix-specific, so it cannot build an AppVeyor assembly.

The reason is that there is a Unix ( Termion ) dependency used by one of the examples, so when I used the AppVeyor template , it cannot create this dev dependency.

So, I made the dependency dependent:

[target.'cfg(unix)'.dev-dependencies]
termion = "1.0"

So far so good, but of course now this example does not work on extern crate termion.

I just need not to create this example for non-Unix-like purposes. I was hoping for something like:

[[target.'cfg(unix)'.example]]
name = "foo"

will work, but I get:

warning: unused manifest key: target.cfg(unix).example
error: no example target named `foo`

- Cargo required-features, , -, Cargo, , , Rust Windows.

, , - #[cfg(unix)] , Windows, .

- , Rust/Cargo?

+4

Source: https://habr.com/ru/post/1675219/


All Articles