Add example
, bin
configurations
#14378
Labels
A-build-scripts
Area: build.rs scripts
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
Problem
I've been looking for a way to automatically enable certain features, when running examples (
cargo run --example ...
). There seem to be at least three 1 2 3 issues open on this matter, over the years - all are still open.If it was possible to use
#[cfg_attr(example, cfg(all()))]
inbuild.rs
, I could add a feature in there and be happy.Tried it:
From the error message it seems we have
cfg(doc, ...)
andcfg(test, ...)
but notexample
andbin
.Is this an oversight or due to historical pedigree? It would feel consistent for me to have (at least) all these four equally covered (perhaps adding
benchmark
as well).Proposed Solution
Have these be available reflecting the use of
--example
,--bin
(and--benchmark
) parameters of thecargo
command:Notes
There are two work-arounds for this.
Manually provide features
This is somewhat tedious and personally, I've wrapped
cargo run --example ...
with aMakefile
to keep things short. Would rather havecargo run
itself be able to do the right thing, consistently.Explicitly making targets of each
example
inCargo.toml
Have not tried this. Mainly because I'd like to treat any file in
examples/
the same; needing to mention them inCargo.toml
creates two tiers of examples.The text was updated successfully, but these errors were encountered: