Build example as lib and bin at the same time #5365
Labels
A-examples
Area: example targets
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
S-propose-close
Status: A team member has nominated this for closing, pending further input from the team
Hi,
I wonder if it's possible to build an example as a lib and binary at the same time. The reason for that is basically the fact that I have a windows only crate with windows only example.
Adding
#![cfg(windows)]
at the top of the source code works well for libraries, but fails to compile for binaries that need explicitmain
.One of solutions is to wrap everything in
example.rs
intomod
and guard it with proper#[cfg(windows)]
however it leads to issues with external crates used in the example since dev deps are defined for windows only too[target.'cfg(windows)'.dev-dependencies]
. So there is a lot of noise in the code if I take this approach.The other approach is split the source code on two targets (lib + binary):
So I configured the example in my
Cargo.toml
to include two crate-types, however Cargo does not seem to understand that configuration. At least what I see during compilation is an error that the compiler can't findmylib
crate.The text was updated successfully, but these errors were encountered: