1

According to the docs "For rustc, arbitrary-set configuration options are set using the --cfg flag." Sure enough I can enable the message using rustc --cfg foo main.rs. How do I do this in cargo?

fn main() {
    #[cfg(foo)]
    println!("FOO");
}

Note: I'd rather not use a feature as discussed in this question. Alternatively convince me why I should always use a feature flag for custom compile time options.

HiDefender
  • 2,088
  • 2
  • 14
  • 31
  • I'm not sure I understand your aversion to features. How will consumers of your crate discover its conditional compilation options? How will they specify those that they require, for downstream users of their crate? These are the problems that features resolve. If you insist on avoiding them however, presumably for a very specific compilation outside the normal use case, there's always `cargo rustc -- --cfg foo`. Or you could define a build script that emits `cargo:rustc-cfg=foo`? – eggyal Aug 22 '20 at 23:10
  • 3
    Why don't you want to use a feature? That's exactly [what they're meant for](https://doc.rust-lang.org/cargo/reference/features.html). – Coder-256 Aug 22 '20 at 23:53

0 Answers0