#cfg #compilation #build #build-rs

build cfg_feature_groups

Build helper for defining feature groups

2 releases

0.1.1 Apr 6, 2019
0.1.0 Apr 6, 2019

#586 in Build Utils

Download history 22/week @ 2024-03-29 9/week @ 2024-04-05

60 downloads per month

MIT license

6KB
75 lines

cfg_feature_groups

define feature groups to improve conditional compilation management

Build Status

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:

[package.metadata.feature_groups]
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:

[build-dependencies]
cfg_feature_groups = "..."
use cfg_feature_groups::setup_feature_groups;
fn main() {
    setup_feature_groups();
}

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.

Documentation

API Docs available on docs.rs.

License

See also

if_cfg crates provides alternative way to tackle conditional compilation.

Dependencies

~235–480KB
~11K SLoC