#build #compilation #cfg #build-rs


Build helper for defining feature groups

2 releases

✓ Uses Rust 2018 edition

0.1.1 Apr 6, 2019
0.1.0 Apr 6, 2019

#72 in Build Utils

26 downloads per month

MIT license

75 lines


define feature groups to improve conditional compilation management

Build Status crates.io

This library allows one to define feature group, that may only take one value out of set. Feature groups defined in Cargo.toml as metadata:

log = ["dummy", "semihosting", "itm"]

Where "dummy", "semihosting", "itm" are features defined separately. Once feature groups are defined, they can be checked during build time and turned into cfg attributes:

cfg_feature_groups = "..."
use cfg_feature_groups::setup_feature_groups;
fn main() {

Then in your program you may use something like this:

#[cfg(log = "itm")]
fn define_itm() {}

setup_feature_groups will ensure that one and only one option is defined for each feature group.

See full example.


API Docs available on docs.rs.


See also

if_cfg crates provides alternative way to tackle conditional compilation.


~12K SLoC