#cfg #build #script #macro

build_cfg

Evaluate cfg() directives in build scripts

2 releases (1 stable)

1.1.0 Jan 13, 2022
0.1.0 Sep 26, 2021

#125 in Build Utils

Download history 12/week @ 2022-03-14 30/week @ 2022-03-21 26/week @ 2022-03-28 19/week @ 2022-04-04 35/week @ 2022-04-11 41/week @ 2022-04-18 41/week @ 2022-04-25 40/week @ 2022-05-02 60/week @ 2022-05-09 111/week @ 2022-05-16 77/week @ 2022-05-23 72/week @ 2022-05-30 47/week @ 2022-06-06 63/week @ 2022-06-13 86/week @ 2022-06-20 78/week @ 2022-06-27

283 downloads per month
Used in 3 crates (2 directly)

MIT license

9KB
177 lines

../README.md


lib.rs:

crates.io

build_cfg

Test cfg directives at build time!

Currently, cfg directives do not work "correctly" in a build script. This is because the build script must be compiled for the host machine to execute. Therefore, it is always compiled to target the native environment.

This means that we can't conditionally compile stuff in our build scripts depending on the target platform we pass in with --target. This crate aims to solve this problem by collecting and evaluating cfg directives at runtime during the build script.

Example

#[macro_use]
extern crate build_cfg;

#[build_cfg_main]
fn main() {
    if build_cfg!(all(target_os = "windows", target_pointer_width = "64")) {
        println!("Building for Windows 64-bit");
    } else {
        println!("Not building for Windows 64-bit");
    }
}

Dependencies

~235–670KB
~16K SLoC